Prefer assert.throws to check for errors

This commit is contained in:
André Bargull 2025-04-30 14:16:13 +02:00 committed by Philip Chimento
parent 8145995ec1
commit c35a9c74ba
97 changed files with 602 additions and 2221 deletions

View File

@ -60,25 +60,11 @@ function test(otherGlobal) {
// For each erroneous case, make sure the error comes from // For each erroneous case, make sure the error comes from
// the other realm (not this realm) // the other realm (not this realm)
for (const [message, f] of typeErrorCalls) { for (const [message, f] of typeErrorCalls) {
try { assert.throws(otherGlobal.TypeError, f, message);
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");
}
} }
for (const [message, f] of rangeErrorCalls) { for (const [message, f] of rangeErrorCalls) {
try { assert.throws(otherGlobal.RangeError, f, message);
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");
}
} }
} }

View File

@ -29,16 +29,9 @@ invokeConversionTwice2();
function dontOverwriteError1() function dontOverwriteError1()
{ {
try assert.throws(TypeError, function() {
{
[].length = { valueOf: {}, toString: {} }; [].length = { valueOf: {}, toString: {} };
throw new Error("didn't throw a TypeError"); }, "expected a TypeError running out of conversion options");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"expected a TypeError running out of conversion options, got " + e);
}
} }
dontOverwriteError1(); dontOverwriteError1();

View File

@ -73,16 +73,9 @@ function strict()
addDataProperty(arr, 27182818, "eep", false, false, false); addDataProperty(arr, 27182818, "eep", false, false, false);
try assert.throws(TypeError, function() {
{
arr.length = 1; arr.length = 1;
throw new Error("didn't throw?!"); }, "non-configurable property should trigger TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"non-configurable property should trigger TypeError, got " + e);
}
assert.sameValue(arr.length, 27182819); assert.sameValue(arr.length, 27182819);

View File

@ -14,16 +14,9 @@ esid: pending
var arr = [0, 1, 2]; var arr = [0, 1, 2];
Object.defineProperty(arr, 1, { configurable: false }); Object.defineProperty(arr, 1, { configurable: false });
try assert.throws(TypeError, function() {
{
Object.defineProperty(arr, "length", { value: 0, writable: false }); Object.defineProperty(arr, "length", { value: 0, writable: false });
} }, "must throw TypeError when array truncation would have to remove non-configurable elements");
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"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"); assert.sameValue(arr.length, 2, "length is highest remaining index plus one");

View File

@ -11,13 +11,6 @@ description: |
esid: pending esid: pending
---*/ ---*/
try assert.throws(TypeError, function() {
{
Object.freeze([]).pop(); Object.freeze([]).pop();
throw new Error("didn't throw"); });
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown TypeError, instead got: " + e);
}

View File

