diff --git a/harness/sm/non262-shell.js b/harness/sm/non262-shell.js index c73bb988a3..c3d352aeb5 100644 --- a/harness/sm/non262-shell.js +++ b/harness/sm/non262-shell.js @@ -5,43 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /*--- -defines: [completesNormally, raisesException, deepEqual, makeIterator, Permutations, assertThrowsValue, assertThrownErrorContains, assertThrowsInstanceOfWithMessageCheck, assertThrowsInstanceOf, assertThrowsInstanceOfWithMessage, assertThrowsInstanceOfWithMessageContains, assertDeepEq] +defines: [makeIterator, Permutations, assertThrowsValue, assertThrownErrorContains, assertThrowsInstanceOfWithMessageCheck, assertThrowsInstanceOf, assertThrowsInstanceOfWithMessage, assertThrowsInstanceOfWithMessageContains, assertDeepEq] allow_unused: True ---*/ (function() { const undefined = void 0; - /* - * completesNormally(CODE) returns true if evaluating CODE (as eval - * code) completes normally (rather than throwing an exception). - */ - globalThis.completesNormally = function completesNormally(code) { - try { - eval(code); - return true; - } catch (exception) { - return false; - } - } - - /* - * raisesException(EXCEPTION)(CODE) returns true if evaluating CODE (as - * eval code) throws an exception object that is an instance of EXCEPTION, - * and returns false if it throws any other error or evaluates - * successfully. For example: raises(TypeError)("0()") == true. - */ - globalThis.raisesException = function raisesException(exception) { - return function (code) { - try { - eval(code); - return false; - } catch (actual) { - return actual instanceof exception; - } - }; - }; - /** Make an iterator with a return method. */ globalThis.makeIterator = function makeIterator(overrides) { var throwMethod; diff --git a/harness/sm/non262-strict-shell.js b/harness/sm/non262-strict-shell.js index 198de81071..c11cd48062 100644 --- a/harness/sm/non262-strict-shell.js +++ b/harness/sm/non262-strict-shell.js @@ -5,11 +5,41 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /*--- -defines: [testLenientAndStrict, parsesSuccessfully, parseRaisesException, returns] +defines: [completesNormally, raisesException, testLenientAndStrict, parsesSuccessfully, parseRaisesException, returns] allow_unused: True ---*/ (function(global) { + /* + * completesNormally(CODE) returns true if evaluating CODE (as eval + * code) completes normally (rather than throwing an exception). + */ + globalThis.completesNormally = function completesNormally(code) { + try { + eval(code); + return true; + } catch (exception) { + return false; + } + } + + /* + * raisesException(EXCEPTION)(CODE) returns true if evaluating CODE (as + * eval code) throws an exception object that is an instance of EXCEPTION, + * and returns false if it throws any other error or evaluates + * successfully. For example: raises(TypeError)("0()") == true. + */ + globalThis.raisesException = function raisesException(exception) { + return function (code) { + try { + eval(code); + return false; + } catch (actual) { + return actual instanceof exception; + } + }; + }; + /* * Return true if both of these return true: * - LENIENT_PRED applied to CODE diff --git a/test/staging/sm/Boolean/15.6.4.2.js b/test/staging/sm/Boolean/15.6.4.2.js index ae0bada5e9..6b50f12c8f 100644 --- a/test/staging/sm/Boolean/15.6.4.2.js +++ b/test/staging/sm/Boolean/15.6.4.2.js @@ -4,21 +4,18 @@ */ /*--- -includes: [sm/non262.js, sm/non262-shell.js] -flags: - - noStrict description: | pending esid: pending ---*/ -assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(42)'), true); -assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call("")'), true); -assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call({})'), true); -assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(null)'), true); -assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call([])'), true); -assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(undefined)'), true); -assert.sameValue(raisesException(TypeError)('Boolean.prototype.toString.call(new String())'), true); -assert.sameValue(completesNormally('Boolean.prototype.toString.call(true)'), true); -assert.sameValue(completesNormally('Boolean.prototype.toString.call(new Boolean(true))'), true); +assert.throws(TypeError, function() { Boolean.prototype.toString.call(42); }); +assert.throws(TypeError, function() { Boolean.prototype.toString.call(""); }); +assert.throws(TypeError, function() { Boolean.prototype.toString.call({}); }); +assert.throws(TypeError, function() { Boolean.prototype.toString.call(null); }); +assert.throws(TypeError, function() { Boolean.prototype.toString.call([]); }); +assert.throws(TypeError, function() { Boolean.prototype.toString.call(undefined); }); +assert.throws(TypeError, function() { Boolean.prototype.toString.call(new String()); }); +assert.sameValue(Boolean.prototype.toString.call(true), "true"); +assert.sameValue(Boolean.prototype.toString.call(new Boolean(true)), "true"); diff --git a/test/staging/sm/Number/15.7.4.2.js b/test/staging/sm/Number/15.7.4.2.js index 3ad39aef88..020d69c833 100644 --- a/test/staging/sm/Number/15.7.4.2.js +++ b/test/staging/sm/Number/15.7.4.2.js @@ -4,23 +4,21 @@ */ /*--- -includes: [sm/non262.js, sm/non262-shell.js] -flags: - - noStrict description: | pending esid: pending ---*/ -assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(true)'), true); -assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call("")'), true); -assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call({})'), true); -assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(null)'), true); -assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call([])'), true); -assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(undefined)'), true); -assert.sameValue(raisesException(TypeError)('Number.prototype.toString.call(new Boolean(true))'), true); -assert.sameValue(completesNormally('Number.prototype.toString.call(42)'), true); -assert.sameValue(completesNormally('Number.prototype.toString.call(new Number(42))'), true); +assert.throws(TypeError, function() { Number.prototype.toString.call(true); }); +assert.throws(TypeError, function() { Number.prototype.toString.call(""); }); +assert.throws(TypeError, function() { Number.prototype.toString.call({}); }); +assert.throws(TypeError, function() { Number.prototype.toString.call(null); }); +assert.throws(TypeError, function() { Number.prototype.toString.call([]); }); +assert.throws(TypeError, function() { Number.prototype.toString.call(undefined); }); +assert.throws(TypeError, function() { Number.prototype.toString.call(new Boolean(true)); }); + +assert.sameValue(Number.prototype.toString.call(42), "42"); +assert.sameValue(Number.prototype.toString.call(new Number(42)), "42"); function testAround(middle) { diff --git a/test/staging/sm/String/15.5.4.2.js b/test/staging/sm/String/15.5.4.2.js index 2b4c346517..78b3d0ace9 100644 --- a/test/staging/sm/String/15.5.4.2.js +++ b/test/staging/sm/String/15.5.4.2.js @@ -4,18 +4,15 @@ */ /*--- -includes: [sm/non262.js, sm/non262-shell.js, sm/non262-String-shell.js] -flags: - - noStrict description: | pending esid: pending ---*/ -assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(42)'), true); -assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(true)'), true); -assert.sameValue(raisesException(TypeError)('String.prototype.toString.call({})'), true); -assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(null)'), true); -assert.sameValue(raisesException(TypeError)('String.prototype.toString.call([])'), true); -assert.sameValue(raisesException(TypeError)('String.prototype.toString.call(undefined)'), true); -assert.sameValue(completesNormally('String.prototype.toString.call("")'), true); +assert.throws(TypeError, function() { String.prototype.toString.call(42); }); +assert.throws(TypeError, function() { String.prototype.toString.call(true); }); +assert.throws(TypeError, function() { String.prototype.toString.call({}); }); +assert.throws(TypeError, function() { String.prototype.toString.call(null); }); +assert.throws(TypeError, function() { String.prototype.toString.call([]); }); +assert.throws(TypeError, function() { String.prototype.toString.call(undefined); }); +assert.sameValue(String.prototype.toString.call(""), ""); diff --git a/test/staging/sm/async-functions/await-in-parameters-of-async-func.js b/test/staging/sm/async-functions/await-in-parameters-of-async-func.js index 77aecc9ac6..c3b5aa7967 100644 --- a/test/staging/sm/async-functions/await-in-parameters-of-async-func.js +++ b/test/staging/sm/async-functions/await-in-parameters-of-async-func.js @@ -26,11 +26,11 @@ function test() printStatus(summary); let testAwaitInDefaultExprOfAsyncFunc = (code) => { - assertThrowsInstanceOf(() => eval(code), SyntaxError, "await expression can't be used in parameter"); + assert.throws(SyntaxError, () => eval(code), "await expression can't be used in parameter"); }; let testNoException = (code) => { - assert.sameValue(completesNormally(code), true); + eval(code); }; // https://www.ecma-international.org/ecma-262/9.0/ diff --git a/test/staging/sm/fields/await-identifier-script.js b/test/staging/sm/fields/await-identifier-script.js index 2431216ad2..c88dca32f8 100644 --- a/test/staging/sm/fields/await-identifier-script.js +++ b/test/staging/sm/fields/await-identifier-script.js @@ -2,13 +2,11 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js] -flags: - - noStrict description: | pending esid: pending ---*/ + var await = 1; async function getClass() { @@ -21,11 +19,10 @@ getClass().then(cl => { assert.sameValue(new cl().x, 1); }); -assert.sameValue(raisesException(SyntaxError)(` -async () => class { [await] = 1 }; -`), true); - -assert.sameValue(raisesException(SyntaxError)(` - async () => class { x = await 1 }; -`), true); +assert.throws(SyntaxError, function() { + eval("async () => class { [await] = 1 };"); +}); +assert.throws(SyntaxError, function() { + eval("async () => class { x = await 1 };"); +}); diff --git a/test/staging/sm/fields/bug1587574.js b/test/staging/sm/fields/bug1587574.js index 8c5a7dd431..3fbd42ff5d 100644 --- a/test/staging/sm/fields/bug1587574.js +++ b/test/staging/sm/fields/bug1587574.js @@ -2,13 +2,11 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -includes: [sm/non262.js, sm/non262-shell.js] -flags: - - noStrict description: | pending esid: pending ---*/ + // Don't Crash var testStr = ` class C extends Object { @@ -20,5 +18,8 @@ class C extends Object { } } new C;` -assert.sameValue(raisesException(ReferenceError)(testStr), true); + +assert.throws(ReferenceError, function() { + eval(testStr); +}); diff --git a/test/staging/sm/strict/8.7.2-01.js b/test/staging/sm/strict/8.7.2-01.js index d165e3a0aa..9c8eca0445 100644 --- a/test/staging/sm/strict/8.7.2-01.js +++ b/test/staging/sm/strict/8.7.2-01.js @@ -4,18 +4,13 @@ */ /*--- -includes: [sm/non262.js, sm/non262-strict-shell.js, sm/non262-shell.js] -flags: - - noStrict description: | pending esid: pending ---*/ + /* Check that assignment to a let-bound variable is permitted in both lenient and strict modes. */ /* Assigning to a let-declared variable is okay in strict and loose modes. */ -assert.sameValue(testLenientAndStrict('let let_declared; let_declared=1', - completesNormally, - completesNormally), - true); - +let let_declared; +let_declared = 1;