chore: migrate $ERROR -> throw new Test262Error in harness/ & test/harness

This commit is contained in:
rwaldron 2021-07-20 15:17:52 -04:00 committed by Rick Waldron
parent 44aac8eadd
commit 488eb365db
12 changed files with 40 additions and 89 deletions

View File

@ -15,7 +15,7 @@ function assert(mustBeTrue, message) {
if (message === undefined) { if (message === undefined) {
message = 'Expected true but got ' + assert._toString(mustBeTrue); message = 'Expected true but got ' + assert._toString(mustBeTrue);
} }
$ERROR(message); throw new Test262Error(message);
} }
assert._isSameValue = function (a, b) { assert._isSameValue = function (a, b) {
@ -34,7 +34,7 @@ assert.sameValue = function (actual, expected, message) {
return; return;
} }
} catch (error) { } catch (error) {
$ERROR(message + ' (_isSameValue operation threw) ' + error); throw new Test262Error(message + ' (_isSameValue operation threw) ' + error);
return; return;
} }
@ -46,7 +46,7 @@ assert.sameValue = function (actual, expected, message) {
message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(expected) + '») to be true'; message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(expected) + '») to be true';
$ERROR(message); throw new Test262Error(message);
}; };
assert.notSameValue = function (actual, unexpected, 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'; message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(unexpected) + '») to be false';
$ERROR(message); throw new Test262Error(message);
}; };
assert.throws = function (expectedErrorConstructor, func, message) { assert.throws = function (expectedErrorConstructor, func, message) {
if (typeof func !== "function") { 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'); 'and a function to run');
return; return;
} }
@ -82,16 +82,16 @@ assert.throws = function (expectedErrorConstructor, func, message) {
} catch (thrown) { } catch (thrown) {
if (typeof thrown !== 'object' || thrown === null) { if (typeof thrown !== 'object' || thrown === null) {
message += 'Thrown value was not an object!'; message += 'Thrown value was not an object!';
$ERROR(message); throw new Test262Error(message);
} else if (thrown.constructor !== expectedErrorConstructor) { } else if (thrown.constructor !== expectedErrorConstructor) {
message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name; message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
$ERROR(message); throw new Test262Error(message);
} }
return; return;
} }
message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all'; 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) { assert._toString = function (value) {

View File