@ -27,8 +27,7 @@ var convertible =
var arr = []; var arr = [];
Object.defineProperty(arr, "length", { value: 0, writable: false }); Object.defineProperty(arr, "length", { value: 0, writable: false });
try assert.throws(SyntaxError, function() {
{
Object.defineProperty(arr, "length", Object.defineProperty(arr, "length",
{ {
value: convertible, value: convertible,
@ -36,12 +35,7 @@ try
configurable: true, configurable: true,
enumerable: 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(count, 1);
assert.sameValue(arr.length, 0); assert.sameValue(arr.length, 0);

View File

@ -10,20 +10,16 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function throwsRangeError(t) { function throwsRangeError(t) {
try { var date = new Date();
var date = new Date(); date.setTime(t);
date.setTime(t);
var r = date.toISOString(); assert.throws(RangeError, function() {
throw new Error("toISOString didn't throw, instead returned " + r); date.toISOString();
} catch (err) { });
assert.sameValue(err instanceof RangeError, true, 'wrong error: ' + err);
return;
}
assert.sameValue(0, 1, 'not good, nyan, nyan');
} }
throwsRangeError(Infinity); throwsRangeError(Infinity);
throwsRangeError(-Infinity); throwsRangeError(-Infinity);
throwsRangeError(NaN); throwsRangeError(NaN);

View File

@ -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 * 1. Let O be the result of calling ToObject, giving it the this value as its
* argument. * argument.
*/ */
try assert.throws(TypeError, function() {
{
dateToJSON.call(null); dateToJSON.call(null);
throw new Error("should have thrown a TypeError"); }, "ToObject throws TypeError for null");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToObject throws TypeError for null/undefined");
}
try assert.throws(TypeError, function() {
{
dateToJSON.call(undefined); dateToJSON.call(undefined);
throw new Error("should have thrown a TypeError"); }, "ToObject throws TypeError for undefined");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToObject throws TypeError for null/undefined");
}
/* /*
@ -123,19 +109,13 @@ assert.sameValue(dateToJSON.call({ valueOf: function() { called = true; return {
NaN); NaN);
assert.sameValue(asserted, true); assert.sameValue(asserted, true);
try assert.throws(TypeError, function() {
{
var r = dateToJSON.call({ valueOf: null, toString: null, var r = dateToJSON.call({ valueOf: null, toString: null,
get toISOString() get toISOString()
{ {
throw new Error("shouldn't have been gotten"); 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. */ /* 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. */ /* 5. If IsCallable(toISO) is false, throw a TypeError exception. */
try assert.throws(TypeError, function() {
{ dateToJSON.call({ toISOString: null });
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);
}
try assert.throws(TypeError, function() {
{ dateToJSON.call({ toISOString: undefined });
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);
}
try assert.throws(TypeError, function() {
{ dateToJSON.call({ toISOString: "oogabooga" });
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);
}
try assert.throws(TypeError, function() {
{ dateToJSON.call({ toISOString: Math.PI });
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);
}
/* /*

View File

@ -11,19 +11,6 @@ description: |
esid: pending 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() { } function fun() { }
var global = this; var global = this;
@ -39,7 +26,7 @@ for (var i = 0, sz = nonfuns.length; i < sz; i++)
}; };
var msg = var msg =
"expected TypeError calling Function.prototype.apply with uncallable this"; "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 f = function() { fun.apply(thisObj, nonobjs[i]); };
var msg = "should have thrown a TypeError with non-object arguments"; var msg = "should have thrown a TypeError with non-object arguments";
expectTypeError(f, msg); assert.throws(TypeError, f, msg);
} }

View File

@ -13,24 +13,9 @@ esid: pending
// behavior // 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; } function bar() { "use strict"; return arguments; }
assert.sameValue(bar().caller, undefined); // No error when accessing arguments.caller in ES2017+ 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; } function baz() { return arguments; }
assert.sameValue(baz().callee, baz); assert.sameValue(baz().callee, baz);

View File

@ -10,13 +10,11 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function checkMethod(method) { function checkMethod(method) {
try { assert.throws(TypeError, function() {
new method(); 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) { function checkMethods(proto) {
@ -54,4 +52,3 @@ var builtin_funcs = [
for (var i = 0; i < builtin_funcs.length; i++) { for (var i = 0; i < builtin_funcs.length; i++) {
checkMethod(builtin_funcs[i]); checkMethod(builtin_funcs[i]);
} }

View File

@ -180,11 +180,9 @@ assert.sameValue(one.bind(null, 1, 2).length, 0);
// retch // retch
var br = Object.create(null, { length: { value: 0 } }); var br = Object.create(null, { length: { value: 0 } });
try assert.throws(TypeError, function() {
{ bind.call(/a/g, /a/g, "aaaa");
br = bind.call(/a/g, /a/g, "aaaa"); });
}
catch (e) { /* nothing */ }
assert.sameValue(br.length, 0); assert.sameValue(br.length, 0);

View File

@ -11,19 +11,6 @@ description: |
esid: pending 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() { } function fun() { }
var global = this; var global = this;
@ -41,7 +28,7 @@ for (var i = 0, sz = nonfuns.length; i < sz; i++)
}; };
var msg = var msg =
"expected TypeError calling Function.prototype.call with uncallable this"; "expected TypeError calling Function.prototype.call with uncallable this";
expectTypeError(f, msg); assert.throws(TypeError, f, msg);
} }

View File

@ -11,23 +11,8 @@ description: |
esid: pending 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"; } function bar() { "use strict"; }
expectTypeError(function barCaller() { bar.caller; }); assert.throws(TypeError, function barCaller() { bar.caller; });
function baz() { "use strict"; return 17; } function baz() { "use strict"; return 17; }
expectTypeError(function bazCaller() { baz.caller; }); assert.throws(TypeError, function bazCaller() { baz.caller; });

View File

@ -23,25 +23,17 @@ function testFunctionName(f) {
function testFunctionNameStrict(f) { function testFunctionNameStrict(f) {
"use strict"; "use strict";
var name = f.name; var name = f.name;
var error; assert.throws(TypeError, function() {
try {
f.name = 'g'; f.name = 'g';
} catch (e) { });
error = e;
}
assert.sameValue(f.name, name); assert.sameValue(f.name, name);
assert.sameValue(error instanceof TypeError, true);
assert.sameValue(delete f.name, true); assert.sameValue(delete f.name, true);
assert.sameValue(f.name, ''); assert.sameValue(f.name, '');
assert.sameValue(f.hasOwnProperty('name'), false); assert.sameValue(f.hasOwnProperty('name'), false);
error = null; assert.throws(TypeError, function() {
try {
f.name = 'g'; f.name = 'g';
} catch (e) { });
error = e;
}
assert.sameValue(f.name, ''); assert.sameValue(f.name, '');
assert.sameValue(error instanceof TypeError, true);
Object.defineProperty(f, 'name', {value: 'g'}); Object.defineProperty(f, 'name', {value: 'g'});
assert.sameValue(f.name, 'g'); assert.sameValue(f.name, 'g');
} }

View File

@ -22,33 +22,17 @@ var desc =
}; };
var obj = Object.defineProperty({ p1: 0 }, "p2", desc); var obj = Object.defineProperty({ p1: 0 }, "p2", desc);
try assert.throws(TypeError, function() {
{ JSON.stringify(obj);
var str = JSON.stringify(obj); });
assert.sameValue(false, true, "should have thrown, got " + str); assert.sameValue(count, 1, "cyclic data structures not detected immediately");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error type: " + e.constructor.name);
assert.sameValue(count, 1,
"cyclic data structures not detected immediately");
}
count = 0; count = 0;
var obj2 = Object.defineProperty({}, "obj", desc); var obj2 = Object.defineProperty({}, "obj", desc);
try assert.throws(TypeError, function() {
{ JSON.stringify(obj2);
var str = JSON.stringify(obj2); });
assert.sameValue(false, true, "should have thrown, got " + str); assert.sameValue(count, 2, "cyclic data structures not detected immediately");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error type: " + e.constructor.name);
assert.sameValue(count, 2,
"cyclic data structures not detected immediately");
}
// arrays // arrays
@ -62,30 +46,14 @@ var desc =
}; };
var arr = Object.defineProperty([], "0", desc); var arr = Object.defineProperty([], "0", desc);
try assert.throws(TypeError, function() {
{ JSON.stringify(arr);
var str = JSON.stringify(arr); });
assert.sameValue(false, true, "should have thrown, got " + str); assert.sameValue(count, 1, "cyclic data structures not detected immediately");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error type: " + e.constructor.name);
assert.sameValue(count, 1,
"cyclic data structures not detected immediately");
}
count = 0; count = 0;
var arr2 = Object.defineProperty([], "0", desc); var arr2 = Object.defineProperty([], "0", desc);
try assert.throws(TypeError, function() {
{ JSON.stringify(arr2);
var str = JSON.stringify(arr2); });
assert.sameValue(false, true, "should have thrown, got " + str); assert.sameValue(count, 2, "cyclic data structures not detected immediately");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error type: " + e.constructor.name);
assert.sameValue(count, 2,
"cyclic data structures not detected immediately");
}

View File

@ -11,12 +11,6 @@ description: |
esid: pending esid: pending
---*/ ---*/
try assert.throws(SyntaxError, function() {
{ JSON.parse();
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);
}

View File

@ -37,13 +37,7 @@ function dontCallMe(k, v)
called = true; called = true;
} }
try assert.throws(SyntaxError, function() {
{
JSON.parse('{{{{{{{}}}}', dontCallMe); JSON.parse('{{{{{{{}}}}', dontCallMe);
throw new Error("didn't throw?"); });
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true, "wrong exception: " + e);
}
assert.sameValue(called, false); assert.sameValue(called, false);

View File

@ -51,34 +51,25 @@ redefine(Object.prototype, "valueOf", objValueOf);
redefine(Number.prototype, "toString", function() { return 42; }); redefine(Number.prototype, "toString", function() { return 42; });
assert.sameValue(JSON.stringify(new Number(5)), "5"); assert.sameValue(JSON.stringify(new Number(5)), "5");
redefine(Number.prototype, "valueOf", function() { return 17; }); redefine(Number.prototype, "valueOf", function() { return 17; });
assert.sameValue(JSON.stringify(new Number(5)), "17"); assert.sameValue(JSON.stringify(new Number(5)), "17");
delete Number.prototype.toString; delete Number.prototype.toString;
assert.sameValue(JSON.stringify(new Number(5)), "17"); assert.sameValue(JSON.stringify(new Number(5)), "17");
delete Number.prototype.valueOf; delete Number.prototype.valueOf;
assert.sameValue(JSON.stringify(new Number(5)), "null"); // isNaN(Number("[object Number]")) assert.sameValue(JSON.stringify(new Number(5)), "null"); // isNaN(Number("[object Number]"))
delete Object.prototype.toString; delete Object.prototype.toString;
try assert.throws(TypeError, function() {
{
JSON.stringify(new Number(5)); JSON.stringify(new Number(5));
throw new Error("didn't throw"); }, "ToNumber failure, should throw TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToNumber failure, should throw TypeError");
}
delete Object.prototype.valueOf; delete Object.prototype.valueOf;
try assert.throws(TypeError, function() {
{
JSON.stringify(new Number(5)); JSON.stringify(new Number(5));
throw new Error("didn't throw"); }, "ToNumber failure, should throw TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToNumber failure, should throw TypeError");
}
redefine(Number.prototype, "toString", numToString); redefine(Number.prototype, "toString", numToString);
@ -89,31 +80,22 @@ redefine(Object.prototype, "valueOf", objValueOf);
redefine(String.prototype, "valueOf", function() { return 17; }); redefine(String.prototype, "valueOf", function() { return 17; });
assert.sameValue(JSON.stringify(new String(5)), '"5"'); assert.sameValue(JSON.stringify(new String(5)), '"5"');
redefine(String.prototype, "toString", function() { return 42; }); redefine(String.prototype, "toString", function() { return 42; });
assert.sameValue(JSON.stringify(new String(5)), '"42"'); assert.sameValue(JSON.stringify(new String(5)), '"42"');
delete String.prototype.toString; delete String.prototype.toString;
assert.sameValue(JSON.stringify(new String(5)), '"[object String]"'); assert.sameValue(JSON.stringify(new String(5)), '"[object String]"');
delete Object.prototype.toString; delete Object.prototype.toString;
assert.sameValue(JSON.stringify(new String(5)), '"17"'); assert.sameValue(JSON.stringify(new String(5)), '"17"');
delete String.prototype.valueOf; delete String.prototype.valueOf;
try assert.throws(TypeError, function() {
{
JSON.stringify(new String(5)); JSON.stringify(new String(5));
throw new Error("didn't throw"); }, "ToString failure, should throw TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToString failure, should throw TypeError");
}
delete Object.prototype.valueOf; delete Object.prototype.valueOf;
try assert.throws(TypeError, function() {
{
JSON.stringify(new String(5)); JSON.stringify(new String(5));
throw new Error("didn't throw"); }, "ToString failure, should throw TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToString failure, should throw TypeError");
}

View File

@ -127,33 +127,15 @@ assert.sameValue(x, '{"0":0,"1":null,"2":2}');
x = JSON.stringify(foo, returnStringForUndefined); x = JSON.stringify(foo, returnStringForUndefined);
assert.sameValue(x, '{"0":0,"1":1,"2":2,"3":"undefined value"}'); assert.sameValue(x, '{"0":0,"1":1,"2":2,"3":"undefined value"}');
try assert.throws(TypeError, function() {
{
JSON.stringify(foo, returnCycleObjectFor1); 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); 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]; foo = [0, 1, 2, undefined];
try assert.throws(TypeError, function() {
{
JSON.stringify(foo, returnCycleObjectFor1); JSON.stringify(foo, returnCycleObjectFor1);
throw new Error("no error thrown"); });
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "no TypeError thrown: " + e);
}

View File

@ -11,13 +11,6 @@ description: |
esid: pending esid: pending
---*/ ---*/
try assert.throws(SyntaxError, function() {
{
eval("0x"); 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);
}

View File

@ -11,19 +11,10 @@ description: |
esid: pending esid: pending
---*/ ---*/
function test(method, prec) function test(method, prec) {
{ assert.throws(RangeError, function() {
try
{
Number.prototype[method].call(0, prec); 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); test("toExponential", -32);

View File

@ -11,17 +11,11 @@ description: |
esid: pending esid: pending
---*/ ---*/
function test(r) function test(r) {
{ assert.throws(RangeError, function() {
try
{
5..toString(r); 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(Math.pow(2, 32) + 10);
test(55); test(55);

View File

@ -32,9 +32,6 @@ class A {
}; };
a = new A; a = new A;
try { assert.throws(TypeError, function() {
a.g(); a.g();
} catch (e) { });
assert.sameValue(e instanceof TypeError, true);
}

View File

@ -17,13 +17,6 @@ class A {
}; };
var p = new Proxy(new A, {}); var p = new Proxy(new A, {});
var completed = false; assert.throws(TypeError, function() {
try {
p.g(); p.g();
completed = true; });
} catch (e) {
assert.sameValue(e instanceof TypeError, true);
}
assert.sameValue(completed, false);

View File

@ -8,20 +8,9 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
// Ensure that the distinction between Proxy Init and Proxy Set holds // 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 target = {};
var p1 = new Proxy(target, {}); var p1 = new Proxy(target, {});
var p2 = 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 // Despite P1 being stamped with A's field, it shouldn't
// be sufficient to set B's field. // be sufficient to set B's field.
assertThrowsTypeError(() => B.sf(p1)); assert.throws(TypeError, () => B.sf(p1));
assertThrowsTypeError(() => B.gf(p1)); assert.throws(TypeError, () => B.gf(p1));
assertThrowsTypeError(() => B.sf(p1)); assert.throws(TypeError, () => B.sf(p1));
new B(p1); new B(p1);
assert.sameValue(B.gf(p1), 25); assert.sameValue(B.gf(p1), 25);
B.sf(p1); B.sf(p1);
assert.sameValue(B.gf(p1), 20); assert.sameValue(B.gf(p1), 20);
// A's field should't be on the target // 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 // 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. // 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. // Still should't be on the target.
assertThrowsTypeError(() => A.gf(target)); assert.throws(TypeError, () => A.gf(target));

View File

@ -16,16 +16,9 @@ function checkFunctionAppliedToRevokedProxy(fun)
var p = Proxy.revocable({}, {}); var p = Proxy.revocable({}, {});
p.revoke(); p.revoke();
try assert.throws(TypeError, function() {
{
fun(p.proxy); fun(p.proxy);
throw "didn't throw"; });
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"expected TypeError, got " + e);
}
} }
checkFunctionAppliedToRevokedProxy(proxy => Object.getPrototypeOf(proxy)); checkFunctionAppliedToRevokedProxy(proxy => Object.getPrototypeOf(proxy));

View File

@ -17,11 +17,7 @@ var regexps = ["/\\\u000A/", "/\\\u000D/", "/\\\u2028/", "/\\\u2029/",
for(var i=0; i<regexps.length; i++) { for(var i=0; i<regexps.length; i++) {
var src = regexps[i]; var src = regexps[i];
try { assert.throws(SyntaxError, function() {
x = eval(src).source; eval(src).source;
} catch(e) { });
assert.sameValue(e.constructor, SyntaxError);
continue;
}
assert.sameValue(0, 1);
} }

View File

@ -11,20 +11,6 @@ description: |
esid: pending 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);
}
}
function checkExec(description, regex, args, obj) function checkExec(description, regex, args, obj)
{ {
var lastIndex = obj.lastIndex; var lastIndex = obj.lastIndex;
@ -47,15 +33,15 @@ var exec = RegExp.prototype.exec;
var r, res, called, obj; var r, res, called, obj;
/* 1. Let R be this RegExp object. */ /* 1. Let R be this RegExp object. */
expectThrowTypeError(function() { exec.call(null); }); assert.throws(TypeError, function() { exec.call(null); });
expectThrowTypeError(function() { exec.call(""); }); assert.throws(TypeError, function() { exec.call(""); });
expectThrowTypeError(function() { exec.call(5); }); assert.throws(TypeError, function() { exec.call(5); });
expectThrowTypeError(function() { exec.call({}); }); assert.throws(TypeError, function() { exec.call({}); });
expectThrowTypeError(function() { exec.call([]); }); assert.throws(TypeError, function() { exec.call([]); });
expectThrowTypeError(function() { exec.call(); }); assert.throws(TypeError, function() { exec.call(); });
expectThrowTypeError(function() { exec.call(true); }); assert.throws(TypeError, function() { exec.call(true); });
expectThrowTypeError(function() { exec.call(Object.create(RegExp.prototype)); }); assert.throws(TypeError, function() { exec.call(Object.create(RegExp.prototype)); });
expectThrowTypeError(function() { exec.call(Object.create(/a/)); }); assert.throws(TypeError, function() { exec.call(Object.create(/a/)); });
/* 2. Let S be the value of ToString(string). */ /* 2. Let S be the value of ToString(string). */
@ -109,9 +95,9 @@ assert.sameValue(r.lastIndex, obj);
*/ */
r = /b/; r = /b/;
r.lastIndex = { valueOf: {}, toString: {} }; r.lastIndex = { valueOf: {}, toString: {} };
expectThrowTypeError(function() { r.exec("foopy"); }); assert.throws(TypeError, function() { r.exec("foopy"); });
r.lastIndex = { valueOf: function() { throw new TypeError(); } }; r.lastIndex = { valueOf: function() { throw new TypeError(); } };
expectThrowTypeError(function() { r.exec("foopy"); }); assert.throws(TypeError, function() { r.exec("foopy"); });
/* /*

View File

@ -18,61 +18,33 @@ var s = '0x2x4x6x8';
var p1 = /x/g; var p1 = /x/g;
Object.defineProperty(p1, "lastIndex", { writable: false }); Object.defineProperty(p1, "lastIndex", { writable: false });
try assert.throws(TypeError, function() {
{
s.match(p1); s.match(p1);
throw "didn't throw"; });
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
}
// Second time with .lastIndex !== 0 // Second time with .lastIndex !== 0
var p2 = /x/g; var p2 = /x/g;
Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 }); Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 });
try assert.throws(TypeError, function() {
{
s.match(p2); s.match(p2);
throw "didn't throw"; });
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
}
// Third time with .lastIndex === 0, no matches // Third time with .lastIndex === 0, no matches
var p3 = /q/g; var p3 = /q/g;
Object.defineProperty(p3, "lastIndex", { writable: false }); Object.defineProperty(p3, "lastIndex", { writable: false });
try assert.throws(TypeError, function() {
{
s.match(p3); s.match(p3);
throw "didn't throw"; });
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
}
// Fourth time with .lastIndex !== 0, no matches // Fourth time with .lastIndex !== 0, no matches
var p4 = /q/g; var p4 = /q/g;
Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 }); Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 });
try assert.throws(TypeError, function() {
{
s.match(p4); s.match(p4);
throw "didn't throw"; });
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
}

View File

@ -18,99 +18,57 @@ var s = '0x2x4x6x8';
var p1 = /x/g; var p1 = /x/g;
Object.defineProperty(p1, "lastIndex", { writable: false }); Object.defineProperty(p1, "lastIndex", { writable: false });
try assert.throws(TypeError, function() {
{
s.replace(p1, ''); s.replace(p1, '');
throw "didn't throw"; });
} assert.sameValue(p1.lastIndex, 0);
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p1.lastIndex, 0);
}
// Second time with .lastIndex !== 0, replacing to '' // Second time with .lastIndex !== 0, replacing to ''
var p2 = /x/g; var p2 = /x/g;
Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 }); Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 });
try assert.throws(TypeError, function() {
{
s.replace(p2, ''); s.replace(p2, '');
throw "didn't throw"; });
} assert.sameValue(p2.lastIndex, 3);
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p2.lastIndex, 3);
}
// Third time with .lastIndex === 0, replacing to 'y' // Third time with .lastIndex === 0, replacing to 'y'
var p3 = /x/g; var p3 = /x/g;
Object.defineProperty(p3, "lastIndex", { writable: false }); Object.defineProperty(p3, "lastIndex", { writable: false });
try assert.throws(TypeError, function() {
{
s.replace(p3, 'y'); s.replace(p3, 'y');
throw "didn't throw"; });
} assert.sameValue(p3.lastIndex, 0);
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p3.lastIndex, 0);
}
// Fourth time with .lastIndex !== 0, replacing to 'y' // Fourth time with .lastIndex !== 0, replacing to 'y'
var p4 = /x/g; var p4 = /x/g;
Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 }); Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 });
try assert.throws(TypeError, function() {
{
s.replace(p4, ''); s.replace(p4, '');
throw "didn't throw"; });
} assert.sameValue(p4.lastIndex, 3);
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p4.lastIndex, 3);
}
// Fifth time with .lastIndex === 0, replacing to 'y', but no match // Fifth time with .lastIndex === 0, replacing to 'y', but no match
var p5 = /q/g; var p5 = /q/g;
Object.defineProperty(p5, "lastIndex", { writable: false }); Object.defineProperty(p5, "lastIndex", { writable: false });
try assert.throws(TypeError, function() {
{
s.replace(p5, 'y'); s.replace(p5, 'y');
throw "didn't throw"; });
} assert.sameValue(p5.lastIndex, 0);
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p5.lastIndex, 0);
}
// Sixth time with .lastIndex !== 0, replacing to 'y', but no match // Sixth time with .lastIndex !== 0, replacing to 'y', but no match
var p6 = /q/g; var p6 = /q/g;
Object.defineProperty(p6, "lastIndex", { writable: false, value: 3 }); Object.defineProperty(p6, "lastIndex", { writable: false, value: 3 });
try assert.throws(TypeError, function() {
{
s.replace(p6, ''); s.replace(p6, '');
throw "didn't throw"; });
} assert.sameValue(p6.lastIndex, 3);
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p6.lastIndex, 3);
}

View File

@ -14,13 +14,6 @@ esid: pending
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
try assert.throws(RangeError, function() {
{
new Uint8Array().set([], -1); new Uint8Array().set([], -1);
throw new Error("didn't throw at all"); });
}
catch (e)
{
assert.sameValue(e instanceof RangeError, true,
"expected RangeError, instead got: " + e);
}

View File

@ -9,11 +9,6 @@ description: |
esid: pending esid: pending
---*/ ---*/
let caught = false; assert.throws(SyntaxError, function() {
try { eval("await 10");
eval("await 10"); });
} catch(e) {
assert.sameValue(e.message.includes("await is only valid in"), true);
caught = true;
}
assert.sameValue(caught, true);

View File

@ -12,14 +12,9 @@ esid: pending
// Function definitions. // Function definitions.
function syntaxError (script) { function syntaxError (script) {
try { assert.throws(SyntaxError, function() {
Function(script); Function(script);
} catch (e) { });
if (e instanceof SyntaxError) {
return;
}
}
throw new Error('Expected syntax error: ' + script);
} }
@ -76,9 +71,9 @@ syntaxError("({[if (0) 0;]})"); // much less a Statement
syntaxError("function f() { {[x]: 1} }"); // that's not even an ObjectLiteral syntaxError("function f() { {[x]: 1} }"); // that's not even an ObjectLiteral
syntaxError("function f() { [x]: 1 }"); // or that syntaxError("function f() { [x]: 1 }"); // or that
syntaxError('a = {[f1@]: "a", [f2]: "b"}'); // unexpected symbol at end of AssignmentExpression syntaxError('a = {[f1@]: "a", [f2]: "b"}'); // unexpected symbol at end of AssignmentExpression
try { JSON.parse('{["a"]:4}'); } catch(e) { assert.throws(SyntaxError, function() {
if (!(e instanceof SyntaxError)) throw new Error('Expected syntax error'); JSON.parse('{["a"]:4}');
} });
// Property characteristics. // Property characteristics.
a = { ["b"] : 4 }; a = { ["b"] : 4 };

View File

@ -11,14 +11,9 @@ esid: pending
// Function definitions. // Function definitions.
function syntaxError (script) { function syntaxError (script) {
try { assert.throws(SyntaxError, function() {
Function(script); Function(script);
} catch (e) { });
if (e instanceof SyntaxError) {
return;
}
}
throw new Error('Expected syntax error: ' + script);
} }

View File

@ -11,14 +11,9 @@ esid: pending
// Function definitions. // Function definitions.
function syntaxError (script) { function syntaxError (script) {
try { assert.throws(SyntaxError, function() {
Function(script); Function(script);
} catch (e) { });
if (e instanceof SyntaxError) {
return;
}
}
throw new Error('Expected syntax error: ' + script);
} }

View File

@ -19,17 +19,9 @@ for (var i = 0; i < 2; i++)
{ {
chars.forEach(function(v) chars.forEach(function(v)
{ {
try assert.throws(SyntaxError, function() {
{
eval('0' + v + i); eval('0' + v + i);
throw "didn't throw"; }, "no syntax error evaluating 0" + v + i);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating 0" + v + i + ", " +
"got " + e);
}
}); });
continue; continue;
} }
@ -40,17 +32,9 @@ for (var i = 0; i < 2; i++)
{ {
chars.forEach(function(v) chars.forEach(function(v)
{ {
try assert.throws(SyntaxError, function() {
{
eval('0' + v + i + j); eval('0' + v + i + j);
throw "didn't throw"; }, "no syntax error evaluating 0" + v + i + j);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating 0" + v + i + j + ", " +
"got " + e);
}
}); });
continue; continue;
} }
@ -61,17 +45,9 @@ for (var i = 0; i < 2; i++)
{ {
chars.forEach(function(v) chars.forEach(function(v)
{ {
try assert.throws(SyntaxError, function() {
{
eval('0' + v + i + j + k); eval('0' + v + i + j + k);
throw "didn't throw"; }, "no syntax error evaluating 0" + v + i + j + k);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating 0" + v + i + j + k + ", " +
"got " + e);
}
}); });
continue; continue;
} }
@ -86,14 +62,9 @@ for (var i = 0; i < 2; i++)
chars.forEach(function(v) chars.forEach(function(v)
{ {
try assert.throws(SyntaxError, function() {
{ eval('0' + v);
} }, "no syntax error evaluating 0" + v);
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating 0" + v + ", got " + e);
}
}); });
// Off-by-one check: '/' immediately precedes '0'. // Off-by-one check: '/' immediately precedes '0'.

View File

@ -13,35 +13,12 @@ esid: pending
function checkSyntaxError(code) function checkSyntaxError(code)
{ {
function helper(maker) assert.throws(SyntaxError, function() {
{ Function(code);
var earlyError = false; });
try assert.throws(SyntaxError, function() {
{ (1, eval)(code); // indirect eval
var f = maker(code); });
var error = "no early error, created a function with code <" + code + ">";
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);
} }
checkSyntaxError("function f() { 'use strict'; delete escape; } f();"); checkSyntaxError("function f() { 'use strict'; delete escape; } f();");

View File

@ -14,51 +14,27 @@ esid: pending
// Don't pollute the top-level script with eval references. // Don't pollute the top-level script with eval references.
var savedEval = this[String.fromCharCode(101, 118, 97, 108)]; 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; var fullCode = prefix + code;
try assert.throws(SyntaxError, function() {
{ exec(fullCode);
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);
}
} }
helper(Function, "", nonstrictErr); helper(Function, "");
helper(Function, "'use strict'; ", strictErr); helper(Function, "'use strict'; ");
helper(savedEval, "", nonstrictErr); helper(savedEval, "");
helper(savedEval, "'use strict'; ", strictErr); helper(savedEval, "'use strict'; ");
} }
// Parenthesized destructuring patterns don't trigger grammar refinement, so we // Parenthesized destructuring patterns don't trigger grammar refinement, so we
// get the usual SyntaxError for an invalid assignment target, per // get the usual SyntaxError for an invalid assignment target, per
// 12.14.1 second bullet. // 12.14.1 second bullet.
checkError("var a, b; ([a, b]) = [1, 2];", SyntaxError, SyntaxError); checkError("var a, b; ([a, b]) = [1, 2];");
checkError("var a, b; ({a, b}) = { a: 1, b: 2 };", SyntaxError, SyntaxError); checkError("var a, b; ({a, b}) = { a: 1, b: 2 };");
// *Nested* parenthesized destructuring patterns, on the other hand, do trigger // *Nested* parenthesized destructuring patterns, on the other hand, do trigger
// grammar refinement. But subtargets in a destructuring pattern must be // 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 // destructuring in an expression, |(a = 3)| is forbidden). Parenthesized
// object/array patterns are neither. And so 12.14.5.1 third bullet requires an // object/array patterns are neither. And so 12.14.5.1 third bullet requires an
// early SyntaxError. // early SyntaxError.
checkError("var a, b; ({ a: ({ b: b }) } = { a: { b: 42 } });", SyntaxError, SyntaxError); checkError("var a, b; ({ a: ({ b: b }) } = { a: { b: 42 } });");
checkError("var a, b; ({ a: { b: (b = 7) } } = { a: {} });", SyntaxError, SyntaxError); checkError("var a, b; ({ a: { b: (b = 7) } } = { a: {} });");
checkError("var a, b; ({ a: ([b]) } = { a: [42] });", SyntaxError, SyntaxError); checkError("var a, b; ({ a: ([b]) } = { a: [42] });");
checkError("var a, b; [(a = 5)] = [1];", SyntaxError, SyntaxError); checkError("var a, b; [(a = 5)] = [1];");
checkError("var a, b; ({ a: (b = 7)} = { b: 1 });", SyntaxError, SyntaxError); checkError("var a, b; ({ a: (b = 7)} = { b: 1 });");
Function("var a, b; [(a), b] = [1, 2];")(); Function("var a, b; [(a), b] = [1, 2];")();
Function("var a, b; [(a) = 5, 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 // As noted above, when the assignment element has an initializer, the
// assignment element must not be parenthesized. // assignment element must not be parenthesized.
checkError("var a, b; [(repair.man = 17)] = [1];", SyntaxError, SyntaxError); checkError("var a, b; [(repair.man = 17)] = [1];");
checkError("var a, b; [(demolition['man'] = 'motel')] = [1, 2];", SyntaxError, SyntaxError); checkError("var a, b; [(demolition['man'] = 'motel')] = [1, 2];");
checkError("var a, b; [(demolition['man' + {}] = 'motel')] = [1];", SyntaxError, SyntaxError); // evade constant-folding checkError("var a, b; [(demolition['man' + {}] = 'motel')] = [1];"); // evade constant-folding
if (classesEnabled()) if (classesEnabled())
{ {
checkError("var a, b; var obj = { x() { [(super.man = 5)] = [1]; } };", SyntaxError, SyntaxError); checkError("var a, b; var obj = { x() { [(super.man = 5)] = [1]; } };");
checkError("var a, b; var obj = { x() { [(super[8] = 'motel')] = [1]; } };", SyntaxError, SyntaxError); checkError("var a, b; var obj = { x() { [(super[8] = 'motel')] = [1]; } };");
checkError("var a, b; var obj = { x() { [(super[8 + {}] = 'motel')] = [1]; } };", SyntaxError, SyntaxError); // evade constant-folding 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() = 'ohai', b] = [1, 2];");
checkError("var a, b; [(f()) = 'kthxbai', b] = [1, 2];", SyntaxError, SyntaxError); 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), b} = { a: 1, b: 2 });")();
Function("var a, b; ({ a: (a) = 5, b} = { a: 1, b: 2 });")(); Function("var a, b; ({ a: (a) = 5, b} = { a: 1, b: 2 });")();

