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. // Reflect.apply requires a target object that's callable.
var nonCallable = [{}, [], (class clsX { constructor() {} })]; var nonCallable = [{}, [], (class clsX { constructor() {} })];
for (var value of nonCallable) { 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. // When target is not callable, Reflect.apply does not try to get argumentList.length before throwing.
var hits = 0; var hits = 0;
var bogusArgumentList = {get length() { hit++; throw "FAIL";}}; var bogusArgumentList = {get length() { hit++; throw "FAIL";}};
assertThrowsInstanceOf(() => Reflect.apply({callable: false}, null, bogusArgumentList), assert.throws(TypeError, () => Reflect.apply({callable: false}, null, bogusArgumentList));
TypeError);
assert.sameValue(hits, 0); assert.sameValue(hits, 0);
// Reflect.apply works on a range of different callable objects. // 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. // 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. // Reflect.apply and Reflect.construct require an argumentList argument that must be an object.
assertThrowsInstanceOf(() => Reflect.apply(Math.min, undefined), // missing assert.throws(TypeError, () => Reflect.apply(Math.min, undefined));
TypeError); assert.throws(TypeError, () => Reflect.construct(Object));
assertThrowsInstanceOf(() => Reflect.construct(Object), // missing
TypeError);
for (var primitive of SOME_PRIMITIVE_VALUES) { for (var primitive of SOME_PRIMITIVE_VALUES) {
assertThrowsInstanceOf(() => Reflect.apply(Math.min, undefined, primitive), assert.throws(TypeError, () => Reflect.apply(Math.min, undefined, primitive));
TypeError); assert.throws(TypeError, () => Reflect.construct(Object, primitive));
assertThrowsInstanceOf(() => Reflect.construct(Object, primitive),
TypeError);
} }
// Array used by several tests below. // Array used by several tests below.

View File

@ -75,8 +75,8 @@ var nonConstructors = [
new Proxy(Reflect.construct, {construct(){}}), new Proxy(Reflect.construct, {construct(){}}),
]; ];
for (var obj of nonConstructors) { for (var obj of nonConstructors) {
assertThrowsInstanceOf(() => Reflect.construct(obj, []), TypeError); assert.throws(TypeError, () => Reflect.construct(obj, []));
assertThrowsInstanceOf(() => Reflect.construct(obj, [], Object), TypeError); assert.throws(TypeError, () => Reflect.construct(obj, [], Object));
} }
@ -100,7 +100,7 @@ for (var ctor of constructors) {
// The newTarget argument must be a constructor. // The newTarget argument must be a constructor.
for (var v of SOME_PRIMITIVE_VALUES.concat(nonConstructors)) { 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 // 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. // many error cases to check that behavior.
// missing attributes argument // missing attributes argument
assertThrowsInstanceOf(() => Reflect.defineProperty(obj, "y"), assert.throws(TypeError, () => Reflect.defineProperty(obj, "y"));
TypeError);
// non-object attributes argument // non-object attributes argument
for (var attributes of SOME_PRIMITIVE_VALUES) { for (var attributes of SOME_PRIMITIVE_VALUES) {
assertThrowsInstanceOf(() => Reflect.defineProperty(obj, "y", attributes), assert.throws(TypeError, () => Reflect.defineProperty(obj, "y", attributes));
TypeError);
} }
// inextensible object // inextensible object
@ -155,8 +153,8 @@ proxy = new Proxy(obj, {
return true; return true;
} }
}); });
assertThrowsInstanceOf(() => Reflect.defineProperty(proxy, "x", {value: 2}), TypeError); assert.throws(TypeError, () => Reflect.defineProperty(proxy, "x", {value: 2}));
assertThrowsInstanceOf(() => Reflect.defineProperty(proxy, "y", {value: 0}), TypeError); assert.throws(TypeError, () => Reflect.defineProperty(proxy, "y", {value: 0}));
assert.sameValue(Reflect.defineProperty(proxy, "x", {value: 1}), true); assert.sameValue(Reflect.defineProperty(proxy, "x", {value: 1}), true);
// The second argument is converted ToPropertyKey before any internal methods // 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}), { proxy = new Proxy(Object.freeze({prop: 1}), {
deleteProperty(t, k) { return true; } deleteProperty(t, k) { return true; }
}); });
assertThrowsInstanceOf(() => Reflect.deleteProperty(proxy, "prop"), TypeError); assert.throws(TypeError, () => Reflect.deleteProperty(proxy, "prop"));
// === Deleting elements from `arguments` // === Deleting elements from `arguments`

View File

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

View File

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

View File

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

View File

@ -28,9 +28,9 @@ for (var obj of someObjects) {
} }
// Error cases. // Error cases.
assertThrowsInstanceOf(() => Reflect.isExtensible(), TypeError); assert.throws(TypeError, () => Reflect.isExtensible());
for (var value of [undefined, null, true, 1, NaN, "Phaedo", Symbol("good")]) { 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. // A proxy's preventExtensions handler can return false without doing anything.
@ -57,7 +57,7 @@ obj = {};
proxy = new Proxy(obj, { proxy = new Proxy(obj, {
preventExtensions() { return true; } preventExtensions() { return true; }
}); });
assertThrowsInstanceOf(() => Reflect.preventExtensions(proxy), TypeError); assert.throws(TypeError, () => Reflect.preventExtensions(proxy));
assert.sameValue(Reflect.isExtensible(obj), true); assert.sameValue(Reflect.isExtensible(obj), true);
assert.sameValue(Reflect.isExtensible(proxy), 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, { proxy = new Proxy(obj, {
set(t, k, v, r) { return true; } 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 // 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. // The proto argument is required too.
obj = {}; obj = {};
assertThrowsInstanceOf(() => Reflect.setPrototypeOf(obj), TypeError); assert.throws(TypeError, () => Reflect.setPrototypeOf(obj));
// The proto argument must be either null or an object. // The proto argument must be either null or an object.
for (proto of [undefined, false, 0, 1.6, "that", Symbol.iterator]) { 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. // Return false if the target isn't extensible.

View File

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

View File

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