mirror of
https://github.com/tc39/test262.git
synced 2025-10-24 09:13:51 +02:00
Replace assertThrowsInstanceOf with assert.throws in sm/Array
This commit is contained in:
parent
e5edd5e620
commit
d7a11ffe21
@ -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));
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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' ];
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]);
|
||||
|
||||
@ -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([], {
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user