From d7a11ffe21c0d5ac6ca076bac51a07c0aea14162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Wed, 30 Apr 2025 14:15:43 +0200 Subject: [PATCH] Replace assertThrowsInstanceOf with assert.throws in sm/Array --- test/staging/sm/Array/fill.js | 16 ++++----- test/staging/sm/Array/from-iterator-close.js | 2 +- test/staging/sm/Array/from_errors.js | 36 ++++++++++--------- test/staging/sm/Array/from_surfaces.js | 2 +- test/staging/sm/Array/frozen-dense-array.js | 24 ++++++------- test/staging/sm/Array/group.js | 16 ++++----- test/staging/sm/Array/includes.js | 12 +++---- test/staging/sm/Array/isArray.js | 4 +-- test/staging/sm/Array/sort-non-function.js | 2 +- test/staging/sm/Array/species.js | 4 +-- .../sm/Array/splice-species-changes-length.js | 4 +-- test/staging/sm/Array/to-length.js | 2 +- test/staging/sm/Array/unscopables.js | 4 +-- 13 files changed, 65 insertions(+), 63 deletions(-) diff --git a/test/staging/sm/Array/fill.js b/test/staging/sm/Array/fill.js index 6476948416..8cf6ce71c4 100644 --- a/test/staging/sm/Array/fill.js +++ b/test/staging/sm/Array/fill.js @@ -93,12 +93,12 @@ Object.freeze(frozenObj); var frozenArray = [1, 1, 1]; Object.freeze(frozenArray); -assertThrowsInstanceOf(() => [].fill.call(objWithGetterOnly, 2), TypeError); -assertThrowsInstanceOf(() => [].fill.call(objWithReadOnlyProp, 2), TypeError); -assertThrowsInstanceOf(() => [].fill.call(objWithNonconfigurableProp, 2), TypeError); -assertThrowsInstanceOf(() => [].fill.call(frozenObj, 2), TypeError); -assertThrowsInstanceOf(() => [].fill.call(frozenArray, 2), TypeError); -assertThrowsInstanceOf(() => [].fill.call("111", 2), TypeError); -assertThrowsInstanceOf(() => [].fill.call(null, 2), TypeError); -assertThrowsInstanceOf(() => [].fill.call(undefined, 2), TypeError); +assert.throws(TypeError, () => [].fill.call(objWithGetterOnly, 2)); +assert.throws(TypeError, () => [].fill.call(objWithReadOnlyProp, 2)); +assert.throws(TypeError, () => [].fill.call(objWithNonconfigurableProp, 2)); +assert.throws(TypeError, () => [].fill.call(frozenObj, 2)); +assert.throws(TypeError, () => [].fill.call(frozenArray, 2)); +assert.throws(TypeError, () => [].fill.call("111", 2)); +assert.throws(TypeError, () => [].fill.call(null, 2)); +assert.throws(TypeError, () => [].fill.call(undefined, 2)); diff --git a/test/staging/sm/Array/from-iterator-close.js b/test/staging/sm/Array/from-iterator-close.js index 08daa56e81..3ce8bb5126 100644 --- a/test/staging/sm/Array/from-iterator-close.js +++ b/test/staging/sm/Array/from-iterator-close.js @@ -56,7 +56,7 @@ function test(ctor, { mapVal=undefined, } assert.sameValue(caught, true); } else if (exceptionType) { - assertThrowsInstanceOf(() => ctor.from(iterable, mapVal), exceptionType); + assert.throws(exceptionType, () => ctor.from(iterable, mapVal)); } else { ctor.from(iterable, mapVal); } diff --git a/test/staging/sm/Array/from_errors.js b/test/staging/sm/Array/from_errors.js index bf5b086daa..2ac11e1819 100644 --- a/test/staging/sm/Array/from_errors.js +++ b/test/staging/sm/Array/from_errors.js @@ -11,10 +11,11 @@ description: | pending esid: pending ---*/ + // Array.from throws if the argument is undefined or null. -assertThrowsInstanceOf(() => Array.from(), TypeError); -assertThrowsInstanceOf(() => Array.from(undefined), TypeError); -assertThrowsInstanceOf(() => Array.from(null), TypeError); +assert.throws(TypeError, () => Array.from()); +assert.throws(TypeError, () => Array.from(undefined)); +assert.throws(TypeError, () => Array.from(null)); // Array.from throws if an element can't be defined on the new object. function ObjectWithReadOnlyElement() { @@ -23,14 +24,14 @@ function ObjectWithReadOnlyElement() { } ObjectWithReadOnlyElement.from = Array.from; assert.deepEqual(ObjectWithReadOnlyElement.from([]), new ObjectWithReadOnlyElement); -assertThrowsInstanceOf(() => ObjectWithReadOnlyElement.from([1]), TypeError); +assert.throws(TypeError, () => ObjectWithReadOnlyElement.from([1])); // The same, but via preventExtensions. function InextensibleObject() { Object.preventExtensions(this); } InextensibleObject.from = Array.from; -assertThrowsInstanceOf(() => InextensibleObject.from([1]), TypeError); +assert.throws(TypeError, () => InextensibleObject.from([1])); // We will now test this property, that Array.from throws if the .length can't // be assigned, using several different kinds of object. @@ -46,13 +47,13 @@ function testUnsettableLength(C, Exc) { C.from = Array.from; obj = null; - assertThrowsInstanceOf(() => C.from([]), Exc); + assert.throws(Exc, () => C.from([])); assert.sameValue(obj instanceof C, true); for (var i = 0; i < 4; i++) assert.sameValue(obj[0], 0); obj = null; - assertThrowsInstanceOf(() => C.from([0, 10, 20, 30]), Exc); + assert.throws(Exc, () => C.from([0, 10, 20, 30])); assert.sameValue(obj instanceof C, true); for (var i = 0; i < 4; i++) assert.sameValue(obj[i], i * 10); @@ -76,7 +77,7 @@ testUnsettableLength(ObjectWithReadOnlyLength); // The same, but using a builtin type. Uint8Array.from = Array.from; -assertThrowsInstanceOf(() => Uint8Array.from([]), TypeError); +assert.throws(TypeError, () => Uint8Array.from([])); // Array.from throws if the new object's .length can't be assigned because it // inherits a readonly .length along the prototype chain. @@ -107,12 +108,12 @@ function ObjectWithThrowingLengthSetter() { testUnsettableLength(ObjectWithThrowingLengthSetter, RangeError); // Array.from throws if mapfn is neither callable nor undefined. -assertThrowsInstanceOf(() => Array.from([3, 4, 5], {}), TypeError); -assertThrowsInstanceOf(() => Array.from([3, 4, 5], "also not a function"), TypeError); -assertThrowsInstanceOf(() => Array.from([3, 4, 5], null), TypeError); +assert.throws(TypeError, () => Array.from([3, 4, 5], {})); +assert.throws(TypeError, () => Array.from([3, 4, 5], "also not a function")); +assert.throws(TypeError, () => Array.from([3, 4, 5], null)); // Even if the function would not have been called. -assertThrowsInstanceOf(() => Array.from([], JSON), TypeError); +assert.throws(TypeError, () => Array.from([], JSON)); // If mapfn is not undefined and not callable, the error happens before anything else. // Before calling the constructor, before touching the arrayLike. @@ -126,7 +127,7 @@ var p = new Proxy({}, { get: function () { log += "2"; }, getOwnPropertyDescriptor: function () { log += "3"; } }); -assertThrowsInstanceOf(() => Array.from.call(C, p, {}), TypeError); +assert.throws(TypeError, () => Array.from.call(C, p, {})); assert.sameValue(log, ""); // If mapfn throws, the new object has already been created. @@ -142,19 +143,20 @@ assert.sameValue(obj instanceof C, true); // It's a TypeError if the @@iterator property is a primitive (except null and undefined). for (var primitive of ["foo", 17, Symbol(), true]) { - assertThrowsInstanceOf(() => Array.from({[Symbol.iterator] : primitive}), TypeError); + assert.throws(TypeError, () => Array.from({[Symbol.iterator] : primitive})); } assert.deepEqual(Array.from({[Symbol.iterator]: null}), []); assert.deepEqual(Array.from({[Symbol.iterator]: undefined}), []); // It's a TypeError if the iterator's .next() method returns a primitive. for (var primitive of [undefined, null, 17]) { - assertThrowsInstanceOf( + assert.throws( + TypeError, () => Array.from({ [Symbol.iterator]() { return {next() { return primitive; }}; } - }), - TypeError); + }) + ); } diff --git a/test/staging/sm/Array/from_surfaces.js b/test/staging/sm/Array/from_surfaces.js index 8f976d9782..cf06e98afe 100644 --- a/test/staging/sm/Array/from_surfaces.js +++ b/test/staging/sm/Array/from_surfaces.js @@ -17,5 +17,5 @@ assert.sameValue(desc.configurable, true); assert.sameValue(desc.enumerable, false); assert.sameValue(desc.writable, true); assert.sameValue(Array.from.length, 1); -assertThrowsInstanceOf(() => new Array.from(), TypeError); // not a constructor +assert.throws(TypeError, () => new Array.from()); // not a constructor diff --git a/test/staging/sm/Array/frozen-dense-array.js b/test/staging/sm/Array/frozen-dense-array.js index 50433a3cd2..144fb3f980 100644 --- a/test/staging/sm/Array/frozen-dense-array.js +++ b/test/staging/sm/Array/frozen-dense-array.js @@ -28,18 +28,18 @@ function assertArrayIsExpected() { assert.sameValue(a[2], 1); } -assertThrowsInstanceOf(() => a.reverse(), TypeError); -assertThrowsInstanceOf(() => a.shift(), TypeError); -assertThrowsInstanceOf(() => a.unshift(0), TypeError); -assertThrowsInstanceOf(() => a.sort(function() {}), TypeError); -assertThrowsInstanceOf(() => a.pop(), TypeError); -assertThrowsInstanceOf(() => a.fill(0), TypeError); -assertThrowsInstanceOf(() => a.splice(0, 1, 1), TypeError); -assertThrowsInstanceOf(() => a.push("foo"), TypeError); -assertThrowsInstanceOf(() => { "use strict"; a.length = 5; }, TypeError); -assertThrowsInstanceOf(() => { "use strict"; a[2] = "foo"; }, TypeError); -assertThrowsInstanceOf(() => { "use strict"; delete a[0]; }, TypeError); -assertThrowsInstanceOf(() => a.splice(Math.a), TypeError); +assert.throws(TypeError, () => a.reverse()); +assert.throws(TypeError, () => a.shift()); +assert.throws(TypeError, () => a.unshift(0)); +assert.throws(TypeError, () => a.sort(function() {})); +assert.throws(TypeError, () => a.pop()); +assert.throws(TypeError, () => a.fill(0)); +assert.throws(TypeError, () => a.splice(0, 1, 1)); +assert.throws(TypeError, () => a.push("foo")); +assert.throws(TypeError, () => { "use strict"; a.length = 5; }); +assert.throws(TypeError, () => { "use strict"; a[2] = "foo"; }); +assert.throws(TypeError, () => { "use strict"; delete a[0]; }); +assert.throws(TypeError, () => a.splice(Math.a)); // Shouldn't throw, since this is not strict mode, but shouldn't change the // value of the property. diff --git a/test/staging/sm/Array/group.js b/test/staging/sm/Array/group.js index 6292186795..8391b656cc 100644 --- a/test/staging/sm/Array/group.js +++ b/test/staging/sm/Array/group.js @@ -41,14 +41,14 @@ function isNeg(x) { assert.deepEqual(negMappedArray.get(0), a1); assert.deepEqual(negMappedArray.size, 1); - assertThrowsInstanceOf(() => Object.groupBy([], undefined), TypeError); - assertThrowsInstanceOf(() => Object.groupBy([], null), TypeError); - assertThrowsInstanceOf(() => Object.groupBy([], 0), TypeError); - assertThrowsInstanceOf(() => Object.groupBy([], ""), TypeError); - assertThrowsInstanceOf(() => Map.groupBy([], undefined), TypeError); - assertThrowsInstanceOf(() => Map.groupBy([], null), TypeError); - assertThrowsInstanceOf(() => Map.groupBy([], 0), TypeError); - assertThrowsInstanceOf(() => Map.groupBy([], ""), TypeError); + assert.throws(TypeError, () => Object.groupBy([], undefined)); + assert.throws(TypeError, () => Object.groupBy([], null)); + assert.throws(TypeError, () => Object.groupBy([], 0)); + assert.throws(TypeError, () => Object.groupBy([], "")); + assert.throws(TypeError, () => Map.groupBy([], undefined)); + assert.throws(TypeError, () => Map.groupBy([], null)); + assert.throws(TypeError, () => Map.groupBy([], 0)); + assert.throws(TypeError, () => Map.groupBy([], "")); } const array = [ 'test' ]; diff --git a/test/staging/sm/Array/includes.js b/test/staging/sm/Array/includes.js index c411a043e1..34623d62a9 100644 --- a/test/staging/sm/Array/includes.js +++ b/test/staging/sm/Array/includes.js @@ -44,12 +44,12 @@ assertFalse(staticIncludes({length: 3, 1: 2}, 2, 2)); assertFalse(staticIncludes({length: 3, get 0(){delete this[1]}, 1: 2}, 2)); assertFalse(staticIncludes({length: -100, 0: 1}, 1)); -assertThrowsInstanceOf(() => staticIncludes(), TypeError); -assertThrowsInstanceOf(() => staticIncludes(null), TypeError); -assertThrowsInstanceOf(() => staticIncludes({get length(){throw TypeError()}}), TypeError); -assertThrowsInstanceOf(() => staticIncludes({length: 3, get 1() {throw TypeError()}}, 2), TypeError); -assertThrowsInstanceOf(() => staticIncludes({__proto__: {get 1() {throw TypeError()}}, length: 3}, 2), TypeError); -assertThrowsInstanceOf(() => staticIncludes(new Proxy([1], {get(){throw TypeError()}})), TypeError); +assert.throws(TypeError, () => staticIncludes()); +assert.throws(TypeError, () => staticIncludes(null)); +assert.throws(TypeError, () => staticIncludes({get length(){throw TypeError()}})); +assert.throws(TypeError, () => staticIncludes({length: 3, get 1() {throw TypeError()}}, 2)); +assert.throws(TypeError, () => staticIncludes({__proto__: {get 1() {throw TypeError()}}, length: 3}, 2)); +assert.throws(TypeError, () => staticIncludes(new Proxy([1], {get(){throw TypeError()}}))); function assertTrue(v) { assert.sameValue(v, true); diff --git a/test/staging/sm/Array/isArray.js b/test/staging/sm/Array/isArray.js index 8f29c7fa32..9a4abecd17 100644 --- a/test/staging/sm/Array/isArray.js +++ b/test/staging/sm/Array/isArray.js @@ -47,10 +47,10 @@ function performTests(pickGlobal) // Revoked proxy to (formerly) an array. revocable.revoke(); - assertThrowsInstanceOf(() => Array.isArray(revocable.proxy), TypeError); + assert.throws(TypeError, () => Array.isArray(revocable.proxy)); // Recursive proxy ultimately terminating in a revoked proxy to an array. - assertThrowsInstanceOf(() => Array.isArray(proxy), TypeError); + assert.throws(TypeError, () => Array.isArray(proxy)); } diff --git a/test/staging/sm/Array/sort-non-function.js b/test/staging/sm/Array/sort-non-function.js index 5dc8f748e6..faea31a6ba 100644 --- a/test/staging/sm/Array/sort-non-function.js +++ b/test/staging/sm/Array/sort-non-function.js @@ -18,7 +18,7 @@ const array = new Array(0); // Throws if the comparator is neither undefined nor callable. for (let invalidComparator of [null, 0, true, Symbol(), {}, []]) { - assertThrowsInstanceOf(() => array.sort(invalidComparator), TypeError); + assert.throws(TypeError, () => array.sort(invalidComparator)); } // Doesn't throw if the comparator is undefined or a callable object. diff --git a/test/staging/sm/Array/species.js b/test/staging/sm/Array/species.js index a6ab7a9d9b..c647c01967 100644 --- a/test/staging/sm/Array/species.js +++ b/test/staging/sm/Array/species.js @@ -97,7 +97,7 @@ function test(funcName, args, expectedLength, expectedLogs) { a.constructor = { [Symbol.species]: species }; - assertThrowsInstanceOf(() => a[funcName](...args), TypeError); + assert.throws(TypeError, () => a[funcName](...args)); } // undefined constructor @@ -110,7 +110,7 @@ function test(funcName, args, expectedLength, expectedLogs) { for (var ctor of [null, 0, 1.1, true, false, "a", Symbol.iterator]) { a = [1, 2, 3, 4, 5]; a.constructor = ctor; - assertThrowsInstanceOf(() => a[funcName](...args), TypeError); + assert.throws(TypeError, () => a[funcName](...args)); } // not an array diff --git a/test/staging/sm/Array/splice-species-changes-length.js b/test/staging/sm/Array/splice-species-changes-length.js index 77cd7420cf..6a7d8bf695 100644 --- a/test/staging/sm/Array/splice-species-changes-length.js +++ b/test/staging/sm/Array/splice-species-changes-length.js @@ -26,7 +26,7 @@ esid: pending } } - assertThrowsInstanceOf(() => Array.prototype.splice.call(array, 0, 1), TypeError); + assert.throws(TypeError, () => Array.prototype.splice.call(array, 0, 1)); assert.sameValue(array.length, 6); assert.compareArray(array, [1, 2, /* hole */, 3, 4, 5]); @@ -49,7 +49,7 @@ esid: pending } } - assertThrowsInstanceOf(() => Array.prototype.splice.call(array, 0, 0, 123), TypeError); + assert.throws(TypeError, () => Array.prototype.splice.call(array, 0, 0, 123)); assert.sameValue(array.length, 6); assert.compareArray(array, [123, 0, 1, 2, 4, 5]); diff --git a/test/staging/sm/Array/to-length.js b/test/staging/sm/Array/to-length.js index dff691163e..e3a2c4df58 100644 --- a/test/staging/sm/Array/to-length.js +++ b/test/staging/sm/Array/to-length.js @@ -31,7 +31,7 @@ assertThrowsValue(() => Array.prototype.copyWithin.call({length: Infinity, get [ assert.sameValue(Array.prototype.includes.call({length: Infinity, [max - 1]: "test"}, "test", max - 3), true); // Invoking the Array constructor with MAX_SAFE_INTEGER will throw, 0 won't -assertThrowsInstanceOf(() => Array.from({length: Infinity}), RangeError); +assert.throws(RangeError, () => Array.from({length: Infinity})); // Make sure ArraySpeciesCreate is called with ToLength applied to the length property var proxy = new Proxy([], { diff --git a/test/staging/sm/Array/unscopables.js b/test/staging/sm/Array/unscopables.js index e3d22f8f33..4ea3f373cb 100644 --- a/test/staging/sm/Array/unscopables.js +++ b/test/staging/sm/Array/unscopables.js @@ -56,11 +56,11 @@ for (let key of keys) assert.sameValue(Array_unscopables[key], true); // Test that it actually works -assertThrowsInstanceOf(() => { +assert.throws(ReferenceError, () => { with ([]) { return entries; } -}, ReferenceError); +}); { let fill = 33;