2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2008 the V8 project authors. All rights reserved.
|
2008-08-14 13:41:48 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
function MjsUnitAssertionError(message) {
|
|
|
|
this.message = message;
|
2017-07-12 15:28:49 +00:00
|
|
|
// Temporarily install a custom stack trace formatter and restore the
|
|
|
|
// previous value.
|
|
|
|
let prevPrepareStackTrace = Error.prepareStackTrace;
|
|
|
|
try {
|
|
|
|
Error.prepareStackTrace = MjsUnitAssertionError.prepareStackTrace;
|
|
|
|
// This allows fetching the stack trace using TryCatch::StackTrace.
|
|
|
|
this.stack = new Error("MjsUnitAssertionError").stack;
|
|
|
|
} finally {
|
|
|
|
Error.prepareStackTrace = prevPrepareStackTrace;
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 13:41:48 +00:00
|
|
|
/*
|
|
|
|
* This file is included in all mini jsunit test cases. The test
|
|
|
|
* framework expects lines that signal failed tests to start with
|
|
|
|
* the f-word and ignore all other lines.
|
|
|
|
*/
|
|
|
|
|
2011-04-14 09:05:43 +00:00
|
|
|
MjsUnitAssertionError.prototype.toString = function () {
|
2015-10-09 13:11:53 +00:00
|
|
|
return this.message + "\n\nStack: " + this.stack;
|
2011-04-14 09:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
// Expected and found values the same objects, or the same primitive
|
|
|
|
// values.
|
|
|
|
// For known primitive values, please use assertEquals.
|
|
|
|
var assertSame;
|
|
|
|
|
2018-02-16 19:39:53 +00:00
|
|
|
// Inverse of assertSame.
|
|
|
|
var assertNotSame;
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
// Expected and found values are identical primitive values or functions
|
|
|
|
// or similarly structured objects (checking internal properties
|
|
|
|
// of, e.g., Number and Date objects, the elements of arrays
|
|
|
|
// and the properties of non-Array objects).
|
|
|
|
var assertEquals;
|
|
|
|
|
2018-09-21 00:39:42 +00:00
|
|
|
// Deep equality predicate used by assertEquals.
|
|
|
|
var deepEquals;
|
|
|
|
|
2017-06-30 13:56:38 +00:00
|
|
|
// Expected and found values are not identical primitive values or functions
|
|
|
|
// or similarly structured objects (checking internal properties
|
|
|
|
// of, e.g., Number and Date objects, the elements of arrays
|
|
|
|
// and the properties of non-Array objects).
|
|
|
|
var assertNotEquals;
|
2013-11-20 15:04:37 +00:00
|
|
|
|
|
|
|
// The difference between expected and found value is within certain tolerance.
|
|
|
|
var assertEqualsDelta;
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
// The found object is an Array with the same length and elements
|
|
|
|
// as the expected object. The expected object doesn't need to be an Array,
|
|
|
|
// as long as it's "array-ish".
|
|
|
|
var assertArrayEquals;
|
|
|
|
|
|
|
|
// The found object must have the same enumerable properties as the
|
|
|
|
// expected object. The type of object isn't checked.
|
|
|
|
var assertPropertiesEqual;
|
|
|
|
|
|
|
|
// Assert that the string conversion of the found value is equal to
|
2017-08-02 08:23:36 +00:00
|
|
|
// the expected string. Only kept for backwards compatibility, please
|
2011-04-15 11:35:36 +00:00
|
|
|
// check the real structure of the found value.
|
|
|
|
var assertToStringEquals;
|
|
|
|
|
|
|
|
// Checks that the found value is true. Use with boolean expressions
|
|
|
|
// for tests that doesn't have their own assertXXX function.
|
|
|
|
var assertTrue;
|
|
|
|
|
|
|
|
// Checks that the found value is false.
|
|
|
|
var assertFalse;
|
|
|
|
|
2012-04-16 13:20:50 +00:00
|
|
|
// Checks that the found value is null. Kept for historical compatibility,
|
2011-04-15 11:35:36 +00:00
|
|
|
// please just use assertEquals(null, expected).
|
|
|
|
var assertNull;
|
|
|
|
|
|
|
|
// Checks that the found value is *not* null.
|
|
|
|
var assertNotNull;
|
|
|
|
|
|
|
|
// Assert that the passed function or eval code throws an exception.
|
|
|
|
// The optional second argument is an exception constructor that the
|
|
|
|
// thrown exception is checked against with "instanceof".
|
2019-02-06 13:09:43 +00:00
|
|
|
// The optional third argument is a message type string or RegExp object that is
|
|
|
|
// compared to the message of the thrown exception.
|
2011-04-15 11:35:36 +00:00
|
|
|
var assertThrows;
|
|
|
|
|
2016-01-07 14:48:57 +00:00
|
|
|
// Assert that the passed function throws an exception.
|
|
|
|
// The exception is checked against the second argument using assertEquals.
|
|
|
|
var assertThrowsEquals;
|
|
|
|
|
2019-02-06 13:09:43 +00:00
|
|
|
// Assert that the passed promise does not resolve, but eventually throws an
|
|
|
|
// exception. The optional second argument is an exception constructor that the
|
|
|
|
// thrown exception is checked against with "instanceof".
|
|
|
|
// The optional third argument is a message type string or RegExp object that is
|
|
|
|
// compared to the message of the thrown exception.
|
|
|
|
var assertThrowsAsync;
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
// Assert that the passed function or eval code does not throw an exception.
|
|
|
|
var assertDoesNotThrow;
|
|
|
|
|
|
|
|
// Asserts that the found value is an instance of the constructor passed
|
|
|
|
// as the second argument.
|
|
|
|
var assertInstanceof;
|
|
|
|
|
|
|
|
// Assert that this code is never executed (i.e., always fails if executed).
|
|
|
|
var assertUnreachable;
|
|
|
|
|
2013-07-22 09:16:33 +00:00
|
|
|
// Assert that the function code is (not) optimized. If "no sync" is passed
|
2013-08-22 16:14:37 +00:00
|
|
|
// as second argument, we do not wait for the concurrent optimization thread to
|
2013-07-22 09:16:33 +00:00
|
|
|
// finish when polling for optimization status.
|
|
|
|
// Only works with --allow-natives-syntax.
|
|
|
|
var assertOptimized;
|
|
|
|
var assertUnoptimized;
|
|
|
|
|
2016-04-21 08:35:21 +00:00
|
|
|
// Assert that a string contains another expected substring.
|
|
|
|
var assertContains;
|
|
|
|
|
2016-10-12 09:17:12 +00:00
|
|
|
// Assert that a string matches a given regex.
|
|
|
|
var assertMatches;
|
|
|
|
|
2018-04-30 11:15:55 +00:00
|
|
|
// Assert that a promise resolves or rejects.
|
|
|
|
// Parameters:
|
|
|
|
// {promise} - the promise
|
|
|
|
// {success} - optional - a callback which is called with the result of the
|
|
|
|
// resolving promise.
|
|
|
|
// {fail} - optional - a callback which is called with the result of the
|
|
|
|
// rejecting promise. If the promise is rejected but no {fail}
|
|
|
|
// callback is set, the error is propagated out of the promise
|
|
|
|
// chain.
|
2017-10-25 14:12:49 +00:00
|
|
|
var assertPromiseResult;
|
2017-03-30 14:52:13 +00:00
|
|
|
|
2017-05-10 16:18:55 +00:00
|
|
|
var promiseTestChain;
|
|
|
|
var promiseTestCount = 0;
|
|
|
|
|
2017-01-27 10:13:53 +00:00
|
|
|
// These bits must be in sync with bits defined in Runtime_GetOptimizationStatus
|
|
|
|
var V8OptimizationStatus = {
|
|
|
|
kIsFunction: 1 << 0,
|
|
|
|
kNeverOptimize: 1 << 1,
|
|
|
|
kAlwaysOptimize: 1 << 2,
|
|
|
|
kMaybeDeopted: 1 << 3,
|
|
|
|
kOptimized: 1 << 4,
|
|
|
|
kTurboFanned: 1 << 5,
|
2017-07-31 12:50:32 +00:00
|
|
|
kInterpreted: 1 << 6,
|
|
|
|
kMarkedForOptimization: 1 << 7,
|
|
|
|
kMarkedForConcurrentOptimization: 1 << 8,
|
|
|
|
kOptimizingConcurrently: 1 << 9,
|
|
|
|
kIsExecuting: 1 << 10,
|
|
|
|
kTopmostFrameIsTurboFanned: 1 << 11,
|
2018-10-22 11:45:45 +00:00
|
|
|
kLiteMode: 1 << 12,
|
2019-08-22 09:39:47 +00:00
|
|
|
kMarkedForDeoptimization: 1 << 13,
|
2021-02-12 11:41:57 +00:00
|
|
|
kBaseline: 1 << 14,
|
2021-04-13 12:52:09 +00:00
|
|
|
kTopmostFrameIsInterpreted: 1 << 15,
|
|
|
|
kTopmostFrameIsBaseline: 1 << 16,
|
2017-01-27 10:13:53 +00:00
|
|
|
};
|
|
|
|
|
2018-10-22 11:45:45 +00:00
|
|
|
// Returns true if --lite-mode is on and we can't ever turn on optimization.
|
|
|
|
var isNeverOptimizeLiteMode;
|
|
|
|
|
2017-04-28 13:33:43 +00:00
|
|
|
// Returns true if --no-opt mode is on.
|
2017-01-27 10:13:53 +00:00
|
|
|
var isNeverOptimize;
|
|
|
|
|
|
|
|
// Returns true if --always-opt mode is on.
|
|
|
|
var isAlwaysOptimize;
|
|
|
|
|
|
|
|
// Returns true if given function in interpreted.
|
|
|
|
var isInterpreted;
|
|
|
|
|
2021-02-12 11:41:57 +00:00
|
|
|
// Returns true if given function in baseline.
|
|
|
|
var isBaseline;
|
2021-02-12 08:41:14 +00:00
|
|
|
|
2021-03-18 15:34:40 +00:00
|
|
|
// Returns true if given function in unoptimized (interpreted or baseline).
|
|
|
|
var isUnoptimized;
|
|
|
|
|
2017-01-27 10:13:53 +00:00
|
|
|
// Returns true if given function is optimized.
|
|
|
|
var isOptimized;
|
|
|
|
|
|
|
|
// Returns true if given function is compiled by TurboFan.
|
|
|
|
var isTurboFanned;
|
|
|
|
|
2017-03-16 18:20:19 +00:00
|
|
|
// Monkey-patchable all-purpose failure handler.
|
|
|
|
var failWithMessage;
|
|
|
|
|
2018-09-21 00:39:42 +00:00
|
|
|
// Returns the formatted failure text. Used by test-async.js.
|
|
|
|
var formatFailureText;
|
|
|
|
|
2018-02-22 03:06:23 +00:00
|
|
|
// Returns a pretty-printed string representation of the passed value.
|
|
|
|
var prettyPrinted;
|
2013-07-22 09:16:33 +00:00
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
(function () { // Scope for utility functions.
|
|
|
|
|
2015-11-19 16:11:00 +00:00
|
|
|
var ObjectPrototypeToString = Object.prototype.toString;
|
|
|
|
var NumberPrototypeValueOf = Number.prototype.valueOf;
|
|
|
|
var BooleanPrototypeValueOf = Boolean.prototype.valueOf;
|
|
|
|
var StringPrototypeValueOf = String.prototype.valueOf;
|
|
|
|
var DatePrototypeValueOf = Date.prototype.valueOf;
|
|
|
|
var RegExpPrototypeToString = RegExp.prototype.toString;
|
2017-07-17 13:50:47 +00:00
|
|
|
var ArrayPrototypeForEach = Array.prototype.forEach;
|
2015-11-19 16:11:00 +00:00
|
|
|
var ArrayPrototypeJoin = Array.prototype.join;
|
2017-07-17 13:50:47 +00:00
|
|
|
var ArrayPrototypeMap = Array.prototype.map;
|
|
|
|
var ArrayPrototypePush = Array.prototype.push;
|
2020-07-18 11:02:52 +00:00
|
|
|
var JSONStringify = JSON.stringify;
|
2015-11-19 16:11:00 +00:00
|
|
|
|
2017-10-27 05:42:08 +00:00
|
|
|
var BigIntPrototypeValueOf;
|
|
|
|
// TODO(neis): Remove try-catch once BigInts are enabled by default.
|
|
|
|
try {
|
|
|
|
BigIntPrototypeValueOf = BigInt.prototype.valueOf;
|
2019-02-04 09:02:58 +00:00
|
|
|
} catch (e) {}
|
2017-10-27 05:42:08 +00:00
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
function classOf(object) {
|
|
|
|
// Argument must not be null or undefined.
|
2015-11-19 16:11:00 +00:00
|
|
|
var string = ObjectPrototypeToString.call(object);
|
2011-04-15 11:35:36 +00:00
|
|
|
// String has format [object <ClassName>].
|
|
|
|
return string.substring(8, string.length - 1);
|
|
|
|
}
|
2011-04-14 09:05:43 +00:00
|
|
|
|
|
|
|
|
2015-11-19 16:11:00 +00:00
|
|
|
function ValueOf(value) {
|
|
|
|
switch (classOf(value)) {
|
|
|
|
case "Number":
|
|
|
|
return NumberPrototypeValueOf.call(value);
|
2017-10-27 05:42:08 +00:00
|
|
|
case "BigInt":
|
|
|
|
return BigIntPrototypeValueOf.call(value);
|
2015-11-19 16:11:00 +00:00
|
|
|
case "String":
|
|
|
|
return StringPrototypeValueOf.call(value);
|
|
|
|
case "Boolean":
|
|
|
|
return BooleanPrototypeValueOf.call(value);
|
|
|
|
case "Date":
|
|
|
|
return DatePrototypeValueOf.call(value);
|
|
|
|
default:
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-22 03:06:23 +00:00
|
|
|
prettyPrinted = function prettyPrinted(value) {
|
2011-04-15 11:35:36 +00:00
|
|
|
switch (typeof value) {
|
|
|
|
case "string":
|
2020-07-18 11:02:52 +00:00
|
|
|
return JSONStringify(value);
|
2017-10-31 18:19:14 +00:00
|
|
|
case "bigint":
|
|
|
|
return String(value) + "n";
|
2011-04-15 11:35:36 +00:00
|
|
|
case "number":
|
|
|
|
if (value === 0 && (1 / value) < 0) return "-0";
|
|
|
|
// FALLTHROUGH.
|
|
|
|
case "boolean":
|
|
|
|
case "undefined":
|
|
|
|
case "function":
|
2015-10-27 10:23:25 +00:00
|
|
|
case "symbol":
|
2011-04-15 11:35:36 +00:00
|
|
|
return String(value);
|
|
|
|
case "object":
|
|
|
|
if (value === null) return "null";
|
|
|
|
var objectClass = classOf(value);
|
|
|
|
switch (objectClass) {
|
2015-11-19 16:11:00 +00:00
|
|
|
case "Number":
|
2017-10-27 05:42:08 +00:00
|
|
|
case "BigInt":
|
2015-11-19 16:11:00 +00:00
|
|
|
case "String":
|
|
|
|
case "Boolean":
|
|
|
|
case "Date":
|
2018-02-22 03:06:23 +00:00
|
|
|
return objectClass + "(" + prettyPrinted(ValueOf(value)) + ")";
|
2015-11-19 16:11:00 +00:00
|
|
|
case "RegExp":
|
|
|
|
return RegExpPrototypeToString.call(value);
|
|
|
|
case "Array":
|
2018-02-22 03:06:23 +00:00
|
|
|
var mapped = ArrayPrototypeMap.call(
|
|
|
|
value, prettyPrintedArrayElement);
|
2015-11-19 16:11:00 +00:00
|
|
|
var joined = ArrayPrototypeJoin.call(mapped, ",");
|
|
|
|
return "[" + joined + "]";
|
2017-03-22 12:25:31 +00:00
|
|
|
case "Uint8Array":
|
|
|
|
case "Int8Array":
|
|
|
|
case "Int16Array":
|
|
|
|
case "Uint16Array":
|
|
|
|
case "Uint32Array":
|
|
|
|
case "Int32Array":
|
|
|
|
case "Float32Array":
|
|
|
|
case "Float64Array":
|
|
|
|
var joined = ArrayPrototypeJoin.call(value, ",");
|
|
|
|
return objectClass + "([" + joined + "])";
|
2015-11-19 16:11:00 +00:00
|
|
|
case "Object":
|
|
|
|
break;
|
|
|
|
default:
|
2018-06-08 13:06:56 +00:00
|
|
|
return objectClass + "(" + String(value) + ")";
|
2011-04-15 11:35:36 +00:00
|
|
|
}
|
Reland "[builtins] Clean up the use of class_name / ES5 [[Class]]"
This is a reland of 29c1eab92efc15db7fccc2d4cea994bdbb6b4812
Original change's description:
> [builtins] Clean up the use of class_name / ES5 [[Class]]
>
> Before ES2015, the ES spec had a [[Class]] internal slot for all
> objects, which Object.prototype.toString() would use to figure the
> returned string. Post-ES2015, the [[Class]] slot was removed in spec for
> all objects, with the @@toStringTag well-known symbol the proper way to
> change Object.prototype.toString() output.
>
> At the time, spec-identical handling without the use of [[Class]] was
> implemented in V8 for all objects other than API objects, where issues
> with the Web IDL spec [1] prevented Blink, and hence V8, to totally
> migrate to @@toStringTag. However, since 2016 [2] Blink has been setting
> @@toStringTag on API class prototypes to manage the
> Object.prototype.toString() output, so the legacy [[Class]] handling in
> V8 has not been necessary for the past couple of years.
>
> This CL removes the remaining legacy [[Class]] handling in
> Object.prototype.toString(), JSReceiver::class_name(), and
> GetConstructorName(). However, it does not remove the class_name field
> in FunctionTemplateInfo, as it is still used for the `name` property of
> created functions.
>
> This CL also cleans up other places in the codebase that still reference
> [[Class]].
>
> This change should have minimal impact on web-compatibility. For the
> change to be observable, a script must do one of the following:
>
> 1. delete APIConstructor.prototype[Symbol.toStringTag];
> 2. Object.setPrototypeOf(apiObject, somethingElse);
>
> Before this CL, these changes will not change the apiObject.toString()
> output. But after this CL, they will make apiObject.toString() show
> "[object Object]" (in the first case) or the @@toStringTag of the other
> prototype (in the latter case).
>
> However, both are deemed unlikely. @@toStringTag is not well-known
> feature of JavaScript, nor does it get tampered much on API
> constructors. In the second case, setting the prototype of an API object
> would effectly render the object useless, as all its methods (including
> property getters/setters) would no longer be accessible.
>
> Currently, @@toStringTag-based API object branding is not yet
> implemented by other browsers. This V8 bug in particular has been an
> impediment to standardizing toString behavior. Fixing this bug will
> unblock [3] and lead to a better Web IDL spec, and better toString()
> compatibility for all.
>
> [1]: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28244
> [2]: https://crrev.com/909c0d7d5a53c8526ded351683c65ea7d17531d4
> [3]: https://github.com/heycam/webidl/pull/357
>
> Bug: chromium:793406
> Cq-Include-Trybots: luci.chromium.try:linux-rel
> Change-Id: Iceded24e37afa2646ec385d5018909f55b177f93
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2146996
> Commit-Queue: Timothy Gu <timothygu@chromium.org>
> Reviewed-by: Toon Verwaest <verwaest@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#67327}
Bug: chromium:793406
Change-Id: Ia5d97bd4e1c44cadc6f18a17ffc9d06b038cf8f1
Cq-Include-Trybots: luci.chromium.try:linux-rel
Cq-Include-Trybots: luci.v8.try:v8_linux_blink_rel
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2163881
Auto-Submit: Timothy Gu <timothygu@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67361}
2020-04-20 18:16:57 +00:00
|
|
|
// classOf() returned "Object".
|
2011-04-15 11:35:36 +00:00
|
|
|
var name = value.constructor.name;
|
|
|
|
if (name) return name + "()";
|
|
|
|
return "Object()";
|
|
|
|
default:
|
|
|
|
return "-- unknown value --";
|
|
|
|
}
|
2011-03-25 13:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-22 03:06:23 +00:00
|
|
|
function prettyPrintedArrayElement(value, index, array) {
|
2011-04-15 11:35:36 +00:00
|
|
|
if (value === undefined && !(index in array)) return "";
|
2018-02-22 03:06:23 +00:00
|
|
|
return prettyPrinted(value);
|
2008-08-14 13:41:48 +00:00
|
|
|
}
|
2011-03-25 13:24:20 +00:00
|
|
|
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2017-03-16 18:20:19 +00:00
|
|
|
failWithMessage = function failWithMessage(message) {
|
2016-10-17 09:34:22 +00:00
|
|
|
throw new MjsUnitAssertionError(message);
|
|
|
|
}
|
|
|
|
|
2018-09-21 00:39:42 +00:00
|
|
|
formatFailureText = function(expectedText, found, name_opt) {
|
2011-04-15 11:35:36 +00:00
|
|
|
var message = "Fail" + "ure";
|
2016-10-15 06:33:47 +00:00
|
|
|
if (name_opt) {
|
|
|
|
// Fix this when we ditch the old test runner.
|
|
|
|
message += " (" + name_opt + ")";
|
2011-04-15 11:35:36 +00:00
|
|
|
}
|
2016-10-15 06:33:47 +00:00
|
|
|
|
2018-02-22 03:06:23 +00:00
|
|
|
var foundText = prettyPrinted(found);
|
2016-11-10 13:10:07 +00:00
|
|
|
if (expectedText.length <= 40 && foundText.length <= 40) {
|
|
|
|
message += ": expected <" + expectedText + "> found <" + foundText + ">";
|
|
|
|
} else {
|
|
|
|
message += ":\nexpected:\n" + expectedText + "\nfound:\n" + foundText;
|
|
|
|
}
|
2017-07-31 10:46:56 +00:00
|
|
|
return message;
|
2017-07-26 16:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fail(expectedText, found, name_opt) {
|
|
|
|
return failWithMessage(formatFailureText(expectedText, found, name_opt));
|
2011-04-14 09:05:43 +00:00
|
|
|
}
|
2009-04-24 08:13:09 +00:00
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
function deepObjectEquals(a, b) {
|
|
|
|
var aProps = Object.keys(a);
|
|
|
|
aProps.sort();
|
|
|
|
var bProps = Object.keys(b);
|
|
|
|
bProps.sort();
|
|
|
|
if (!deepEquals(aProps, bProps)) {
|
2009-01-14 11:32:23 +00:00
|
|
|
return false;
|
2011-04-15 11:35:36 +00:00
|
|
|
}
|
|
|
|
for (var i = 0; i < aProps.length; i++) {
|
|
|
|
if (!deepEquals(a[aProps[i]], b[aProps[i]])) {
|
2009-01-14 11:32:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-21 00:39:42 +00:00
|
|
|
deepEquals = function deepEquals(a, b) {
|
2011-04-15 11:35:36 +00:00
|
|
|
if (a === b) {
|
|
|
|
// Check for -0.
|
|
|
|
if (a === 0) return (1 / a) === (1 / b);
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-17 12:07:51 +00:00
|
|
|
if (typeof a !== typeof b) return false;
|
|
|
|
if (typeof a === "number") return isNaN(a) && isNaN(b);
|
2011-04-15 11:35:36 +00:00
|
|
|
if (typeof a !== "object" && typeof a !== "function") return false;
|
|
|
|
// Neither a nor b is primitive.
|
|
|
|
var objectClass = classOf(a);
|
|
|
|
if (objectClass !== classOf(b)) return false;
|
|
|
|
if (objectClass === "RegExp") {
|
|
|
|
// For RegExp, just compare pattern and flags using its toString.
|
2015-11-19 16:11:00 +00:00
|
|
|
return RegExpPrototypeToString.call(a) ===
|
|
|
|
RegExpPrototypeToString.call(b);
|
2011-04-15 11:35:36 +00:00
|
|
|
}
|
|
|
|
// Functions are only identical to themselves.
|
|
|
|
if (objectClass === "Function") return false;
|
|
|
|
if (objectClass === "Array") {
|
|
|
|
var elementCount = 0;
|
2015-02-17 12:07:51 +00:00
|
|
|
if (a.length !== b.length) {
|
2011-04-15 11:35:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
|
|
|
if (!deepEquals(a[i], b[i])) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-17 12:07:51 +00:00
|
|
|
if (objectClass === "String" || objectClass === "Number" ||
|
2017-10-27 05:42:08 +00:00
|
|
|
objectClass === "BigInt" || objectClass === "Boolean" ||
|
|
|
|
objectClass === "Date") {
|
2015-11-19 16:11:00 +00:00
|
|
|
if (ValueOf(a) !== ValueOf(b)) return false;
|
2011-04-15 11:35:36 +00:00
|
|
|
}
|
|
|
|
return deepObjectEquals(a, b);
|
2011-02-18 10:53:38 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertSame = function assertSame(expected, found, name_opt) {
|
2019-07-03 14:28:44 +00:00
|
|
|
if (Object.is(expected, found)) return;
|
2018-02-22 03:06:23 +00:00
|
|
|
fail(prettyPrinted(expected), found, name_opt);
|
2011-04-15 11:35:36 +00:00
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2018-02-16 19:39:53 +00:00
|
|
|
assertNotSame = function assertNotSame(expected, found, name_opt) {
|
2019-07-03 14:28:44 +00:00
|
|
|
if (!Object.is(expected, found)) return;
|
|
|
|
fail("not same as " + prettyPrinted(expected), found, name_opt);
|
2018-02-16 19:39:53 +00:00
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertEquals = function assertEquals(expected, found, name_opt) {
|
|
|
|
if (!deepEquals(found, expected)) {
|
2018-02-22 03:06:23 +00:00
|
|
|
fail(prettyPrinted(expected), found, name_opt);
|
2008-08-14 13:41:48 +00:00
|
|
|
}
|
2011-04-15 11:35:36 +00:00
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2017-06-30 13:56:38 +00:00
|
|
|
assertNotEquals = function assertNotEquals(expected, found, name_opt) {
|
|
|
|
if (deepEquals(found, expected)) {
|
2018-02-22 03:06:23 +00:00
|
|
|
fail("not equals to " + prettyPrinted(expected), found, name_opt);
|
2017-06-30 13:56:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2013-11-20 15:04:37 +00:00
|
|
|
assertEqualsDelta =
|
|
|
|
function assertEqualsDelta(expected, found, delta, name_opt) {
|
2017-03-20 16:14:23 +00:00
|
|
|
if (Math.abs(expected - found) > delta) {
|
2018-02-22 03:06:23 +00:00
|
|
|
fail(prettyPrinted(expected) + " +- " + prettyPrinted(delta), found, name_opt);
|
2017-03-20 16:14:23 +00:00
|
|
|
}
|
2013-11-20 15:04:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertArrayEquals = function assertArrayEquals(expected, found, name_opt) {
|
|
|
|
var start = "";
|
|
|
|
if (name_opt) {
|
|
|
|
start = name_opt + " - ";
|
|
|
|
}
|
|
|
|
assertEquals(expected.length, found.length, start + "array length");
|
2015-02-17 12:07:51 +00:00
|
|
|
if (expected.length === found.length) {
|
2011-04-15 11:35:36 +00:00
|
|
|
for (var i = 0; i < expected.length; ++i) {
|
|
|
|
assertEquals(expected[i], found[i],
|
|
|
|
start + "array element at index " + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertPropertiesEqual = function assertPropertiesEqual(expected, found,
|
|
|
|
name_opt) {
|
|
|
|
// Check properties only.
|
|
|
|
if (!deepObjectEquals(expected, found)) {
|
|
|
|
fail(expected, found, name_opt);
|
|
|
|
}
|
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertToStringEquals = function assertToStringEquals(expected, found,
|
|
|
|
name_opt) {
|
2015-02-17 12:07:51 +00:00
|
|
|
if (expected !== String(found)) {
|
2011-04-15 11:35:36 +00:00
|
|
|
fail(expected, found, name_opt);
|
|
|
|
}
|
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertTrue = function assertTrue(value, name_opt) {
|
|
|
|
assertEquals(true, value, name_opt);
|
|
|
|
};
|
2009-04-16 16:05:17 +00:00
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertFalse = function assertFalse(value, name_opt) {
|
|
|
|
assertEquals(false, value, name_opt);
|
|
|
|
};
|
2009-04-16 16:05:17 +00:00
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertNull = function assertNull(value, name_opt) {
|
|
|
|
if (value !== null) {
|
|
|
|
fail("null", value, name_opt);
|
2009-04-24 08:13:09 +00:00
|
|
|
}
|
2011-04-15 11:35:36 +00:00
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertNotNull = function assertNotNull(value, name_opt) {
|
|
|
|
if (value === null) {
|
|
|
|
fail("not null", value, name_opt);
|
|
|
|
}
|
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2019-02-04 09:02:58 +00:00
|
|
|
function executeCode(code) {
|
|
|
|
if (typeof code === 'function') return code();
|
|
|
|
if (typeof code === 'string') return eval(code);
|
|
|
|
failWithMessage(
|
|
|
|
'Given code is neither function nor string, but ' + (typeof code) +
|
|
|
|
': <' + prettyPrinted(code) + '>');
|
|
|
|
}
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2019-02-06 13:09:43 +00:00
|
|
|
function checkException(e, type_opt, cause_opt) {
|
|
|
|
if (type_opt !== undefined) {
|
|
|
|
assertEquals('function', typeof type_opt);
|
|
|
|
assertInstanceof(e, type_opt);
|
|
|
|
}
|
|
|
|
if (RegExp !== undefined && cause_opt instanceof RegExp) {
|
|
|
|
assertMatches(cause_opt, e.message, 'Error message');
|
|
|
|
} else if (cause_opt !== undefined) {
|
|
|
|
assertEquals(cause_opt, e.message, 'Error message');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertThrows = function assertThrows(code, type_opt, cause_opt) {
|
2019-04-29 17:06:02 +00:00
|
|
|
if (arguments.length > 1 && type_opt === undefined) {
|
|
|
|
failWithMessage('invalid use of assertThrows, unknown type_opt given');
|
|
|
|
}
|
2019-02-06 13:09:43 +00:00
|
|
|
if (type_opt !== undefined && typeof type_opt !== 'function') {
|
|
|
|
failWithMessage(
|
|
|
|
'invalid use of assertThrows, maybe you want assertThrowsEquals');
|
|
|
|
}
|
2011-04-15 11:35:36 +00:00
|
|
|
try {
|
2019-02-04 09:02:58 +00:00
|
|
|
executeCode(code);
|
2011-04-15 11:35:36 +00:00
|
|
|
} catch (e) {
|
2019-02-06 13:09:43 +00:00
|
|
|
checkException(e, type_opt, cause_opt);
|
2011-04-15 11:35:36 +00:00
|
|
|
return;
|
2009-08-17 09:31:58 +00:00
|
|
|
}
|
2019-02-06 13:09:43 +00:00
|
|
|
let msg = 'Did not throw exception';
|
|
|
|
if (type_opt !== undefined && type_opt.name !== undefined)
|
|
|
|
msg += ', expected ' + type_opt.name;
|
|
|
|
failWithMessage(msg);
|
2011-04-15 11:35:36 +00:00
|
|
|
};
|
2008-08-14 13:41:48 +00:00
|
|
|
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals = function assertThrowsEquals(fun, val) {
|
|
|
|
try {
|
|
|
|
fun();
|
2019-02-04 09:02:58 +00:00
|
|
|
} catch (e) {
|
2018-06-06 05:51:02 +00:00
|
|
|
assertSame(val, e);
|
2016-01-07 14:48:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-02-06 13:09:43 +00:00
|
|
|
failWithMessage('Did not throw exception, expected ' + prettyPrinted(val));
|
2016-01-07 14:48:57 +00:00
|
|
|
};
|
|
|
|
|
2019-02-06 13:09:43 +00:00
|
|
|
assertThrowsAsync = function assertThrowsAsync(promise, type_opt, cause_opt) {
|
2019-04-29 17:06:02 +00:00
|
|
|
if (arguments.length > 1 && type_opt === undefined) {
|
|
|
|
failWithMessage('invalid use of assertThrows, unknown type_opt given');
|
|
|
|
}
|
2019-02-06 13:09:43 +00:00
|
|
|
if (type_opt !== undefined && typeof type_opt !== 'function') {
|
|
|
|
failWithMessage(
|
|
|
|
'invalid use of assertThrows, maybe you want assertThrowsEquals');
|
|
|
|
}
|
|
|
|
let msg = 'Promise did not throw exception';
|
|
|
|
if (type_opt !== undefined && type_opt.name !== undefined)
|
|
|
|
msg += ', expected ' + type_opt.name;
|
|
|
|
return assertPromiseResult(
|
|
|
|
promise,
|
|
|
|
// Use setTimeout to throw the error again to get out of the promise
|
|
|
|
// chain.
|
|
|
|
res => setTimeout(_ => fail('<throw>', res, msg), 0),
|
|
|
|
e => checkException(e, type_opt, cause_opt));
|
|
|
|
};
|
2016-01-07 14:48:57 +00:00
|
|
|
|
2011-04-15 11:35:36 +00:00
|
|
|
assertInstanceof = function assertInstanceof(obj, type) {
|
|
|
|
if (!(obj instanceof type)) {
|
|
|
|
var actualTypeName = null;
|
2020-03-23 10:46:51 +00:00
|
|
|
var actualConstructor = obj && Object.getPrototypeOf(obj).constructor;
|
|
|
|
if (typeof actualConstructor === 'function') {
|
2011-04-15 11:35:36 +00:00
|
|
|
actualTypeName = actualConstructor.name || String(actualConstructor);
|
|
|
|
}
|
2020-03-23 10:46:51 +00:00
|
|
|
failWithMessage(
|
|
|
|
'Object <' + prettyPrinted(obj) + '> is not an instance of <' +
|
|
|
|
(type.name || type) + '>' +
|
|
|
|
(actualTypeName ? ' but of <' + actualTypeName + '>' : ''));
|
2011-04-15 11:35:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-04 09:02:58 +00:00
|
|
|
assertDoesNotThrow = function assertDoesNotThrow(code, name_opt) {
|
2011-04-15 11:35:36 +00:00
|
|
|
try {
|
2019-02-04 09:02:58 +00:00
|
|
|
executeCode(code);
|
2011-04-15 11:35:36 +00:00
|
|
|
} catch (e) {
|
2019-02-04 09:02:58 +00:00
|
|
|
if (e instanceof MjsUnitAssertionError) throw e;
|
2016-10-17 09:34:22 +00:00
|
|
|
failWithMessage("threw an exception: " + (e.message || e));
|
2011-04-15 11:35:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
assertUnreachable = function assertUnreachable(name_opt) {
|
|
|
|
// Fix this when we ditch the old test runner.
|
|
|
|
var message = "Fail" + "ure: unreachable";
|
|
|
|
if (name_opt) {
|
|
|
|
message += " - " + name_opt;
|
|
|
|
}
|
2016-10-17 09:34:22 +00:00
|
|
|
failWithMessage(message);
|
2011-04-15 11:35:36 +00:00
|
|
|
};
|
|
|
|
|
2016-04-21 08:35:21 +00:00
|
|
|
assertContains = function(sub, value, name_opt) {
|
|
|
|
if (value == null ? (sub != null) : value.indexOf(sub) == -1) {
|
|
|
|
fail("contains '" + String(sub) + "'", value, name_opt);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-12 09:17:12 +00:00
|
|
|
assertMatches = function(regexp, str, name_opt) {
|
|
|
|
if (!(regexp instanceof RegExp)) {
|
|
|
|
regexp = new RegExp(regexp);
|
|
|
|
}
|
|
|
|
if (!str.match(regexp)) {
|
|
|
|
fail("should match '" + regexp + "'", str, name_opt);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-30 11:15:55 +00:00
|
|
|
function concatenateErrors(stack, exception) {
|
|
|
|
// If the exception does not contain a stack trace, wrap it in a new Error.
|
|
|
|
if (!exception.stack) exception = new Error(exception);
|
2017-10-25 14:12:49 +00:00
|
|
|
|
2018-04-30 11:15:55 +00:00
|
|
|
// If the exception already provides a special stack trace, we do not modify
|
|
|
|
// it.
|
|
|
|
if (typeof exception.stack !== 'string') {
|
|
|
|
return exception;
|
2017-10-25 14:12:49 +00:00
|
|
|
}
|
2018-04-30 11:15:55 +00:00
|
|
|
exception.stack = stack + '\n\n' + exception.stack;
|
|
|
|
return exception;
|
|
|
|
}
|
2017-10-25 14:12:49 +00:00
|
|
|
|
2018-04-30 11:15:55 +00:00
|
|
|
assertPromiseResult = function(promise, success, fail) {
|
2019-02-01 13:51:23 +00:00
|
|
|
if (success !== undefined) assertEquals('function', typeof success);
|
|
|
|
if (fail !== undefined) assertEquals('function', typeof fail);
|
2019-02-06 13:09:43 +00:00
|
|
|
assertInstanceof(promise, Promise);
|
2018-04-30 11:15:55 +00:00
|
|
|
const stack = (new Error()).stack;
|
|
|
|
|
|
|
|
var test_promise = promise.then(
|
|
|
|
result => {
|
|
|
|
try {
|
|
|
|
if (--promiseTestCount == 0) testRunner.notifyDone();
|
2019-02-01 13:51:23 +00:00
|
|
|
if (success !== undefined) success(result);
|
2018-04-30 11:15:55 +00:00
|
|
|
} catch (e) {
|
|
|
|
// Use setTimeout to throw the error again to get out of the promise
|
|
|
|
// chain.
|
|
|
|
setTimeout(_ => {
|
|
|
|
throw concatenateErrors(stack, e);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
result => {
|
|
|
|
try {
|
|
|
|
if (--promiseTestCount == 0) testRunner.notifyDone();
|
2019-02-01 13:51:23 +00:00
|
|
|
if (fail === undefined) throw result;
|
2017-10-25 14:12:49 +00:00
|
|
|
fail(result);
|
2018-04-30 11:15:55 +00:00
|
|
|
} catch (e) {
|
|
|
|
// Use setTimeout to throw the error again to get out of the promise
|
|
|
|
// chain.
|
|
|
|
setTimeout(_ => {
|
|
|
|
throw concatenateErrors(stack, e);
|
|
|
|
}, 0);
|
2017-10-25 14:12:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!promiseTestChain) promiseTestChain = Promise.resolve();
|
2017-05-10 16:18:55 +00:00
|
|
|
// waitUntilDone is idempotent.
|
|
|
|
testRunner.waitUntilDone();
|
|
|
|
++promiseTestCount;
|
2017-10-25 14:12:49 +00:00
|
|
|
return promiseTestChain.then(test_promise);
|
2017-03-30 14:52:13 +00:00
|
|
|
};
|
|
|
|
|
2014-05-27 12:52:15 +00:00
|
|
|
var OptimizationStatusImpl = undefined;
|
|
|
|
|
2014-05-27 11:53:12 +00:00
|
|
|
var OptimizationStatus = function(fun, sync_opt) {
|
2014-05-27 12:52:15 +00:00
|
|
|
if (OptimizationStatusImpl === undefined) {
|
|
|
|
try {
|
|
|
|
OptimizationStatusImpl = new Function(
|
|
|
|
"fun", "sync", "return %GetOptimizationStatus(fun, sync);");
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error("natives syntax not allowed");
|
|
|
|
}
|
2013-07-22 09:16:33 +00:00
|
|
|
}
|
2014-06-25 08:01:13 +00:00
|
|
|
return OptimizationStatusImpl(fun, sync_opt);
|
2013-07-22 09:16:33 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 12:39:00 +00:00
|
|
|
assertUnoptimized = function assertUnoptimized(
|
|
|
|
fun, sync_opt, name_opt, skip_if_maybe_deopted = true) {
|
2013-07-22 09:16:33 +00:00
|
|
|
if (sync_opt === undefined) sync_opt = "";
|
2017-01-27 10:13:53 +00:00
|
|
|
var opt_status = OptimizationStatus(fun, sync_opt);
|
2017-06-08 16:23:27 +00:00
|
|
|
// Tests that use assertUnoptimized() do not make sense if --always-opt
|
2017-01-27 10:13:53 +00:00
|
|
|
// option is provided. Such tests must add --no-always-opt to flags comment.
|
|
|
|
assertFalse((opt_status & V8OptimizationStatus.kAlwaysOptimize) !== 0,
|
|
|
|
"test does not make sense with --always-opt");
|
|
|
|
assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0, name_opt);
|
2017-10-09 11:52:11 +00:00
|
|
|
if (skip_if_maybe_deopted &&
|
|
|
|
(opt_status & V8OptimizationStatus.kMaybeDeopted) !== 0) {
|
2017-01-27 11:58:47 +00:00
|
|
|
// When --deopt-every-n-times flag is specified it's no longer guaranteed
|
|
|
|
// that particular function is still deoptimized, so keep running the test
|
|
|
|
// to stress test the deoptimizer.
|
|
|
|
return;
|
|
|
|
}
|
2021-02-12 08:41:14 +00:00
|
|
|
var is_optimized = (opt_status & V8OptimizationStatus.kOptimized) !== 0;
|
2021-03-18 15:34:40 +00:00
|
|
|
assertFalse(is_optimized, name_opt);
|
2013-07-22 09:16:33 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 12:39:00 +00:00
|
|
|
assertOptimized = function assertOptimized(
|
|
|
|
fun, sync_opt, name_opt, skip_if_maybe_deopted = true) {
|
2013-07-22 09:16:33 +00:00
|
|
|
if (sync_opt === undefined) sync_opt = "";
|
2017-01-27 10:13:53 +00:00
|
|
|
var opt_status = OptimizationStatus(fun, sync_opt);
|
2018-10-22 11:45:45 +00:00
|
|
|
// Tests that use assertOptimized() do not make sense for Lite mode where
|
|
|
|
// optimization is always disabled, explicitly exit the test with a warning.
|
|
|
|
if (opt_status & V8OptimizationStatus.kLiteMode) {
|
|
|
|
print("Warning: Test uses assertOptimized in Lite mode, skipping test.");
|
2019-03-06 11:17:30 +00:00
|
|
|
testRunner.quit(0);
|
2018-10-22 11:45:45 +00:00
|
|
|
}
|
2017-04-28 13:33:43 +00:00
|
|
|
// Tests that use assertOptimized() do not make sense if --no-opt
|
|
|
|
// option is provided. Such tests must add --opt to flags comment.
|
2017-01-27 10:13:53 +00:00
|
|
|
assertFalse((opt_status & V8OptimizationStatus.kNeverOptimize) !== 0,
|
2017-04-28 13:33:43 +00:00
|
|
|
"test does not make sense with --no-opt");
|
2019-02-04 09:02:58 +00:00
|
|
|
assertTrue(
|
|
|
|
(opt_status & V8OptimizationStatus.kIsFunction) !== 0,
|
|
|
|
'should be a function: ' + name_opt);
|
2017-10-09 11:52:11 +00:00
|
|
|
if (skip_if_maybe_deopted &&
|
|
|
|
(opt_status & V8OptimizationStatus.kMaybeDeopted) !== 0) {
|
2017-01-27 10:13:53 +00:00
|
|
|
// When --deopt-every-n-times flag is specified it's no longer guaranteed
|
|
|
|
// that particular function is still optimized, so keep running the test
|
|
|
|
// to stress test the deoptimizer.
|
|
|
|
return;
|
|
|
|
}
|
2019-02-04 09:02:58 +00:00
|
|
|
assertTrue(
|
|
|
|
(opt_status & V8OptimizationStatus.kOptimized) !== 0,
|
|
|
|
'should be optimized: ' + name_opt);
|
2017-01-27 10:13:53 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 11:45:45 +00:00
|
|
|
isNeverOptimizeLiteMode = function isNeverOptimizeLiteMode() {
|
|
|
|
var opt_status = OptimizationStatus(undefined, "");
|
|
|
|
return (opt_status & V8OptimizationStatus.kLiteMode) !== 0;
|
|
|
|
}
|
|
|
|
|
2017-01-27 10:13:53 +00:00
|
|
|
isNeverOptimize = function isNeverOptimize() {
|
|
|
|
var opt_status = OptimizationStatus(undefined, "");
|
|
|
|
return (opt_status & V8OptimizationStatus.kNeverOptimize) !== 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
isAlwaysOptimize = function isAlwaysOptimize() {
|
|
|
|
var opt_status = OptimizationStatus(undefined, "");
|
|
|
|
return (opt_status & V8OptimizationStatus.kAlwaysOptimize) !== 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
isInterpreted = function isInterpreted(fun) {
|
|
|
|
var opt_status = OptimizationStatus(fun, "");
|
|
|
|
assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0,
|
|
|
|
"not a function");
|
|
|
|
return (opt_status & V8OptimizationStatus.kOptimized) === 0 &&
|
|
|
|
(opt_status & V8OptimizationStatus.kInterpreted) !== 0;
|
|
|
|
}
|
|
|
|
|
2021-02-12 11:41:57 +00:00
|
|
|
isBaseline = function isBaseline(fun) {
|
2021-02-12 08:41:14 +00:00
|
|
|
var opt_status = OptimizationStatus(fun, "");
|
|
|
|
assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0,
|
|
|
|
"not a function");
|
|
|
|
return (opt_status & V8OptimizationStatus.kOptimized) === 0 &&
|
2021-02-12 11:41:57 +00:00
|
|
|
(opt_status & V8OptimizationStatus.kBaseline) !== 0;
|
2021-02-12 08:41:14 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 15:34:40 +00:00
|
|
|
isUnoptimized = function isUnoptimized(fun) {
|
|
|
|
return isInterpreted(fun) || isBaseline(fun);
|
|
|
|
}
|
|
|
|
|
2017-01-27 10:13:53 +00:00
|
|
|
isOptimized = function isOptimized(fun) {
|
|
|
|
var opt_status = OptimizationStatus(fun, "");
|
|
|
|
assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0,
|
|
|
|
"not a function");
|
|
|
|
return (opt_status & V8OptimizationStatus.kOptimized) !== 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
isTurboFanned = function isTurboFanned(fun) {
|
|
|
|
var opt_status = OptimizationStatus(fun, "");
|
|
|
|
assertTrue((opt_status & V8OptimizationStatus.kIsFunction) !== 0,
|
|
|
|
"not a function");
|
|
|
|
return (opt_status & V8OptimizationStatus.kOptimized) !== 0 &&
|
|
|
|
(opt_status & V8OptimizationStatus.kTurboFanned) !== 0;
|
2013-07-22 09:16:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 13:50:47 +00:00
|
|
|
// Custom V8-specific stack trace formatter that is temporarily installed on
|
|
|
|
// the Error object.
|
|
|
|
MjsUnitAssertionError.prepareStackTrace = function(error, stack) {
|
|
|
|
// Trigger default formatting with recursion.
|
|
|
|
try {
|
|
|
|
// Filter-out all but the first mjsunit frame.
|
|
|
|
let filteredStack = [];
|
|
|
|
let inMjsunit = true;
|
|
|
|
for (let i = 0; i < stack.length; i++) {
|
|
|
|
let frame = stack[i];
|
|
|
|
if (inMjsunit) {
|
|
|
|
let file = frame.getFileName();
|
|
|
|
if (!file || !file.endsWith("mjsunit.js")) {
|
|
|
|
inMjsunit = false;
|
|
|
|
// Push the last mjsunit frame, typically containing the assertion
|
|
|
|
// function.
|
|
|
|
if (i > 0) ArrayPrototypePush.call(filteredStack, stack[i-1]);
|
|
|
|
ArrayPrototypePush.call(filteredStack, stack[i]);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ArrayPrototypePush.call(filteredStack, frame);
|
|
|
|
}
|
|
|
|
stack = filteredStack;
|
|
|
|
|
|
|
|
// Infer function names and calculate {max_name_length}
|
|
|
|
let max_name_length = 0;
|
|
|
|
ArrayPrototypeForEach.call(stack, each => {
|
|
|
|
let name = each.getFunctionName();
|
|
|
|
if (name == null) name = "";
|
|
|
|
if (each.isEval()) {
|
|
|
|
name = name;
|
|
|
|
} else if (each.isConstructor()) {
|
|
|
|
name = "new " + name;
|
|
|
|
} else if (each.isNative()) {
|
|
|
|
name = "native " + name;
|
|
|
|
} else if (!each.isToplevel()) {
|
|
|
|
name = each.getTypeName() + "." + name;
|
|
|
|
}
|
|
|
|
each.name = name;
|
|
|
|
max_name_length = Math.max(name.length, max_name_length)
|
|
|
|
});
|
|
|
|
|
|
|
|
// Format stack frames.
|
|
|
|
stack = ArrayPrototypeMap.call(stack, each => {
|
|
|
|
let frame = " at " + each.name.padEnd(max_name_length);
|
|
|
|
let fileName = each.getFileName();
|
|
|
|
if (each.isEval()) return frame + " " + each.getEvalOrigin();
|
|
|
|
frame += " " + (fileName ? fileName : "");
|
|
|
|
let line= each.getLineNumber();
|
|
|
|
frame += " " + (line ? line : "");
|
|
|
|
let column = each.getColumnNumber();
|
|
|
|
frame += (column ? ":" + column : "");
|
|
|
|
return frame;
|
|
|
|
});
|
|
|
|
return "" + error.message + "\n" + ArrayPrototypeJoin.call(stack, "\n");
|
2019-02-04 09:02:58 +00:00
|
|
|
} catch (e) {};
|
2017-07-17 13:50:47 +00:00
|
|
|
return error.stack;
|
|
|
|
}
|
2011-04-15 11:35:36 +00:00
|
|
|
})();
|