diff --git a/test/staging/sm/Array/change-array-by-copy-errors-from-correct-realm.js b/test/staging/sm/Array/change-array-by-copy-errors-from-correct-realm.js index f3a8ec5af4..466e4ef529 100644 --- a/test/staging/sm/Array/change-array-by-copy-errors-from-correct-realm.js +++ b/test/staging/sm/Array/change-array-by-copy-errors-from-correct-realm.js @@ -60,25 +60,11 @@ function test(otherGlobal) { // For each erroneous case, make sure the error comes from // the other realm (not this realm) for (const [message, f] of typeErrorCalls) { - try { - f(); - } catch (exc) { - assert.sameValue(exc instanceof TypeError, false, message + " threw TypeError from wrong realm"); - assert.sameValue(exc instanceof otherGlobal.TypeError, true, message + " didn't throw TypeError from other realm"); - assert.sameValue(Object.getPrototypeOf(exc) !== Object.getPrototypeOf(TypeError), true, - message + " TypeError has wrong prototype"); - } + assert.throws(otherGlobal.TypeError, f, message); } for (const [message, f] of rangeErrorCalls) { - try { - f(); - } catch (exc) { - assert.sameValue(exc instanceof RangeError, false, message + " threw RangeError from wrong realm"); - assert.sameValue(exc instanceof otherGlobal.RangeError, true, message + " didn't throw RangeError from other realm"); - assert.sameValue(Object.getPrototypeOf(exc) !== Object.getPrototypeOf(RangeError), true, - message + " TypeError has wrong prototype"); - } + assert.throws(otherGlobal.RangeError, f, message); } } diff --git a/test/staging/sm/Array/length-set-object.js b/test/staging/sm/Array/length-set-object.js index d24bf5174c..ed3c93b01e 100644 --- a/test/staging/sm/Array/length-set-object.js +++ b/test/staging/sm/Array/length-set-object.js @@ -29,16 +29,9 @@ invokeConversionTwice2(); function dontOverwriteError1() { - try - { + assert.throws(TypeError, function() { [].length = { valueOf: {}, toString: {} }; - throw new Error("didn't throw a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "expected a TypeError running out of conversion options, got " + e); - } + }, "expected a TypeError running out of conversion options"); } dontOverwriteError1(); diff --git a/test/staging/sm/Array/length-truncate-nonconfigurable-sparse.js b/test/staging/sm/Array/length-truncate-nonconfigurable-sparse.js index 7869915e61..7eee512f27 100644 --- a/test/staging/sm/Array/length-truncate-nonconfigurable-sparse.js +++ b/test/staging/sm/Array/length-truncate-nonconfigurable-sparse.js @@ -73,16 +73,9 @@ function strict() addDataProperty(arr, 27182818, "eep", false, false, false); - try - { + assert.throws(TypeError, function() { arr.length = 1; - throw new Error("didn't throw?!"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "non-configurable property should trigger TypeError, got " + e); - } + }, "non-configurable property should trigger TypeError"); assert.sameValue(arr.length, 27182819); diff --git a/test/staging/sm/Array/length-truncate-nonconfigurable.js b/test/staging/sm/Array/length-truncate-nonconfigurable.js index c95e96063b..60bc8619ec 100644 --- a/test/staging/sm/Array/length-truncate-nonconfigurable.js +++ b/test/staging/sm/Array/length-truncate-nonconfigurable.js @@ -14,16 +14,9 @@ esid: pending var arr = [0, 1, 2]; Object.defineProperty(arr, 1, { configurable: false }); -try -{ +assert.throws(TypeError, function() { Object.defineProperty(arr, "length", { value: 0, writable: false }); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "must throw TypeError when array truncation would have to remove " + - "non-configurable elements"); -} +}, "must throw TypeError when array truncation would have to remove non-configurable elements"); assert.sameValue(arr.length, 2, "length is highest remaining index plus one"); diff --git a/test/staging/sm/Array/pop-empty-nonwritable.js b/test/staging/sm/Array/pop-empty-nonwritable.js index 858c2f50f3..a59c120010 100644 --- a/test/staging/sm/Array/pop-empty-nonwritable.js +++ b/test/staging/sm/Array/pop-empty-nonwritable.js @@ -11,13 +11,6 @@ description: | esid: pending ---*/ -try -{ +assert.throws(TypeError, function() { Object.freeze([]).pop(); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "should have thrown TypeError, instead got: " + e); -} +}); diff --git a/test/staging/sm/Array/redefine-nonwritable-length-custom-conversion-throw.js b/test/staging/sm/Array/redefine-nonwritable-length-custom-conversion-throw.js index 88fc4811e7..25179a8db0 100644 --- a/test/staging/sm/Array/redefine-nonwritable-length-custom-conversion-throw.js +++ b/test/staging/sm/Array/redefine-nonwritable-length-custom-conversion-throw.js @@ -27,8 +27,7 @@ var convertible = var arr = []; Object.defineProperty(arr, "length", { value: 0, writable: false }); -try -{ +assert.throws(SyntaxError, function() { Object.defineProperty(arr, "length", { value: convertible, @@ -36,12 +35,7 @@ try configurable: true, enumerable: true }); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, "expected SyntaxError, got " + e); -} +}); assert.sameValue(count, 1); assert.sameValue(arr.length, 0); diff --git a/test/staging/sm/Date/toISOString.js b/test/staging/sm/Date/toISOString.js index 19d23a241b..934d3d4ded 100644 --- a/test/staging/sm/Date/toISOString.js +++ b/test/staging/sm/Date/toISOString.js @@ -10,20 +10,16 @@ description: | pending esid: pending ---*/ + function throwsRangeError(t) { - try { - var date = new Date(); - date.setTime(t); - var r = date.toISOString(); - throw new Error("toISOString didn't throw, instead returned " + r); - } catch (err) { - assert.sameValue(err instanceof RangeError, true, 'wrong error: ' + err); - return; - } - assert.sameValue(0, 1, 'not good, nyan, nyan'); + var date = new Date(); + date.setTime(t); + + assert.throws(RangeError, function() { + date.toISOString(); + }); } throwsRangeError(Infinity); throwsRangeError(-Infinity); throwsRangeError(NaN); - diff --git a/test/staging/sm/Date/toJSON-01.js b/test/staging/sm/Date/toJSON-01.js index 81adf58531..f1ed1c340c 100644 --- a/test/staging/sm/Date/toJSON-01.js +++ b/test/staging/sm/Date/toJSON-01.js @@ -30,27 +30,13 @@ assert.sameValue(dateToJSON.length, 1); * 1. Let O be the result of calling ToObject, giving it the this value as its * argument. */ -try -{ +assert.throws(TypeError, function() { dateToJSON.call(null); - throw new Error("should have thrown a TypeError"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "ToObject throws TypeError for null/undefined"); -} +}, "ToObject throws TypeError for null"); -try -{ +assert.throws(TypeError, function() { dateToJSON.call(undefined); - throw new Error("should have thrown a TypeError"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "ToObject throws TypeError for null/undefined"); -} +}, "ToObject throws TypeError for undefined"); /* @@ -123,19 +109,13 @@ assert.sameValue(dateToJSON.call({ valueOf: function() { called = true; return { NaN); assert.sameValue(asserted, true); -try -{ +assert.throws(TypeError, function() { var r = dateToJSON.call({ valueOf: null, toString: null, get toISOString() { throw new Error("shouldn't have been gotten"); } }); - throw new Error("didn't throw, returned: " + r); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "bad exception: " + e); -} +}); /* 3. If tv is a Number and is not finite, return null. */ @@ -167,45 +147,21 @@ catch (e) /* 5. If IsCallable(toISO) is false, throw a TypeError exception. */ -try -{ - var r = dateToJSON.call({ toISOString: null }); - throw new Error("didn't throw, returned: " + r); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "bad exception: " + e); -} +assert.throws(TypeError, function() { + dateToJSON.call({ toISOString: null }); +}); -try -{ - var r = dateToJSON.call({ toISOString: undefined }); - throw new Error("didn't throw, returned: " + r); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "bad exception: " + e); -} +assert.throws(TypeError, function() { + dateToJSON.call({ toISOString: undefined }); +}); -try -{ - var r = dateToJSON.call({ toISOString: "oogabooga" }); - throw new Error("didn't throw, returned: " + r); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "bad exception: " + e); -} +assert.throws(TypeError, function() { + dateToJSON.call({ toISOString: "oogabooga" }); +}); -try -{ - var r = dateToJSON.call({ toISOString: Math.PI }); - throw new Error("didn't throw, returned: " + r); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "bad exception: " + e); -} +assert.throws(TypeError, function() { + dateToJSON.call({ toISOString: Math.PI }); +}); /* diff --git a/test/staging/sm/Function/15.3.4.3-01.js b/test/staging/sm/Function/15.3.4.3-01.js index 565d772a8e..3e6571e362 100644 --- a/test/staging/sm/Function/15.3.4.3-01.js +++ b/test/staging/sm/Function/15.3.4.3-01.js @@ -11,19 +11,6 @@ description: | esid: pending ---*/ -function expectTypeError(fun, msg) -{ - try - { - fun(); - assert.sameValue(true, false, "should have thrown a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, msg + "; instead threw " + e); - } -} - function fun() { } var global = this; @@ -39,7 +26,7 @@ for (var i = 0, sz = nonfuns.length; i < sz; i++) }; var msg = "expected TypeError calling Function.prototype.apply with uncallable this"; - expectTypeError(f, msg); + assert.throws(TypeError, f, msg); } @@ -123,7 +110,7 @@ for (var i = 0, sz = nonobjs.length; i < sz; i++) { var f = function() { fun.apply(thisObj, nonobjs[i]); }; var msg = "should have thrown a TypeError with non-object arguments"; - expectTypeError(f, msg); + assert.throws(TypeError, f, msg); } diff --git a/test/staging/sm/Function/arguments-caller-callee.js b/test/staging/sm/Function/arguments-caller-callee.js index bb253dd4b6..c0cfb8da48 100644 --- a/test/staging/sm/Function/arguments-caller-callee.js +++ b/test/staging/sm/Function/arguments-caller-callee.js @@ -13,24 +13,9 @@ esid: pending // behavior -function expectTypeError(fun) -{ - try - { - fun(); - throw new Error("didn't throw"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "expected TypeError calling function" + - ("name" in fun ? " " + fun.name : "") + ", instead got: " + e); - } -} - function bar() { "use strict"; return arguments; } assert.sameValue(bar().caller, undefined); // No error when accessing arguments.caller in ES2017+ -expectTypeError(function barCallee() { bar().callee; }); +assert.throws(TypeError, function barCallee() { bar().callee; }); function baz() { return arguments; } assert.sameValue(baz().callee, baz); diff --git a/test/staging/sm/Function/builtin-no-construct.js b/test/staging/sm/Function/builtin-no-construct.js index a9d803162c..2ecda81be3 100644 --- a/test/staging/sm/Function/builtin-no-construct.js +++ b/test/staging/sm/Function/builtin-no-construct.js @@ -10,13 +10,11 @@ description: | pending esid: pending ---*/ + function checkMethod(method) { - try { + assert.throws(TypeError, function() { new method(); - assert.sameValue(0, 1, "not reached " + method); - } catch (e) { - assert.sameValue(e.message.indexOf(" is not a constructor") === -1, false); - } + }); } function checkMethods(proto) { @@ -54,4 +52,3 @@ var builtin_funcs = [ for (var i = 0; i < builtin_funcs.length; i++) { checkMethod(builtin_funcs[i]); } - diff --git a/test/staging/sm/Function/function-bind.js b/test/staging/sm/Function/function-bind.js index cec3cd85ea..5c2daf59c7 100644 --- a/test/staging/sm/Function/function-bind.js +++ b/test/staging/sm/Function/function-bind.js @@ -180,11 +180,9 @@ assert.sameValue(one.bind(null, 1, 2).length, 0); // retch var br = Object.create(null, { length: { value: 0 } }); -try -{ - br = bind.call(/a/g, /a/g, "aaaa"); -} -catch (e) { /* nothing */ } +assert.throws(TypeError, function() { + bind.call(/a/g, /a/g, "aaaa"); +}); assert.sameValue(br.length, 0); diff --git a/test/staging/sm/Function/function-call.js b/test/staging/sm/Function/function-call.js index f4e0dc554a..0515d2e08b 100644 --- a/test/staging/sm/Function/function-call.js +++ b/test/staging/sm/Function/function-call.js @@ -11,19 +11,6 @@ description: | esid: pending ---*/ -function expectTypeError(fun, msg) -{ - try - { - fun(); - assert.sameValue(true, false, "should have thrown a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, msg + "; instead threw " + e); - } -} - function fun() { } var global = this; @@ -41,7 +28,7 @@ for (var i = 0, sz = nonfuns.length; i < sz; i++) }; var msg = "expected TypeError calling Function.prototype.call with uncallable this"; - expectTypeError(f, msg); + assert.throws(TypeError, f, msg); } diff --git a/test/staging/sm/Function/function-caller.js b/test/staging/sm/Function/function-caller.js index 60bd813866..aeaf282f99 100644 --- a/test/staging/sm/Function/function-caller.js +++ b/test/staging/sm/Function/function-caller.js @@ -11,23 +11,8 @@ description: | esid: pending ---*/ -function expectTypeError(fun) -{ - try - { - fun(); - throw new Error("didn't throw"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "expected TypeError calling function" + - ("name" in fun ? " " + fun.name : "") + ", instead got: " + e); - } -} - function bar() { "use strict"; } -expectTypeError(function barCaller() { bar.caller; }); +assert.throws(TypeError, function barCaller() { bar.caller; }); function baz() { "use strict"; return 17; } -expectTypeError(function bazCaller() { baz.caller; }); +assert.throws(TypeError, function bazCaller() { baz.caller; }); diff --git a/test/staging/sm/Function/function-name.js b/test/staging/sm/Function/function-name.js index bc1a6e1408..e1cf804624 100644 --- a/test/staging/sm/Function/function-name.js +++ b/test/staging/sm/Function/function-name.js @@ -23,25 +23,17 @@ function testFunctionName(f) { function testFunctionNameStrict(f) { "use strict"; var name = f.name; - var error; - try { + assert.throws(TypeError, function() { f.name = 'g'; - } catch (e) { - error = e; - } + }); assert.sameValue(f.name, name); - assert.sameValue(error instanceof TypeError, true); assert.sameValue(delete f.name, true); assert.sameValue(f.name, ''); assert.sameValue(f.hasOwnProperty('name'), false); - error = null; - try { + assert.throws(TypeError, function() { f.name = 'g'; - } catch (e) { - error = e; - } + }); assert.sameValue(f.name, ''); - assert.sameValue(error instanceof TypeError, true); Object.defineProperty(f, 'name', {value: 'g'}); assert.sameValue(f.name, 'g'); } diff --git a/test/staging/sm/JSON/cyclic-stringify.js b/test/staging/sm/JSON/cyclic-stringify.js index d8d69026c7..0872df47ee 100644 --- a/test/staging/sm/JSON/cyclic-stringify.js +++ b/test/staging/sm/JSON/cyclic-stringify.js @@ -22,33 +22,17 @@ var desc = }; var obj = Object.defineProperty({ p1: 0 }, "p2", desc); -try -{ - var str = JSON.stringify(obj); - assert.sameValue(false, true, "should have thrown, got " + str); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "wrong error type: " + e.constructor.name); - assert.sameValue(count, 1, - "cyclic data structures not detected immediately"); -} +assert.throws(TypeError, function() { + JSON.stringify(obj); +}); +assert.sameValue(count, 1, "cyclic data structures not detected immediately"); count = 0; var obj2 = Object.defineProperty({}, "obj", desc); -try -{ - var str = JSON.stringify(obj2); - assert.sameValue(false, true, "should have thrown, got " + str); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "wrong error type: " + e.constructor.name); - assert.sameValue(count, 2, - "cyclic data structures not detected immediately"); -} +assert.throws(TypeError, function() { + JSON.stringify(obj2); +}); +assert.sameValue(count, 2, "cyclic data structures not detected immediately"); // arrays @@ -62,30 +46,14 @@ var desc = }; var arr = Object.defineProperty([], "0", desc); -try -{ - var str = JSON.stringify(arr); - assert.sameValue(false, true, "should have thrown, got " + str); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "wrong error type: " + e.constructor.name); - assert.sameValue(count, 1, - "cyclic data structures not detected immediately"); -} +assert.throws(TypeError, function() { + JSON.stringify(arr); +}); +assert.sameValue(count, 1, "cyclic data structures not detected immediately"); count = 0; var arr2 = Object.defineProperty([], "0", desc); -try -{ - var str = JSON.stringify(arr2); - assert.sameValue(false, true, "should have thrown, got " + str); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "wrong error type: " + e.constructor.name); - assert.sameValue(count, 2, - "cyclic data structures not detected immediately"); -} +assert.throws(TypeError, function() { + JSON.stringify(arr2); +}); +assert.sameValue(count, 2, "cyclic data structures not detected immediately"); diff --git a/test/staging/sm/JSON/parse-arguments.js b/test/staging/sm/JSON/parse-arguments.js index 99a0ba80d7..618adc78de 100644 --- a/test/staging/sm/JSON/parse-arguments.js +++ b/test/staging/sm/JSON/parse-arguments.js @@ -11,12 +11,6 @@ description: | esid: pending ---*/ -try -{ - var r = JSON.parse(); - throw new Error("didn't throw, returned " + r); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, "expected syntax error, got: " + e); -} +assert.throws(SyntaxError, function() { + JSON.parse(); +}); diff --git a/test/staging/sm/JSON/parse-reviver.js b/test/staging/sm/JSON/parse-reviver.js index c449f48690..aa3b2852e2 100644 --- a/test/staging/sm/JSON/parse-reviver.js +++ b/test/staging/sm/JSON/parse-reviver.js @@ -37,13 +37,7 @@ function dontCallMe(k, v) called = true; } -try -{ +assert.throws(SyntaxError, function() { JSON.parse('{{{{{{{}}}}', dontCallMe); - throw new Error("didn't throw?"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, "wrong exception: " + e); -} +}); assert.sameValue(called, false); diff --git a/test/staging/sm/JSON/stringify-boxed-primitives.js b/test/staging/sm/JSON/stringify-boxed-primitives.js index 78e991e839..b2b356cadb 100644 --- a/test/staging/sm/JSON/stringify-boxed-primitives.js +++ b/test/staging/sm/JSON/stringify-boxed-primitives.js @@ -51,34 +51,25 @@ redefine(Object.prototype, "valueOf", objValueOf); redefine(Number.prototype, "toString", function() { return 42; }); assert.sameValue(JSON.stringify(new Number(5)), "5"); + redefine(Number.prototype, "valueOf", function() { return 17; }); assert.sameValue(JSON.stringify(new Number(5)), "17"); + delete Number.prototype.toString; assert.sameValue(JSON.stringify(new Number(5)), "17"); + delete Number.prototype.valueOf; assert.sameValue(JSON.stringify(new Number(5)), "null"); // isNaN(Number("[object Number]")) + delete Object.prototype.toString; -try -{ +assert.throws(TypeError, function() { JSON.stringify(new Number(5)); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "ToNumber failure, should throw TypeError"); -} +}, "ToNumber failure, should throw TypeError"); + delete Object.prototype.valueOf; -try -{ +assert.throws(TypeError, function() { JSON.stringify(new Number(5)); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "ToNumber failure, should throw TypeError"); -} +}, "ToNumber failure, should throw TypeError"); redefine(Number.prototype, "toString", numToString); @@ -89,31 +80,22 @@ redefine(Object.prototype, "valueOf", objValueOf); redefine(String.prototype, "valueOf", function() { return 17; }); assert.sameValue(JSON.stringify(new String(5)), '"5"'); + redefine(String.prototype, "toString", function() { return 42; }); assert.sameValue(JSON.stringify(new String(5)), '"42"'); + delete String.prototype.toString; assert.sameValue(JSON.stringify(new String(5)), '"[object String]"'); + delete Object.prototype.toString; assert.sameValue(JSON.stringify(new String(5)), '"17"'); + delete String.prototype.valueOf; -try -{ +assert.throws(TypeError, function() { JSON.stringify(new String(5)); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "ToString failure, should throw TypeError"); -} +}, "ToString failure, should throw TypeError"); + delete Object.prototype.valueOf; -try -{ +assert.throws(TypeError, function() { JSON.stringify(new String(5)); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "ToString failure, should throw TypeError"); -} +}, "ToString failure, should throw TypeError"); diff --git a/test/staging/sm/JSON/stringify-replacer.js b/test/staging/sm/JSON/stringify-replacer.js index dbc666ffef..d326525fc0 100644 --- a/test/staging/sm/JSON/stringify-replacer.js +++ b/test/staging/sm/JSON/stringify-replacer.js @@ -127,33 +127,15 @@ assert.sameValue(x, '{"0":0,"1":null,"2":2}'); x = JSON.stringify(foo, returnStringForUndefined); assert.sameValue(x, '{"0":0,"1":1,"2":2,"3":"undefined value"}'); -try -{ +assert.throws(TypeError, function() { JSON.stringify(foo, returnCycleObjectFor1); - throw new Error("no error thrown"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "no TypeError thrown: " + e); -} +}); -try -{ +assert.throws(TypeError, function() { JSON.stringify(foo, returnCycleArrayFor1); - throw new Error("no error thrown"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "no TypeError thrown: " + e); -} +}); foo = [0, 1, 2, undefined]; -try -{ +assert.throws(TypeError, function() { JSON.stringify(foo, returnCycleObjectFor1); - throw new Error("no error thrown"); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, "no TypeError thrown: " + e); -} +}); diff --git a/test/staging/sm/Number/0x-without-following-hexdigits.js b/test/staging/sm/Number/0x-without-following-hexdigits.js index 9283ac9ea4..f89e4dfe2c 100644 --- a/test/staging/sm/Number/0x-without-following-hexdigits.js +++ b/test/staging/sm/Number/0x-without-following-hexdigits.js @@ -11,13 +11,6 @@ description: | esid: pending ---*/ -try -{ +assert.throws(SyntaxError, function() { eval("0x"); - throw new Error("didn't throw parsing 0x (with no subsequent hex digits)"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, - "bad exception thrown: " + e); -} +}); diff --git a/test/staging/sm/Number/conversion-invalid-precision.js b/test/staging/sm/Number/conversion-invalid-precision.js index 67a5d8cfa0..7f6a695f4f 100644 --- a/test/staging/sm/Number/conversion-invalid-precision.js +++ b/test/staging/sm/Number/conversion-invalid-precision.js @@ -11,19 +11,10 @@ description: | esid: pending ---*/ -function test(method, prec) -{ - try - { +function test(method, prec) { + assert.throws(RangeError, function() { Number.prototype[method].call(0, prec); - throw "should have thrown"; - } - catch (e) - { - assert.sameValue(e instanceof RangeError, true, - "expected RangeError for " + method + " with precision " + prec + - ", got " + e); - } + }); } test("toExponential", -32); diff --git a/test/staging/sm/Number/toString-radix-handling.js b/test/staging/sm/Number/toString-radix-handling.js index 6ebab29bb7..4931290773 100644 --- a/test/staging/sm/Number/toString-radix-handling.js +++ b/test/staging/sm/Number/toString-radix-handling.js @@ -11,17 +11,11 @@ description: | esid: pending ---*/ -function test(r) -{ - try - { +function test(r) { + assert.throws(RangeError, function() { 5..toString(r); - throw "should have thrown"; - } - catch (e) - { - assert.sameValue(e instanceof RangeError, true, "expected a RangeError, got " + e); - } + }); } + test(Math.pow(2, 32) + 10); test(55); diff --git a/test/staging/sm/PrivateName/nested-class-name-used.js b/test/staging/sm/PrivateName/nested-class-name-used.js index a8c29b6e07..d6e1650eb8 100644 --- a/test/staging/sm/PrivateName/nested-class-name-used.js +++ b/test/staging/sm/PrivateName/nested-class-name-used.js @@ -32,9 +32,6 @@ class A { }; a = new A; -try { +assert.throws(TypeError, function() { a.g(); -} catch (e) { - assert.sameValue(e instanceof TypeError, true); -} - +}); diff --git a/test/staging/sm/PrivateName/proxy-1.js b/test/staging/sm/PrivateName/proxy-1.js index 232eb55f99..c23c4c5cec 100644 --- a/test/staging/sm/PrivateName/proxy-1.js +++ b/test/staging/sm/PrivateName/proxy-1.js @@ -17,13 +17,6 @@ class A { }; var p = new Proxy(new A, {}); -var completed = false; -try { +assert.throws(TypeError, function() { p.g(); - completed = true; -} catch (e) { - assert.sameValue(e instanceof TypeError, true); -} -assert.sameValue(completed, false); - - +}); diff --git a/test/staging/sm/PrivateName/proxy-init-set.js b/test/staging/sm/PrivateName/proxy-init-set.js index 96bba1a2d9..240ca337e3 100644 --- a/test/staging/sm/PrivateName/proxy-init-set.js +++ b/test/staging/sm/PrivateName/proxy-init-set.js @@ -8,20 +8,9 @@ description: | pending esid: pending ---*/ + // Ensure that the distinction between Proxy Init and Proxy Set holds -function assertThrowsTypeError(f) { - var type; - try { - f(); - } catch (ex) { - type = ex.name; - } - assert.sameValue(type, 'TypeError'); -} - - - var target = {}; var p1 = new Proxy(target, {}); var p2 = new Proxy(target, {}); @@ -60,23 +49,22 @@ assert.sameValue(A.gf(p1), 15); // Despite P1 being stamped with A's field, it shouldn't // be sufficient to set B's field. -assertThrowsTypeError(() => B.sf(p1)); -assertThrowsTypeError(() => B.gf(p1)); -assertThrowsTypeError(() => B.sf(p1)); +assert.throws(TypeError, () => B.sf(p1)); +assert.throws(TypeError, () => B.gf(p1)); +assert.throws(TypeError, () => B.sf(p1)); new B(p1); assert.sameValue(B.gf(p1), 25); B.sf(p1); assert.sameValue(B.gf(p1), 20); // A's field should't be on the target -assertThrowsTypeError(() => A.gf(target)); +assert.throws(TypeError, () => A.gf(target)); // Can't set the field, doesn't exist -assertThrowsTypeError(() => A.sf(p2)); +assert.throws(TypeError, () => A.sf(p2)); // Definitely can't get the field, doesn't exist. -assertThrowsTypeError(() => A.gf(p2)); +assert.throws(TypeError, () => A.gf(p2)); // Still should't be on the target. -assertThrowsTypeError(() => A.gf(target)); - +assert.throws(TypeError, () => A.gf(target)); diff --git a/test/staging/sm/Proxy/revocable-proxy-prototype.js b/test/staging/sm/Proxy/revocable-proxy-prototype.js index c609f29dfc..ccd9d62c99 100644 --- a/test/staging/sm/Proxy/revocable-proxy-prototype.js +++ b/test/staging/sm/Proxy/revocable-proxy-prototype.js @@ -16,16 +16,9 @@ function checkFunctionAppliedToRevokedProxy(fun) var p = Proxy.revocable({}, {}); p.revoke(); - try - { + assert.throws(TypeError, function() { fun(p.proxy); - throw "didn't throw"; - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "expected TypeError, got " + e); - } + }); } checkFunctionAppliedToRevokedProxy(proxy => Object.getPrototypeOf(proxy)); diff --git a/test/staging/sm/RegExp/7.8.5-01.js b/test/staging/sm/RegExp/7.8.5-01.js index 36a45dd4f7..c648b12c4b 100644 --- a/test/staging/sm/RegExp/7.8.5-01.js +++ b/test/staging/sm/RegExp/7.8.5-01.js @@ -17,11 +17,7 @@ var regexps = ["/\\\u000A/", "/\\\u000D/", "/\\\u2028/", "/\\\u2029/", for(var i=0; i"; - try - { - f(); - error += ", and the function can be called without error"; - } - catch (e) - { - error +=", and calling the function throws " + e; - } - - throw new Error(error); - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "expected syntax error, got " + e); - } - } - - helper(Function); - helper(eval); + assert.throws(SyntaxError, function() { + Function(code); + }); + assert.throws(SyntaxError, function() { + (1, eval)(code); // indirect eval + }); } checkSyntaxError("function f() { 'use strict'; delete escape; } f();"); diff --git a/test/staging/sm/expressions/destructuring-pattern-parenthesized.js b/test/staging/sm/expressions/destructuring-pattern-parenthesized.js index cec92af72a..57017214cb 100644 --- a/test/staging/sm/expressions/destructuring-pattern-parenthesized.js +++ b/test/staging/sm/expressions/destructuring-pattern-parenthesized.js @@ -14,51 +14,27 @@ esid: pending // Don't pollute the top-level script with eval references. var savedEval = this[String.fromCharCode(101, 118, 97, 108)]; -function checkError(code, nonstrictErr, strictErr) +function checkError(code) { - function helper(exec, prefix, err) + function helper(exec, prefix) { var fullCode = prefix + code; - try - { - var f = exec(fullCode); - - var error = - "no early error, parsed code <" + fullCode + "> using " + exec.name; - if (typeof f === "function") - { - try - { - f(); - error += ", and the function can be called without error"; - } - catch (e) - { - error +=", and calling the function throws " + e; - } - } - - throw new Error(error); - } - catch (e) - { - assert.sameValue(e instanceof err, true, - "expected " + err.name + ", got " + e + " " + - "for code <" + fullCode + "> when parsed using " + exec.name); - } + assert.throws(SyntaxError, function() { + exec(fullCode); + }); } - helper(Function, "", nonstrictErr); - helper(Function, "'use strict'; ", strictErr); - helper(savedEval, "", nonstrictErr); - helper(savedEval, "'use strict'; ", strictErr); + helper(Function, ""); + helper(Function, "'use strict'; "); + helper(savedEval, ""); + helper(savedEval, "'use strict'; "); } // Parenthesized destructuring patterns don't trigger grammar refinement, so we // get the usual SyntaxError for an invalid assignment target, per // 12.14.1 second bullet. -checkError("var a, b; ([a, b]) = [1, 2];", SyntaxError, SyntaxError); -checkError("var a, b; ({a, b}) = { a: 1, b: 2 };", SyntaxError, SyntaxError); +checkError("var a, b; ([a, b]) = [1, 2];"); +checkError("var a, b; ({a, b}) = { a: 1, b: 2 };"); // *Nested* parenthesized destructuring patterns, on the other hand, do trigger // grammar refinement. But subtargets in a destructuring pattern must be @@ -68,11 +44,11 @@ checkError("var a, b; ({a, b}) = { a: 1, b: 2 };", SyntaxError, SyntaxError); // destructuring in an expression, |(a = 3)| is forbidden). Parenthesized // object/array patterns are neither. And so 12.14.5.1 third bullet requires an // early SyntaxError. -checkError("var a, b; ({ a: ({ b: b }) } = { a: { b: 42 } });", SyntaxError, SyntaxError); -checkError("var a, b; ({ a: { b: (b = 7) } } = { a: {} });", SyntaxError, SyntaxError); -checkError("var a, b; ({ a: ([b]) } = { a: [42] });", SyntaxError, SyntaxError); -checkError("var a, b; [(a = 5)] = [1];", SyntaxError, SyntaxError); -checkError("var a, b; ({ a: (b = 7)} = { b: 1 });", SyntaxError, SyntaxError); +checkError("var a, b; ({ a: ({ b: b }) } = { a: { b: 42 } });"); +checkError("var a, b; ({ a: { b: (b = 7) } } = { a: {} });"); +checkError("var a, b; ({ a: ([b]) } = { a: [42] });"); +checkError("var a, b; [(a = 5)] = [1];"); +checkError("var a, b; ({ a: (b = 7)} = { b: 1 });"); Function("var a, b; [(a), b] = [1, 2];")(); Function("var a, b; [(a) = 5, b] = [1, 2];")(); @@ -110,18 +86,18 @@ if (classesEnabled()) // As noted above, when the assignment element has an initializer, the // assignment element must not be parenthesized. -checkError("var a, b; [(repair.man = 17)] = [1];", SyntaxError, SyntaxError); -checkError("var a, b; [(demolition['man'] = 'motel')] = [1, 2];", SyntaxError, SyntaxError); -checkError("var a, b; [(demolition['man' + {}] = 'motel')] = [1];", SyntaxError, SyntaxError); // evade constant-folding +checkError("var a, b; [(repair.man = 17)] = [1];"); +checkError("var a, b; [(demolition['man'] = 'motel')] = [1, 2];"); +checkError("var a, b; [(demolition['man' + {}] = 'motel')] = [1];"); // evade constant-folding if (classesEnabled()) { - checkError("var a, b; var obj = { x() { [(super.man = 5)] = [1]; } };", SyntaxError, SyntaxError); - checkError("var a, b; var obj = { x() { [(super[8] = 'motel')] = [1]; } };", SyntaxError, SyntaxError); - checkError("var a, b; var obj = { x() { [(super[8 + {}] = 'motel')] = [1]; } };", SyntaxError, SyntaxError); // evade constant-folding + checkError("var a, b; var obj = { x() { [(super.man = 5)] = [1]; } };"); + checkError("var a, b; var obj = { x() { [(super[8] = 'motel')] = [1]; } };"); + checkError("var a, b; var obj = { x() { [(super[8 + {}] = 'motel')] = [1]; } };"); // evade constant-folding } -checkError("var a, b; [f() = 'ohai', b] = [1, 2];", SyntaxError, SyntaxError); -checkError("var a, b; [(f()) = 'kthxbai', b] = [1, 2];", SyntaxError, SyntaxError); +checkError("var a, b; [f() = 'ohai', b] = [1, 2];"); +checkError("var a, b; [(f()) = 'kthxbai', b] = [1, 2];"); Function("var a, b; ({ a: (a), b} = { a: 1, b: 2 });")(); Function("var a, b; ({ a: (a) = 5, b} = { a: 1, b: 2 });")(); diff --git a/test/staging/sm/expressions/named-accessor-function.js b/test/staging/sm/expressions/named-accessor-function.js index e6fd2a56a3..806f591f46 100644 --- a/test/staging/sm/expressions/named-accessor-function.js +++ b/test/staging/sm/expressions/named-accessor-function.js @@ -19,33 +19,11 @@ for (var i = 0, sz = BAD_CODE.length; i < sz; i++) { var code = BAD_CODE[i]; - var err = "no exception"; - try - { + assert.throws(SyntaxError, function() { eval(code); - } - catch (e) - { - err = e; - } - if (!(err instanceof SyntaxError)) - { - assert.sameValue(true, false, - "bad or no exception thrown for eval(" + code + "): " + err); - } + }, "bad or no exception thrown for eval(" + code + ")"); - err = "no exception"; - try - { - new Function(code); - } - catch (e) - { - err = e; - } - if (!(err instanceof SyntaxError)) - { - assert.sameValue(true, false, - "bad or no exception thrown for Function(" + code + "): " + err); - } + assert.throws(SyntaxError, function() { + Function(code); + }, "bad or no exception thrown for Function(" + code + ")"); } diff --git a/test/staging/sm/expressions/nullish-coalescing.js b/test/staging/sm/expressions/nullish-coalescing.js index 1cda3d8ed9..7e14628adc 100644 --- a/test/staging/sm/expressions/nullish-coalescing.js +++ b/test/staging/sm/expressions/nullish-coalescing.js @@ -24,15 +24,9 @@ function shouldNotThrow(script) { } function shouldThrowSyntaxError(script) { - let error; - try { + assert.throws(SyntaxError, function() { eval(script); - } catch (e) { - error = e; - } - - if (!(error instanceof SyntaxError)) - throw new Error('Expected SyntaxError!'); + }); } function testBasicCases() { diff --git a/test/staging/sm/expressions/object-literal-accessor-arguments.js b/test/staging/sm/expressions/object-literal-accessor-arguments.js index ee847c6994..cd0273ab1a 100644 --- a/test/staging/sm/expressions/object-literal-accessor-arguments.js +++ b/test/staging/sm/expressions/object-literal-accessor-arguments.js @@ -13,16 +13,9 @@ esid: pending function expectSyntaxError(s) { - try - { + assert.throws(SyntaxError, function() { eval(s); - throw new Error("no error thrown"); - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "expected syntax error parsing '" + s + "', got: " + e); - } + }, "expected syntax error parsing '" + s + "'"); } expectSyntaxError("({ get x(a) { } })"); diff --git a/test/staging/sm/expressions/octal-literals.js b/test/staging/sm/expressions/octal-literals.js index d847db96e0..c7bcade4cd 100644 --- a/test/staging/sm/expressions/octal-literals.js +++ b/test/staging/sm/expressions/octal-literals.js @@ -19,17 +19,9 @@ for (var i = 0; i < 8; i++) { chars.forEach(function(v) { - try - { + assert.throws(SyntaxError, function() { eval('0' + v + i); - throw "didn't throw"; - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "no syntax error evaluating 0" + v + i + ", " + - "got " + e); - } + }, "syntax error evaluating 0" + v + i); }); continue; } @@ -40,17 +32,9 @@ for (var i = 0; i < 8; i++) { chars.forEach(function(v) { - try - { + assert.throws(SyntaxError, function() { eval('0' + v + i + j); - throw "didn't throw"; - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "no syntax error evaluating 0" + v + i + j + ", " + - "got " + e); - } + }, "syntax error evaluating 0" + v + i + j); }); continue; } @@ -61,17 +45,9 @@ for (var i = 0; i < 8; i++) { chars.forEach(function(v) { - try - { + assert.throws(SyntaxError, function() { eval('0' + v + i + j + k); - throw "didn't throw"; - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "no syntax error evaluating 0" + v + i + j + k + ", " + - "got " + e); - } + }, "no syntax error evaluating 0" + v + i + j + k); }); continue; } diff --git a/test/staging/sm/expressions/string-literal-escape-sequences.js b/test/staging/sm/expressions/string-literal-escape-sequences.js index 52152e1d73..eabb21802d 100644 --- a/test/staging/sm/expressions/string-literal-escape-sequences.js +++ b/test/staging/sm/expressions/string-literal-escape-sequences.js @@ -13,15 +13,9 @@ esid: pending function expectSyntaxError(str) { - try - { + assert.throws(SyntaxError, function() { eval(str); - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "no syntax error evaluating " + str); - } + }, "syntax error evaluating " + str); } expectSyntaxError('"\\x"'); diff --git a/test/staging/sm/extensions/ArrayBuffer-slice-arguments-detaching.js b/test/staging/sm/extensions/ArrayBuffer-slice-arguments-detaching.js index 74842ab7ed..aa47eae28f 100644 --- a/test/staging/sm/extensions/ArrayBuffer-slice-arguments-detaching.js +++ b/test/staging/sm/extensions/ArrayBuffer-slice-arguments-detaching.js @@ -25,16 +25,9 @@ function testStart() } }; - var ok = false; - try - { + assert.throws(TypeError, function() { ab.slice(start); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "start weirdness should have thrown"); + }, "start weirdness should have thrown"); assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); } testStart(); @@ -53,16 +46,9 @@ function testEnd() } }; - var ok = false; - try - { + assert.throws(TypeError, function() { ab.slice(0x800, end); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "byteLength weirdness should have thrown"); + }, "byteLength weirdness should have thrown"); assert.sameValue(ab.byteLength, 0, "detaching should work for byteLength weirdness"); } testEnd(); diff --git a/test/staging/sm/extensions/DataView-construct-arguments-detaching.js b/test/staging/sm/extensions/DataView-construct-arguments-detaching.js index bd28b3e85e..7c62eec4a8 100644 --- a/test/staging/sm/extensions/DataView-construct-arguments-detaching.js +++ b/test/staging/sm/extensions/DataView-construct-arguments-detaching.js @@ -25,16 +25,9 @@ function testByteOffset() } }; - var ok = false; - try - { + assert.throws(TypeError, function() { new DataView(ab, start); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "byteOffset weirdness should have thrown"); + }, "byteOffset weirdness should have thrown"); assert.sameValue(ab.byteLength, 0, "detaching should work for byteOffset weirdness"); } testByteOffset(); @@ -53,16 +46,9 @@ function testByteLength() } }; - var ok = false; - try - { + assert.throws(TypeError, function() { new DataView(ab, 0x800, len); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "byteLength weirdness should have thrown"); + }, "byteLength weirdness should have thrown"); assert.sameValue(ab.byteLength, 0, "detaching should work for byteLength weirdness"); } testByteLength(); diff --git a/test/staging/sm/extensions/DataView-set-arguments-detaching.js b/test/staging/sm/extensions/DataView-set-arguments-detaching.js index c624e3d9b7..60d538186d 100644 --- a/test/staging/sm/extensions/DataView-set-arguments-detaching.js +++ b/test/staging/sm/extensions/DataView-set-arguments-detaching.js @@ -27,16 +27,9 @@ function testIndex() } }; - var ok = false; - try - { + assert.throws(TypeError, function() { dv.setUint8(start, 0x42); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "should have thrown"); + }); assert.sameValue(ab.byteLength, 0, "should have been detached correctly"); } testIndex(); @@ -57,16 +50,9 @@ function testValue() } }; - var ok = false; - try - { + assert.throws(TypeError, function() { dv.setUint8(0xFFFFF, value); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "should have thrown"); + }); assert.sameValue(ab.byteLength, 0, "should have been detached correctly"); } testValue(); diff --git a/test/staging/sm/extensions/TypedArray-subarray-arguments-detaching.js b/test/staging/sm/extensions/TypedArray-subarray-arguments-detaching.js index 208246d4ab..e1d64808c9 100644 --- a/test/staging/sm/extensions/TypedArray-subarray-arguments-detaching.js +++ b/test/staging/sm/extensions/TypedArray-subarray-arguments-detaching.js @@ -26,16 +26,9 @@ function testBegin() var ta = new Uint8Array(ab); - var ok = false; - try - { - ta.subarray(begin); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "start weirdness should have thrown"); + assert.throws(TypeError, function() { + ta.subarray(begin) + }, "start weirdness should have thrown"); assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); } testBegin(); @@ -55,16 +48,9 @@ function testBeginWithEnd() var ta = new Uint8Array(ab); - var ok = false; - try - { + assert.throws(TypeError, function() { ta.subarray(begin, 0x1000); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "start weirdness should have thrown"); + }, "start weirdness should have thrown"); assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); } testBeginWithEnd(); @@ -84,16 +70,9 @@ function testEnd() var ta = new Uint8Array(ab); - var ok = false; - try - { + assert.throws(TypeError, function() { ta.subarray(0x800, end); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "start weirdness should have thrown"); - assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); + }, "end weirdness should have thrown"); + assert.sameValue(ab.byteLength, 0, "detaching should work for end weirdness"); } testEnd(); diff --git a/test/staging/sm/extensions/arguments-property-access-in-function.js b/test/staging/sm/extensions/arguments-property-access-in-function.js index 015e3f2d8a..146dc8bd42 100644 --- a/test/staging/sm/extensions/arguments-property-access-in-function.js +++ b/test/staging/sm/extensions/arguments-property-access-in-function.js @@ -30,17 +30,9 @@ var sobj = { "use strict"; - try - { - var args = sobj.test.arguments; - throw new Error("access to arguments property of strict mode " + - "function didn't throw"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "should have thrown TypeError, instead got: " + e); - } + assert.throws(TypeError, function() { + sobj.test.arguments; + }, "access to arguments property of strict mode function"); } }; sobj.test(5, undefined); diff --git a/test/staging/sm/extensions/dataview.js b/test/staging/sm/extensions/dataview.js index 5b423ed95a..af1836dbc5 100644 --- a/test/staging/sm/extensions/dataview.js +++ b/test/staging/sm/extensions/dataview.js @@ -12,23 +12,8 @@ esid: pending ---*/ function test(sharedMem) { - function die(message, uplevel) { - throw new Error(message); - } - function checkThrow(fun, type) { - var thrown = false; - try { - fun(); - } catch (x) { - thrown = x; - } - - if (!thrown) { - die('no exception thrown, expected ' + type.name, 2); - } else if (!(thrown instanceof type)) { - die('expected ' + type.name + ', got ' + thrown, 2); - } + assert.throws(type, fun); } function bufferize(u8array) { diff --git a/test/staging/sm/extensions/destructure-accessor.js b/test/staging/sm/extensions/destructure-accessor.js index 599feeb37d..b31babfc29 100644 --- a/test/staging/sm/extensions/destructure-accessor.js +++ b/test/staging/sm/extensions/destructure-accessor.js @@ -27,16 +27,9 @@ function expectOk(s) function expectSyntaxError(s) { - try - { + assert.throws(SyntaxError, function() { eval(s); - throw new Error("no error thrown"); - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "expected syntax error parsing '" + s + "', got: " + e); - } + }, "expected syntax error parsing '" + s + "'"); } expectSyntaxError("({ get x([]) { } })"); diff --git a/test/staging/sm/extensions/es5ish-defineGetter-defineSetter.js b/test/staging/sm/extensions/es5ish-defineGetter-defineSetter.js index 692af31995..3658f63052 100644 --- a/test/staging/sm/extensions/es5ish-defineGetter-defineSetter.js +++ b/test/staging/sm/extensions/es5ish-defineGetter-defineSetter.js @@ -67,20 +67,6 @@ function check(obj, prop, expected) checkField("configurable", desc, expected); } -function expectTypeError(f) -{ - try - { - f(); - throw new Error("no error thrown"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "wrong error thrown: got " + e + ", not a TypeError"); - } -} - /************** * BEGIN TEST * **************/ @@ -137,8 +123,8 @@ gsobj.__defineSetter__("baz", s3); check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: true }); Object.defineProperty(gsobj, "baz", { configurable: false }); -expectTypeError(function() { gsobj.__defineSetter__("baz", s2); }); -expectTypeError(function() { gsobj.__defineSetter__("baz", s3); }); +assert.throws(TypeError, function() { gsobj.__defineSetter__("baz", s2); }); +assert.throws(TypeError, function() { gsobj.__defineSetter__("baz", s3); }); check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: false }); /******************************************************************************/ @@ -169,8 +155,8 @@ sgobj.__defineSetter__("baz", s4); check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: true }); Object.defineProperty(sgobj, "baz", { configurable: false }); -expectTypeError(function() { sgobj.__defineGetter__("baz", g3); }); -expectTypeError(function() { sgobj.__defineSetter__("baz", s4); }); +assert.throws(TypeError, function() { sgobj.__defineGetter__("baz", g3); }); +assert.throws(TypeError, function() { sgobj.__defineSetter__("baz", s4); }); check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: false }); /******************************************************************************/ @@ -231,7 +217,7 @@ check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurabl Object.defineProperty(gncover, "moo", { configurable: false }); check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); -expectTypeError(function() { gncover.__defineGetter__("moo", g7); }); +assert.throws(TypeError, function() { gncover.__defineGetter__("moo", g7); }); check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); /******************************************************************************/ @@ -244,7 +230,7 @@ check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurabl Object.defineProperty(sncover, "moo", { configurable: false }); check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); -expectTypeError(function() { sncover.__defineSetter__("moo", s7); }); +assert.throws(TypeError, function() { sncover.__defineSetter__("moo", s7); }); check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false }); /******************************************************************************/ @@ -257,7 +243,7 @@ check(gncwover, "fwoosh", { value: 17, writable: true, enumerable: true, configu Object.defineProperty(gncwover, "fwoosh", { writable: false, configurable: false }); check(gncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); -expectTypeError(function() { gncwover.__defineGetter__("fwoosh", g7); }); +assert.throws(TypeError, function() { gncwover.__defineGetter__("fwoosh", g7); }); check(gncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); /******************************************************************************/ @@ -270,5 +256,5 @@ check(sncwover, "fwoosh", { value: 17, writable: true, enumerable: true, configu Object.defineProperty(sncwover, "fwoosh", { writable: false, configurable: false }); check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); -expectTypeError(function() { sncwover.__defineSetter__("fwoosh", s7); }); +assert.throws(TypeError, function() { sncwover.__defineSetter__("fwoosh", s7); }); check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false }); diff --git a/test/staging/sm/extensions/expression-closure-syntax.js b/test/staging/sm/extensions/expression-closure-syntax.js index a8c0af4ec7..e3a399b3a8 100644 --- a/test/staging/sm/extensions/expression-closure-syntax.js +++ b/test/staging/sm/extensions/expression-closure-syntax.js @@ -16,19 +16,9 @@ esid: pending { function testOne(replacement) { - var x, rv; - try - { - rv = eval(code.replace("@@@", replacement)); - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "should have thrown a SyntaxError, instead got: " + e); - return; - } - - assert.sameValue(true, false, "should have thrown, instead returned " + rv); + assert.throws(SyntaxError, function() { + eval(code.replace("@@@", replacement)); + }); } testOne("function"); diff --git a/test/staging/sm/extensions/extension-methods-reject-null-undefined-this.js b/test/staging/sm/extensions/extension-methods-reject-null-undefined-this.js index 06fe50f278..982511f41d 100644 --- a/test/staging/sm/extensions/extension-methods-reject-null-undefined-this.js +++ b/test/staging/sm/extensions/extension-methods-reject-null-undefined-this.js @@ -39,44 +39,23 @@ function testMethod(Class, className, method) var badThis = badThisValues[i]; expr = className + ".prototype." + method + ".call(" + badThis + ")"; - try - { + assert.throws(TypeError, function() { Class.prototype[method].call(badThis); - throw new Error(expr + " didn't throw a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "wrong error for " + expr + ", instead threw " + e); - } + }, "wrong error for " + expr); expr = className + ".prototype." + method + ".apply(" + badThis + ")"; - try - { + assert.throws(TypeError, function() { Class.prototype[method].apply(badThis); - throw new Error(expr + " didn't throw a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "wrong error for " + expr + ", instead threw " + e); - } + }, "wrong error for " + expr); } // ..and for good measure.. expr = "(0, " + className + ".prototype." + method + ")()" - try - { + assert.throws(TypeError, function() { // comma operator to call GetValue() on the method and de-Reference it (0, Class.prototype[method])(); - throw new Error(expr + " didn't throw a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "wrong error for " + expr + ", instead threw " + e); - } + }, "wrong error for " + expr); } for (var className in ClassToMethodMap) diff --git a/test/staging/sm/extensions/new-cross-compartment.js b/test/staging/sm/extensions/new-cross-compartment.js index d32a7d1cae..3a20c4acac 100644 --- a/test/staging/sm/extensions/new-cross-compartment.js +++ b/test/staging/sm/extensions/new-cross-compartment.js @@ -17,15 +17,9 @@ var otherStr = new g.String("foo"); assert.sameValue(otherStr instanceof g.String, true); assert.sameValue(otherStr.valueOf(), "foo"); -try -{ +// NOTE: not |g.TypeError|, because |new| itself throws because +// |!IsConstructor(constructor)|. +assert.throws(TypeError, function() { var constructor = g.parseInt; new constructor(); - throw new Error("no error thrown"); -} -catch (e) -{ - // NOTE: not |g.TypeError|, because |new| itself throws because - // |!IsConstructor(constructor)|. - assert.sameValue(e instanceof TypeError, true); -} +}); diff --git a/test/staging/sm/extensions/proxy-array-target-length-definition.js b/test/staging/sm/extensions/proxy-array-target-length-definition.js index d1e3d5472a..210a2b7371 100644 --- a/test/staging/sm/extensions/proxy-array-target-length-definition.js +++ b/test/staging/sm/extensions/proxy-array-target-length-definition.js @@ -14,21 +14,11 @@ esid: pending var arr = []; var p = new Proxy(arr, {}); -function assertThrowsTypeError(f) -{ - try { - f(); - assert.sameValue(false, true, "Must have thrown"); - } catch (e) { - assert.sameValue(e instanceof TypeError, true, "Must have thrown TypeError"); - } -} - // Redefining non-configurable length should throw a TypeError -assertThrowsTypeError(function () { Object.defineProperty(p, "length", { value: 17, configurable: true }); }); +assert.throws(TypeError, function () { Object.defineProperty(p, "length", { value: 17, configurable: true }); }); // Same here. -assertThrowsTypeError(function () { Object.defineProperty(p, "length", { value: 42, enumerable: true }); }); +assert.throws(TypeError, function () { Object.defineProperty(p, "length", { value: 42, enumerable: true }); }); // Check the property went unchanged. var pd = Object.getOwnPropertyDescriptor(p, "length"); diff --git a/test/staging/sm/extensions/regress-469625-01.js b/test/staging/sm/extensions/regress-469625-01.js index 2cdddc68cd..ef3a85ed6a 100644 --- a/test/staging/sm/extensions/regress-469625-01.js +++ b/test/staging/sm/extensions/regress-469625-01.js @@ -11,27 +11,8 @@ description: | esid: pending ---*/ -var actual = ''; -var expect = ''; +Array.prototype.__proto__ = function () { return 3; }; -//----------------------------------------------------------------------------- -test(); -//----------------------------------------------------------------------------- - -function test() -{ - expect = 'TypeError: [].__proto__ is not a function'; - - Array.prototype.__proto__ = function () { return 3; }; - - try - { - [].__proto__(); - } - catch(ex) - { - actual = ex + ''; - } - - assert.sameValue(expect, actual); -} +assert.throws(TypeError, function() { + [].__proto__(); +}); diff --git a/test/staging/sm/extensions/regress-bug629723.js b/test/staging/sm/extensions/regress-bug629723.js index 994ec88a95..3414dc8666 100644 --- a/test/staging/sm/extensions/regress-bug629723.js +++ b/test/staging/sm/extensions/regress-bug629723.js @@ -8,19 +8,10 @@ description: | pending esid: pending ---*/ + function f(foo) { "use strict"; foo.bar; } -var actual; -try { - f(); - actual = "no error"; -} catch (x) { - actual = (x instanceof TypeError) ? "type error" : "some other error"; - actual += (/use strict/.test(x)) ? " with directive" : " without directive"; -} - -assert.sameValue("type error without directive", actual, - "decompiled expressions in error messages should not include directive prologues"); +assert.throws(TypeError, f); diff --git a/test/staging/sm/extensions/typedarray-copyWithin-arguments-detaching.js b/test/staging/sm/extensions/typedarray-copyWithin-arguments-detaching.js index 5168b6fd00..9ca6ddf071 100644 --- a/test/staging/sm/extensions/typedarray-copyWithin-arguments-detaching.js +++ b/test/staging/sm/extensions/typedarray-copyWithin-arguments-detaching.js @@ -26,17 +26,10 @@ function testBegin() var ta = new Uint8Array(ab); - var ok = false; - try - { + assert.throws(TypeError, function() { ta.copyWithin(0, begin, 0x1000); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "start weirdness should have thrown"); - assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); + }, "begin weirdness should have thrown"); + assert.sameValue(ab.byteLength, 0, "detaching should work for begin weirdness"); } testBegin(); @@ -55,17 +48,10 @@ function testEnd() var ta = new Uint8Array(ab); - var ok = false; - try - { + assert.throws(TypeError, function() { ta.copyWithin(0, 0x800, end); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "start weirdness should have thrown"); - assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); + }, "end weirdness should have thrown"); + assert.sameValue(ab.byteLength, 0, "detaching should work for end weirdness"); } testEnd(); @@ -84,16 +70,9 @@ function testDest() var ta = new Uint8Array(ab); - var ok = false; - try - { + assert.throws(TypeError, function() { ta.copyWithin(dest, 0x800, 0x1000); - } - catch (e) - { - ok = true; - } - assert.sameValue(ok, true, "start weirdness should have thrown"); - assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); + }, "dest weirdness should have thrown"); + assert.sameValue(ab.byteLength, 0, "detaching should work for dest weirdness"); } testDest(); diff --git a/test/staging/sm/extensions/weakmap.js b/test/staging/sm/extensions/weakmap.js index 913e3dfd43..5ad1b48777 100644 --- a/test/staging/sm/extensions/weakmap.js +++ b/test/staging/sm/extensions/weakmap.js @@ -15,46 +15,12 @@ test(); function test() { - var TestPassCount = 0; - var TestFailCount = 0; - var TestTodoCount = 0; - - var TODO = 1; - - function check(fun, todo) { - var thrown = null; - var success = false; - try { - success = fun(); - } catch (x) { - thrown = x; - } - - if (thrown) - success = false; - - if (todo) { - TestTodoCount++; - - return; - } - - if (success) { - TestPassCount++; - } else { - TestFailCount++; - } + function check(fun) { + assert.sameValue(fun(), true); } - function checkThrows(fun, todo) { - let thrown = false; - try { - fun(); - } catch (x) { - thrown = true; - } - - check(() => thrown, todo); + function checkThrows(fun) { + assert.throws(TypeError, fun); } var key = {}; @@ -93,6 +59,4 @@ function test() check(() => map.get(key) == undefined); checkThrows(() => map.set("non-object key", value)); - - assert.sameValue(0, TestFailCount, "weak map tests"); } diff --git a/test/staging/sm/generators/syntax.js b/test/staging/sm/generators/syntax.js index 631bd06554..4731dd1f3c 100644 --- a/test/staging/sm/generators/syntax.js +++ b/test/staging/sm/generators/syntax.js @@ -17,17 +17,10 @@ esid: pending function assertSyntaxError(str) { var msg; var evil = eval; - try { + assert.throws(SyntaxError, function() { // Non-direct eval. evil(str); - } catch (exc) { - if (exc instanceof SyntaxError) - return; - msg = "Assertion failed: expected SyntaxError, got " + exc; - } - if (msg === undefined) - msg = "Assertion failed: expected SyntaxError, but no exception thrown"; - throw new Error(msg + " - " + str); + }); } // Yield statements. diff --git a/test/staging/sm/global/bug660612.js b/test/staging/sm/global/bug660612.js index 7d37f04262..c0de147249 100644 --- a/test/staging/sm/global/bug660612.js +++ b/test/staging/sm/global/bug660612.js @@ -8,9 +8,7 @@ description: | pending esid: pending ---*/ -try { - decodeURIComponent('%ED%A0%80'); - assert.sameValue(true, false, "expected an URIError"); -} catch (e) { - assert.sameValue(e instanceof URIError, true); -} + +assert.throws(URIError, function() { + decodeURIComponent('%ED%A0%80'); +}); diff --git a/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-label.js b/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-label.js index 22df8691fb..7a8d270a17 100644 --- a/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-label.js +++ b/test/staging/sm/lexical-environment/block-scoped-functions-annex-b-label.js @@ -8,32 +8,23 @@ description: | pending esid: pending ---*/ -function expectSyntaxError(str) { - var threwSyntaxError; - try { - eval(str); - } catch (e) { - threwSyntaxError = e instanceof SyntaxError; - } - assert.sameValue(threwSyntaxError, true); - try { +function expectSyntaxError(str) { + assert.throws(SyntaxError, function() { + eval(str); + }); + + assert.throws(SyntaxError, function() { eval('"use strict";' + str); - } catch (e) { - threwSyntaxError = e instanceof SyntaxError; - } - assert.sameValue(threwSyntaxError, true); + }); } function expectSloppyPass(str) { eval(str); - try { + assert.throws(SyntaxError, function() { eval('"use strict";' + str); - } catch (e) { - threwSyntaxError = e instanceof SyntaxError; - } - assert.sameValue(threwSyntaxError, true); + }); } expectSloppyPass(`l: function f1() {}`); @@ -49,4 +40,3 @@ expectSyntaxError(`while (0) l: function f5() {}`); expectSyntaxError(`for (;;) l: function f6() {}`); expectSloppyPass(`switch (1) { case 1: l: function f7() {} }`); expectSloppyPass(`switch (1) { case 1: assert.sameValue(f8(), 'f8'); case 2: l: function f8() { return 'f8'; } } assert.sameValue(f8(), 'f8');`); - diff --git a/test/staging/sm/lexical-environment/block-scoped-functions-deprecated-redecl.js b/test/staging/sm/lexical-environment/block-scoped-functions-deprecated-redecl.js index 6b1d76d9ff..ada1357a95 100644 --- a/test/staging/sm/lexical-environment/block-scoped-functions-deprecated-redecl.js +++ b/test/staging/sm/lexical-environment/block-scoped-functions-deprecated-redecl.js @@ -8,6 +8,7 @@ description: | pending esid: pending ---*/ + { assert.sameValue(f(), 4); function f() { return 3; } @@ -46,41 +47,27 @@ function test() { test(); -var log = ''; - -try { - // Strict mode still cannot redeclare. +// Strict mode still cannot redeclare. +assert.throws(SyntaxError, function() { eval(`"use strict"; { function f() { } function f() { } }`); -} catch (e) { - assert.sameValue(e instanceof SyntaxError, true); - log += 'e'; -} +}); -try { - // Redeclaring an explicitly 'let'-declared binding doesn't work. +// Redeclaring an explicitly 'let'-declared binding doesn't work. +assert.throws(SyntaxError, function() { eval(`{ let x = 42; function x() {} }`); -} catch (e) { - assert.sameValue(e instanceof SyntaxError, true); - log += 'e'; -} +}); -try { - // Redeclaring an explicitly 'const'-declared binding doesn't work. +// Redeclaring an explicitly 'const'-declared binding doesn't work. +assert.throws(SyntaxError, function() { eval(`{ const x = 42; function x() {} }`); -} catch (e) { - assert.sameValue(e instanceof SyntaxError, true); - log += 'e'; -} - -assert.sameValue(log, 'eee'); - +}); diff --git a/test/staging/sm/lexical-environment/block-scoped-functions-hoisted-tdz.js b/test/staging/sm/lexical-environment/block-scoped-functions-hoisted-tdz.js index 60e8cb31c1..d64daef0ee 100644 --- a/test/staging/sm/lexical-environment/block-scoped-functions-hoisted-tdz.js +++ b/test/staging/sm/lexical-environment/block-scoped-functions-hoisted-tdz.js @@ -8,31 +8,19 @@ description: | pending esid: pending ---*/ -var log = ""; -try { - (function() { - { - let y = f(); - function f() { y; } - } - })() -} catch (e) { - log += e instanceof ReferenceError; -} -try { - function f() { - switch (1) { - case 0: - let x; - case 1: - (function() { x; })(); - } +assert.throws(ReferenceError, function() { + { + let y = f(); + function f() { y; } } - f(); -} catch (e) { - log += e instanceof ReferenceError; -} - -assert.sameValue(log, "truetrue"); +}); +assert.throws(ReferenceError, function() { + switch (1) { + case 0: + let x; + case 1: + (function() { x; })(); + } +}); diff --git a/test/staging/sm/lexical-environment/for-loop.js b/test/staging/sm/lexical-environment/for-loop.js index d452ca19a2..17005a002e 100644 --- a/test/staging/sm/lexical-environment/for-loop.js +++ b/test/staging/sm/lexical-environment/for-loop.js @@ -13,16 +13,9 @@ esid: pending function isError(code, type) { - try - { + assert.throws(type, function() { Function(code); - throw new Error("didn't throw"); - } - catch (e) - { - assert.sameValue(e instanceof type, true, - "unexpected error for `" + code + "`: got " + e); - } + }); } function isOK(code) diff --git a/test/staging/sm/misc/builtin-methods-reject-null-undefined-this.js b/test/staging/sm/misc/builtin-methods-reject-null-undefined-this.js index 6713320dc5..0c8a9a2b3a 100644 --- a/test/staging/sm/misc/builtin-methods-reject-null-undefined-this.js +++ b/test/staging/sm/misc/builtin-methods-reject-null-undefined-this.js @@ -92,44 +92,24 @@ function testMethod(Class, className, method) var badThis = badThisValues[i]; expr = className + ".prototype." + method + ".call(" + badThis + ")"; - try - { + assert.throws(TypeError, function() { Class.prototype[method].call(badThis); - throw new Error(expr + " didn't throw a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "wrong error for " + expr + ", instead threw " + e); - } + }, "wrong error for " + expr); + expr = className + ".prototype." + method + ".apply(" + badThis + ")"; - try - { + assert.throws(TypeError, function() { Class.prototype[method].apply(badThis); - throw new Error(expr + " didn't throw a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "wrong error for " + expr + ", instead threw " + e); - } + }, "wrong error for " + expr); } // ..and for good measure.. - expr = "(0, " + className + ".prototype." + method + ")()" - try - { + expr = "(0, " + className + ".prototype." + method + ")()"; + assert.throws(TypeError, function() { // comma operator to call GetValue() on the method and de-Reference it (0, Class.prototype[method])(); - throw new Error(expr + " didn't throw a TypeError"); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "wrong error for " + expr + ", instead threw " + e); - } + }, "wrong error for " + expr); } for (var className in ClassToMethodMap) diff --git a/test/staging/sm/misc/future-reserved-words.js b/test/staging/sm/misc/future-reserved-words.js index ac26e1d017..45052ef699 100644 --- a/test/staging/sm/misc/future-reserved-words.js +++ b/test/staging/sm/misc/future-reserved-words.js @@ -14,7 +14,7 @@ esid: pending var futureReservedWords = [ "class", - // "const", // Mozilla extension enabled even for versionless code + "const", "enum", "export", "extends", @@ -26,459 +26,97 @@ var strictFutureReservedWords = [ "implements", "interface", - "let", // enabled: this file doesn't execute as JS1.7 + "let", "package", "private", "protected", "public", "static", - "yield", // enabled: this file doesn't execute as JS1.7 + "yield", ]; -function testWord(word, expectNormal, expectStrict) -{ - var actual, status; +function testNormalAndStrict(word, code, message) { + if (strictFutureReservedWords.includes(word)) { + eval(code); + } else { + assert(futureReservedWords.includes(word)); + assert.throws(SyntaxError, function() { + eval(code); + }, word + ": normal " + message); + } + assert.throws(SyntaxError, function() { + eval("'use strict'; " + code); + }, word + ": strict " + message); +} + +function testWord(word) { // USE AS LHS FOR ASSIGNMENT - - actual = ""; - status = word + ": normal assignment"; - try - { - eval(word + " = 'foo';"); - actual = "no error"; - } - catch(e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict assignment"; - try - { - eval("'use strict'; " + word + " = 'foo';"); - actual = "no error"; - } - catch(e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + testNormalAndStrict(word, word + " = 'foo';", "assignment"); // USE AS DESTRUCTURING SHORTHAND - - actual = ""; - status = word + ": destructuring shorthand"; - try - { - eval("({ " + word + " } = 'foo');"); - actual = "no error"; - } - catch(e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict destructuring shorthand"; - try - { - eval("'use strict'; ({ " + word + " } = 'foo');"); - actual = "no error"; - } - catch(e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + testNormalAndStrict(word, "({ " + word + " } = 'foo');", "destructuring shorthand"); // USE IN VARIABLE DECLARATION - - actual = ""; - status = word + ": normal var"; - try - { - eval("var " + word + ";"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict var"; - try - { - eval("'use strict'; var " + word + ";"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + testNormalAndStrict(word, "var " + word + ";", "var"); // USE IN FOR-IN VARIABLE DECLARATION - - actual = ""; - status = word + ": normal for-in var"; - try - { - eval("for (var " + word + " in {});"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict for-in var"; - try - { - eval("'use strict'; for (var " + word + " in {});"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + testNormalAndStrict(word, "for (var " + word + " in {});", "for-in var"); // USE AS CATCH IDENTIFIER - - actual = ""; - status = word + ": normal var"; - try - { - eval("try { } catch (" + word + ") { }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict var"; - try - { - eval("'use strict'; try { } catch (" + word + ") { }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + testNormalAndStrict(word, "try { } catch (" + word + ") { }", "catch var"); // USE AS LABEL - - actual = ""; - status = word + ": normal label"; - try - { - eval(word + ": while (false);"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict label"; - try - { - eval("'use strict'; " + word + ": while (false);"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + testNormalAndStrict(word, word + ": while (false);", "label"); // USE AS ARGUMENT NAME IN FUNCTION DECLARATION + testNormalAndStrict(word, "function foo(" + word + ") { }", "function argument"); - actual = ""; - status = word + ": normal function argument"; - try - { - eval("function foo(" + word + ") { }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict function argument"; - try - { - eval("'use strict'; function foo(" + word + ") { }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); - - actual = ""; - status = word + ": function argument retroactively strict"; - try - { + assert.throws(SyntaxError, function() { eval("function foo(" + word + ") { 'use strict'; }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + }, word + ": function argument retroactively strict"); // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION + testNormalAndStrict(word, "var s = (function foo(" + word + ") { });", "function expression argument"); - actual = ""; - status = word + ": normal function expression argument"; - try - { - eval("var s = (function foo(" + word + ") { });"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict function expression argument"; - try - { - eval("'use strict'; var s = (function foo(" + word + ") { });"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); - - actual = ""; - status = word + ": function expression argument retroactively strict"; - try - { + assert.throws(SyntaxError, function() { eval("var s = (function foo(" + word + ") { 'use strict'; });"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + }, word + ": function expression argument retroactively strict"); // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR - - actual = ""; - status = word + ": argument with normal Function"; - try - { + if (strictFutureReservedWords.includes(word)) { Function(word, "return 17"); - actual = "no error"; + } else { + assert.throws(SyntaxError, function() { + Function(word, "return 17"); + }, word + ": argument with normal Function"); } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - actual = ""; - status = word + ": argument with strict Function"; - try - { + assert.throws(SyntaxError, function() { Function(word, "'use strict'; return 17"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + }, word + ": argument with strict Function"); // USE AS ARGUMENT NAME IN PROPERTY SETTER + testNormalAndStrict(word, "var o = { set x(" + word + ") { } };", "property setter argument"); - actual = ""; - status = word + ": normal property setter argument"; - try - { - eval("var o = { set x(" + word + ") { } };"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict property setter argument"; - try - { - eval("'use strict'; var o = { set x(" + word + ") { } };"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); - - actual = ""; - status = word + ": property setter argument retroactively strict"; - try - { + assert.throws(SyntaxError, function() { eval("var o = { set x(" + word + ") { 'use strict'; } };"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + }, word + ": property setter argument retroactively strict"); // USE AS FUNCTION NAME IN FUNCTION DECLARATION + testNormalAndStrict(word, "function " + word + "() { }", "function name"); - actual = ""; - status = word + ": normal function name"; - try - { - eval("function " + word + "() { }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict function name"; - try - { - eval("'use strict'; function " + word + "() { }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); - - actual = ""; - status = word + ": function name retroactively strict"; - try - { + assert.throws(SyntaxError, function() { eval("function " + word + "() { 'use strict'; }"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + }, word + ": function name retroactively strict"); // USE AS FUNCTION NAME IN FUNCTION EXPRESSION + testNormalAndStrict(word, "var s = (function " + word + "() { });", "function expression name"); - actual = ""; - status = word + ": normal function expression name"; - try - { - eval("var s = (function " + word + "() { });"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectNormal, status); - - actual = ""; - status = word + ": strict function expression name"; - try - { - eval("'use strict'; var s = (function " + word + "() { });"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); - - actual = ""; - status = word + ": function expression name retroactively strict"; - try - { + assert.throws(SyntaxError, function() { eval("var s = (function " + word + "() { 'use strict'; });"); - actual = "no error"; - } - catch (e) - { - actual = e.name; - status += ", " + e.name + ": " + e.message + " "; - } - assert.sameValue(actual, expectStrict, status); + }, word + ": function expression name retroactively strict"); } -function testFutureReservedWord(word) -{ - testWord(word, "SyntaxError", "SyntaxError"); -} - -function testStrictFutureReservedWord(word) -{ - testWord(word, "no error", "SyntaxError"); -} - -futureReservedWords.forEach(testFutureReservedWord); -strictFutureReservedWords.forEach(testStrictFutureReservedWord); +futureReservedWords.forEach(testWord); +strictFutureReservedWords.forEach(testWord); diff --git a/test/staging/sm/misc/global-numeric-properties.js b/test/staging/sm/misc/global-numeric-properties.js index 6ce3ca9985..3f38822719 100644 --- a/test/staging/sm/misc/global-numeric-properties.js +++ b/test/staging/sm/misc/global-numeric-properties.js @@ -11,7 +11,7 @@ description: | esid: pending ---*/ -var desc, old, error; +var desc, old; var global = this; var names = ["NaN", "Infinity", "undefined"]; @@ -29,22 +29,8 @@ for (var i = 0; i < names.length; i++) global[name] = 17; assert.sameValue(global[name], old, name + " changed on setting?"); - error = "before"; - try - { - throw new TypeError("SpiderMonkey doesn't currently implement " + - "strict-mode throwing when setting a readonly " + - "property, not running this bit of test for now; " + - "see bug 537873"); - - (function() { "use strict"; global[name] = 42; error = "didn't throw"; })(); - } - catch (e) - { - if (e instanceof TypeError) - error = "typeerror"; - else - error = "bad exception: " + e; - } - assert.sameValue(error, "typeerror", "wrong strict mode error setting " + name); + assert.throws(TypeError, function() { + "use strict"; + global[name] = 42; + }, "wrong strict mode error setting " + name); } diff --git a/test/staging/sm/misc/new-with-non-constructor.js b/test/staging/sm/misc/new-with-non-constructor.js index 574f78f18b..20a78c8992 100644 --- a/test/staging/sm/misc/new-with-non-constructor.js +++ b/test/staging/sm/misc/new-with-non-constructor.js @@ -10,14 +10,11 @@ description: | pending esid: pending ---*/ + function checkConstruct(thing) { - try { - new thing(); - assert.sameValue(0, 1, "not reached " + thing); - } catch (e) { - assert.sameValue(e.message.includes(" is not a constructor") || - e.message === "Function.prototype.toString called on incompatible object", true); - } + assert.throws(TypeError, function() { + new thing(); + }); } var re = /aaa/ @@ -34,4 +31,3 @@ checkConstruct(proxiedFunctionPrototype); var proxiedBuiltin = new Proxy(parseInt, {}); checkConstruct(proxiedBuiltin); - diff --git a/test/staging/sm/misc/syntax-error-end-of-for-head-part.js b/test/staging/sm/misc/syntax-error-end-of-for-head-part.js index 0eee14a67f..3fbf89888d 100644 --- a/test/staging/sm/misc/syntax-error-end-of-for-head-part.js +++ b/test/staging/sm/misc/syntax-error-end-of-for-head-part.js @@ -13,16 +13,9 @@ esid: pending function checkSyntaxError(str) { - try - { - var f = Function("for(w in\\"); - throw new Error("didn't throw, returned " + f); - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "expected SyntaxError, got " + e); - } + assert.throws(SyntaxError, function() { + Function(str); + }); } checkSyntaxError("for(var w in \\"); diff --git a/test/staging/sm/misc/unicode-escaped-keyword.js b/test/staging/sm/misc/unicode-escaped-keyword.js index fa4e5848bf..07a5aca0a3 100644 --- a/test/staging/sm/misc/unicode-escaped-keyword.js +++ b/test/staging/sm/misc/unicode-escaped-keyword.js @@ -10,18 +10,14 @@ description: | pending esid: pending ---*/ + function throws(code) { - var type; - try { - eval(code); - } catch (ex) { - type = ex.name; - } - assert.sameValue(type, 'SyntaxError'); + assert.throws(SyntaxError, function() { + eval(code); + }); } var s = '\\u0073'; throws('var thi' + s); throws('switch (' + s + 'witch) {}') throws('var ' + s + 'witch'); - diff --git a/test/staging/sm/misc/unicode-identifier-1d17.js b/test/staging/sm/misc/unicode-identifier-1d17.js index c286d7209f..2e9fcb396f 100644 --- a/test/staging/sm/misc/unicode-identifier-1d17.js +++ b/test/staging/sm/misc/unicode-identifier-1d17.js @@ -10,12 +10,7 @@ description: | pending esid: pending ---*/ -var o = {} -try { - eval('o.\\u1d17 = 42;'); -} -catch (e) { - assert.sameValue('should not fail', true); -} -assert.sameValue(o['\u1d17'], 42); +var o = {} +eval('o.\\u1d17 = 42;'); +assert.sameValue(o['\u1d17'], 42); diff --git a/test/staging/sm/misc/unicode-identifier-82f1.js b/test/staging/sm/misc/unicode-identifier-82f1.js index 709d0afa1d..483d2b4cbb 100644 --- a/test/staging/sm/misc/unicode-identifier-82f1.js +++ b/test/staging/sm/misc/unicode-identifier-82f1.js @@ -10,12 +10,7 @@ description: | pending esid: pending ---*/ -var o = {} -try { - eval('o.\\u82f1 = 42;'); -} -catch (e) { - assert.sameValue('should not fail', true); -} -assert.sameValue(o['\u82f1'], 42); +var o = {} +eval('o.\\u82f1 = 42;'); +assert.sameValue(o['\u82f1'], 42); diff --git a/test/staging/sm/object/15.2.3.5-01.js b/test/staging/sm/object/15.2.3.5-01.js index 3c0d65652a..f1e2c495ad 100644 --- a/test/staging/sm/object/15.2.3.5-01.js +++ b/test/staging/sm/object/15.2.3.5-01.js @@ -42,11 +42,8 @@ assert.sameValue(Object.getOwnPropertyDescriptor(o, "baz"), undefined); assert.sameValue(o.baz, 12); assert.sameValue(o.hasOwnProperty("baz"), false); -try { - var actual = - Object.create(Object.create({}, - { boom: { get: function() { return "base"; }}}), - { boom: { get: function() { return "overridden"; }}}).boom -} catch (e) { -} +var actual = + Object.create(Object.create({}, + { boom: { get: function() { return "base"; }}}), + { boom: { get: function() { return "overridden"; }}}).boom assert.sameValue(actual, "overridden"); diff --git a/test/staging/sm/object/15.2.3.7-01.js b/test/staging/sm/object/15.2.3.7-01.js index 88aa00ff6d..0a55e723f9 100644 --- a/test/staging/sm/object/15.2.3.7-01.js +++ b/test/staging/sm/object/15.2.3.7-01.js @@ -41,20 +41,10 @@ props = c: { value: NaN, enumerable: false, configurable: true, writable: true }, b: { value: 44 } }; -var error = "before"; -try -{ + +assert.throws(TypeError, function() { Object.defineProperties(o, props); - error = "no exception thrown"; -} -catch (e) -{ - if (e instanceof TypeError) - error = "typeerror"; - else - error = "bad exception: " + e; -} -assert.sameValue(error, "typeerror", "didn't throw or threw wrongly"); +}); assert.sameValue("c" in o, true, "new property added"); assert.sameValue(o.b, 42, "old property value preserved"); @@ -84,46 +74,14 @@ assert.sameValue("bar" in o, false, "bar is not an enumerable own property"); Object.defineProperties(o, ""); assert.sameValue("quux" in o, false, "quux is not an enumerable own property"); -error = "before"; -try -{ +assert.throws(TypeError, function() { Object.defineProperties(o, "1"); -} -catch (e) -{ - if (e instanceof TypeError) - error = "typeerror"; - else - error = "bad exception: " + e; -} -assert.sameValue(error, "typeerror", - "should throw on Properties == '1' due to '1'[0] not being a " + - "property descriptor"); +}, "should throw on Properties == '1' due to '1'[0] not being a property descriptor"); -error = "before"; -try -{ +assert.throws(TypeError, function() { Object.defineProperties(o, null); -} -catch (e) -{ - if (e instanceof TypeError) - error = "typeerror"; - else - error = "bad exception: " + e; -} -assert.sameValue(error, "typeerror", "should throw on Properties == null"); +}, "should throw on Properties == null"); -error = "before"; -try -{ +assert.throws(TypeError, function() { Object.defineProperties(o, undefined); -} -catch (e) -{ - if (e instanceof TypeError) - error = "typeerror"; - else - error = "bad exception: " + e; -} -assert.sameValue(error, "typeerror", "should throw on Properties == undefined"); +}, "should throw on Properties == undefined"); diff --git a/test/staging/sm/object/extensibility-01.js b/test/staging/sm/object/extensibility-01.js index 90234224ff..931bd4ca3f 100644 --- a/test/staging/sm/object/extensibility-01.js +++ b/test/staging/sm/object/extensibility-01.js @@ -11,56 +11,31 @@ description: | esid: pending ---*/ -function trySetProperty(o, p, v, strict) +function tryStrictSetProperty(o, p, v) { - function strictSetProperty() - { + assert.sameValue(Object.prototype.hasOwnProperty.call(o, p), false); + assert.throws(TypeError, function() { "use strict"; o[p] = v; - } - - function setProperty() - { - o[p] = v; - } + }); +} +function trySetProperty(o, p, v) +{ assert.sameValue(Object.prototype.hasOwnProperty.call(o, p), false); - try - { - if (strict) - strictSetProperty(); - else - setProperty(); - if (o[p] === v) - return "set"; - if (p in o) - return "set-converted"; - return "swallowed"; - } - catch (e) - { - return "throw"; - } + o[p] = v; + + assert.notSameValue(o[p], v); + assert.sameValue(p in o, false); } function tryDefineProperty(o, p, v) { assert.sameValue(Object.prototype.hasOwnProperty.call(o, p), false); - - try - { + assert.throws(TypeError, function() { Object.defineProperty(o, p, { value: v }); - if (o[p] === v) - return "set"; - if (p in o) - return "set-converted"; - return "swallowed"; - } - catch (e) - { - return "throw"; - } + }); } assert.sameValue(typeof Object.preventExtensions, "function"); @@ -81,12 +56,7 @@ for (var i = 0, sz = objs.length; i < sz; i++) assert.sameValue(Object.isExtensible(o), false, "object " + i + " is extensible?"); - assert.sameValue(trySetProperty(o, "baz", 17, true), "throw", - "unexpected behavior for strict-mode property-addition to " + - "object " + i); - assert.sameValue(trySetProperty(o, "baz", 17, false), "swallowed", - "unexpected behavior for property-addition to object " + i); - - assert.sameValue(tryDefineProperty(o, "baz", 17), "throw", - "unexpected behavior for new property definition on object " + i); + tryStrictSetProperty(o, "baz", 17); + trySetProperty(o, "baz", 17); + tryDefineProperty(o, "baz", 17); } diff --git a/test/staging/sm/object/isPrototypeOf.js b/test/staging/sm/object/isPrototypeOf.js index 57094e7690..8a585318a0 100644 --- a/test/staging/sm/object/isPrototypeOf.js +++ b/test/staging/sm/object/isPrototypeOf.js @@ -11,20 +11,6 @@ description: | esid: pending ---*/ -function expectThrowTypeError(fun) -{ - try - { - var r = fun(); - throw new Error("didn't throw TypeError, returned " + r); - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "didn't throw TypeError, got: " + e); - } -} - var isPrototypeOf = Object.prototype.isPrototypeOf; /* @@ -48,12 +34,12 @@ assert.sameValue(isPrototypeOf(null), false); * argument. */ var protoGlobal = Object.create(this); -expectThrowTypeError(function() { isPrototypeOf.call(null, {}); }); -expectThrowTypeError(function() { isPrototypeOf.call(undefined, {}); }); -expectThrowTypeError(function() { isPrototypeOf({}); }); -expectThrowTypeError(function() { isPrototypeOf.call(null, protoGlobal); }); -expectThrowTypeError(function() { isPrototypeOf.call(undefined, protoGlobal); }); -expectThrowTypeError(function() { isPrototypeOf(protoGlobal); }); +assert.throws(TypeError, function() { isPrototypeOf.call(null, {}); }); +assert.throws(TypeError, function() { isPrototypeOf.call(undefined, {}); }); +assert.throws(TypeError, function() { isPrototypeOf({}); }); +assert.throws(TypeError, function() { isPrototypeOf.call(null, protoGlobal); }); +assert.throws(TypeError, function() { isPrototypeOf.call(undefined, protoGlobal); }); +assert.throws(TypeError, function() { isPrototypeOf(protoGlobal); }); /* diff --git a/test/staging/sm/object/propertyIsEnumerable.js b/test/staging/sm/object/propertyIsEnumerable.js index 342c3065c5..b309349374 100644 --- a/test/staging/sm/object/propertyIsEnumerable.js +++ b/test/staging/sm/object/propertyIsEnumerable.js @@ -11,25 +11,6 @@ description: | esid: pending ---*/ -function expectThrowError(errorCtor, fun) -{ - try - { - var r = fun(); - throw "didn't throw TypeError, returned " + r; - } - catch (e) - { - assert.sameValue(e instanceof errorCtor, true, - "didn't throw " + errorCtor.prototype.name + ", got: " + e); - } -} - -function expectThrowTypeError(fun) -{ - expectThrowError(TypeError, fun); -} - function withToString(fun) { return { toString: fun }; @@ -45,106 +26,106 @@ var propertyIsEnumerable = Object.prototype.propertyIsEnumerable; /* * 1. Let P be ToString(V). */ -expectThrowError(ReferenceError, function() +assert.throws(ReferenceError, function() { propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; })); }); -expectThrowError(ReferenceError, function() +assert.throws(ReferenceError, function() { propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; })); }); -expectThrowError(ReferenceError, function() +assert.throws(ReferenceError, function() { propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; })); }); -expectThrowError(ReferenceError, function() +assert.throws(ReferenceError, function() { propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; })); }); -expectThrowError(ReferenceError, function() +assert.throws(ReferenceError, function() { propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; })); }); -expectThrowError(ReferenceError, function() +assert.throws(ReferenceError, function() { propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; })); }); -expectThrowError(SyntaxError, function() +assert.throws(SyntaxError, function() { propertyIsEnumerable(withToString(function() { eval("}"); })); }); -expectThrowError(SyntaxError, function() +assert.throws(SyntaxError, function() { propertyIsEnumerable.call(null, withToString(function() { eval("}"); })); }); -expectThrowError(SyntaxError, function() +assert.throws(SyntaxError, function() { propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); })); }); -expectThrowError(SyntaxError, function() +assert.throws(SyntaxError, function() { propertyIsEnumerable(withValueOf(function() { eval("}"); })); }); -expectThrowError(SyntaxError, function() +assert.throws(SyntaxError, function() { propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); })); }); -expectThrowError(SyntaxError, function() +assert.throws(SyntaxError, function() { propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable(withToString(function() { [].length = -1; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(null, withToString(function() { [].length = -1; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable(withValueOf(function() { [].length = -1; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable(withToString(function() { [].length = 0.7; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable(withValueOf(function() { [].length = 0.7; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; })); }); -expectThrowError(RangeError, function() +assert.throws(RangeError, function() { propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = 0.7; })); }); @@ -153,19 +134,19 @@ expectThrowError(RangeError, function() * 2. Let O be the result of calling ToObject passing the this value as the * argument. */ -expectThrowTypeError(function() { propertyIsEnumerable("s"); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(null, "s"); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, "s"); }); -expectThrowTypeError(function() { propertyIsEnumerable(true); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(null, true); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, true); }); -expectThrowTypeError(function() { propertyIsEnumerable(NaN); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(null, NaN); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, NaN); }); +assert.throws(TypeError, function() { propertyIsEnumerable("s"); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(null, "s"); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, "s"); }); +assert.throws(TypeError, function() { propertyIsEnumerable(true); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(null, true); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, true); }); +assert.throws(TypeError, function() { propertyIsEnumerable(NaN); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(null, NaN); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, NaN); }); -expectThrowTypeError(function() { propertyIsEnumerable({}); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(null, {}); }); -expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, {}); }); +assert.throws(TypeError, function() { propertyIsEnumerable({}); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(null, {}); }); +assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, {}); }); /* * 3. Let desc be the result of calling the [[GetOwnProperty]] internal method @@ -180,7 +161,7 @@ assert.sameValue(propertyIsEnumerable.call(true, "toString"), false); assert.sameValue(propertyIsEnumerable.call({}, "__proto__"), false); assert.sameValue(propertyIsEnumerable.call(Object, "getOwnPropertyDescriptor"), false); -assert.sameValue(propertyIsEnumerable.call(this, "expectThrowTypeError"), true); +assert.sameValue(propertyIsEnumerable.call(this, "withToString"), true); assert.sameValue(propertyIsEnumerable.call("s", "length"), false); assert.sameValue(propertyIsEnumerable.call("s", 0), true); assert.sameValue(propertyIsEnumerable.call(Number, "MAX_VALUE"), false); diff --git a/test/staging/sm/object/toLocaleString.js b/test/staging/sm/object/toLocaleString.js index 67fe6eaaaf..9111d57ce9 100644 --- a/test/staging/sm/object/toLocaleString.js +++ b/test/staging/sm/object/toLocaleString.js @@ -11,30 +11,16 @@ description: | esid: pending ---*/ -function expectThrowTypeError(fun) -{ - try - { - var r = fun(); - throw "didn't throw TypeError, returned " + r; - } - catch (e) - { - assert.sameValue(e instanceof TypeError, true, - "didn't throw TypeError, got: " + e); - } -} - var toLocaleString = Object.prototype.toLocaleString; /* * 1. Let O be the result of calling ToObject passing the this value as the * argument. */ -expectThrowTypeError(function() { toLocaleString.call(null); }); -expectThrowTypeError(function() { toLocaleString.call(undefined); }); -expectThrowTypeError(function() { toLocaleString.apply(null); }); -expectThrowTypeError(function() { toLocaleString.apply(undefined); }); +assert.throws(TypeError, function() { toLocaleString.call(null); }); +assert.throws(TypeError, function() { toLocaleString.call(undefined); }); +assert.throws(TypeError, function() { toLocaleString.apply(null); }); +assert.throws(TypeError, function() { toLocaleString.apply(undefined); }); /* @@ -53,27 +39,27 @@ catch (e) /* 3. If IsCallable(toString) is false, throw a TypeError exception. */ -expectThrowTypeError(function() { toLocaleString.call({ toString: 12 }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: 0.3423423452352e9 }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: undefined }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: false }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: [] }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: {} }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: new String }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: new Number(7.7) }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: new Boolean(true) }); }); -expectThrowTypeError(function() { toLocaleString.call({ toString: JSON }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: 12 }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: 0.3423423452352e9 }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: undefined }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: false }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: [] }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: {} }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: new String }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: new Number(7.7) }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: new Boolean(true) }); }); +assert.throws(TypeError, function() { toLocaleString.call({ toString: JSON }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 12 }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 0.3423423452352e9 }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: undefined }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: false }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: [] }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: {} }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new String }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Number(7.7) }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Boolean(true) }); }); -expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: JSON }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: 12 }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: 0.3423423452352e9 }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: undefined }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: false }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: [] }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: {} }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: new String }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: new Number(7.7) }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: new Boolean(true) }); }); +assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: JSON }); }); /* diff --git a/test/staging/sm/object/values-entries-typedarray.js b/test/staging/sm/object/values-entries-typedarray.js index 9c211ff315..b36107b469 100644 --- a/test/staging/sm/object/values-entries-typedarray.js +++ b/test/staging/sm/object/values-entries-typedarray.js @@ -9,41 +9,13 @@ description: | pending esid: pending ---*/ + function assertSameEntries(actual, expected) { assert.sameValue(actual.length, expected.length); for (let i = 0; i < expected.length; ++i) assert.compareArray(actual[i], expected[i]); } -function throwsTypeError(fn) { - try { - fn(); - } catch (e) { - assert.sameValue(e instanceof TypeError, true); - return true; - } - return false; -} - -// Non-standard: Accessing elements of detached array buffers should throw, but -// this is currently not implemented. -const ACCESS_ON_DETACHED_ARRAY_BUFFER_THROWS = (() => { - let ta = new Int32Array(10); - $262.detachArrayBuffer(ta.buffer); - let throws = throwsTypeError(() => ta[0]); - // Ensure [[Get]] and [[GetOwnProperty]] return consistent results. - assert.sameValue(throwsTypeError(() => Object.getOwnPropertyDescriptor(ta, 0)), throws); - return throws; -})(); - -function maybeThrowOnDetached(fn, returnValue) { - if (ACCESS_ON_DETACHED_ARRAY_BUFFER_THROWS) { - assert.throws(TypeError, fn); - return returnValue; - } - return fn(); -} - // Ensure Object.keys/values/entries work correctly on typed arrays. for (let len of [0, 1, 10]) { let array = new Array(len).fill(1); @@ -55,8 +27,7 @@ for (let len of [0, 1, 10]) { $262.detachArrayBuffer(ta.buffer); - assert.compareArray(maybeThrowOnDetached(() => Object.keys(ta), []), []); - assert.compareArray(maybeThrowOnDetached(() => Object.values(ta), []), []); - assertSameEntries(maybeThrowOnDetached(() => Object.entries(ta), []), []); + assert.compareArray(Object.keys(ta), []); + assert.compareArray(Object.values(ta), []); + assertSameEntries(Object.entries(ta), []); } - diff --git a/test/staging/sm/regress/regress-410852.js b/test/staging/sm/regress/regress-410852.js index 0a65d50986..a3dcb40317 100644 --- a/test/staging/sm/regress/regress-410852.js +++ b/test/staging/sm/regress/regress-410852.js @@ -11,17 +11,6 @@ description: | esid: pending ---*/ -test(); - -function test() -{ - try - { - eval('function(){if(t)'); - } - catch(ex) - { - assert.sameValue(ex instanceof SyntaxError, true, "wrong error: " + ex); - } - -} +assert.throws(SyntaxError, function() { + eval('function(){if(t)'); +}); diff --git a/test/staging/sm/regress/regress-499524.js b/test/staging/sm/regress/regress-499524.js index 341d753a49..f7b4d6ac6f 100644 --- a/test/staging/sm/regress/regress-499524.js +++ b/test/staging/sm/regress/regress-499524.js @@ -10,15 +10,15 @@ description: | pending esid: pending ---*/ -function isSyntaxError(code) { - try { + +function throwsNoSyntaxError(code) { + eval(code); +}; + +function throwsSyntaxError(code) { + assert.throws(SyntaxError, function() { eval(code); - return false; - } catch (exception) { - if (SyntaxError.prototype.isPrototypeOf(exception)) - return true; - throw exception; - }; + }); }; /* @@ -27,28 +27,27 @@ function isSyntaxError(code) { * user has opted in to a modicum of sanity, and we forbid duplicate * parameter names. */ -assert.sameValue(isSyntaxError("function f(x,x){}"), false); +throwsNoSyntaxError("function f(x,x){}"); -assert.sameValue(isSyntaxError("function f(x,[x]){})"), true); -assert.sameValue(isSyntaxError("function f(x,{y:x}){})"), true); -assert.sameValue(isSyntaxError("function f(x,{x}){})"), true); +throwsSyntaxError("function f(x,[x]){})"); +throwsSyntaxError("function f(x,{y:x}){})"); +throwsSyntaxError("function f(x,{x}){})"); -assert.sameValue(isSyntaxError("function f([x],x){})"), true); -assert.sameValue(isSyntaxError("function f({y:x},x){})"), true); -assert.sameValue(isSyntaxError("function f({x},x){})"), true); +throwsSyntaxError("function f([x],x){})"); +throwsSyntaxError("function f({y:x},x){})"); +throwsSyntaxError("function f({x},x){})"); -assert.sameValue(isSyntaxError("function f([x,x]){}"), true); -assert.sameValue(isSyntaxError("function f({x,x}){}"), true); -assert.sameValue(isSyntaxError("function f({y:x,z:x}){}"), true); +throwsSyntaxError("function f([x,x]){}"); +throwsSyntaxError("function f({x,x}){}"); +throwsSyntaxError("function f({y:x,z:x}){}"); -assert.sameValue(isSyntaxError("function f(x,x,[y]){}"), true); -assert.sameValue(isSyntaxError("function f(x,x,{y}){}"), true); -assert.sameValue(isSyntaxError("function f([y],x,x){}"), true); -assert.sameValue(isSyntaxError("function f({y},x,x){}"), true); - -assert.sameValue(isSyntaxError("function f(a,b,c,d,e,f,g,h,b,[y]){}"), true); -assert.sameValue(isSyntaxError("function f([y],a,b,c,d,e,f,g,h,a){}"), true); -assert.sameValue(isSyntaxError("function f([a],b,c,d,e,f,g,h,i,a){}"), true); -assert.sameValue(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true); -assert.sameValue(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true); +throwsSyntaxError("function f(x,x,[y]){}"); +throwsSyntaxError("function f(x,x,{y}){}"); +throwsSyntaxError("function f([y],x,x){}"); +throwsSyntaxError("function f({y},x,x){}"); +throwsSyntaxError("function f(a,b,c,d,e,f,g,h,b,[y]){}"); +throwsSyntaxError("function f([y],a,b,c,d,e,f,g,h,a){}"); +throwsSyntaxError("function f([a],b,c,d,e,f,g,h,i,a){}"); +throwsSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"); +throwsSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"); diff --git a/test/staging/sm/regress/regress-571014.js b/test/staging/sm/regress/regress-571014.js index b712323fb7..acd475342a 100644 --- a/test/staging/sm/regress/regress-571014.js +++ b/test/staging/sm/regress/regress-571014.js @@ -14,29 +14,19 @@ var F, o; F = function () {}; F.prototype = new ArrayBuffer(1); o = new F(); -try { - o.byteLength; -} catch (ex) { - // o is not a platform object - assert.sameValue(ex instanceof TypeError, true); -} +assert.throws(TypeError, function() { + o.byteLength; +}); o = {}; o.__proto__ = new Int32Array(1); -try { - o.buffer.byteLength; -} catch (ex) { - // o is not a platform object - assert.sameValue(ex instanceof TypeError, true); -} +assert.throws(TypeError, function() { + o.buffer.byteLength; +}); F = function () {}; F.prototype = new Int32Array(1); o = new F(); -try { - o.slice(0, 1); - reportFailure("Expected an exception!"); -} catch (ex) { -} - -assert.sameValue("ok", "ok", "bug 571014"); +assert.throws(TypeError, function() { + o.slice(0, 1); +}); diff --git a/test/staging/sm/regress/regress-573875.js b/test/staging/sm/regress/regress-573875.js index 401b2185e9..bb0114c19d 100644 --- a/test/staging/sm/regress/regress-573875.js +++ b/test/staging/sm/regress/regress-573875.js @@ -10,19 +10,12 @@ description: | pending esid: pending ---*/ + var o = {__iterator__:null, a:1, b:2, c:3} var expect = '__iterator__,a,b,c,'; var actual = ''; -try { - for (var i in o) - actual += i + ','; -} catch (e) { - actual = '' + e; - if (/invalid __iterator__ value/.test(actual) || - /null is not a function/.test(actual)) { - expect = actual; - } -} +for (var i in o) + actual += i + ','; assert.sameValue(expect, actual, "ok"); diff --git a/test/staging/sm/regress/regress-617405-2.js b/test/staging/sm/regress/regress-617405-2.js index 762babff45..d36e12cdb4 100644 --- a/test/staging/sm/regress/regress-617405-2.js +++ b/test/staging/sm/regress/regress-617405-2.js @@ -10,13 +10,12 @@ description: | pending esid: pending ---*/ + function C(){} C.prototype = 1; -try { - Object.defineProperty(C, "prototype", {get: function() { throw 0; }}); - actual = "no exception"; -} catch (exc) { - actual = exc.name; -} + +assert.throws(TypeError, function() { + Object.defineProperty(C, "prototype", {get: function() { throw 0; }}); +}); + new C; // don't assert -assert.sameValue(actual, "TypeError"); diff --git a/test/staging/sm/regress/regress-618572.js b/test/staging/sm/regress/regress-618572.js index 2cf9b11c35..0ce12ee933 100644 --- a/test/staging/sm/regress/regress-618572.js +++ b/test/staging/sm/regress/regress-618572.js @@ -7,31 +7,10 @@ flags: - noStrict description: | - pending + Do not assert when ungetting a Unicode char sequence esid: pending ---*/ -//----------------------------------------------------------------------------- -var BUGNUMBER = 618572; -var summary = 'Do not assert when ungetting a Unicode char sequence'; -var actual = ''; -var expect = ''; -//----------------------------------------------------------------------------- -test(); -//----------------------------------------------------------------------------- - -function test() -{ - expect = 'SyntaxError'; - - try - { - eval("var a\\0021 = 3;"); - } - catch(ex) - { - actual = ex.constructor.name; - } - - assert.sameValue(expect, actual, summary); -} +assert.throws(SyntaxError, function() { + eval("var a\\0021 = 3;"); +}); diff --git a/test/staging/sm/regress/regress-624968.js b/test/staging/sm/regress/regress-624968.js index 8a2dce5a70..4048c59fca 100644 --- a/test/staging/sm/regress/regress-624968.js +++ b/test/staging/sm/regress/regress-624968.js @@ -10,7 +10,7 @@ description: | pending esid: pending ---*/ -try { - new {prototype: TypeError.prototype}; -} catch (e) {} +assert.throws(TypeError, function() { + new {prototype: TypeError.prototype}; +}); diff --git a/test/staging/sm/statements/arrow-function-in-for-statement-head.js b/test/staging/sm/statements/arrow-function-in-for-statement-head.js index 36c177c337..6a3c1ca0b9 100644 --- a/test/staging/sm/statements/arrow-function-in-for-statement-head.js +++ b/test/staging/sm/statements/arrow-function-in-for-statement-head.js @@ -11,13 +11,6 @@ description: | esid: pending ---*/ -try -{ +assert.throws(SyntaxError, function() { Function("for (x => 0 in 1;;) break;"); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, - "expected syntax error, got " + e); -} +}); diff --git a/test/staging/sm/statements/for-of-var-with-initializer.js b/test/staging/sm/statements/for-of-var-with-initializer.js index f9ef77ddc8..bcaba3d3c1 100644 --- a/test/staging/sm/statements/for-of-var-with-initializer.js +++ b/test/staging/sm/statements/for-of-var-with-initializer.js @@ -11,13 +11,6 @@ description: | esid: pending ---*/ -try -{ +assert.throws(SyntaxError, function() { Function("for (var x = 3 of 42);"); - throw new Error("didn't throw"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, - "expected syntax error, got: " + e); -} +}); diff --git a/test/staging/sm/strict/assign-to-callee-name.js b/test/staging/sm/strict/assign-to-callee-name.js index a8c53f0fbc..5d4bebdf44 100644 --- a/test/staging/sm/strict/assign-to-callee-name.js +++ b/test/staging/sm/strict/assign-to-callee-name.js @@ -12,17 +12,7 @@ esid: pending ---*/ var f = function assignSelfStrict() { "use strict"; assignSelfStrict = 12; }; - -try -{ - var r = f(); - throw new Error("should have thrown a TypeError, returned " + r); -} -catch (e) -{ - assert.sameValue(e instanceof TypeError, true, - "didn't throw a TypeError: " + e); -} +assert.throws(TypeError, f); var assignSelf = 42; var f2 = function assignSelf() { assignSelf = 12; }; diff --git a/test/staging/sm/strict/directive-prologue-01.js b/test/staging/sm/strict/directive-prologue-01.js index c48edd2a32..8bc7bfa8e1 100644 --- a/test/staging/sm/strict/directive-prologue-01.js +++ b/test/staging/sm/strict/directive-prologue-01.js @@ -11,51 +11,21 @@ description: | esid: pending ---*/ -try -{ +assert.throws(SyntaxError, function() { eval(" '\\145'; 'use strict'; "); - throw new Error("no error thrown for eval"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, - "wrong error for octal-escape before strict directive in eval"); -} +}, "wrong error for octal-escape before strict directive in eval"); -try -{ +assert.throws(SyntaxError, function() { Function(" '\\145'; 'use strict'; "); - throw new Error("no error thrown for Function"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, - "wrong error for octal-escape before strict directive in Function"); -} +}, "wrong error for octal-escape before strict directive in Function"); -try -{ +assert.throws(SyntaxError, function() { eval(" function f(){ '\\145'; 'use strict'; } "); - throw new Error("no error thrown for eval of function"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, - "wrong error for octal-escape before strict directive in eval of " + - "function"); -} +}, "wrong error for octal-escape before strict directive in eval of function"); -try -{ +assert.throws(SyntaxError, function() { Function(" function f(){ '\\145'; 'use strict'; } "); - throw new Error("no error thrown for eval of function"); -} -catch (e) -{ - assert.sameValue(e instanceof SyntaxError, true, - "wrong error for octal-escape before strict directive in eval of " + - "function"); -} +}, "wrong error for octal-escape before strict directive in eval of function"); eval("function notAnError1() { 5; '\\145'; function g() { 'use strict'; } }"); diff --git a/test/staging/sm/strict/rebind-eval-should-fail-in-strict-mode.js b/test/staging/sm/strict/rebind-eval-should-fail-in-strict-mode.js index 716ec45eed..914042d65a 100644 --- a/test/staging/sm/strict/rebind-eval-should-fail-in-strict-mode.js +++ b/test/staging/sm/strict/rebind-eval-should-fail-in-strict-mode.js @@ -29,17 +29,10 @@ var BadSyntaxStrings = [ ]; function testString(s, i) { - var gotSyntaxError = -1; - try { + assert.throws(SyntaxError, function() { eval(s); - } catch(err) { - if (err instanceof SyntaxError) - gotSyntaxError = i; - } - - assert.sameValue(gotSyntaxError, i); + }); } for (var i = 0; i < BadSyntaxStrings.length; i++) testString(BadSyntaxStrings[i], i); - diff --git a/test/staging/sm/strict/unbrand-this.js b/test/staging/sm/strict/unbrand-this.js index 793141c6bb..7041543d34 100644 --- a/test/staging/sm/strict/unbrand-this.js +++ b/test/staging/sm/strict/unbrand-this.js @@ -18,32 +18,15 @@ function strict() { function bar() {} } -var exception; - // Try 'undefined' as a |this| value. -exception = null; -try { +assert.throws(TypeError, function() { strict.call(undefined); -} catch (x) { - exception = x; -} -assert.sameValue(exception instanceof TypeError, true); +}); // Try 'null' as a |this| value. -exception = null; -try { +assert.throws(TypeError, function() { strict.call(null); -} catch (x) { - exception = x; -} -assert.sameValue(exception instanceof TypeError, true); +}); // An object as a |this| value should be fine. -exception = null; -try { - strict.call({}); -} catch (x) { - exception = x; -} -assert.sameValue(exception, null); - +strict.call({}); diff --git a/test/staging/sm/syntax/class-error.js b/test/staging/sm/syntax/class-error.js index c629a19c5a..4f8dda4666 100644 --- a/test/staging/sm/syntax/class-error.js +++ b/test/staging/sm/syntax/class-error.js @@ -8,19 +8,7 @@ description: | pending esid: pending ---*/ -function assertThrowsSyntaxError(x) { - let success = false; - try { - eval(x); - success = true; - } catch (e) { - assert.sameValue(e instanceof SyntaxError, true); - } - assert.sameValue(success, false); -} - -assertThrowsSyntaxError("class X { x: 1 }") - -if ('assert.sameValue' in this) { -} +assert.throws(SyntaxError, function() { + eval("class X { x: 1 }"); +}); diff --git a/test/staging/sm/syntax/linefeed-at-eof-in-unterminated-string-or-template.js b/test/staging/sm/syntax/linefeed-at-eof-in-unterminated-string-or-template.js index ba8351ba86..f6eb38bd9b 100644 --- a/test/staging/sm/syntax/linefeed-at-eof-in-unterminated-string-or-template.js +++ b/test/staging/sm/syntax/linefeed-at-eof-in-unterminated-string-or-template.js @@ -13,16 +13,9 @@ esid: pending function expectSyntaxError(code) { - try - { + assert.throws(SyntaxError, function() { eval(code); - throw new Error("didn't throw"); - } - catch (e) - { - assert.sameValue(e instanceof SyntaxError, true, - "got " + e.name + ", expected SyntaxError"); - } + }); } // The fundamental requirements of this test: diff --git a/test/staging/sm/types/8.12.5-01.js b/test/staging/sm/types/8.12.5-01.js index e8a7acd117..1c063d1f98 100644 --- a/test/staging/sm/types/8.12.5-01.js +++ b/test/staging/sm/types/8.12.5-01.js @@ -7,17 +7,9 @@ flags: - noStrict description: | - pending + Assignments to a property that has a getter but not a setter should not throw a TypeError per ES5 (at least not until strict mode is supported) esid: pending ---*/ -//----------------------------------------------------------------------------- -var BUGNUMBER = 523846; -var summary = - "Assignments to a property that has a getter but not a setter should not " + - "throw a TypeError per ES5 (at least not until strict mode is supported)"; -var actual = "Early failure"; -var expect = "No errors"; - var o = { get p() { return "a"; } }; @@ -55,56 +47,7 @@ function strictTest2() assert.sameValue(y.p, "a"); } -var errors = []; -try -{ - try - { - test1(); - } - catch (e) - { - errors.push(e); - } - - try - { - test2(); - } - catch (e) - { - errors.push(e); - } - - try - { - strictTest1(); - errors.push("strictTest1 didn't fail"); - } - catch (e) - { - if (!(e instanceof TypeError)) - errors.push("strictTest1 didn't fail with a TypeError: " + e); - } - - try - { - strictTest2(); - errors.push("strictTest2 didn't fail"); - } - catch (e) - { - if (!(e instanceof TypeError)) - errors.push("strictTest2 didn't fail with a TypeError: " + e); - } -} -catch (e) -{ - errors.push("Unexpected error: " + e); -} -finally -{ - actual = errors.length > 0 ? errors.join(", ") : "No errors"; -} - -assert.sameValue(expect, actual, summary); +test1(); +test2(); +assert.throws(TypeError, strictTest1); +assert.throws(TypeError, strictTest2);