View File

@ -19,33 +19,11 @@ for (var i = 0, sz = BAD_CODE.length; i < sz; i++)
{ {
var code = BAD_CODE[i]; var code = BAD_CODE[i];
var err = "no exception"; assert.throws(SyntaxError, function() {
try
{
eval(code); eval(code);
} }, "bad or no exception thrown for eval(" + code + ")");
catch (e)
{
err = e;
}
if (!(err instanceof SyntaxError))
{
assert.sameValue(true, false,
"bad or no exception thrown for eval(" + code + "): " + err);
}
err = "no exception"; assert.throws(SyntaxError, function() {
try Function(code);
{ }, "bad or no exception thrown for Function(" + code + ")");
new Function(code);
}
catch (e)
{
err = e;
}
if (!(err instanceof SyntaxError))
{
assert.sameValue(true, false,
"bad or no exception thrown for Function(" + code + "): " + err);
}
} }

View File

@ -24,15 +24,9 @@ function shouldNotThrow(script) {
} }
function shouldThrowSyntaxError(script) { function shouldThrowSyntaxError(script) {
let error; assert.throws(SyntaxError, function() {
try {
eval(script); eval(script);
} catch (e) { });
error = e;
}
if (!(error instanceof SyntaxError))
throw new Error('Expected SyntaxError!');
} }
function testBasicCases() { function testBasicCases() {

View File

@ -13,16 +13,9 @@ esid: pending
function expectSyntaxError(s) function expectSyntaxError(s)
{ {
try assert.throws(SyntaxError, function() {
{
eval(s); eval(s);
throw new Error("no error thrown"); }, "expected syntax error parsing '" + s + "'");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"expected syntax error parsing '" + s + "', got: " + e);
}
} }
expectSyntaxError("({ get x(a) { } })"); expectSyntaxError("({ get x(a) { } })");

View File

@ -19,17 +19,9 @@ for (var i = 0; i < 8; i++)
{ {
chars.forEach(function(v) chars.forEach(function(v)
{ {
try assert.throws(SyntaxError, function() {
{
eval('0' + v + i); eval('0' + v + i);
throw "didn't throw"; }, "syntax error evaluating 0" + v + i);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating 0" + v + i + ", " +
"got " + e);
}
}); });
continue; continue;
} }
@ -40,17 +32,9 @@ for (var i = 0; i < 8; i++)
{ {
chars.forEach(function(v) chars.forEach(function(v)
{ {
try assert.throws(SyntaxError, function() {
{
eval('0' + v + i + j); eval('0' + v + i + j);
throw "didn't throw"; }, "syntax error evaluating 0" + v + i + j);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating 0" + v + i + j + ", " +
"got " + e);
}
}); });
continue; continue;
} }
@ -61,17 +45,9 @@ for (var i = 0; i < 8; i++)
{ {
chars.forEach(function(v) chars.forEach(function(v)
{ {
try assert.throws(SyntaxError, function() {
{
eval('0' + v + i + j + k); eval('0' + v + i + j + k);
throw "didn't throw"; }, "no syntax error evaluating 0" + v + i + j + k);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating 0" + v + i + j + k + ", " +
"got " + e);
}
}); });
continue; continue;
} }

