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
// the other realm (not this realm)
for (const [message, f] of typeErrorCalls) {
try {
f();
} catch (exc) {
assert.sameValue(exc instanceof TypeError, false, message + " threw TypeError from wrong realm");
assert.sameValue(exc instanceof otherGlobal.TypeError, true, message + " didn't throw TypeError from other realm");
assert.sameValue(Object.getPrototypeOf(exc) !== Object.getPrototypeOf(TypeError), true,
message + " TypeError has wrong prototype");
}
assert.throws(otherGlobal.TypeError, f, message);
}
for (const [message, f] of rangeErrorCalls) {
try {
f();
} catch (exc) {
assert.sameValue(exc instanceof RangeError, false, message + " threw RangeError from wrong realm");
assert.sameValue(exc instanceof otherGlobal.RangeError, true, message + " didn't throw RangeError from other realm");
assert.sameValue(Object.getPrototypeOf(exc) !== Object.getPrototypeOf(RangeError), true,
message + " TypeError has wrong prototype");
}
assert.throws(otherGlobal.RangeError, f, message);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -27,8 +27,7 @@ var convertible =
var arr = [];
Object.defineProperty(arr, "length", { value: 0, writable: false });
try
{
assert.throws(SyntaxError, function() {
Object.defineProperty(arr, "length",
{
value: convertible,
@ -36,12 +35,7 @@ try
configurable: true,
enumerable: true
});
throw new Error("didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true, "expected SyntaxError, got " + e);
}
});
assert.sameValue(count, 1);
assert.sameValue(arr.length, 0);

View File

@ -10,20 +10,16 @@ description: |
pending
esid: pending
---*/
function throwsRangeError(t) {
try {
var date = new Date();
date.setTime(t);
var r = date.toISOString();
throw new Error("toISOString didn't throw, instead returned " + r);
} catch (err) {
assert.sameValue(err instanceof RangeError, true, 'wrong error: ' + err);
return;
}
assert.sameValue(0, 1, 'not good, nyan, nyan');
assert.throws(RangeError, function() {
date.toISOString();
});
}
throwsRangeError(Infinity);
throwsRangeError(-Infinity);
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
* argument.
*/
try
{
assert.throws(TypeError, function() {
dateToJSON.call(null);
throw new Error("should have thrown a TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToObject throws TypeError for null/undefined");
}
}, "ToObject throws TypeError for null");
try
{
assert.throws(TypeError, function() {
dateToJSON.call(undefined);
throw new Error("should have thrown a TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"ToObject throws TypeError for null/undefined");
}
}, "ToObject throws TypeError for undefined");
/*
@ -123,19 +109,13 @@ assert.sameValue(dateToJSON.call({ valueOf: function() { called = true; return {
NaN);
assert.sameValue(asserted, true);
try
{
assert.throws(TypeError, function() {
var r = dateToJSON.call({ valueOf: null, toString: null,
get toISOString()
{
throw new Error("shouldn't have been gotten");
} });
throw new Error("didn't throw, returned: " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "bad exception: " + e);
}
});
/* 3. If tv is a Number and is not finite, return null. */
@ -167,45 +147,21 @@ catch (e)
/* 5. If IsCallable(toISO) is false, throw a TypeError exception. */
try
{
var r = dateToJSON.call({ toISOString: null });
throw new Error("didn't throw, returned: " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "bad exception: " + e);
}
assert.throws(TypeError, function() {
dateToJSON.call({ toISOString: null });
});
try
{
var r = dateToJSON.call({ toISOString: undefined });
throw new Error("didn't throw, returned: " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "bad exception: " + e);
}
assert.throws(TypeError, function() {
dateToJSON.call({ toISOString: undefined });
});
try
{
var r = dateToJSON.call({ toISOString: "oogabooga" });
throw new Error("didn't throw, returned: " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "bad exception: " + e);
}
assert.throws(TypeError, function() {
dateToJSON.call({ toISOString: "oogabooga" });
});
try
{
var r = dateToJSON.call({ toISOString: Math.PI });
throw new Error("didn't throw, returned: " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, "bad exception: " + e);
}
assert.throws(TypeError, function() {
dateToJSON.call({ toISOString: Math.PI });
});
/*

View File

@ -11,19 +11,6 @@ description: |
esid: pending
---*/
function expectTypeError(fun, msg)
{
try
{
fun();
assert.sameValue(true, false, "should have thrown a TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, msg + "; instead threw " + e);
}
}
function fun() { }
var global = this;
@ -39,7 +26,7 @@ for (var i = 0, sz = nonfuns.length; i < sz; i++)
};
var msg =
"expected TypeError calling Function.prototype.apply with uncallable this";
expectTypeError(f, msg);
assert.throws(TypeError, f, msg);
}
@ -123,7 +110,7 @@ for (var i = 0, sz = nonobjs.length; i < sz; i++)
{
var f = function() { fun.apply(thisObj, nonobjs[i]); };
var msg = "should have thrown a TypeError with non-object arguments";
expectTypeError(f, msg);
assert.throws(TypeError, f, msg);
}

View File

@ -13,24 +13,9 @@ esid: pending
// behavior
function expectTypeError(fun)
{
try
{
fun();
throw new Error("didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"expected TypeError calling function" +
("name" in fun ? " " + fun.name : "") + ", instead got: " + e);
}
}
function bar() { "use strict"; return arguments; }
assert.sameValue(bar().caller, undefined); // No error when accessing arguments.caller in ES2017+
expectTypeError(function barCallee() { bar().callee; });
assert.throws(TypeError, function barCallee() { bar().callee; });
function baz() { return arguments; }
assert.sameValue(baz().callee, baz);

View File

@ -10,13 +10,11 @@ description: |
pending
esid: pending
---*/
function checkMethod(method) {
try {
assert.throws(TypeError, function() {
new method();
assert.sameValue(0, 1, "not reached " + method);
} catch (e) {
assert.sameValue(e.message.indexOf(" is not a constructor") === -1, false);
}
});
}
function checkMethods(proto) {
@ -54,4 +52,3 @@ var builtin_funcs = [
for (var i = 0; i < builtin_funcs.length; i++) {
checkMethod(builtin_funcs[i]);
}

View File

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

View File

@ -11,19 +11,6 @@ description: |
esid: pending
---*/
function expectTypeError(fun, msg)
{
try
{
fun();
assert.sameValue(true, false, "should have thrown a TypeError");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true, msg + "; instead threw " + e);
}
}
function fun() { }
var global = this;
@ -41,7 +28,7 @@ for (var i = 0, sz = nonfuns.length; i < sz; i++)
};
var msg =
"expected TypeError calling Function.prototype.call with uncallable this";
expectTypeError(f, msg);
assert.throws(TypeError, f, msg);
}

View File

@ -11,23 +11,8 @@ description: |
esid: pending
---*/
function expectTypeError(fun)
{
try
{
fun();
throw new Error("didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"expected TypeError calling function" +
("name" in fun ? " " + fun.name : "") + ", instead got: " + e);
}
}
function bar() { "use strict"; }
expectTypeError(function barCaller() { bar.caller; });
assert.throws(TypeError, function barCaller() { bar.caller; });
function baz() { "use strict"; return 17; }
expectTypeError(function bazCaller() { baz.caller; });
assert.throws(TypeError, function bazCaller() { baz.caller; });

View File

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

View File

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

View File

@ -11,12 +11,6 @@ description: |
esid: pending
---*/
try
{
var r = JSON.parse();
throw new Error("didn't throw, returned " + r);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true, "expected syntax error, got: " + e);
}
assert.throws(SyntaxError, function() {
JSON.parse();
});