@ -17,7 +17,7 @@ function assertRelativeDateMs(date, expectedMs) {
var localOffset = date.getTimezoneOffset() * 60000; var localOffset = date.getTimezoneOffset() * 60000;
if (actualMs - localOffset !== expectedMs) { if (actualMs - localOffset !== expectedMs) {
$ERROR( throw new Test262Error(
'Expected ' + date + ' to be ' + expectedMs + 'Expected ' + date + ' to be ' + expectedMs +
' milliseconds from the Unix epoch' ' milliseconds from the Unix epoch'
); );

View File

@ -105,7 +105,7 @@ $262.agent.safeBroadcast = function(typedArray) {
// want to ensure that this typedArray CAN be waited on and is shareable. // want to ensure that this typedArray CAN be waited on and is shareable.
Atomics.wait(temp, 0, Constructor === Int32Array ? 1 : BigInt(1)); Atomics.wait(temp, 0, Constructor === Int32Array ? 1 : BigInt(1));
} catch (error) { } 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); $262.agent.broadcast(typedArray.buffer);

View File

@ -215,6 +215,6 @@ const assertNativeFunction = function(fn, special) {
try { try {
validateNativeFunctionSource(actual); validateNativeFunctionSource(actual);
} catch (unused) { } catch (unused) {
$ERROR('Conforms to NativeFunction Syntax: ' + JSON.stringify(actual) + (special ? ' (' + special + ')' : '')); throw new Test262Error('Conforms to NativeFunction Syntax: ' + JSON.stringify(actual) + (special ? ' (' + special + ')' : ''));
} }
}; };

View File

@ -12,7 +12,7 @@ defines: [checkSequence, checkSettledPromises]
function checkSequence(arr, message) { function checkSequence(arr, message) {
arr.forEach(function(e, i) { arr.forEach(function(e, i) {
if (e !== (i+1)) { if (e !== (i+1)) {
$ERROR((message ? message : "Steps in unexpected sequence:") + throw new Test262Error((message ? message : "Steps in unexpected sequence:") +
" '" + arr.join(',') + "'"); " '" + arr.join(',') + "'");
} }
}); });

View File

@ -106,7 +106,7 @@ function isConfigurable(obj, name) {
delete obj[name]; delete obj[name];
} catch (e) { } catch (e) {
if (!(e instanceof TypeError)) { if (!(e instanceof TypeError)) {
$ERROR("Expected TypeError, got " + e); throw new Test262Error("Expected TypeError, got " + e);
} }
} }
return !hasOwnProperty.call(obj, name); return !hasOwnProperty.call(obj, name);
@ -153,7 +153,7 @@ function isWritable(obj, name, verifyProp, value) {
obj[name] = newValue; obj[name] = newValue;
} catch (e) { } catch (e) {
if (!(e instanceof TypeError)) { 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) { function verifyEqualTo(obj, name, value) {
if (!isSameValue(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]); ", actually " + obj[name]);
} }
} }
@ -186,7 +186,7 @@ function verifyWritable(obj, name, verifyProp, value) {
"Expected obj[" + String(name) + "] to have writable:true."); "Expected obj[" + String(name) + "] to have writable:true.");
} }
if (!isWritable(obj, name, verifyProp, value)) { 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."); "Expected obj[" + String(name) + "] to have writable:false.");
} }
if (isWritable(obj, name, verifyProp)) { 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, assert(Object.getOwnPropertyDescriptor(obj, name).enumerable,
"Expected obj[" + String(name) + "] to have enumerable:true."); "Expected obj[" + String(name) + "] to have enumerable:true.");
if (!isEnumerable(obj, name)) { 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, assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable,
"Expected obj[" + String(name) + "] to have enumerable:false."); "Expected obj[" + String(name) + "] to have enumerable:false.");
if (isEnumerable(obj, name)) { 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, assert(Object.getOwnPropertyDescriptor(obj, name).configurable,
"Expected obj[" + String(name) + "] to have configurable:true."); "Expected obj[" + String(name) + "] to have configurable:true.");
if (!isConfigurable(obj, name)) { 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, assert(!Object.getOwnPropertyDescriptor(obj, name).configurable,
"Expected obj[" + String(name) + "] to have configurable:false."); "Expected obj[" + String(name) + "] to have configurable:false.");
if (isConfigurable(obj, name)) { 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.");
} }
} }

View File