View File

@ -13,15 +13,9 @@ esid: pending
function expectSyntaxError(str) function expectSyntaxError(str)
{ {
try assert.throws(SyntaxError, function() {
{
eval(str); eval(str);
} }, "syntax error evaluating " + str);
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"no syntax error evaluating " + str);
}
} }
expectSyntaxError('"\\x"'); expectSyntaxError('"\\x"');

View File

@ -25,16 +25,9 @@ function testStart()
} }
}; };
var ok = false; assert.throws(TypeError, function() {
try
{
ab.slice(start); ab.slice(start);
} }, "start weirdness should have thrown");
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "start weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness");
} }
testStart(); testStart();
@ -53,16 +46,9 @@ function testEnd()
} }
}; };
var ok = false; assert.throws(TypeError, function() {
try
{
ab.slice(0x800, end); ab.slice(0x800, end);
} }, "byteLength weirdness should have thrown");
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "byteLength weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for byteLength weirdness"); assert.sameValue(ab.byteLength, 0, "detaching should work for byteLength weirdness");
} }
testEnd(); testEnd();

View File

@ -25,16 +25,9 @@ function testByteOffset()
} }
}; };
var ok = false; assert.throws(TypeError, function() {
try
{
new DataView(ab, start); new DataView(ab, start);
} }, "byteOffset weirdness should have thrown");
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "byteOffset weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for byteOffset weirdness"); assert.sameValue(ab.byteLength, 0, "detaching should work for byteOffset weirdness");
} }
testByteOffset(); testByteOffset();
@ -53,16 +46,9 @@ function testByteLength()
} }
}; };
var ok = false; assert.throws(TypeError, function() {
try
{
new DataView(ab, 0x800, len); new DataView(ab, 0x800, len);
} }, "byteLength weirdness should have thrown");
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "byteLength weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for byteLength weirdness"); assert.sameValue(ab.byteLength, 0, "detaching should work for byteLength weirdness");
} }
testByteLength(); testByteLength();

View File

@ -27,16 +27,9 @@ function testIndex()
} }
}; };
var ok = false; assert.throws(TypeError, function() {
try
{
dv.setUint8(start, 0x42); 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"); assert.sameValue(ab.byteLength, 0, "should have been detached correctly");
} }
testIndex(); testIndex();
@ -57,16 +50,9 @@ function testValue()
} }
}; };
var ok = false; assert.throws(TypeError, function() {
try
{
dv.setUint8(0xFFFFF, value); 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"); assert.sameValue(ab.byteLength, 0, "should have been detached correctly");
} }
testValue(); testValue();

View File

@ -26,16 +26,9 @@ function testBegin()
var ta = new Uint8Array(ab); var ta = new Uint8Array(ab);
var ok = false; assert.throws(TypeError, function() {
try ta.subarray(begin)
{ }, "start weirdness should have thrown");
ta.subarray(begin);
}
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "start weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness");
} }
testBegin(); testBegin();
@ -55,16 +48,9 @@ function testBeginWithEnd()
var ta = new Uint8Array(ab); var ta = new Uint8Array(ab);
var ok = false; assert.throws(TypeError, function() {
try
{
ta.subarray(begin, 0x1000); ta.subarray(begin, 0x1000);
} }, "start weirdness should have thrown");
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "start weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness"); assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness");
} }
testBeginWithEnd(); testBeginWithEnd();
@ -84,16 +70,9 @@ function testEnd()
var ta = new Uint8Array(ab); var ta = new Uint8Array(ab);
var ok = false; assert.throws(TypeError, function() {
try
{
ta.subarray(0x800, end); ta.subarray(0x800, end);
} }, "end weirdness should have thrown");
catch (e) assert.sameValue(ab.byteLength, 0, "detaching should work for end weirdness");
{
ok = true;
}
assert.sameValue(ok, true, "start weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness");
} }
testEnd(); testEnd();

View File

@ -30,17 +30,9 @@ var sobj =
{ {
"use strict"; "use strict";
try assert.throws(TypeError, function() {
{ sobj.test.arguments;
var args = sobj.test.arguments; }, "access to arguments property of strict mode function");
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);
}
} }
}; };
sobj.test(5, undefined); sobj.test(5, undefined);

View File

