mirror of https://github.com/tc39/test262.git
chore: migrate $ERROR -> throw new Test262Error in harness/ & test/harness
This commit is contained in:
parent
44aac8eadd
commit
488eb365db
|
@ -15,7 +15,7 @@ function assert(mustBeTrue, message) {
|
|||
if (message === undefined) {
|
||||
message = 'Expected true but got ' + assert._toString(mustBeTrue);
|
||||
}
|
||||
$ERROR(message);
|
||||
throw new Test262Error(message);
|
||||
}
|
||||
|
||||
assert._isSameValue = function (a, b) {
|
||||
|
@ -34,7 +34,7 @@ assert.sameValue = function (actual, expected, message) {
|
|||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
$ERROR(message + ' (_isSameValue operation threw) ' + error);
|
||||
throw new Test262Error(message + ' (_isSameValue operation threw) ' + error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ assert.sameValue = function (actual, expected, message) {
|
|||
|
||||
message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(expected) + '») to be true';
|
||||
|
||||
$ERROR(message);
|
||||
throw new Test262Error(message);
|
||||
};
|
||||
|
||||
assert.notSameValue = function (actual, unexpected, message) {
|
||||
|
@ -62,12 +62,12 @@ assert.notSameValue = function (actual, unexpected, message) {
|
|||
|
||||
message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(unexpected) + '») to be false';
|
||||
|
||||
$ERROR(message);
|
||||
throw new Test262Error(message);
|
||||
};
|
||||
|
||||
assert.throws = function (expectedErrorConstructor, func, message) {
|
||||
if (typeof func !== "function") {
|
||||
$ERROR('assert.throws requires two arguments: the error constructor ' +
|
||||
throw new Test262Error('assert.throws requires two arguments: the error constructor ' +
|
||||
'and a function to run');
|
||||
return;
|
||||
}
|
||||
|
@ -82,16 +82,16 @@ assert.throws = function (expectedErrorConstructor, func, message) {
|
|||
} catch (thrown) {
|
||||
if (typeof thrown !== 'object' || thrown === null) {
|
||||
message += 'Thrown value was not an object!';
|
||||
$ERROR(message);
|
||||
throw new Test262Error(message);
|
||||
} else if (thrown.constructor !== expectedErrorConstructor) {
|
||||
message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
|
||||
$ERROR(message);
|
||||
throw new Test262Error(message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
|
||||
$ERROR(message);
|
||||
throw new Test262Error(message);
|
||||
};
|
||||
|
||||
assert._toString = function (value) {
|
||||
|
|
|
@ -17,7 +17,7 @@ function assertRelativeDateMs(date, expectedMs) {
|
|||
var localOffset = date.getTimezoneOffset() * 60000;
|
||||
|
||||
if (actualMs - localOffset !== expectedMs) {
|
||||
$ERROR(
|
||||
throw new Test262Error(
|
||||
'Expected ' + date + ' to be ' + expectedMs +
|
||||
' milliseconds from the Unix epoch'
|
||||
);
|
||||
|
|
|
@ -105,7 +105,7 @@ $262.agent.safeBroadcast = function(typedArray) {
|
|||
// want to ensure that this typedArray CAN be waited on and is shareable.
|
||||
Atomics.wait(temp, 0, Constructor === Int32Array ? 1 : BigInt(1));
|
||||
} catch (error) {
|
||||
$ERROR(`${Constructor.name} cannot be used as a shared typed array. (${error})`);
|
||||
throw new Test262Error(`${Constructor.name} cannot be used as a shared typed array. (${error})`);
|
||||
}
|
||||
|
||||
$262.agent.broadcast(typedArray.buffer);
|
||||
|
|
|
@ -215,6 +215,6 @@ const assertNativeFunction = function(fn, special) {
|
|||
try {
|
||||
validateNativeFunctionSource(actual);
|
||||
} catch (unused) {
|
||||
$ERROR('Conforms to NativeFunction Syntax: ' + JSON.stringify(actual) + (special ? ' (' + special + ')' : ''));
|
||||
throw new Test262Error('Conforms to NativeFunction Syntax: ' + JSON.stringify(actual) + (special ? ' (' + special + ')' : ''));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@ defines: [checkSequence, checkSettledPromises]
|
|||
function checkSequence(arr, message) {
|
||||
arr.forEach(function(e, i) {
|
||||
if (e !== (i+1)) {
|
||||
$ERROR((message ? message : "Steps in unexpected sequence:") +
|
||||
throw new Test262Error((message ? message : "Steps in unexpected sequence:") +
|
||||
" '" + arr.join(',') + "'");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -106,7 +106,7 @@ function isConfigurable(obj, name) {
|
|||
delete obj[name];
|
||||
} catch (e) {
|
||||
if (!(e instanceof TypeError)) {
|
||||
$ERROR("Expected TypeError, got " + e);
|
||||
throw new Test262Error("Expected TypeError, got " + e);
|
||||
}
|
||||
}
|
||||
return !hasOwnProperty.call(obj, name);
|
||||
|
@ -153,7 +153,7 @@ function isWritable(obj, name, verifyProp, value) {
|
|||
obj[name] = newValue;
|
||||
} catch (e) {
|
||||
if (!(e instanceof TypeError)) {
|
||||
$ERROR("Expected TypeError, got " + e);
|
||||
throw new Test262Error("Expected TypeError, got " + e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ function isWritable(obj, name, verifyProp, value) {
|
|||
|
||||
function verifyEqualTo(obj, name, value) {
|
||||
if (!isSameValue(obj[name], value)) {
|
||||
$ERROR("Expected obj[" + String(name) + "] to equal " + value +
|
||||
throw new Test262Error("Expected obj[" + String(name) + "] to equal " + value +
|
||||
", actually " + obj[name]);
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ function verifyWritable(obj, name, verifyProp, value) {
|
|||
"Expected obj[" + String(name) + "] to have writable:true.");
|
||||
}
|
||||
if (!isWritable(obj, name, verifyProp, value)) {
|
||||
$ERROR("Expected obj[" + String(name) + "] to be writable, but was not.");
|
||||
throw new Test262Error("Expected obj[" + String(name) + "] to be writable, but was not.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ function verifyNotWritable(obj, name, verifyProp, value) {
|
|||
"Expected obj[" + String(name) + "] to have writable:false.");
|
||||
}
|
||||
if (isWritable(obj, name, verifyProp)) {
|
||||
$ERROR("Expected obj[" + String(name) + "] NOT to be writable, but was.");
|
||||
throw new Test262Error("Expected obj[" + String(name) + "] NOT to be writable, but was.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ function verifyEnumerable(obj, name) {
|
|||
assert(Object.getOwnPropertyDescriptor(obj, name).enumerable,
|
||||
"Expected obj[" + String(name) + "] to have enumerable:true.");
|
||||
if (!isEnumerable(obj, name)) {
|
||||
$ERROR("Expected obj[" + String(name) + "] to be enumerable, but was not.");
|
||||
throw new Test262Error("Expected obj[" + String(name) + "] to be enumerable, but was not.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ function verifyNotEnumerable(obj, name) {
|
|||
assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable,
|
||||
"Expected obj[" + String(name) + "] to have enumerable:false.");
|
||||
if (isEnumerable(obj, name)) {
|
||||
$ERROR("Expected obj[" + String(name) + "] NOT to be enumerable, but was.");
|
||||
throw new Test262Error("Expected obj[" + String(name) + "] NOT to be enumerable, but was.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ function verifyConfigurable(obj, name) {
|
|||
assert(Object.getOwnPropertyDescriptor(obj, name).configurable,
|
||||
"Expected obj[" + String(name) + "] to have configurable:true.");
|
||||
if (!isConfigurable(obj, name)) {
|
||||
$ERROR("Expected obj[" + String(name) + "] to be configurable, but was not.");
|
||||
throw new Test262Error("Expected obj[" + String(name) + "] to be configurable, but was not.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,6 +228,6 @@ function verifyNotConfigurable(obj, name) {
|
|||
assert(!Object.getOwnPropertyDescriptor(obj, name).configurable,
|
||||
"Expected obj[" + String(name) + "] to have configurable:false.");
|
||||
if (isConfigurable(obj, name)) {
|
||||
$ERROR("Expected obj[" + String(name) + "] NOT to be configurable, but was.");
|
||||
throw new Test262Error("Expected obj[" + String(name) + "] NOT to be configurable, but was.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ Test262Error.prototype.toString = function () {
|
|||
Test262Error.thrower = (message) => {
|
||||
throw new Test262Error(message);
|
||||
};
|
||||
|
||||
// TODO: Remove when $ERROR migration is completed
|
||||
var $ERROR = Test262Error.thrower;
|
||||
|
||||
function $DONOTEVALUATE() {
|
||||
|
|
|
@ -69,7 +69,7 @@ function testWithIntlConstructors(f) {
|
|||
function taintDataProperty(obj, property) {
|
||||
Object.defineProperty(obj, property, {
|
||||
set: function(value) {
|
||||
$ERROR("Client code can adversely affect behavior: setter for " + property + ".");
|
||||
throw new Test262Error("Client code can adversely affect behavior: setter for " + property + ".");
|
||||
},
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
|
@ -86,7 +86,7 @@ function taintDataProperty(obj, property) {
|
|||
function taintMethod(obj, property) {
|
||||
Object.defineProperty(obj, property, {
|
||||
value: function() {
|
||||
$ERROR("Client code can adversely affect behavior: method " + property + ".");
|
||||
throw new Test262Error("Client code can adversely affect behavior: method " + property + ".");
|
||||
},
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
|
@ -1920,13 +1920,13 @@ function testOption(Constructor, property, type, values, fallback, testOptions)
|
|||
obj = new Constructor(undefined, options);
|
||||
if (noReturn) {
|
||||
if (obj.resolvedOptions().hasOwnProperty(property)) {
|
||||
$ERROR("Option property " + property + " is returned, but shouldn't be.");
|
||||
throw new Test262Error("Option property " + property + " is returned, but shouldn't be.");
|
||||
}
|
||||
} else {
|
||||
actual = obj.resolvedOptions()[property];
|
||||
if (isILD) {
|
||||
if (actual !== undefined && values.indexOf(actual) === -1) {
|
||||
$ERROR("Invalid value " + actual + " returned for property " + property + ".");
|
||||
throw new Test262Error("Invalid value " + actual + " returned for property " + property + ".");
|
||||
}
|
||||
} else {
|
||||
if (type === "boolean") {
|
||||
|
@ -1935,7 +1935,7 @@ function testOption(Constructor, property, type, values, fallback, testOptions)
|
|||
expected = String(value);
|
||||
}
|
||||
if (actual !== expected && !(isOptional && actual === undefined)) {
|
||||
$ERROR("Option value " + value + " for property " + property +
|
||||
throw new Test262Error("Option value " + value + " for property " + property +
|
||||
" was not accepted; got " + actual + " instead.");
|
||||
}
|
||||
}
|
||||
|
@ -1962,9 +1962,9 @@ function testOption(Constructor, property, type, values, fallback, testOptions)
|
|||
error = e;
|
||||
}
|
||||
if (error === undefined) {
|
||||
$ERROR("Invalid option value " + value + " for property " + property + " was not rejected.");
|
||||
throw new Test262Error("Invalid option value " + value + " for property " + property + " was not rejected.");
|
||||
} else if (error.name !== "RangeError") {
|
||||
$ERROR("Invalid option value " + value + " for property " + property + " was rejected with wrong error " + error.name + ".");
|
||||
throw new Test262Error("Invalid option value " + value + " for property " + property + " was rejected with wrong error " + error.name + ".");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1978,12 +1978,12 @@ function testOption(Constructor, property, type, values, fallback, testOptions)
|
|||
if (!(isOptional && actual === undefined)) {
|
||||
if (fallback !== undefined) {
|
||||
if (actual !== fallback) {
|
||||
$ERROR("Option fallback value " + fallback + " for property " + property +
|
||||
throw new Test262Error("Option fallback value " + fallback + " for property " + property +
|
||||
" was not used; got " + actual + " instead.");
|
||||
}
|
||||
} else {
|
||||
if (values.indexOf(actual) === -1 && !(isILD && actual === undefined)) {
|
||||
$ERROR("Invalid value " + actual + " returned for property " + property + ".");
|
||||
throw new Test262Error("Invalid value " + actual + " returned for property " + property + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2021,7 +2021,7 @@ function testForUnwantedRegExpChanges(testFunc) {
|
|||
testFunc();
|
||||
regExpProperties.forEach(function (property) {
|
||||
if (RegExp[property] !== regExpPropertiesDefaultValues[property]) {
|
||||
$ERROR("RegExp has unexpected property " + property + " with value " +
|
||||
throw new Test262Error("RegExp has unexpected property " + property + " with value " +
|
||||
RegExp[property] + ".");
|
||||
}
|
||||
});
|
||||
|
@ -2240,7 +2240,7 @@ function testNumberFormat(locales, numberingSystems, options, testData) {
|
|||
var oneoneRE = "([^" + digits + "]*)[" + digits + "]+([^" + digits + "]+)[" + digits + "]+([^" + digits + "]*)";
|
||||
var match = formatted.match(new RegExp(oneoneRE));
|
||||
if (match === null) {
|
||||
$ERROR("Unexpected formatted " + n + " for " +
|
||||
throw new Test262Error("Unexpected formatted " + n + " for " +
|
||||
format.resolvedOptions().locale + " and options " +
|
||||
JSON.stringify(options) + ": " + formatted);
|
||||
}
|
||||
|
@ -2283,7 +2283,7 @@ function testNumberFormat(locales, numberingSystems, options, testData) {
|
|||
var expected = buildExpected(rawExpected, patternParts);
|
||||
var actual = format.format(input);
|
||||
if (actual !== expected) {
|
||||
$ERROR("Formatted value for " + input + ", " +
|
||||
throw new Test262Error("Formatted value for " + input + ", " +
|
||||
format.resolvedOptions().locale + " and options " +
|
||||
JSON.stringify(options) + " is " + actual + "; expected " + expected + ".");
|
||||
}
|
||||
|
@ -2327,7 +2327,7 @@ function getDateTimeComponentValues(component) {
|
|||
|
||||
var result = components[component];
|
||||
if (result === undefined) {
|
||||
$ERROR("Internal error: No values defined for date-time component " + component + ".");
|
||||
throw new Test262Error("Internal error: No values defined for date-time component " + component + ".");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ defines: [setTimeout]
|
|||
//setTimeout is not available, hence this script was loaded
|
||||
if (Promise === undefined && this.setTimeout === undefined) {
|
||||
if(/\$DONE()/.test(code))
|
||||
$ERROR("Async test capability is not supported in your test environment");
|
||||
throw new Test262Error("Async test capability is not supported in your test environment");
|
||||
}
|
||||
|
||||
if (Promise !== undefined && this.setTimeout === undefined) {
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
The global `$ERROR` function throws an instance of the global `Test262Error`
|
||||
function with the specified message.
|
||||
---*/
|
||||
var threw = false;
|
||||
|
||||
try {
|
||||
$ERROR('This is a test message');
|
||||
} catch(err) {
|
||||
threw = true;
|
||||
if (err.constructor !== Test262Error) {
|
||||
throw new Error(
|
||||
'Expected a Test262Error, but a "' + err.constructor.name +
|
||||
'" was thrown.'
|
||||
);
|
||||
}
|
||||
if (err.message !== 'This is a test message') {
|
||||
throw new Error('The error thrown did not define the specified message.');
|
||||
}
|
||||
}
|
||||
|
||||
if (threw === false) {
|
||||
throw new Error('Expected a Test262Error, but no error was thrown.');
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
// Copyright (c) 2017 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
description: >
|
||||
Including sta.js will expose two functions:
|
||||
|
||||
Test262Error
|
||||
$ERROR
|
||||
|
||||
Assert that global $ERROR is overridable
|
||||
---*/
|
||||
function BaloneyError() {}
|
||||
|
||||
// Override $ERROR
|
||||
$ERROR = function() {
|
||||
throw new BaloneyError();
|
||||
};
|
||||
|
||||
assert.throws(BaloneyError, function() {
|
||||
$ERROR();
|
||||
});
|
|
@ -2,13 +2,14 @@
|
|||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
description: >
|
||||
Including sta.js will expose two functions:
|
||||
Including sta.js will expose three functions:
|
||||
|
||||
Test262Error
|
||||
$ERROR
|
||||
Test262Error.thrower
|
||||
$DONOTEVALUATE
|
||||
---*/
|
||||
|
||||
assert(typeof Test262Error === "function");
|
||||
assert(typeof Test262Error.prototype.toString === "function");
|
||||
assert(typeof $ERROR === "function");
|
||||
assert(typeof Test262Error.thrower === "function");
|
||||
assert(typeof $DONOTEVALUATE === "function");
|
||||
|
|
Loading…
Reference in New Issue