View File

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

View File

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

View File

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

View File

@ -11,13 +11,6 @@ description: |
esid: pending
---*/
try
{
assert.throws(SyntaxError, function() {
eval("0x");
throw new Error("didn't throw parsing 0x (with no subsequent hex digits)");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"bad exception thrown: " + e);
}
});

View File

@ -11,19 +11,10 @@ description: |
esid: pending
---*/
function test(method, prec)
{
try
{
function test(method, prec) {
assert.throws(RangeError, function() {
Number.prototype[method].call(0, prec);
throw "should have thrown";
}
catch (e)
{
assert.sameValue(e instanceof RangeError, true,
"expected RangeError for " + method + " with precision " + prec +
", got " + e);
}
});
}
test("toExponential", -32);

View File

@ -11,17 +11,11 @@ description: |
esid: pending
---*/
function test(r)
{
try
{
function test(r) {
assert.throws(RangeError, function() {
5..toString(r);
throw "should have thrown";
}
catch (e)
{
assert.sameValue(e instanceof RangeError, true, "expected a RangeError, got " + e);
}
});
}
test(Math.pow(2, 32) + 10);
test(55);

View File

@ -32,9 +32,6 @@ class A {
};
a = new A;
try {
assert.throws(TypeError, function() {
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 completed = false;
try {
assert.throws(TypeError, function() {
p.g();
completed = true;
} catch (e) {
assert.sameValue(e instanceof TypeError, true);
}
assert.sameValue(completed, false);
});

View File

@ -8,20 +8,9 @@ description: |
pending
esid: pending
---*/
// Ensure that the distinction between Proxy Init and Proxy Set holds
function assertThrowsTypeError(f) {
var type;
try {
f();
} catch (ex) {
type = ex.name;
}
assert.sameValue(type, 'TypeError');
}
var target = {};
var p1 = new Proxy(target, {});
var p2 = new Proxy(target, {});
@ -60,23 +49,22 @@ assert.sameValue(A.gf(p1), 15);
// Despite P1 being stamped with A's field, it shouldn't
// be sufficient to set B's field.
assertThrowsTypeError(() => B.sf(p1));
assertThrowsTypeError(() => B.gf(p1));
assertThrowsTypeError(() => B.sf(p1));
assert.throws(TypeError, () => B.sf(p1));
assert.throws(TypeError, () => B.gf(p1));
assert.throws(TypeError, () => B.sf(p1));
new B(p1);
assert.sameValue(B.gf(p1), 25);
B.sf(p1);
assert.sameValue(B.gf(p1), 20);
// A's field should't be on the target
assertThrowsTypeError(() => A.gf(target));
assert.throws(TypeError, () => A.gf(target));
// Can't set the field, doesn't exist
assertThrowsTypeError(() => A.sf(p2));
assert.throws(TypeError, () => A.sf(p2));
// Definitely can't get the field, doesn't exist.
assertThrowsTypeError(() => A.gf(p2));
assert.throws(TypeError, () => A.gf(p2));
// Still should't be on the target.
assertThrowsTypeError(() => A.gf(target));
assert.throws(TypeError, () => A.gf(target));

View File

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

View File

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

View File

@ -11,20 +11,6 @@ description: |
esid: pending
---*/
function expectThrowTypeError(fun)
{
try
{
var r = fun();
throw new Error("didn't throw TypeError, returned " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"didn't throw TypeError, got: " + e);
}
}
function checkExec(description, regex, args, obj)
{
var lastIndex = obj.lastIndex;
@ -47,15 +33,15 @@ var exec = RegExp.prototype.exec;
var r, res, called, obj;
/* 1. Let R be this RegExp object. */
expectThrowTypeError(function() { exec.call(null); });
expectThrowTypeError(function() { exec.call(""); });
expectThrowTypeError(function() { exec.call(5); });
expectThrowTypeError(function() { exec.call({}); });
expectThrowTypeError(function() { exec.call([]); });
expectThrowTypeError(function() { exec.call(); });
expectThrowTypeError(function() { exec.call(true); });
expectThrowTypeError(function() { exec.call(Object.create(RegExp.prototype)); });
expectThrowTypeError(function() { exec.call(Object.create(/a/)); });
assert.throws(TypeError, function() { exec.call(null); });
assert.throws(TypeError, function() { exec.call(""); });
assert.throws(TypeError, function() { exec.call(5); });
assert.throws(TypeError, function() { exec.call({}); });
assert.throws(TypeError, function() { exec.call([]); });
assert.throws(TypeError, function() { exec.call(); });
assert.throws(TypeError, function() { exec.call(true); });
assert.throws(TypeError, function() { exec.call(Object.create(RegExp.prototype)); });
assert.throws(TypeError, function() { exec.call(Object.create(/a/)); });
/* 2. Let S be the value of ToString(string). */
@ -109,9 +95,9 @@ assert.sameValue(r.lastIndex, obj);
*/
r = /b/;
r.lastIndex = { valueOf: {}, toString: {} };
expectThrowTypeError(function() { r.exec("foopy"); });
assert.throws(TypeError, function() { r.exec("foopy"); });
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;
Object.defineProperty(p1, "lastIndex", { writable: false });
try
{
assert.throws(TypeError, function() {
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
var p2 = /x/g;
Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 });
try
{
assert.throws(TypeError, function() {
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
var p3 = /q/g;
Object.defineProperty(p3, "lastIndex", { writable: false });
try
{
assert.throws(TypeError, function() {
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
var p4 = /q/g;
Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 });
try
{
assert.throws(TypeError, function() {
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;
Object.defineProperty(p1, "lastIndex", { writable: false });
try
{
assert.throws(TypeError, function() {
s.replace(p1, '');
throw "didn't throw";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p1.lastIndex, 0);
}
});
assert.sameValue(p1.lastIndex, 0);
// Second time with .lastIndex !== 0, replacing to ''
var p2 = /x/g;
Object.defineProperty(p2, "lastIndex", { writable: false, value: 3 });
try
{
assert.throws(TypeError, function() {
s.replace(p2, '');
throw "didn't throw";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p2.lastIndex, 3);
}
});
assert.sameValue(p2.lastIndex, 3);
// Third time with .lastIndex === 0, replacing to 'y'
var p3 = /x/g;
Object.defineProperty(p3, "lastIndex", { writable: false });
try
{
assert.throws(TypeError, function() {
s.replace(p3, 'y');
throw "didn't throw";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p3.lastIndex, 0);
}
});
assert.sameValue(p3.lastIndex, 0);
// Fourth time with .lastIndex !== 0, replacing to 'y'
var p4 = /x/g;
Object.defineProperty(p4, "lastIndex", { writable: false, value: 3 });
try
{
assert.throws(TypeError, function() {
s.replace(p4, '');
throw "didn't throw";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p4.lastIndex, 3);
}
});
assert.sameValue(p4.lastIndex, 3);
// Fifth time with .lastIndex === 0, replacing to 'y', but no match
var p5 = /q/g;
Object.defineProperty(p5, "lastIndex", { writable: false });
try
{
assert.throws(TypeError, function() {
s.replace(p5, 'y');
throw "didn't throw";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p5.lastIndex, 0);
}
});
assert.sameValue(p5.lastIndex, 0);
// Sixth time with .lastIndex !== 0, replacing to 'y', but no match
var p6 = /q/g;
Object.defineProperty(p6, "lastIndex", { writable: false, value: 3 });
try
{
assert.throws(TypeError, function() {
s.replace(p6, '');
throw "didn't throw";
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown a TypeError, instead got: " + e);
assert.sameValue(p6.lastIndex, 3);
}
});
assert.sameValue(p6.lastIndex, 3);

View File

@ -14,13 +14,6 @@ esid: pending
* http://creativecommons.org/publicdomain/zero/1.0/
*/
try
{
assert.throws(RangeError, function() {
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
---*/
let caught = false;
try {
assert.throws(SyntaxError, function() {
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 syntaxError (script) {
try {
assert.throws(SyntaxError, function() {
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 }"); // or that
syntaxError('a = {[f1@]: "a", [f2]: "b"}'); // unexpected symbol at end of AssignmentExpression
try { JSON.parse('{["a"]:4}'); } catch(e) {
if (!(e instanceof SyntaxError)) throw new Error('Expected syntax error');
}
assert.throws(SyntaxError, function() {
JSON.parse('{["a"]:4}');
});
// Property characteristics.
a = { ["b"] : 4 };

View File

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

View File

@ -13,35 +13,12 @@ esid: pending
function checkSyntaxError(code)
{
function helper(maker)
{
var earlyError = false;
try
{
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);
assert.throws(SyntaxError, function() {
Function(code);
});
assert.throws(SyntaxError, function() {
(1, eval)(code); // indirect eval
});
}
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.
var savedEval = this[String.fromCharCode(101, 118, 97, 108)];
function checkError(code, nonstrictErr, strictErr)
function checkError(code)
{
function helper(exec, prefix, err)
function helper(exec, prefix)
{
var fullCode = prefix + code;
try
{
var f = exec(fullCode);
var error =
"no early error, parsed code <" + fullCode + "> using " + exec.name;
if (typeof f === "function")
{
try
{
f();
error += ", and the function can be called without error";
}
catch (e)
{
error +=", and calling the function throws " + e;
}
assert.throws(SyntaxError, function() {
exec(fullCode);
});
}
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, "'use strict'; ", strictErr);
helper(savedEval, "", nonstrictErr);
helper(savedEval, "'use strict'; ", strictErr);
helper(Function, "");
helper(Function, "'use strict'; ");
helper(savedEval, "");
helper(savedEval, "'use strict'; ");
}
// Parenthesized destructuring patterns don't trigger grammar refinement, so we
// get the usual SyntaxError for an invalid assignment target, per
// 12.14.1 second bullet.
checkError("var a, b; ([a, b]) = [1, 2];", SyntaxError, SyntaxError);
checkError("var a, b; ({a, b}) = { a: 1, b: 2 };", SyntaxError, SyntaxError);
checkError("var a, b; ([a, b]) = [1, 2];");
checkError("var a, b; ({a, b}) = { a: 1, b: 2 };");
// *Nested* parenthesized destructuring patterns, on the other hand, do trigger
// grammar refinement. But subtargets in a destructuring pattern must be
@ -68,11 +44,11 @@ checkError("var a, b; ({a, b}) = { a: 1, b: 2 };", SyntaxError, SyntaxError);
// destructuring in an expression, |(a = 3)| is forbidden). Parenthesized
// object/array patterns are neither. And so 12.14.5.1 third bullet requires an
// early SyntaxError.
checkError("var a, b; ({ a: ({ b: b }) } = { a: { b: 42 } });", SyntaxError, SyntaxError);
checkError("var a, b; ({ a: { b: (b = 7) } } = { a: {} });", SyntaxError, SyntaxError);
checkError("var a, b; ({ a: ([b]) } = { a: [42] });", SyntaxError, SyntaxError);
checkError("var a, b; [(a = 5)] = [1];", SyntaxError, SyntaxError);
checkError("var a, b; ({ a: (b = 7)} = { b: 1 });", SyntaxError, SyntaxError);
checkError("var a, b; ({ a: ({ b: b }) } = { a: { b: 42 } });");
checkError("var a, b; ({ a: { b: (b = 7) } } = { a: {} });");
checkError("var a, b; ({ a: ([b]) } = { a: [42] });");
checkError("var a, b; [(a = 5)] = [1];");
checkError("var a, b; ({ a: (b = 7)} = { b: 1 });");
Function("var a, b; [(a), b] = [1, 2];")();
Function("var a, b; [(a) = 5, b] = [1, 2];")();
@ -110,18 +86,18 @@ if (classesEnabled())
// As noted above, when the assignment element has an initializer, the
// assignment element must not be parenthesized.
checkError("var a, b; [(repair.man = 17)] = [1];", SyntaxError, SyntaxError);
checkError("var a, b; [(demolition['man'] = 'motel')] = [1, 2];", SyntaxError, SyntaxError);
checkError("var a, b; [(demolition['man' + {}] = 'motel')] = [1];", SyntaxError, SyntaxError); // evade constant-folding
checkError("var a, b; [(repair.man = 17)] = [1];");
checkError("var a, b; [(demolition['man'] = 'motel')] = [1, 2];");
checkError("var a, b; [(demolition['man' + {}] = 'motel')] = [1];"); // evade constant-folding
if (classesEnabled())
{
checkError("var a, b; var obj = { x() { [(super.man = 5)] = [1]; } };", SyntaxError, SyntaxError);
checkError("var a, b; var obj = { x() { [(super[8] = 'motel')] = [1]; } };", SyntaxError, SyntaxError);
checkError("var a, b; var obj = { x() { [(super[8 + {}] = 'motel')] = [1]; } };", SyntaxError, SyntaxError); // evade constant-folding
checkError("var a, b; var obj = { x() { [(super.man = 5)] = [1]; } };");
checkError("var a, b; var obj = { x() { [(super[8] = 'motel')] = [1]; } };");
checkError("var a, b; var obj = { x() { [(super[8 + {}] = 'motel')] = [1]; } };"); // evade constant-folding
}
checkError("var a, b; [f() = 'ohai', b] = [1, 2];", SyntaxError, SyntaxError);
checkError("var a, b; [(f()) = 'kthxbai', b] = [1, 2];", SyntaxError, SyntaxError);
checkError("var a, b; [f() = 'ohai', b] = [1, 2];");
checkError("var a, b; [(f()) = 'kthxbai', b] = [1, 2];");
Function("var a, b; ({ a: (a), b} = { a: 1, b: 2 });")();
Function("var a, b; ({ a: (a) = 5, b} = { a: 1, b: 2 });")();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -27,16 +27,9 @@ function testIndex()
}
};
var ok = false;
try
{
assert.throws(TypeError, function() {
dv.setUint8(start, 0x42);
}
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "should have thrown");
});
assert.sameValue(ab.byteLength, 0, "should have been detached correctly");
}
testIndex();
@ -57,16 +50,9 @@ function testValue()
}
};
var ok = false;
try
{
assert.throws(TypeError, function() {
dv.setUint8(0xFFFFF, value);
}
catch (e)
{
ok = true;
}
assert.sameValue(ok, true, "should have thrown");
});
assert.sameValue(ab.byteLength, 0, "should have been detached correctly");
}
testValue();

View File

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

View File

@ -30,17 +30,9 @@ var sobj =
{
"use strict";
try
{
var args = sobj.test.arguments;
throw new Error("access to arguments property of strict mode " +
"function didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"should have thrown TypeError, instead got: " + e);
}
assert.throws(TypeError, function() {
sobj.test.arguments;
}, "access to arguments property of strict mode function");
}
};
sobj.test(5, undefined);

View File

@ -12,23 +12,8 @@ esid: pending
---*/
function test(sharedMem) {
function die(message, uplevel) {
throw new Error(message);
}
function checkThrow(fun, type) {
var thrown = false;
try {
fun();
} catch (x) {
thrown = x;
}
if (!thrown) {
die('no exception thrown, expected ' + type.name, 2);
} else if (!(thrown instanceof type)) {
die('expected ' + type.name + ', got ' + thrown, 2);
}
assert.throws(type, fun);
}
function bufferize(u8array) {

View File

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

View File

@ -67,20 +67,6 @@ function check(obj, prop, expected)
checkField("configurable", desc, expected);
}
function expectTypeError(f)
{
try
{
f();
throw new Error("no error thrown");
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"wrong error thrown: got " + e + ", not a TypeError");
}
}
/**************
* BEGIN TEST *
**************/
@ -137,8 +123,8 @@ gsobj.__defineSetter__("baz", s3);
check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: true });
Object.defineProperty(gsobj, "baz", { configurable: false });
expectTypeError(function() { gsobj.__defineSetter__("baz", s2); });
expectTypeError(function() { gsobj.__defineSetter__("baz", s3); });
assert.throws(TypeError, function() { gsobj.__defineSetter__("baz", s2); });
assert.throws(TypeError, function() { gsobj.__defineSetter__("baz", s3); });
check(gsobj, "baz", { get: g3, set: s3, enumerable: true, configurable: false });
/******************************************************************************/
@ -169,8 +155,8 @@ sgobj.__defineSetter__("baz", s4);
check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: true });
Object.defineProperty(sgobj, "baz", { configurable: false });
expectTypeError(function() { sgobj.__defineGetter__("baz", g3); });
expectTypeError(function() { sgobj.__defineSetter__("baz", s4); });
assert.throws(TypeError, function() { sgobj.__defineGetter__("baz", g3); });
assert.throws(TypeError, function() { sgobj.__defineSetter__("baz", s4); });
check(sgobj, "baz", { get: g4, set: s4, enumerable: true, configurable: false });
/******************************************************************************/
@ -231,7 +217,7 @@ check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurabl
Object.defineProperty(gncover, "moo", { configurable: false });
check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false });
expectTypeError(function() { gncover.__defineGetter__("moo", g7); });
assert.throws(TypeError, function() { gncover.__defineGetter__("moo", g7); });
check(gncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false });
/******************************************************************************/
@ -244,7 +230,7 @@ check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurabl
Object.defineProperty(sncover, "moo", { configurable: false });
check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false });
expectTypeError(function() { sncover.__defineSetter__("moo", s7); });
assert.throws(TypeError, function() { sncover.__defineSetter__("moo", s7); });
check(sncover, "moo", { value: 17, writable: true, enumerable: true, configurable: false });
/******************************************************************************/
@ -257,7 +243,7 @@ check(gncwover, "fwoosh", { value: 17, writable: true, enumerable: true, configu
Object.defineProperty(gncwover, "fwoosh", { writable: false, configurable: false });
check(gncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false });
expectTypeError(function() { gncwover.__defineGetter__("fwoosh", g7); });
assert.throws(TypeError, function() { gncwover.__defineGetter__("fwoosh", g7); });
check(gncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false });
/******************************************************************************/
@ -270,5 +256,5 @@ check(sncwover, "fwoosh", { value: 17, writable: true, enumerable: true, configu
Object.defineProperty(sncwover, "fwoosh", { writable: false, configurable: false });
check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false });
expectTypeError(function() { sncwover.__defineSetter__("fwoosh", s7); });
assert.throws(TypeError, function() { sncwover.__defineSetter__("fwoosh", s7); });
check(sncwover, "fwoosh", { value: 17, writable: false, enumerable: true, configurable: false });

View File

@ -16,19 +16,9 @@ esid: pending
{
function testOne(replacement)
{
var x, rv;
try
{
rv = eval(code.replace("@@@", replacement));
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"should have thrown a SyntaxError, instead got: " + e);
return;
}
assert.sameValue(true, false, "should have thrown, instead returned " + rv);
assert.throws(SyntaxError, function() {
eval(code.replace("@@@", replacement));
});
}
testOne("function");

View File

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

View File

@ -17,15 +17,9 @@ var otherStr = new g.String("foo");
assert.sameValue(otherStr instanceof g.String, true);
assert.sameValue(otherStr.valueOf(), "foo");
try
{
// NOTE: not |g.TypeError|, because |new| itself throws because
// |!IsConstructor(constructor)|.
assert.throws(TypeError, function() {
var constructor = g.parseInt;
new constructor();
throw new Error("no error thrown");
}
catch (e)
{
// NOTE: not |g.TypeError|, because |new| itself throws because
// |!IsConstructor(constructor)|.
assert.sameValue(e instanceof TypeError, true);
}
});

View File

@ -14,21 +14,11 @@ esid: pending
var arr = [];
var p = new Proxy(arr, {});
function assertThrowsTypeError(f)
{
try {
f();
assert.sameValue(false, true, "Must have thrown");
} catch (e) {
assert.sameValue(e instanceof TypeError, true, "Must have thrown TypeError");
}
}
// Redefining non-configurable length should throw a TypeError
assertThrowsTypeError(function () { Object.defineProperty(p, "length", { value: 17, configurable: true }); });
assert.throws(TypeError, function () { Object.defineProperty(p, "length", { value: 17, configurable: true }); });
// Same here.
assertThrowsTypeError(function () { Object.defineProperty(p, "length", { value: 42, enumerable: true }); });
assert.throws(TypeError, function () { Object.defineProperty(p, "length", { value: 42, enumerable: true }); });
// Check the property went unchanged.
var pd = Object.getOwnPropertyDescriptor(p, "length");

View File

@ -11,27 +11,8 @@ description: |
esid: pending
---*/
var actual = '';
var expect = '';
Array.prototype.__proto__ = function () { return 3; };
//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------
function test()
{
expect = 'TypeError: [].__proto__ is not a function';
Array.prototype.__proto__ = function () { return 3; };
try
{
assert.throws(TypeError, function() {
[].__proto__();
}
catch(ex)
{
actual = ex + '';
}
assert.sameValue(expect, actual);
}
});

View File

@ -8,19 +8,10 @@ description: |
pending
esid: pending
---*/
function f(foo) {
"use strict";
foo.bar;
}
var actual;
try {
f();
actual = "no error";
} catch (x) {
actual = (x instanceof TypeError) ? "type error" : "some other error";
actual += (/use strict/.test(x)) ? " with directive" : " without directive";
}
assert.sameValue("type error without directive", actual,
"decompiled expressions in error messages should not include directive prologues");
assert.throws(TypeError, f);

View File

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

View File

@ -15,46 +15,12 @@ test();
function test()
{
var TestPassCount = 0;
var TestFailCount = 0;
var TestTodoCount = 0;
var TODO = 1;
function check(fun, todo) {
var thrown = null;
var success = false;
try {
success = fun();
} catch (x) {
thrown = x;
function check(fun) {
assert.sameValue(fun(), true);
}
if (thrown)
success = false;
if (todo) {
TestTodoCount++;
return;
}
if (success) {
TestPassCount++;
} else {
TestFailCount++;
}
}
function checkThrows(fun, todo) {
let thrown = false;
try {
fun();
} catch (x) {
thrown = true;
}
check(() => thrown, todo);
function checkThrows(fun) {
assert.throws(TypeError, fun);
}
var key = {};
@ -93,6 +59,4 @@ function test()
check(() => map.get(key) == undefined);
checkThrows(() => map.set("non-object key", value));
assert.sameValue(0, TestFailCount, "weak map tests");
}

View File

@ -17,17 +17,10 @@ esid: pending
function assertSyntaxError(str) {
var msg;
var evil = eval;
try {
assert.throws(SyntaxError, function() {
// Non-direct eval.
evil(str);
} catch (exc) {
if (exc instanceof SyntaxError)
return;
msg = "Assertion failed: expected SyntaxError, got " + exc;
}
if (msg === undefined)
msg = "Assertion failed: expected SyntaxError, but no exception thrown";
throw new Error(msg + " - " + str);
});
}
// Yield statements.

View File

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

View File

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

View File

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

View File

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

View File

@ -13,16 +13,9 @@ esid: pending
function isError(code, type)
{
try
{
assert.throws(type, function() {
Function(code);
throw new Error("didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof type, true,
"unexpected error for `" + code + "`: got " + e);
}
});
}
function isOK(code)

View File

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

View File

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

View File

@ -11,7 +11,7 @@ description: |
esid: pending
---*/
var desc, old, error;
var desc, old;
var global = this;
var names = ["NaN", "Infinity", "undefined"];
@ -29,22 +29,8 @@ for (var i = 0; i < names.length; i++)
global[name] = 17;
assert.sameValue(global[name], old, name + " changed on setting?");
error = "before";
try
{
throw new TypeError("SpiderMonkey doesn't currently implement " +
"strict-mode throwing when setting a readonly " +
"property, not running this bit of test for now; " +
"see bug 537873");
(function() { "use strict"; global[name] = 42; error = "didn't throw"; })();
}
catch (e)
{
if (e instanceof TypeError)
error = "typeerror";
else
error = "bad exception: " + e;
}
assert.sameValue(error, "typeerror", "wrong strict mode error setting " + name);
assert.throws(TypeError, function() {
"use strict";
global[name] = 42;
}, "wrong strict mode error setting " + name);
}

View File

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

View File

@ -13,16 +13,9 @@ esid: pending
function checkSyntaxError(str)
{
try
{
var f = Function("for(w in\\");
throw new Error("didn't throw, returned " + f);
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"expected SyntaxError, got " + e);
}
assert.throws(SyntaxError, function() {
Function(str);
});
}
checkSyntaxError("for(var w in \\");

View File

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

View File

@ -10,12 +10,7 @@ description: |
pending
esid: pending
---*/
var o = {}
try {
eval('o.\\u1d17 = 42;');
}
catch (e) {
assert.sameValue('should not fail', true);
}
assert.sameValue(o['\u1d17'], 42);
var o = {}
eval('o.\\u1d17 = 42;');
assert.sameValue(o['\u1d17'], 42);

View File

@ -10,12 +10,7 @@ description: |
pending
esid: pending
---*/
var o = {}
try {
eval('o.\\u82f1 = 42;');
}
catch (e) {
assert.sameValue('should not fail', true);
}
assert.sameValue(o['\u82f1'], 42);
var o = {}
eval('o.\\u82f1 = 42;');
assert.sameValue(o['\u82f1'], 42);

View File

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

View File

@ -41,20 +41,10 @@ props =
c: { value: NaN, enumerable: false, configurable: true, writable: true },
b: { value: 44 }
};
var error = "before";
try
{
assert.throws(TypeError, function() {
Object.defineProperties(o, props);
error = "no exception thrown";
}
catch (e)
{
if (e instanceof TypeError)
error = "typeerror";
else
error = "bad exception: " + e;
}
assert.sameValue(error, "typeerror", "didn't throw or threw wrongly");
});
assert.sameValue("c" in o, true, "new property added");
assert.sameValue(o.b, 42, "old property value preserved");
@ -84,46 +74,14 @@ assert.sameValue("bar" in o, false, "bar is not an enumerable own property");
Object.defineProperties(o, "");
assert.sameValue("quux" in o, false, "quux is not an enumerable own property");
error = "before";
try
{
assert.throws(TypeError, function() {
Object.defineProperties(o, "1");
}
catch (e)
{
if (e instanceof TypeError)
error = "typeerror";
else
error = "bad exception: " + e;
}
assert.sameValue(error, "typeerror",
"should throw on Properties == '1' due to '1'[0] not being a " +
"property descriptor");
}, "should throw on Properties == '1' due to '1'[0] not being a property descriptor");
error = "before";
try
{
assert.throws(TypeError, function() {
Object.defineProperties(o, null);
}
catch (e)
{
if (e instanceof TypeError)
error = "typeerror";
else
error = "bad exception: " + e;
}
assert.sameValue(error, "typeerror", "should throw on Properties == null");
}, "should throw on Properties == null");
error = "before";
try
{
assert.throws(TypeError, function() {
Object.defineProperties(o, undefined);
}
catch (e)
{
if (e instanceof TypeError)
error = "typeerror";
else
error = "bad exception: " + e;
}
assert.sameValue(error, "typeerror", "should throw on Properties == undefined");
}, "should throw on Properties == undefined");

View File

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

View File

@ -11,20 +11,6 @@ description: |
esid: pending
---*/
function expectThrowTypeError(fun)
{
try
{
var r = fun();
throw new Error("didn't throw TypeError, returned " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"didn't throw TypeError, got: " + e);
}
}
var isPrototypeOf = Object.prototype.isPrototypeOf;
/*
@ -48,12 +34,12 @@ assert.sameValue(isPrototypeOf(null), false);
* argument.
*/
var protoGlobal = Object.create(this);
expectThrowTypeError(function() { isPrototypeOf.call(null, {}); });
expectThrowTypeError(function() { isPrototypeOf.call(undefined, {}); });
expectThrowTypeError(function() { isPrototypeOf({}); });
expectThrowTypeError(function() { isPrototypeOf.call(null, protoGlobal); });
expectThrowTypeError(function() { isPrototypeOf.call(undefined, protoGlobal); });
expectThrowTypeError(function() { isPrototypeOf(protoGlobal); });
assert.throws(TypeError, function() { isPrototypeOf.call(null, {}); });
assert.throws(TypeError, function() { isPrototypeOf.call(undefined, {}); });
assert.throws(TypeError, function() { isPrototypeOf({}); });
assert.throws(TypeError, function() { isPrototypeOf.call(null, protoGlobal); });
assert.throws(TypeError, function() { isPrototypeOf.call(undefined, protoGlobal); });
assert.throws(TypeError, function() { isPrototypeOf(protoGlobal); });
/*

View File

@ -11,25 +11,6 @@ description: |
esid: pending
---*/
function expectThrowError(errorCtor, fun)
{
try
{
var r = fun();
throw "didn't throw TypeError, returned " + r;
}
catch (e)
{
assert.sameValue(e instanceof errorCtor, true,
"didn't throw " + errorCtor.prototype.name + ", got: " + e);
}
}
function expectThrowTypeError(fun)
{
expectThrowError(TypeError, fun);
}
function withToString(fun)
{
return { toString: fun };
@ -45,106 +26,106 @@ var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
/*
* 1. Let P be ToString(V).
*/
expectThrowError(ReferenceError, function()
assert.throws(ReferenceError, function()
{
propertyIsEnumerable(withToString(function() { fahslkjdfhlkjdsl; }));
});
expectThrowError(ReferenceError, function()
assert.throws(ReferenceError, function()
{
propertyIsEnumerable.call(null, withToString(function() { fahslkjdfhlkjdsl; }));
});
expectThrowError(ReferenceError, function()
assert.throws(ReferenceError, function()
{
propertyIsEnumerable.call(undefined, withToString(function() { fahslkjdfhlkjdsl; }));
});
expectThrowError(ReferenceError, function()
assert.throws(ReferenceError, function()
{
propertyIsEnumerable(withValueOf(function() { fahslkjdfhlkjdsl; }));
});
expectThrowError(ReferenceError, function()
assert.throws(ReferenceError, function()
{
propertyIsEnumerable.call(null, withValueOf(function() { fahslkjdfhlkjdsl; }));
});
expectThrowError(ReferenceError, function()
assert.throws(ReferenceError, function()
{
propertyIsEnumerable.call(undefined, withValueOf(function() { fahslkjdfhlkjdsl; }));
});
expectThrowError(SyntaxError, function()
assert.throws(SyntaxError, function()
{
propertyIsEnumerable(withToString(function() { eval("}"); }));
});
expectThrowError(SyntaxError, function()
assert.throws(SyntaxError, function()
{
propertyIsEnumerable.call(null, withToString(function() { eval("}"); }));
});
expectThrowError(SyntaxError, function()
assert.throws(SyntaxError, function()
{
propertyIsEnumerable.call(undefined, withToString(function() { eval("}"); }));
});
expectThrowError(SyntaxError, function()
assert.throws(SyntaxError, function()
{
propertyIsEnumerable(withValueOf(function() { eval("}"); }));
});
expectThrowError(SyntaxError, function()
assert.throws(SyntaxError, function()
{
propertyIsEnumerable.call(null, withValueOf(function() { eval("}"); }));
});
expectThrowError(SyntaxError, function()
assert.throws(SyntaxError, function()
{
propertyIsEnumerable.call(undefined, withValueOf(function() { eval("}"); }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable(withToString(function() { [].length = -1; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(null, withToString(function() { [].length = -1; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(undefined, withToString(function() { [].length = -1; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable(withValueOf(function() { [].length = -1; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(null, withValueOf(function() { [].length = -1; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = -1; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable(withToString(function() { [].length = 0.7; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(null, withToString(function() { [].length = 0.7; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(undefined, withToString(function() { [].length = 0.7; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable(withValueOf(function() { [].length = 0.7; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(null, withValueOf(function() { [].length = 0.7; }));
});
expectThrowError(RangeError, function()
assert.throws(RangeError, function()
{
propertyIsEnumerable.call(undefined, withValueOf(function() { [].length = 0.7; }));
});
@ -153,19 +134,19 @@ expectThrowError(RangeError, function()
* 2. Let O be the result of calling ToObject passing the this value as the
* argument.
*/
expectThrowTypeError(function() { propertyIsEnumerable("s"); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, "s"); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, "s"); });
expectThrowTypeError(function() { propertyIsEnumerable(true); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, true); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, true); });
expectThrowTypeError(function() { propertyIsEnumerable(NaN); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, NaN); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, NaN); });
assert.throws(TypeError, function() { propertyIsEnumerable("s"); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(null, "s"); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, "s"); });
assert.throws(TypeError, function() { propertyIsEnumerable(true); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(null, true); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, true); });
assert.throws(TypeError, function() { propertyIsEnumerable(NaN); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(null, NaN); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, NaN); });
expectThrowTypeError(function() { propertyIsEnumerable({}); });
expectThrowTypeError(function() { propertyIsEnumerable.call(null, {}); });
expectThrowTypeError(function() { propertyIsEnumerable.call(undefined, {}); });
assert.throws(TypeError, function() { propertyIsEnumerable({}); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(null, {}); });
assert.throws(TypeError, function() { propertyIsEnumerable.call(undefined, {}); });
/*
* 3. Let desc be the result of calling the [[GetOwnProperty]] internal method
@ -180,7 +161,7 @@ assert.sameValue(propertyIsEnumerable.call(true, "toString"), false);
assert.sameValue(propertyIsEnumerable.call({}, "__proto__"), false);
assert.sameValue(propertyIsEnumerable.call(Object, "getOwnPropertyDescriptor"), false);
assert.sameValue(propertyIsEnumerable.call(this, "expectThrowTypeError"), true);
assert.sameValue(propertyIsEnumerable.call(this, "withToString"), true);
assert.sameValue(propertyIsEnumerable.call("s", "length"), false);
assert.sameValue(propertyIsEnumerable.call("s", 0), true);
assert.sameValue(propertyIsEnumerable.call(Number, "MAX_VALUE"), false);

View File

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

View File

@ -9,41 +9,13 @@ description: |
pending
esid: pending
---*/
function assertSameEntries(actual, expected) {
assert.sameValue(actual.length, expected.length);
for (let i = 0; i < expected.length; ++i)
assert.compareArray(actual[i], expected[i]);
}
function throwsTypeError(fn) {
try {
fn();
} catch (e) {
assert.sameValue(e instanceof TypeError, true);
return true;
}
return false;
}
// Non-standard: Accessing elements of detached array buffers should throw, but
// this is currently not implemented.
const ACCESS_ON_DETACHED_ARRAY_BUFFER_THROWS = (() => {
let ta = new Int32Array(10);
$262.detachArrayBuffer(ta.buffer);
let throws = throwsTypeError(() => ta[0]);
// Ensure [[Get]] and [[GetOwnProperty]] return consistent results.
assert.sameValue(throwsTypeError(() => Object.getOwnPropertyDescriptor(ta, 0)), throws);
return throws;
})();
function maybeThrowOnDetached(fn, returnValue) {
if (ACCESS_ON_DETACHED_ARRAY_BUFFER_THROWS) {
assert.throws(TypeError, fn);
return returnValue;
}
return fn();
}
// Ensure Object.keys/values/entries work correctly on typed arrays.
for (let len of [0, 1, 10]) {
let array = new Array(len).fill(1);
@ -55,8 +27,7 @@ for (let len of [0, 1, 10]) {
$262.detachArrayBuffer(ta.buffer);
assert.compareArray(maybeThrowOnDetached(() => Object.keys(ta), []), []);
assert.compareArray(maybeThrowOnDetached(() => Object.values(ta), []), []);
assertSameEntries(maybeThrowOnDetached(() => Object.entries(ta), []), []);
assert.compareArray(Object.keys(ta), []);
assert.compareArray(Object.values(ta), []);
assertSameEntries(Object.entries(ta), []);
}

View File

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

View File

@ -10,15 +10,15 @@ description: |
pending
esid: pending
---*/
function isSyntaxError(code) {
try {
function throwsNoSyntaxError(code) {
eval(code);
return false;
} catch (exception) {
if (SyntaxError.prototype.isPrototypeOf(exception))
return true;
throw exception;
};
};
function throwsSyntaxError(code) {
assert.throws(SyntaxError, function() {
eval(code);
});
};
/*
@ -27,28 +27,27 @@ function isSyntaxError(code) {
* user has opted in to a modicum of sanity, and we forbid duplicate
* parameter names.
*/
assert.sameValue(isSyntaxError("function f(x,x){}"), false);
throwsNoSyntaxError("function f(x,x){}");
assert.sameValue(isSyntaxError("function f(x,[x]){})"), true);
assert.sameValue(isSyntaxError("function f(x,{y:x}){})"), true);
assert.sameValue(isSyntaxError("function f(x,{x}){})"), true);
throwsSyntaxError("function f(x,[x]){})");
throwsSyntaxError("function f(x,{y:x}){})");
throwsSyntaxError("function f(x,{x}){})");
assert.sameValue(isSyntaxError("function f([x],x){})"), true);
assert.sameValue(isSyntaxError("function f({y:x},x){})"), true);
assert.sameValue(isSyntaxError("function f({x},x){})"), true);
throwsSyntaxError("function f([x],x){})");
throwsSyntaxError("function f({y:x},x){})");
throwsSyntaxError("function f({x},x){})");
assert.sameValue(isSyntaxError("function f([x,x]){}"), true);
assert.sameValue(isSyntaxError("function f({x,x}){}"), true);
assert.sameValue(isSyntaxError("function f({y:x,z:x}){}"), true);
throwsSyntaxError("function f([x,x]){}");
throwsSyntaxError("function f({x,x}){}");
throwsSyntaxError("function f({y:x,z:x}){}");
assert.sameValue(isSyntaxError("function f(x,x,[y]){}"), true);
assert.sameValue(isSyntaxError("function f(x,x,{y}){}"), true);
assert.sameValue(isSyntaxError("function f([y],x,x){}"), true);
assert.sameValue(isSyntaxError("function f({y},x,x){}"), true);
assert.sameValue(isSyntaxError("function f(a,b,c,d,e,f,g,h,b,[y]){}"), true);
assert.sameValue(isSyntaxError("function f([y],a,b,c,d,e,f,g,h,a){}"), true);
assert.sameValue(isSyntaxError("function f([a],b,c,d,e,f,g,h,i,a){}"), true);
assert.sameValue(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true);
assert.sameValue(isSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}"), true);
throwsSyntaxError("function f(x,x,[y]){}");
throwsSyntaxError("function f(x,x,{y}){}");
throwsSyntaxError("function f([y],x,x){}");
throwsSyntaxError("function f({y},x,x){}");
throwsSyntaxError("function f(a,b,c,d,e,f,g,h,b,[y]){}");
throwsSyntaxError("function f([y],a,b,c,d,e,f,g,h,a){}");
throwsSyntaxError("function f([a],b,c,d,e,f,g,h,i,a){}");
throwsSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}");
throwsSyntaxError("function f(a,b,c,d,e,f,g,h,i,[a]){}");

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ description: |
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
---*/
try
{
assert.throws(SyntaxError, function() {
Function("for (x => 0 in 1;;) break;");
throw new Error("didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"expected syntax error, got " + e);
}
});

View File

@ -11,13 +11,6 @@ description: |
esid: pending
---*/
try
{
assert.throws(SyntaxError, function() {
Function("for (var x = 3 of 42);");
throw new Error("didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"expected syntax error, got: " + e);
}
});

View File

@ -12,17 +12,7 @@ esid: pending
---*/
var f = function assignSelfStrict() { "use strict"; assignSelfStrict = 12; };
try
{
var r = f();
throw new Error("should have thrown a TypeError, returned " + r);
}
catch (e)
{
assert.sameValue(e instanceof TypeError, true,
"didn't throw a TypeError: " + e);
}
assert.throws(TypeError, f);
var assignSelf = 42;
var f2 = function assignSelf() { assignSelf = 12; };

View File

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

View File

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

View File

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

View File

@ -8,19 +8,7 @@ description: |
pending
esid: pending
---*/
function assertThrowsSyntaxError(x) {
let success = false;
try {
eval(x);
success = true;
} catch (e) {
assert.sameValue(e instanceof SyntaxError, true);
}
assert.sameValue(success, false);
}
assertThrowsSyntaxError("class X { x: 1 }")
if ('assert.sameValue' in this) {
}
assert.throws(SyntaxError, function() {
eval("class X { x: 1 }");
});

View File

@ -13,16 +13,9 @@ esid: pending
function expectSyntaxError(code)
{
try
{
assert.throws(SyntaxError, function() {
eval(code);
throw new Error("didn't throw");
}
catch (e)
{
assert.sameValue(e instanceof SyntaxError, true,
"got " + e.name + ", expected SyntaxError");
}
});
}
// The fundamental requirements of this test:

View File

@ -7,17 +7,9 @@
flags:
- noStrict
description: |
pending
Assignments to a property that has a getter but not a setter should not throw a TypeError per ES5 (at least not until strict mode is supported)
esid: pending
---*/
//-----------------------------------------------------------------------------
var BUGNUMBER = 523846;
var summary =
"Assignments to a property that has a getter but not a setter should not " +
"throw a TypeError per ES5 (at least not until strict mode is supported)";
var actual = "Early failure";
var expect = "No errors";
var o = { get p() { return "a"; } };
@ -55,56 +47,7 @@ function strictTest2()
assert.sameValue(y.p, "a");
}
var errors = [];
try
{
try
{
test1();
}
catch (e)
{
errors.push(e);
}
try
{
test2();
}
catch (e)
{
errors.push(e);
}
try
{
strictTest1();
errors.push("strictTest1 didn't fail");
}
catch (e)
{
if (!(e instanceof TypeError))
errors.push("strictTest1 didn't fail with a TypeError: " + e);
}
try
{
strictTest2();
errors.push("strictTest2 didn't fail");
}
catch (e)
{
if (!(e instanceof TypeError))
errors.push("strictTest2 didn't fail with a TypeError: " + e);
}
}
catch (e)
{
errors.push("Unexpected error: " + e);
}
finally
{
actual = errors.length > 0 ? errors.join(", ") : "No errors";
}
assert.sameValue(expect, actual, summary);
test1();
test2();
assert.throws(TypeError, strictTest1);
assert.throws(TypeError, strictTest2);