@ -12,23 +12,8 @@ esid: pending
---*/ ---*/
function test(sharedMem) { function test(sharedMem) {
function die(message, uplevel) {
throw new Error(message);
}
function checkThrow(fun, type) { function checkThrow(fun, type) {
var thrown = false; assert.throws(type, fun);
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);
}
} }
function bufferize(u8array) { function bufferize(u8array) {

View File

@ -27,16 +27,9 @@ function expectOk(s)
function expectSyntaxError(s) function expectSyntaxError(s)
{ {
try assert.throws(SyntaxError, function() {
{
eval(s); eval(s);
throw new Error("no error thrown"); }, "expected syntax error parsing '" + s + "'");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"expected syntax error parsing '" + s + "', got: " + e);
}
} }
expectSyntaxError("({ get x([]) { } })"); expectSyntaxError("({ get x([]) { } })");

View File

@ -67,20 +67,6 @@ function check(obj, prop, expected)
checkField("configurable", desc, 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 * * BEGIN TEST *
**************/ **************/
@ -137,8 +123,8 @@ gsobj.__defineSetter__("baz", s3);
check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: true }); check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: true });
Object.defineProperty(gsobj, "baz", { configurable: false }); Object.defineProperty(gsobj, "baz", { configurable: false });
expectTypeError(function() { gsobj.__defineSetter__("baz", s2); }); assert.throws(TypeError, function() { gsobj.__defineSetter__("baz", s2); });
expectTypeError(function() { gsobj.__defineSetter__("baz", s3); }); assert.throws(TypeError, function() { gsobj.__defineSetter__("baz", s3); });
check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: false }); 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 }); check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: true });
Object.defineProperty(sgobj, "baz", { configurable: false }); Object.defineProperty(sgobj, "baz", { configurable: false });
expectTypeError(function() { sgobj.__defineGetter__("baz", g3); }); assert.throws(TypeError, function() { sgobj.__defineGetter__("baz", g3); });
expectTypeError(function() { sgobj.__defineSetter__("baz", s4); }); assert.throws(TypeError, function() { sgobj.__defineSetter__("baz", s4); });
check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: false }); 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 }); Object.defineProperty(gncover, "moo", { configurable: false });
check(gncover, "moo", { value: 17, writable: true, enumerable: true, 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 }); 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 }); Object.defineProperty(sncover, "moo", { configurable: false });
check(sncover, "moo", { value: 17, writable: true, enumerable: true, 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 }); 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 }); Object.defineProperty(gncwover, "fwoosh", { writable: false, configurable: false });
check(gncwover, "fwoosh", { value: 17, writable: false, enumerable: true, 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 }); 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 }); Object.defineProperty(sncwover, "fwoosh", { writable: false, configurable: false });
check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, 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 }); check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false });

View File

@ -16,19 +16,9 @@ esid: pending
{ {
function testOne(replacement) function testOne(replacement)
{ {
var x, rv; assert.throws(SyntaxError, function() {
try eval(code.replace("@@@", replacement));
{ });
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);
} }
testOne("function"); testOne("function");

View File

@ -39,44 +39,23 @@ function testMethod(Class, className, method)
var badThis = badThisValues[i]; var badThis = badThisValues[i];
expr = className + ".prototype." + method + ".call(" + badThis + ")"; expr = className + ".prototype." + method + ".call(" + badThis + ")";
try assert.throws(TypeError, function() {
{
Class.prototype[method].call(badThis); Class.prototype[method].call(badThis);
throw new Error(expr + " didn't throw a TypeError"); }, "wrong error for " + expr);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error for " + expr + ", instead threw " + e);
}
expr = className + ".prototype." + method + ".apply(" + badThis + ")"; expr = className + ".prototype." + method + ".apply(" + badThis + ")";
try assert.throws(TypeError, function() {
{
Class.prototype[method].apply(badThis); Class.prototype[method].apply(badThis);
throw new Error(expr + " didn't throw a TypeError"); }, "wrong error for " + expr);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error for " + expr + ", instead threw " + e);
}
} }
// ..and for good measure.. // ..and for good measure..
expr = "(0, " + className + ".prototype." + method + ")()" expr = "(0, " + className + ".prototype." + method + ")()"
try assert.throws(TypeError, function() {
{
// comma operator to call GetValue() on the method and de-Reference it // comma operator to call GetValue() on the method and de-Reference it
(0, Class.prototype[method])(); (0, Class.prototype[method])();
throw new Error(expr + " didn't throw a TypeError"); }, "wrong error for " + expr);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error for " + expr + ", instead threw " + e);
}
} }
for (var className in ClassToMethodMap) for (var className in ClassToMethodMap)

View File

@ -17,15 +17,9 @@ var otherStr = new g.String("foo");
assert.sameValue(otherStr instanceof g.String, true); assert.sameValue(otherStr instanceof g.String, true);
assert.sameValue(otherStr.valueOf(), "foo"); 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; var constructor = g.parseInt;
new constructor(); 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);
}

View File

@ -14,21 +14,11 @@ esid: pending
var arr = []; var arr = [];
var p = new Proxy(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 // 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. // 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. // Check the property went unchanged.
var pd = Object.getOwnPropertyDescriptor(p, "length"); var pd = Object.getOwnPropertyDescriptor(p, "length");

View File

@ -11,27 +11,8 @@ description: |
esid: pending esid: pending
---*/ ---*/
var actual = ''; Array.prototype.__proto__ = function () { return 3; };
var expect = '';
//----------------------------------------------------------------------------- assert.throws(TypeError, function() {
test(); [].__proto__();
//----------------------------------------------------------------------------- });
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);
}

View File

@ -8,19 +8,10 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function f(foo) { function f(foo) {
"use strict"; "use strict";
foo.bar; foo.bar;
} }
var actual; assert.throws(TypeError, f);
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");

View File

@ -26,17 +26,10 @@ function testBegin()
var ta = new Uint8Array(ab); var ta = new Uint8Array(ab);
var ok = false; assert.throws(TypeError, function() {
try
{
ta.copyWithin(0, begin, 0x1000); ta.copyWithin(0, begin, 0x1000);
} }, "begin weirdness should have thrown");
catch (e) assert.sameValue(ab.byteLength, 0, "detaching should work for begin weirdness");
{
ok = true;
}
assert.sameValue(ok, true, "start weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness");
} }
testBegin(); testBegin();
@ -55,17 +48,10 @@ function testEnd()
var ta = new Uint8Array(ab); var ta = new Uint8Array(ab);
var ok = false; assert.throws(TypeError, function() {
try
{
ta.copyWithin(0, 0x800, end); ta.copyWithin(0, 0x800, end);
} }, "end weirdness should have thrown");
catch (e) assert.sameValue(ab.byteLength, 0, "detaching should work for end weirdness");
{
ok = true;
}
assert.sameValue(ok, true, "start weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness");
} }
testEnd(); testEnd();
@ -84,16 +70,9 @@ function testDest()
var ta = new Uint8Array(ab); var ta = new Uint8Array(ab);
var ok = false; assert.throws(TypeError, function() {
try
{
ta.copyWithin(dest, 0x800, 0x1000); ta.copyWithin(dest, 0x800, 0x1000);
} }, "dest weirdness should have thrown");
catch (e) assert.sameValue(ab.byteLength, 0, "detaching should work for dest weirdness");
{
ok = true;
}
assert.sameValue(ok, true, "start weirdness should have thrown");
assert.sameValue(ab.byteLength, 0, "detaching should work for start weirdness");
} }
testDest(); testDest();

View File

@ -15,46 +15,12 @@ test();
function test() function test()
{ {
var TestPassCount = 0; function check(fun) {
var TestFailCount = 0; assert.sameValue(fun(), true);
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 checkThrows(fun, todo) { function checkThrows(fun) {
let thrown = false; assert.throws(TypeError, fun);
try {
fun();
} catch (x) {
thrown = true;
}
check(() => thrown, todo);
} }
var key = {}; var key = {};
@ -93,6 +59,4 @@ function test()
check(() => map.get(key) == undefined); check(() => map.get(key) == undefined);
checkThrows(() => map.set("non-object key", value)); checkThrows(() => map.set("non-object key", value));
assert.sameValue(0, TestFailCount, "weak map tests");
} }

View File

@ -17,17 +17,10 @@ esid: pending
function assertSyntaxError(str) { function assertSyntaxError(str) {
var msg; var msg;
var evil = eval; var evil = eval;
try { assert.throws(SyntaxError, function() {
// Non-direct eval. // Non-direct eval.
evil(str); 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. // Yield statements.

View File

@ -8,9 +8,7 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
try {
decodeURIComponent('%ED%A0%80'); assert.throws(URIError, function() {
assert.sameValue(true, false, "expected an URIError"); decodeURIComponent('%ED%A0%80');
} catch (e) { });
assert.sameValue(e instanceof URIError, true);
}

View File

@ -8,32 +8,23 @@ description: |
pending pending
esid: 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); eval('"use strict";' + str);
} catch (e) { });
threwSyntaxError = e instanceof SyntaxError;
}
assert.sameValue(threwSyntaxError, true);
} }
function expectSloppyPass(str) { function expectSloppyPass(str) {
eval(str); eval(str);
try { assert.throws(SyntaxError, function() {
eval('"use strict";' + str); eval('"use strict";' + str);
} catch (e) { });
threwSyntaxError = e instanceof SyntaxError;
}
assert.sameValue(threwSyntaxError, true);
} }
expectSloppyPass(`l: function f1() {}`); expectSloppyPass(`l: function f1() {}`);
@ -49,4 +40,3 @@ expectSyntaxError(`while (0) l: function f5() {}`);
expectSyntaxError(`for (;;) l: function f6() {}`); expectSyntaxError(`for (;;) l: function f6() {}`);
expectSloppyPass(`switch (1) { case 1: l: function f7() {} }`); 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');`); expectSloppyPass(`switch (1) { case 1: assert.sameValue(f8(), 'f8'); case 2: l: function f8() { return 'f8'; } } assert.sameValue(f8(), 'f8');`);

View File

