Replace assertThrowsInstanceOf with assert.throws in sm/Function

This commit is contained in:
André Bargull 2025-04-30 14:15:52 +02:00 committed by Philip Chimento
parent 3dc9cae778
commit a43514eb2d
13 changed files with 50 additions and 57 deletions

View File

@ -15,6 +15,6 @@ assert.deepEqual(desc,
assert.sameValue(Function.prototype.prototype, undefined);
assert.sameValue(Function.prototype.callee, undefined);
assertThrowsInstanceOf(() => Function.prototype.caller, TypeError);
assertThrowsInstanceOf(() => Function.prototype.arguments, TypeError);
assert.throws(TypeError, () => Function.prototype.caller);
assert.throws(TypeError, () => Function.prototype.arguments);

View File

@ -14,12 +14,12 @@ function f0(a, a) {
}
// SyntaxError should be thrown if arrow function has duplicated name.
assertThrowsInstanceOf(() => eval(`
assert.throws(SyntaxError, () => eval(`
(a, a) => {
};
`), SyntaxError);
assertThrowsInstanceOf(() => eval(`
`));
assert.throws(SyntaxError, () => eval(`
(a, ...a) => {
};
`), SyntaxError);
`));

View File

@ -22,6 +22,6 @@ for (var obj of objects) {
// Make sure they are callable, but not constructable.
obj();
assertThrowsInstanceOf(() => new obj, TypeError);
assert.throws(TypeError, () => new obj);
}

View File

@ -18,9 +18,9 @@ var newTarget = Object.defineProperty(function(){}.bind(), "prototype", {
}
});
assertThrowsInstanceOf(() => {
assert.throws(SyntaxError, () => {
Reflect.construct(Function, ["@error"], newTarget);
}, SyntaxError);
});
assert.sameValue(getProtoCalled, false);

View File

@ -47,27 +47,22 @@ assert.sameValue(strictReturnThis.bind("foopy")(), "foopy");
// rigorous, step-by-step testing
function expectThrowTypeError(fun)
{
assertThrowsInstanceOf(fun, TypeError);
}
/*
* 1. Let Target be the this value.
* 2. If IsCallable(Target) is false, throw a TypeError exception.
*/
expectThrowTypeError(function() { bind.call(null); });
expectThrowTypeError(function() { bind.call(undefined); });
expectThrowTypeError(function() { bind.call(NaN); });
expectThrowTypeError(function() { bind.call(0); });
expectThrowTypeError(function() { bind.call(-0); });
expectThrowTypeError(function() { bind.call(17); });
expectThrowTypeError(function() { bind.call(42); });
expectThrowTypeError(function() { bind.call("foobar"); });
expectThrowTypeError(function() { bind.call(true); });
expectThrowTypeError(function() { bind.call(false); });
expectThrowTypeError(function() { bind.call([]); });
expectThrowTypeError(function() { bind.call({}); });
assert.throws(TypeError, function() { bind.call(null); });
assert.throws(TypeError, function() { bind.call(undefined); });
assert.throws(TypeError, function() { bind.call(NaN); });
assert.throws(TypeError, function() { bind.call(0); });
assert.throws(TypeError, function() { bind.call(-0); });
assert.throws(TypeError, function() { bind.call(17); });
assert.throws(TypeError, function() { bind.call(42); });
assert.throws(TypeError, function() { bind.call("foobar"); });
assert.throws(TypeError, function() { bind.call(true); });
assert.throws(TypeError, function() { bind.call(false); });
assert.throws(TypeError, function() { bind.call([]); });
assert.throws(TypeError, function() { bind.call({}); });
/*
@ -254,8 +249,8 @@ function testBound(fun)
assert.sameValue(Object.getOwnPropertyDescriptor(boundf, "caller"), undefined,
"should be no caller property");
expectThrowTypeError(function() { return boundf.arguments; });
expectThrowTypeError(function() { return boundf.caller; });
assert.throws(TypeError, function() { return boundf.arguments; });
assert.throws(TypeError, function() { return boundf.caller; });
}
testBound(strict);

View File

@ -53,11 +53,11 @@ for (let nonCallable of nonCallables) {
// Non-callables should throw when used on the right hand side
// of `instanceof`.
assertThrowsInstanceOf(() => {
assert.throws(TypeError, () => {
function foo() {};
let obj = {};
foo instanceof obj;
}, TypeError);
});
// Non-callables do not throw for overridden methods
let o = {[Symbol.hasInstance](v) { return true; }}
@ -97,7 +97,7 @@ assert.sameValue(desc.configurable, false);
// Attempting to use a non-callable @@hasInstance triggers a type error
// Bug 1280892
assertThrowsInstanceOf(() => {
assert.throws(TypeError, () => {
var fun = function() {}
var p = new Proxy(fun, {
get(target, key) {
@ -105,6 +105,6 @@ assertThrowsInstanceOf(() => {
}
});
fun instanceof p;
}, TypeError);
});

View File

@ -32,6 +32,6 @@ const tests = [
for (const test of tests) {
DumpFunction(...test);
assertThrowsInstanceOf(() => new Function(...test), SyntaxError);
assert.throws(SyntaxError, () => new Function(...test));
}

View File

@ -9,11 +9,11 @@ description: |
pending
esid: pending
---*/
assertThrowsInstanceOf(() => eval("() \n => {}"), SyntaxError);
assertThrowsInstanceOf(() => eval("a \n => {}"), SyntaxError);
assertThrowsInstanceOf(() => eval("(a) /*\n*/ => {}"), SyntaxError);
assertThrowsInstanceOf(() => eval("(a, b) \n => {}"), SyntaxError);
assertThrowsInstanceOf(() => eval("(a, b = 1) \n => {}"), SyntaxError);
assertThrowsInstanceOf(() => eval("(a, ...b) \n => {}"), SyntaxError);
assertThrowsInstanceOf(() => eval("(a, b = 1, ...c) \n => {}"), SyntaxError);
assert.throws(SyntaxError, () => eval("() \n => {}"));
assert.throws(SyntaxError, () => eval("a \n => {}"));
assert.throws(SyntaxError, () => eval("(a) /*\n*/ => {}"));
assert.throws(SyntaxError, () => eval("(a, b) \n => {}"));
assert.throws(SyntaxError, () => eval("(a, b = 1) \n => {}"));
assert.throws(SyntaxError, () => eval("(a, ...b) \n => {}"));
assert.throws(SyntaxError, () => eval("(a, b = 1, ...c) \n => {}"));