@ -21,7 +21,7 @@ Test262Error.prototype.toString = function () {
Test262Error.thrower = (message) => { Test262Error.thrower = (message) => {
throw new Test262Error(message); throw new Test262Error(message);
}; };
// TODO: Remove when $ERROR migration is completed
var $ERROR = Test262Error.thrower; var $ERROR = Test262Error.thrower;
function $DONOTEVALUATE() { function $DONOTEVALUATE() {

View File

@ -69,7 +69,7 @@ function testWithIntlConstructors(f) {
function taintDataProperty(obj, property) { function taintDataProperty(obj, property) {
Object.defineProperty(obj, property, { Object.defineProperty(obj, property, {
set: function(value) { 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, enumerable: false,
configurable: true configurable: true
@ -86,7 +86,7 @@ function taintDataProperty(obj, property) {
function taintMethod(obj, property) { function taintMethod(obj, property) {
Object.defineProperty(obj, property, { Object.defineProperty(obj, property, {
value: function() { value: function() {
$ERROR("Client code can adversely affect behavior: method " + property + "."); throw new Test262Error("Client code can adversely affect behavior: method " + property + ".");
}, },
writable: true, writable: true,
enumerable: false, enumerable: false,
@ -1920,13 +1920,13 @@ function testOption(Constructor, property, type, values, fallback, testOptions)
obj = new Constructor(undefined, options); obj = new Constructor(undefined, options);
if (noReturn) { if (noReturn) {
if (obj.resolvedOptions().hasOwnProperty(property)) { 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 { } else {
actual = obj.resolvedOptions()[property]; actual = obj.resolvedOptions()[property];
if (isILD) { if (isILD) {
if (actual !== undefined && values.indexOf(actual) === -1) { 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 { } else {
if (type === "boolean") { if (type === "boolean") {
@ -1935,7 +1935,7 @@ function testOption(Constructor, property, type, values, fallback, testOptions)
expected = String(value); expected = String(value);
} }
if (actual !== expected && !(isOptional && actual === undefined)) { 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."); " was not accepted; got " + actual + " instead.");
} }
} }
@ -1962,9 +1962,9 @@ function testOption(Constructor, property, type, values, fallback, testOptions)
error = e; error = e;
} }
if (error === undefined) { 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") { } 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 (!(isOptional && actual === undefined)) {
if (fallback !== undefined) { if (fallback !== undefined) {
if (actual !== fallback) { 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."); " was not used; got " + actual + " instead.");
} }
} else { } else {
if (values.indexOf(actual) === -1 && !(isILD && actual === undefined)) { 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(); testFunc();
regExpProperties.forEach(function (property) { regExpProperties.forEach(function (property) {
if (RegExp[property] !== regExpPropertiesDefaultValues[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] + "."); RegExp[property] + ".");
} }
}); });
@ -2240,7 +2240,7 @@ function testNumberFormat(locales, numberingSystems, options, testData) {
var oneoneRE = "([^" + digits + "]*)[" + digits + "]+([^" + digits + "]+)[" + digits + "]+([^" + digits + "]*)"; var oneoneRE = "([^" + digits + "]*)[" + digits + "]+([^" + digits + "]+)[" + digits + "]+([^" + digits + "]*)";
var match = formatted.match(new RegExp(oneoneRE)); var match = formatted.match(new RegExp(oneoneRE));
if (match === null) { if (match === null) {
$ERROR("Unexpected formatted " + n + " for " + throw new Test262Error("Unexpected formatted " + n + " for " +
format.resolvedOptions().locale + " and options " + format.resolvedOptions().locale + " and options " +
JSON.stringify(options) + ": " + formatted); JSON.stringify(options) + ": " + formatted);
} }
@ -2283,7 +2283,7 @@ function testNumberFormat(locales, numberingSystems, options, testData) {
var expected = buildExpected(rawExpected, patternParts); var expected = buildExpected(rawExpected, patternParts);
var actual = format.format(input); var actual = format.format(input);
if (actual !== expected) { if (actual !== expected) {
$ERROR("Formatted value for " + input + ", " + throw new Test262Error("Formatted value for " + input + ", " +
format.resolvedOptions().locale + " and options " + format.resolvedOptions().locale + " and options " +
JSON.stringify(options) + " is " + actual + "; expected " + expected + "."); JSON.stringify(options) + " is " + actual + "; expected " + expected + ".");
} }
@ -2327,7 +2327,7 @@ function getDateTimeComponentValues(component) {
var result = components[component]; var result = components[component];
if (result === undefined) { 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; return result;
} }

View File

@ -8,7 +8,7 @@ defines: [setTimeout]
//setTimeout is not available, hence this script was loaded //setTimeout is not available, hence this script was loaded
if (Promise === undefined && this.setTimeout === undefined) { if (Promise === undefined && this.setTimeout === undefined) {
if(/\$DONE()/.test(code)) 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) { if (Promise !== undefined && this.setTimeout === undefined) {

View File

@ -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.');
}

View File

@ -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();
});

View File

@ -2,13 +2,14 @@
// This code is governed by the BSD license found in the LICENSE file. // This code is governed by the BSD license found in the LICENSE file.
/*--- /*---
description: > description: >
Including sta.js will expose two functions: Including sta.js will expose three functions:
Test262Error Test262Error
$ERROR Test262Error.thrower
$DONOTEVALUATE
---*/ ---*/
assert(typeof Test262Error === "function"); assert(typeof Test262Error === "function");
assert(typeof Test262Error.prototype.toString === "function"); assert(typeof Test262Error.prototype.toString === "function");
assert(typeof $ERROR === "function"); assert(typeof Test262Error.thrower === "function");
assert(typeof $DONOTEVALUATE === "function"); assert(typeof $DONOTEVALUATE === "function");