@ -8,6 +8,7 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
{ {
assert.sameValue(f(), 4); assert.sameValue(f(), 4);
function f() { return 3; } function f() { return 3; }
@ -46,41 +47,27 @@ function test() {
test(); test();
var log = ''; // Strict mode still cannot redeclare.
assert.throws(SyntaxError, function() {
try {
// Strict mode still cannot redeclare.
eval(`"use strict"; eval(`"use strict";
{ {
function f() { } function f() { }
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(`{ eval(`{
let x = 42; let x = 42;
function x() {} 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(`{ eval(`{
const x = 42; const x = 42;
function x() {} function x() {}
}`); }`);
} catch (e) { });
assert.sameValue(e instanceof SyntaxError, true);
log += 'e';
}
assert.sameValue(log, 'eee');

View File

@ -8,31 +8,19 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var log = "";
try {
(function() {
{
let y = f();
function f() { y; }
}
})()
} catch (e) {
log += e instanceof ReferenceError;
}
try { assert.throws(ReferenceError, function() {
function f() { {
switch (1) { let y = f();
case 0: function f() { y; }
let x;
case 1:
(function() { x; })();
}
} }
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; })();
}
});

View File

@ -13,16 +13,9 @@ esid: pending
function isError(code, type) function isError(code, type)
{ {
try assert.throws(type, function() {
{
Function(code); 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) function isOK(code)

View File

@ -92,44 +92,24 @@ function testMethod(Class, className, method)
var badThis = badThisValues[i]; var badThis = badThisValues[i];
expr = className + ".prototype." + method + ".call(" + badThis + ")"; expr = className + ".prototype." + method + ".call(" + badThis + ")";
try assert.throws(TypeError, function() {
{
Class.prototype[method].call(badThis); Class.prototype[method].call(badThis);
throw new Error(expr + " didn't throw a TypeError"); }, "wrong error for " + expr);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error for " + expr + ", instead threw " + e);
}
expr = className + ".prototype." + method + ".apply(" + badThis + ")"; expr = className + ".prototype." + method + ".apply(" + badThis + ")";
try assert.throws(TypeError, function() {
{
Class.prototype[method].apply(badThis); Class.prototype[method].apply(badThis);
throw new Error(expr + " didn't throw a TypeError"); }, "wrong error for " + expr);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error for " + expr + ", instead threw " + e);
}
} }
// ..and for good measure.. // ..and for good measure..
expr = "(0, " + className + ".prototype." + method + ")()" expr = "(0, " + className + ".prototype." + method + ")()";
try assert.throws(TypeError, function() {
{
// comma operator to call GetValue() on the method and de-Reference it // comma operator to call GetValue() on the method and de-Reference it
(0, Class.prototype[method])(); (0, Class.prototype[method])();
throw new Error(expr + " didn't throw a TypeError"); }, "wrong error for " + expr);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error for " + expr + ", instead threw " + e);
}
} }
for (var className in ClassToMethodMap) for (var className in ClassToMethodMap)

View File

@ -14,7 +14,7 @@ esid: pending
var futureReservedWords = var futureReservedWords =
[ [
"class", "class",
// "const", // Mozilla extension enabled even for versionless code "const",
"enum", "enum",
"export", "export",
"extends", "extends",
@ -26,459 +26,97 @@ var strictFutureReservedWords =
[ [
"implements", "implements",
"interface", "interface",
"let", // enabled: this file doesn't execute as JS1.7 "let",
"package", "package",
"private", "private",
"protected", "protected",
"public", "public",
"static", "static",
"yield", // enabled: this file doesn't execute as JS1.7 "yield",
]; ];
function testWord(word, expectNormal, expectStrict) function testNormalAndStrict(word, code, message) {
{ if (strictFutureReservedWords.includes(word)) {
var actual, status; 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 // USE AS LHS FOR ASSIGNMENT
testNormalAndStrict(word, word + " = 'foo';", "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);
// USE AS DESTRUCTURING SHORTHAND // USE AS DESTRUCTURING SHORTHAND
testNormalAndStrict(word, "({ " + word + " } = 'foo');", "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);
// USE IN VARIABLE DECLARATION // USE IN VARIABLE DECLARATION
testNormalAndStrict(word, "var " + word + ";", "var");
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);
// USE IN FOR-IN VARIABLE DECLARATION // USE IN FOR-IN VARIABLE DECLARATION
testNormalAndStrict(word, "for (var " + word + " in {});", "for-in var");
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);
// USE AS CATCH IDENTIFIER // USE AS CATCH IDENTIFIER
testNormalAndStrict(word, "try { } catch (" + word + ") { }", "catch var");
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);
// USE AS LABEL // USE AS LABEL
testNormalAndStrict(word, word + ": while (false);", "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);
// USE AS ARGUMENT NAME IN FUNCTION DECLARATION // USE AS ARGUMENT NAME IN FUNCTION DECLARATION
testNormalAndStrict(word, "function foo(" + word + ") { }", "function argument");
actual = ""; assert.throws(SyntaxError, function() {
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
{
eval("function foo(" + word + ") { 'use strict'; }"); eval("function foo(" + word + ") { 'use strict'; }");
actual = "no error"; }, word + ": function argument retroactively strict");
}
catch (e)
{
actual = e.name;
status += ", " + e.name + ": " + e.message + " ";
}
assert.sameValue(actual, expectStrict, status);
// USE AS ARGUMENT NAME IN FUNCTION EXPRESSION // USE AS ARGUMENT NAME IN FUNCTION EXPRESSION
testNormalAndStrict(word, "var s = (function foo(" + word + ") { });", "function expression argument");
actual = ""; assert.throws(SyntaxError, function() {
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
{
eval("var s = (function foo(" + word + ") { 'use strict'; });"); eval("var s = (function foo(" + word + ") { 'use strict'; });");
actual = "no error"; }, word + ": function expression argument retroactively strict");
}
catch (e)
{
actual = e.name;
status += ", " + e.name + ": " + e.message + " ";
}
assert.sameValue(actual, expectStrict, status);
// USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR // USE AS ARGUMENT NAME WITH FUNCTION CONSTRUCTOR
if (strictFutureReservedWords.includes(word)) {
actual = "";
status = word + ": argument with normal Function";
try
{
Function(word, "return 17"); 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 = ""; assert.throws(SyntaxError, function() {
status = word + ": argument with strict Function";
try
{
Function(word, "'use strict'; return 17"); Function(word, "'use strict'; return 17");
actual = "no error"; }, word + ": argument with strict Function");
}
catch (e)
{
actual = e.name;
status += ", " + e.name + ": " + e.message + " ";
}
assert.sameValue(actual, expectStrict, status);
// USE AS ARGUMENT NAME IN PROPERTY SETTER // USE AS ARGUMENT NAME IN PROPERTY SETTER
testNormalAndStrict(word, "var o = { set x(" + word + ") { } };", "property setter argument");
actual = ""; assert.throws(SyntaxError, function() {
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
{
eval("var o = { set x(" + word + ") { 'use strict'; } };"); eval("var o = { set x(" + word + ") { 'use strict'; } };");
actual = "no error"; }, word + ": property setter argument retroactively strict");
}
catch (e)
{
actual = e.name;
status += ", " + e.name + ": " + e.message + " ";
}
assert.sameValue(actual, expectStrict, status);
// USE AS FUNCTION NAME IN FUNCTION DECLARATION // USE AS FUNCTION NAME IN FUNCTION DECLARATION
testNormalAndStrict(word, "function " + word + "() { }", "function name");
actual = ""; assert.throws(SyntaxError, function() {
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
{
eval("function " + word + "() { 'use strict'; }"); eval("function " + word + "() { 'use strict'; }");
actual = "no error"; }, word + ": function name retroactively strict");
}
catch (e)
{
actual = e.name;
status += ", " + e.name + ": " + e.message + " ";
}
assert.sameValue(actual, expectStrict, status);
// USE AS FUNCTION NAME IN FUNCTION EXPRESSION // USE AS FUNCTION NAME IN FUNCTION EXPRESSION
testNormalAndStrict(word, "var s = (function " + word + "() { });", "function expression name");
actual = ""; assert.throws(SyntaxError, function() {
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
{
eval("var s = (function " + word + "() { 'use strict'; });"); eval("var s = (function " + word + "() { 'use strict'; });");
actual = "no error"; }, word + ": function expression name retroactively strict");
}
catch (e)
{
actual = e.name;
status += ", " + e.name + ": " + e.message + " ";
}
assert.sameValue(actual, expectStrict, status);
} }
function testFutureReservedWord(word) futureReservedWords.forEach(testWord);
{ strictFutureReservedWords.forEach(testWord);
testWord(word, "SyntaxError", "SyntaxError");
}
function testStrictFutureReservedWord(word)
{
testWord(word, "no error", "SyntaxError");
}
futureReservedWords.forEach(testFutureReservedWord);
strictFutureReservedWords.forEach(testStrictFutureReservedWord);

View File

@ -11,7 +11,7 @@ description: |
esid: pending esid: pending
---*/ ---*/
var desc, old, error; var desc, old;
var global = this; var global = this;
var names = ["NaN", "Infinity", "undefined"]; var names = ["NaN", "Infinity", "undefined"];
@ -29,22 +29,8 @@ for (var i = 0; i < names.length; i++)
global[name] = 17; global[name] = 17;
assert.sameValue(global[name], old, name + " changed on setting?"); assert.sameValue(global[name], old, name + " changed on setting?");
error = "before"; assert.throws(TypeError, function() {
try "use strict";
{ global[name] = 42;
throw new TypeError("SpiderMonkey doesn't currently implement " + }, "wrong strict mode error setting " + name);
"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);
} }

View File

@ -10,14 +10,11 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function checkConstruct(thing) { function checkConstruct(thing) {
try { assert.throws(TypeError, function() {
new thing(); 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);
}
} }
var re = /aaa/ var re = /aaa/
@ -34,4 +31,3 @@ checkConstruct(proxiedFunctionPrototype);
var proxiedBuiltin = new Proxy(parseInt, {}); var proxiedBuiltin = new Proxy(parseInt, {});
checkConstruct(proxiedBuiltin); checkConstruct(proxiedBuiltin);

View File

@ -13,16 +13,9 @@ esid: pending
function checkSyntaxError(str) function checkSyntaxError(str)
{ {
try assert.throws(SyntaxError, function() {
{ Function(str);
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);
}
} }
checkSyntaxError("for(var w in \\"); checkSyntaxError("for(var w in \\");

View File

@ -10,18 +10,14 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function throws(code) { function throws(code) {
var type; assert.throws(SyntaxError, function() {
try { eval(code);
eval(code); });
} catch (ex) {
type = ex.name;
}
assert.sameValue(type, 'SyntaxError');
} }
var s = '\\u0073'; var s = '\\u0073';
throws('var thi' + s); throws('var thi' + s);
throws('switch (' + s + 'witch) {}') throws('switch (' + s + 'witch) {}')
throws('var ' + s + 'witch'); throws('var ' + s + 'witch');

View File

@ -10,12 +10,7 @@ description: |
pending pending
esid: 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);

View File

@ -10,12 +10,7 @@ description: |
pending pending
esid: 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);

View File

@ -42,11 +42,8 @@ assert.sameValue(Object.getOwnPropertyDescriptor(o, "baz"), undefined);
assert.sameValue(o.baz, 12); assert.sameValue(o.baz, 12);
assert.sameValue(o.hasOwnProperty("baz"), false); assert.sameValue(o.hasOwnProperty("baz"), false);
try { var actual =
var actual = Object.create(Object.create({},
Object.create(Object.create({}, { boom: { get: function() { return "base"; }}}),
{ boom: { get: function() { return "base"; }}}), { boom: { get: function() { return "overridden"; }}}).boom
{ boom: { get: function() { return "overridden"; }}}).boom
} catch (e) {
}
assert.sameValue(actual, "overridden"); assert.sameValue(actual, "overridden");

View File

@ -41,20 +41,10 @@ props =
c: { value: NaN, enumerable: false, configurable: true, writable: true }, c: { value: NaN, enumerable: false, configurable: true, writable: true },
b: { value: 44 } b: { value: 44 }
}; };
var error = "before";
try assert.throws(TypeError, function() {
{
Object.defineProperties(o, props); 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("c" in o, true, "new property added");
assert.sameValue(o.b, 42, "old property value preserved"); 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, ""); Object.defineProperties(o, "");
assert.sameValue("quux" in o, false, "quux is not an enumerable own property"); assert.sameValue("quux" in o, false, "quux is not an enumerable own property");
error = "before"; assert.throws(TypeError, function() {
try
{
Object.defineProperties(o, "1"); Object.defineProperties(o, "1");
} }, "should throw on Properties == '1' due to '1'[0] not being a property descriptor");
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");
error = "before"; assert.throws(TypeError, function() {
try
{
Object.defineProperties(o, null); Object.defineProperties(o, null);
} }, "should throw on Properties == null");
catch (e)
{
if (e instanceof TypeError)
error = "typeerror";
else
error = "bad exception: " + e;
}
assert.sameValue(error, "typeerror", "should throw on Properties == null");
error = "before"; assert.throws(TypeError, function() {
try
{
Object.defineProperties(o, undefined); Object.defineProperties(o, undefined);
} }, "should throw on Properties == undefined");
catch (e)
{
if (e instanceof TypeError)
error = "typeerror";
else
error = "bad exception: " + e;
}
assert.sameValue(error, "typeerror", "should throw on Properties == undefined");

View File

@ -11,56 +11,31 @@ description: |
esid: pending 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"; "use strict";
o[p] = v; o[p] = v;
} });
}
function setProperty()
{
o[p] = v;
}
function trySetProperty(o, p, v)
{
assert.sameValue(Object.prototype.hasOwnProperty.call(o, p), false); assert.sameValue(Object.prototype.hasOwnProperty.call(o, p), false);
try o[p] = v;
{
if (strict) assert.notSameValue(o[p], v);
strictSetProperty(); assert.sameValue(p in o, false);
else
setProperty();
if (o[p] === v)
return "set";
if (p in o)
return "set-converted";
return "swallowed";
}
catch (e)
{
return "throw";
}
} }
function tryDefineProperty(o, p, v) function tryDefineProperty(o, p, v)
{ {
assert.sameValue(Object.prototype.hasOwnProperty.call(o, p), false); assert.sameValue(Object.prototype.hasOwnProperty.call(o, p), false);
assert.throws(TypeError, function() {
try
{
Object.defineProperty(o, p, { value: v }); 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"); 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(Object.isExtensible(o), false, "object " + i + " is extensible?");
assert.sameValue(trySetProperty(o, "baz", 17, true), "throw", tryStrictSetProperty(o, "baz", 17);
"unexpected behavior for strict-mode property-addition to " + trySetProperty(o, "baz", 17);
"object " + i); tryDefineProperty(o, "baz", 17);
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);
} }

View File

@ -11,20 +11,6 @@ description: |
esid: pending 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; var isPrototypeOf = Object.prototype.isPrototypeOf;
/* /*
@ -48,12 +34,12 @@ assert.sameValue(isPrototypeOf(null), false);
* argument. * argument.
*/ */
var protoGlobal = Object.create(this); var protoGlobal = Object.create(this);
expectThrowTypeError(function() { isPrototypeOf.call(null, {}); }); assert.throws(TypeError, function() { isPrototypeOf.call(null, {}); });
expectThrowTypeError(function() { isPrototypeOf.call(undefined, {}); }); assert.throws(TypeError, function() { isPrototypeOf.call(undefined, {}); });
expectThrowTypeError(function() { isPrototypeOf({}); }); assert.throws(TypeError, function() { isPrototypeOf({}); });
expectThrowTypeError(function() { isPrototypeOf.call(null, protoGlobal); }); assert.throws(TypeError, function() { isPrototypeOf.call(null, protoGlobal); });
expectThrowTypeError(function() { isPrototypeOf.call(undefined, protoGlobal); }); assert.throws(TypeError, function() { isPrototypeOf.call(undefined, protoGlobal); });
expectThrowTypeError(function() { isPrototypeOf(protoGlobal); }); assert.throws(TypeError, function() { isPrototypeOf(protoGlobal); });
/* /*

View File

@ -11,25 +11,6 @@ description: |
esid: pending 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) function withToString(fun)
{ {
return { toString: fun }; return { toString: fun };
@ -45,106 +26,106 @@ var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
/* /*
* 1. Let P be ToString(V). * 1. Let P be ToString(V).
*/ */
expectThrowError(ReferenceError, function() assert.throws(ReferenceError, function()
{ {
propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; })); propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; }));
}); });
expectThrowError(ReferenceError, function() assert.throws(ReferenceError, function()
{ {
propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; })); propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; }));
}); });
expectThrowError(ReferenceError, function() assert.throws(ReferenceError, function()
{ {
propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; })); propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; }));
}); });
expectThrowError(ReferenceError, function() assert.throws(ReferenceError, function()
{ {
propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; })); propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; }));
}); });
expectThrowError(ReferenceError, function() assert.throws(ReferenceError, function()
{ {
propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; })); propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; }));
}); });
expectThrowError(ReferenceError, function() assert.throws(ReferenceError, function()
{ {
propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; })); propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; }));
}); });
expectThrowError(SyntaxError, function() assert.throws(SyntaxError, function()
{ {
propertyIsEnumerable(withToString(function() { eval("}"); })); propertyIsEnumerable(withToString(function() { eval("}"); }));
}); });
expectThrowError(SyntaxError, function() assert.throws(SyntaxError, function()
{ {
propertyIsEnumerable.call(null, withToString(function() { eval("}"); })); propertyIsEnumerable.call(null, withToString(function() { eval("}"); }));
}); });
expectThrowError(SyntaxError, function() assert.throws(SyntaxError, function()
{ {
propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); })); propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); }));
}); });
expectThrowError(SyntaxError, function() assert.throws(SyntaxError, function()
{ {
propertyIsEnumerable(withValueOf(function() { eval("}"); })); propertyIsEnumerable(withValueOf(function() { eval("}"); }));
}); });
expectThrowError(SyntaxError, function() assert.throws(SyntaxError, function()
{ {
propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); })); propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); }));
}); });
expectThrowError(SyntaxError, function() assert.throws(SyntaxError, function()
{ {
propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); })); propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable(withToString(function() { [].length = -1; })); propertyIsEnumerable(withToString(function() { [].length = -1; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(null, withToString(function() { [].length = -1; })); propertyIsEnumerable.call(null, withToString(function() { [].length = -1; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; })); propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable(withValueOf(function() { [].length = -1; })); propertyIsEnumerable(withValueOf(function() { [].length = -1; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; })); propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; })); propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable(withToString(function() { [].length = 0.7; })); propertyIsEnumerable(withToString(function() { [].length = 0.7; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; })); propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; })); propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable(withValueOf(function() { [].length = 0.7; })); propertyIsEnumerable(withValueOf(function() { [].length = 0.7; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; })); propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; }));
}); });
expectThrowError(RangeError, function() assert.throws(RangeError, function()
{ {
propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = 0.7; })); 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 * 2. Let O be the result of calling ToObject passing the this value as the
* argument. * argument.
*/ */
expectThrowTypeError(function() { propertyIsEnumerable("s"); }); assert.throws(TypeError, function() { propertyIsEnumerable("s"); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, "s"); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(null, "s"); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, "s"); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, "s"); });
expectThrowTypeError(function() { propertyIsEnumerable(true); }); assert.throws(TypeError, function() { propertyIsEnumerable(true); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, true); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(null, true); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, true); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, true); });
expectThrowTypeError(function() { propertyIsEnumerable(NaN); }); assert.throws(TypeError, function() { propertyIsEnumerable(NaN); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, NaN); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(null, NaN); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, NaN); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, NaN); });
expectThrowTypeError(function() { propertyIsEnumerable({}); }); assert.throws(TypeError, function() { propertyIsEnumerable({}); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, {}); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(null, {}); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, {}); }); assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, {}); });
/* /*
* 3. Let desc be the result of calling the [[GetOwnProperty]] internal method * 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({}, "__proto__"), false);
assert.sameValue(propertyIsEnumerable.call(Object, "getOwnPropertyDescriptor"), 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", "length"), false);
assert.sameValue(propertyIsEnumerable.call("s", 0), true); assert.sameValue(propertyIsEnumerable.call("s", 0), true);
assert.sameValue(propertyIsEnumerable.call(Number, "MAX_VALUE"), false); assert.sameValue(propertyIsEnumerable.call(Number, "MAX_VALUE"), false);

View File

@ -11,30 +11,16 @@ description: |
esid: pending 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; var toLocaleString = Object.prototype.toLocaleString;
/* /*
* 1. Let O be the result of calling ToObject passing the this value as the * 1. Let O be the result of calling ToObject passing the this value as the
* argument. * argument.
*/ */
expectThrowTypeError(function() { toLocaleString.call(null); }); assert.throws(TypeError, function() { toLocaleString.call(null); });
expectThrowTypeError(function() { toLocaleString.call(undefined); }); assert.throws(TypeError, function() { toLocaleString.call(undefined); });
expectThrowTypeError(function() { toLocaleString.apply(null); }); assert.throws(TypeError, function() { toLocaleString.apply(null); });
expectThrowTypeError(function() { toLocaleString.apply(undefined); }); assert.throws(TypeError, function() { toLocaleString.apply(undefined); });
/* /*
@ -53,27 +39,27 @@ catch (e)
/* 3. If IsCallable(toString) is false, throw a TypeError exception. */ /* 3. If IsCallable(toString) is false, throw a TypeError exception. */
expectThrowTypeError(function() { toLocaleString.call({ toString: 12 }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: 12 }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: 0.3423423452352e9 }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: 0.3423423452352e9 }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: undefined }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: undefined }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: false }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: false }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: [] }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: [] }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: {} }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: {} }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: new String }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: new String }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: new Number(7.7) }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: new Number(7.7) }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: new Boolean(true) }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: new Boolean(true) }); });
expectThrowTypeError(function() { toLocaleString.call({ toString: JSON }); }); assert.throws(TypeError, function() { toLocaleString.call({ toString: JSON }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 12 }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: 12 }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: 0.3423423452352e9 }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: 0.3423423452352e9 }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: undefined }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: undefined }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: false }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: false }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: [] }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: [] }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: {} }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: {} }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new String }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: new String }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Number(7.7) }); }); assert.throws(TypeError, function() { toLocaleString.call({ valueOf: 0, toString: new Number(7.7) }); });
expectThrowTypeError(function() { toLocaleString.call({ valueOf: 0, toString: new Boolean(true) }); }); assert.throws(TypeError, 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: JSON }); });
/* /*

View File

@ -9,41 +9,13 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function assertSameEntries(actual, expected) { function assertSameEntries(actual, expected) {
assert.sameValue(actual.length, expected.length); assert.sameValue(actual.length, expected.length);
for (let i = 0; i < expected.length; ++i) for (let i = 0; i < expected.length; ++i)
assert.compareArray(actual[i], expected[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. // Ensure Object.keys/values/entries work correctly on typed arrays.
for (let len of [0, 1, 10]) { for (let len of [0, 1, 10]) {
let array = new Array(len).fill(1); let array = new Array(len).fill(1);
@ -55,8 +27,7 @@ for (let len of [0, 1, 10]) {
$262.detachArrayBuffer(ta.buffer); $262.detachArrayBuffer(ta.buffer);
assert.compareArray(maybeThrowOnDetached(() => Object.keys(ta), []), []); assert.compareArray(Object.keys(ta), []);
assert.compareArray(maybeThrowOnDetached(() => Object.values(ta), []), []); assert.compareArray(Object.values(ta), []);
assertSameEntries(maybeThrowOnDetached(() => Object.entries(ta), []), []); assertSameEntries(Object.entries(ta), []);
} }

View File

@ -11,17 +11,6 @@ description: |
esid: pending esid: pending
---*/ ---*/
test(); assert.throws(SyntaxError, function() {
eval('function(){if(t)');
function test() });
{
try
{
eval('function(){if(t)');
}
catch(ex)
{
assert.sameValue(ex instanceof SyntaxError, true, "wrong error: " + ex);
}
}