View File

@ -14,16 +14,16 @@ function f0(a) {
}
// SyntaxError should be thrown if method definition has duplicated name.
assertThrowsInstanceOf(() => eval(`
assert.throws(SyntaxError, () => eval(`
({
m1(a, a) {
}
});
`), SyntaxError);
assertThrowsInstanceOf(() => eval(`
`));
assert.throws(SyntaxError, () => eval(`
({
m2(a, ...a) {
}
});
`), SyntaxError);
`));

View File

@ -15,14 +15,14 @@ function f1(a = 0) {
}
// 'let' and 'const' at body-level are not allowed to redeclare parameters.
assertThrowsInstanceOf(() => {
assert.throws(SyntaxError, () => {
eval(`function f2(a = 0) {
let a;
}`);
}, SyntaxError);
assertThrowsInstanceOf(() => {
});
assert.throws(SyntaxError, () => {
eval(`function f3(a = 0) {
const a;
}`);
}, SyntaxError);
});

View File

@ -14,14 +14,14 @@ function f0(a, a) {
}
// SyntaxError should be thrown if rest parameter name is duplicated.
assertThrowsInstanceOf(() => eval(`
assert.throws(SyntaxError, () => eval(`
function f1(a, ...a) {
}
`), SyntaxError);
`));
// SyntaxError should be thrown if there is a duplicated parameter.
assertThrowsInstanceOf(() => eval(`
assert.throws(SyntaxError, () => eval(`
function f2(a, a, ...b) {
}
`), SyntaxError);
`));

View File

@ -61,11 +61,9 @@ function h()
for (var badName of ["yield", "eval", "let"])
{
assertThrowsInstanceOf(() => eval(`var q = (...${badName}) => ${badName} + 42;`),
SyntaxError);
assert.throws(SyntaxError, () => eval(`var q = (...${badName}) => ${badName} + 42;`));
assertThrowsInstanceOf(() => eval(`function r(x, ...${badName}) { return x + ${badName}; }`),
SyntaxError);
assert.throws(SyntaxError, () => eval(`function r(x, ...${badName}) { return x + ${badName}; }`));
}
}
h();

View File

@ -32,6 +32,6 @@ for (let primitive of primitives) {
return primitive;
}
};
assertThrowsInstanceOf(() => f(...arg), TypeError);
assert.throws(TypeError, () => f(...arg));
}