Replace assertThrowsInstanceOf with assert.throws in sm/Reflect

This commit is contained in:
André Bargull 2025-04-30 14:15:49 +02:00 committed by Philip Chimento
parent 2fe9977b83
commit ad6b866f42
13 changed files with 26 additions and 33 deletions

View File

@ -17,14 +17,13 @@ assert.sameValue(Reflect.apply(Math.floor, undefined, [1.75]), 1);
// Reflect.apply requires a target object that's callable.
var nonCallable = [{}, [], (class clsX { constructor() {} })];
for (var value of nonCallable) {
assertThrowsInstanceOf(() => Reflect.apply(nonCallable), TypeError);
assert.throws(TypeError, () => Reflect.apply(nonCallable));
}
// When target is not callable, Reflect.apply does not try to get argumentList.length before throwing.
var hits = 0;
var bogusArgumentList = {get length() { hit++; throw "FAIL";}};
assertThrowsInstanceOf(() => Reflect.apply({callable: false}, null, bogusArgumentList),
TypeError);
assert.throws(TypeError, () => Reflect.apply({callable: false}, null, bogusArgumentList));
assert.sameValue(hits, 0);
// Reflect.apply works on a range of different callable objects.

View File

@ -14,15 +14,11 @@ esid: pending
// Tests for the argumentList argument to Reflect.apply and Reflect.construct.
// Reflect.apply and Reflect.construct require an argumentList argument that must be an object.
assertThrowsInstanceOf(() => Reflect.apply(Math.min, undefined), // missing
TypeError);
assertThrowsInstanceOf(() => Reflect.construct(Object), // missing
TypeError);
assert.throws(TypeError, () => Reflect.apply(Math.min, undefined));
assert.throws(TypeError, () => Reflect.construct(Object));
for (var primitive of SOME_PRIMITIVE_VALUES) {
assertThrowsInstanceOf(() => Reflect.apply(Math.min, undefined, primitive),
TypeError);
assertThrowsInstanceOf(() => Reflect.construct(Object, primitive),
TypeError);
assert.throws(TypeError, () => Reflect.apply(Math.min, undefined, primitive));
assert.throws(TypeError, () => Reflect.construct(Object, primitive));
}
// Array used by several tests below.

View File

@ -75,8 +75,8 @@ var nonConstructors = [
new Proxy(Reflect.construct, {construct(){}}),
];
for (var obj of nonConstructors) {
assertThrowsInstanceOf(() => Reflect.construct(obj, []), TypeError);
assertThrowsInstanceOf(() => Reflect.construct(obj, [], Object), TypeError);
assert.throws(TypeError, () => Reflect.construct(obj, []));
assert.throws(TypeError, () => Reflect.construct(obj, [], Object));
}
@ -100,7 +100,7 @@ for (var ctor of constructors) {
// The newTarget argument must be a constructor.
for (var v of SOME_PRIMITIVE_VALUES.concat(nonConstructors)) {
assertThrowsInstanceOf(() => Reflect.construct(checkNewTarget, [], v), TypeError);
assert.throws(TypeError, () => Reflect.construct(checkNewTarget, [], v));
}
// The builtin Array constructor uses new.target.prototype and always

View File

@ -79,13 +79,11 @@ assert.sameValue(Reflect.defineProperty(proxy, "prop", attributes), true);
// many error cases to check that behavior.
// missing attributes argument
assertThrowsInstanceOf(() => Reflect.defineProperty(obj, "y"),
TypeError);
assert.throws(TypeError, () => Reflect.defineProperty(obj, "y"));
// non-object attributes argument
for (var attributes of SOME_PRIMITIVE_VALUES) {
assertThrowsInstanceOf(() => Reflect.defineProperty(obj, "y", attributes),
TypeError);
assert.throws(TypeError, () => Reflect.defineProperty(obj, "y", attributes));
}
// inextensible object
@ -155,8 +153,8 @@ proxy = new Proxy(obj, {
return true;
}
});
assertThrowsInstanceOf(() => Reflect.defineProperty(proxy, "x", {value: 2}), TypeError);
assertThrowsInstanceOf(() => Reflect.defineProperty(proxy, "y", {value: 0}), TypeError);
assert.throws(TypeError, () => Reflect.defineProperty(proxy, "x", {value: 2}));
assert.throws(TypeError, () => Reflect.defineProperty(proxy, "y", {value: 0}));
assert.sameValue(Reflect.defineProperty(proxy, "x", {value: 1}), true);
// The second argument is converted ToPropertyKey before any internal methods

View File