View File

@ -10,15 +10,15 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function isSyntaxError(code) {
try { function throwsNoSyntaxError(code) {
eval(code);
};
function throwsSyntaxError(code) {
assert.throws(SyntaxError, function() {
eval(code); 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 * user has opted in to a modicum of sanity, and we forbid duplicate
* parameter names. * parameter names.
*/ */
assert.sameValue(isSyntaxError("function f(x,x){}"), false); throwsNoSyntaxError("function f(x,x){}");
assert.sameValue(isSyntaxError("function f(x,[x]){})"), true); throwsSyntaxError("function f(x,[x]){})");
assert.sameValue(isSyntaxError("function f(x,{y:x}){})"), true); throwsSyntaxError("function f(x,{y:x}){})");
assert.sameValue(isSyntaxError("function f(x,{x}){})"), true); throwsSyntaxError("function f(x,{x}){})");
assert.sameValue(isSyntaxError("function f([x],x){})"), true); throwsSyntaxError("function f([x],x){})");
assert.sameValue(isSyntaxError("function f({y:x},x){})"), true); throwsSyntaxError("function f({y:x},x){})");
assert.sameValue(isSyntaxError("function f({x},x){})"), true); throwsSyntaxError("function f({x},x){})");
assert.sameValue(isSyntaxError("function f([x,x]){}"), true); throwsSyntaxError("function f([x,x]){}");
assert.sameValue(isSyntaxError("function f({x,x}){}"), true); throwsSyntaxError("function f({x,x}){}");
assert.sameValue(isSyntaxError("function f({y:x,z:x}){}"), true); throwsSyntaxError("function f({y:x,z:x}){}");
assert.sameValue(isSyntaxError("function f(x,x,[y]){}"), true); throwsSyntaxError("function f(x,x,[y]){}");
assert.sameValue(isSyntaxError("function f(x,x,{y}){}"), true); throwsSyntaxError("function f(x,x,{y}){}");
assert.sameValue(isSyntaxError("function f([y],x,x){}"), true); throwsSyntaxError("function f([y],x,x){}");
assert.sameValue(isSyntaxError("function f({y},x,x){}"), true); throwsSyntaxError("function f({y},x,x){}");
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(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]){}");

View File

@ -14,29 +14,19 @@ var F, o;
F = function () {}; F = function () {};
F.prototype = new ArrayBuffer(1); F.prototype = new ArrayBuffer(1);
o = new F(); o = new F();
try { assert.throws(TypeError, function() {
o.byteLength; o.byteLength;
} catch (ex) { });
// o is not a platform object
assert.sameValue(ex instanceof TypeError, true);
}
o = {}; o = {};
o.__proto__ = new Int32Array(1); o.__proto__ = new Int32Array(1);
try { assert.throws(TypeError, function() {
o.buffer.byteLength; o.buffer.byteLength;
} catch (ex) { });
// o is not a platform object
assert.sameValue(ex instanceof TypeError, true);
}
F = function () {}; F = function () {};
F.prototype = new Int32Array(1); F.prototype = new Int32Array(1);
o = new F(); o = new F();
try { assert.throws(TypeError, function() {
o.slice(0, 1); o.slice(0, 1);
reportFailure("Expected an exception!"); });
} catch (ex) {
}
assert.sameValue("ok", "ok", "bug 571014");

View File

@ -10,19 +10,12 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
var o = {__iterator__:null, a:1, b:2, c:3} var o = {__iterator__:null, a:1, b:2, c:3}
var expect = '__iterator__,a,b,c,'; var expect = '__iterator__,a,b,c,';
var actual = ''; var actual = '';
try { for (var i in o)
for (var i in o) actual += i + ',';
actual += i + ',';
} catch (e) {
actual = '' + e;
if (/invalid __iterator__ value/.test(actual) ||
/null is not a function/.test(actual)) {
expect = actual;
}
}
assert.sameValue(expect, actual, "ok"); assert.sameValue(expect, actual, "ok");

View File

@ -10,13 +10,12 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
function C(){} function C(){}
C.prototype = 1; C.prototype = 1;
try {
Object.defineProperty(C, "prototype", {get: function() { throw 0; }}); assert.throws(TypeError, function() {
actual = "no exception"; Object.defineProperty(C, "prototype", {get: function() { throw 0; }});
} catch (exc) { });
actual = exc.name;
}
new C; // don't assert new C; // don't assert
assert.sameValue(actual, "TypeError");

View File

@ -7,31 +7,10 @@
flags: flags:
- noStrict - noStrict
description: | description: |
pending Do not assert when ungetting a Unicode char sequence
esid: pending esid: pending
---*/ ---*/
//-----------------------------------------------------------------------------
var BUGNUMBER = 618572;
var summary = 'Do not assert when ungetting a Unicode char sequence';
var actual = '';
var expect = '';
//----------------------------------------------------------------------------- assert.throws(SyntaxError, function() {
test(); eval("var a\\0021 = 3;");
//----------------------------------------------------------------------------- });
function test()
{
expect = 'SyntaxError';
try
{
eval("var a\\0021 = 3;");
}
catch(ex)
{
actual = ex.constructor.name;
}
assert.sameValue(expect, actual, summary);
}

View File

@ -10,7 +10,7 @@ description: |
pending pending
esid: pending esid: pending
---*/ ---*/
try {
new {prototype: TypeError.prototype};
} catch (e) {}
assert.throws(TypeError, function() {
new {prototype: TypeError.prototype};
});

View File

@ -11,13 +11,6 @@ description: |
esid: pending esid: pending
---*/ ---*/
try assert.throws(SyntaxError, function() {
{
Function("for (x => 0 in 1;;) break;"); 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);
}

View File

@ -11,13 +11,6 @@ description: |
esid: pending esid: pending
---*/ ---*/
try assert.throws(SyntaxError, function() {
{
Function("for (var x = 3 of 42);"); 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);
}

View File

@ -12,17 +12,7 @@ esid: pending
---*/ ---*/
var f = function assignSelfStrict() { "use strict"; assignSelfStrict = 12; }; var f = function assignSelfStrict() { "use strict"; assignSelfStrict = 12; };
assert.throws(TypeError, f);
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);
}
var assignSelf = 42; var assignSelf = 42;
var f2 = function assignSelf() { assignSelf = 12; }; var f2 = function assignSelf() { assignSelf = 12; };

View File

@ -11,51 +11,21 @@ description: |
esid: pending esid: pending
---*/ ---*/
try assert.throws(SyntaxError, function() {
{
eval(" '\\145'; 'use strict'; "); eval(" '\\145'; 'use strict'; ");
throw new Error("no error thrown for eval"); }, "wrong error for octal-escape before strict directive in eval");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"wrong error for octal-escape before strict directive in eval");
}
try assert.throws(SyntaxError, function() {
{
Function(" '\\145'; 'use strict'; "); Function(" '\\145'; 'use strict'; ");
throw new Error("no error thrown for Function"); }, "wrong error for octal-escape before strict directive in Function");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"wrong error for octal-escape before strict directive in Function");
}
try assert.throws(SyntaxError, function() {
{
eval(" function f(){ '\\145'; 'use strict'; } "); eval(" function f(){ '\\145'; 'use strict'; } ");
throw new Error("no error thrown for eval of function"); }, "wrong error for octal-escape before strict directive in eval of function");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"wrong error for octal-escape before strict directive in eval of " +
"function");
}
try assert.throws(SyntaxError, function() {
{
Function(" function f(){ '\\145'; 'use strict'; } "); Function(" function f(){ '\\145'; 'use strict'; } ");
throw new Error("no error thrown for eval of function"); }, "wrong error for octal-escape before strict directive in eval of function");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"wrong error for octal-escape before strict directive in eval of " +
"function");
}
eval("function notAnError1() { 5; '\\145'; function g() { 'use strict'; } }"); eval("function notAnError1() { 5; '\\145'; function g() { 'use strict'; } }");

View File

@ -29,17 +29,10 @@ var BadSyntaxStrings = [
]; ];
function testString(s, i) { function testString(s, i) {
var gotSyntaxError = -1; assert.throws(SyntaxError, function() {
try {
eval(s); eval(s);
} catch(err) { });
if (err instanceof SyntaxError)
gotSyntaxError = i;
}
assert.sameValue(gotSyntaxError, i);
} }
for (var i = 0; i < BadSyntaxStrings.length; i++) for (var i = 0; i < BadSyntaxStrings.length; i++)
testString(BadSyntaxStrings[i], i); testString(BadSyntaxStrings[i], i);

View File

@ -18,32 +18,15 @@ function strict() {
function bar() {} function bar() {}
} }
var exception;
// Try 'undefined' as a |this| value. // Try 'undefined' as a |this| value.
exception = null; assert.throws(TypeError, function() {
try {
strict.call(undefined); strict.call(undefined);
} catch (x) { });
exception = x;
}
assert.sameValue(exception instanceof TypeError, true);
// Try 'null' as a |this| value. // Try 'null' as a |this| value.
exception = null; assert.throws(TypeError, function() {
try {
strict.call(null); strict.call(null);
} catch (x) { });
exception = x;
}
assert.sameValue(exception instanceof TypeError, true);
// An object as a |this| value should be fine. // An object as a |this| value should be fine.
exception = null; strict.call({});
try {
strict.call({});
} catch (x) {
exception = x;
}
assert.sameValue(exception, null);

View File

@ -8,19 +8,7 @@ description: |
pending pending
esid: 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);
}
assert.throws(SyntaxError, function() {
assertThrowsSyntaxError("class X { x: 1 }") eval("class X { x: 1 }");
});
if ('assert.sameValue' in this) {
}

View File

@ -13,16 +13,9 @@ esid: pending
function expectSyntaxError(code) function expectSyntaxError(code)
{ {
try assert.throws(SyntaxError, function() {
{
eval(code); 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: // The fundamental requirements of this test:

View File

@ -7,17 +7,9 @@
flags: flags:
- noStrict - noStrict
description: | 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 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"; } }; var o = { get p() { return "a"; } };
@ -55,56 +47,7 @@ function strictTest2()
assert.sameValue(y.p, "a"); assert.sameValue(y.p, "a");
} }
var errors = []; test1();
try test2();
{ assert.throws(TypeError, strictTest1);
try assert.throws(TypeError, strictTest2);
{
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);