@ -62,7 +62,7 @@ assertThrowsValue(() => Reflect.deleteProperty(proxy, "prop"), "vase");
proxy = new Proxy(Object.freeze({prop: 1}), {
deleteProperty(t, k) { return true; }
});
assertThrowsInstanceOf(() => Reflect.deleteProperty(proxy, "prop"), TypeError);
assert.throws(TypeError, () => Reflect.deleteProperty(proxy, "prop"));
// === Deleting elements from `arguments`

View File

@ -46,7 +46,7 @@ var obj = new Proxy(x, {
assert.sameValue(Reflect.get(obj, "mood"), "moodful");
// Exceptions thrown by a proxy's get handler are propagated.
assertThrowsInstanceOf(() => Reflect.get(obj, Symbol()), TypeError);
assert.throws(TypeError, () => Reflect.get(obj, Symbol()));
// Ordinary object, property has a setter and no getter
obj = {set name(x) {}};

View File

@ -60,7 +60,7 @@ assertThrowsValue(() => Reflect.isExtensible(proxy), "oops");
proxy = new Proxy({}, {
isExtensible() { return false; }
});
assertThrowsInstanceOf(() => Reflect.isExtensible(proxy), TypeError);
assert.throws(TypeError, () => Reflect.isExtensible(proxy));
// For more Reflect.isExtensible tests, see target.js.

View File

@ -69,7 +69,7 @@ var obj = Object.preventExtensions({});
var proxy = new Proxy(obj, {
ownKeys() { return ["something"]; }
});
assertThrowsInstanceOf(() => Reflect.ownKeys(proxy), TypeError);
assert.throws(TypeError, () => Reflect.ownKeys(proxy));
// For more Reflect.ownKeys tests, see target.js.

View File

@ -28,9 +28,9 @@ for (var obj of someObjects) {
}
// Error cases.
assertThrowsInstanceOf(() => Reflect.isExtensible(), TypeError);
assert.throws(TypeError, () => Reflect.isExtensible());
for (var value of [undefined, null, true, 1, NaN, "Phaedo", Symbol("good")]) {
assertThrowsInstanceOf(() => Reflect.isExtensible(value), TypeError);
assert.throws(TypeError, () => Reflect.isExtensible(value));
}
// A proxy's preventExtensions handler can return false without doing anything.
@ -57,7 +57,7 @@ obj = {};
proxy = new Proxy(obj, {
preventExtensions() { return true; }
});
assertThrowsInstanceOf(() => Reflect.preventExtensions(proxy), TypeError);
assert.throws(TypeError, () => Reflect.preventExtensions(proxy));
assert.sameValue(Reflect.isExtensible(obj), true);
assert.sameValue(Reflect.isExtensible(proxy), true);

View File

@ -237,7 +237,7 @@ for (obj of [{a: 0}, {get a() { return 0; }}]) {
proxy = new Proxy(obj, {
set(t, k, v, r) { return true; }
});
assertThrowsInstanceOf(() => Reflect.set(proxy, "a", "b"), TypeError);
assert.throws(TypeError, () => Reflect.set(proxy, "a", "b"));
}
// Per spec, this should first call p.[[Set]]("0", 42, a) and

View File

@ -25,11 +25,11 @@ assert.sameValue(Object.getPrototypeOf(obj), null);
// The proto argument is required too.
obj = {};
assertThrowsInstanceOf(() => Reflect.setPrototypeOf(obj), TypeError);
assert.throws(TypeError, () => Reflect.setPrototypeOf(obj));
// The proto argument must be either null or an object.
for (proto of [undefined, false, 0, 1.6, "that", Symbol.iterator]) {
assertThrowsInstanceOf(() => Reflect.setPrototypeOf(obj, proto), TypeError);
assert.throws(TypeError, () => Reflect.setPrototypeOf(obj, proto));
}
// Return false if the target isn't extensible.

View File

@ -15,7 +15,7 @@ esid: pending
assert.sameValue(typeof Reflect, 'object');
assert.sameValue(Object.getPrototypeOf(Reflect), Object.prototype);
assert.sameValue(Reflect.toString(), '[object Reflect]');
assertThrowsInstanceOf(() => new Reflect, TypeError);
assert.throws(TypeError, () => new Reflect);
var desc = Object.getOwnPropertyDescriptor(this, "Reflect");
assert.sameValue(desc.enumerable, false);

View File

@ -43,11 +43,11 @@ for (const name of Object.keys(methodInfo)) {
var args = methodInfo[name];
// The target argument is required.
assertThrowsInstanceOf(Reflect[name], TypeError);
assert.throws(TypeError, Reflect[name]);
// Throw if the target argument is not an object.
for (var value of SOME_PRIMITIVE_VALUES) {
assertThrowsInstanceOf(() => Reflect[name](value, ...args), TypeError);
assert.throws(TypeError, () => Reflect[name](value, ...args));
}
}