mirror of
https://github.com/tc39/test262.git
synced 2025-10-24 17:23:53 +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];
|
var frozenArray = [1, 1, 1];
|
||||||
Object.freeze(frozenArray);
|
Object.freeze(frozenArray);
|
||||||
|
|
||||||
assertThrowsInstanceOf(() => [].fill.call(objWithGetterOnly, 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call(objWithGetterOnly, 2));
|
||||||
assertThrowsInstanceOf(() => [].fill.call(objWithReadOnlyProp, 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call(objWithReadOnlyProp, 2));
|
||||||
assertThrowsInstanceOf(() => [].fill.call(objWithNonconfigurableProp, 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call(objWithNonconfigurableProp, 2));
|
||||||
assertThrowsInstanceOf(() => [].fill.call(frozenObj, 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call(frozenObj, 2));
|
||||||
assertThrowsInstanceOf(() => [].fill.call(frozenArray, 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call(frozenArray, 2));
|
||||||
assertThrowsInstanceOf(() => [].fill.call("111", 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call("111", 2));
|
||||||
assertThrowsInstanceOf(() => [].fill.call(null, 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call(null, 2));
|
||||||
assertThrowsInstanceOf(() => [].fill.call(undefined, 2), TypeError);
|
assert.throws(TypeError, () => [].fill.call(undefined, 2));
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,7 @@ function test(ctor, { mapVal=undefined,
|
|||||||
}
|
}
|
||||||
assert.sameValue(caught, true);
|
assert.sameValue(caught, true);
|
||||||
} else if (exceptionType) {
|
} else if (exceptionType) {
|
||||||
assertThrowsInstanceOf(() => ctor.from(iterable, mapVal), exceptionType);
|
assert.throws(exceptionType, () => ctor.from(iterable, mapVal));
|
||||||
} else {
|
} else {
|
||||||
ctor.from(iterable, mapVal);
|
ctor.from(iterable, mapVal);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,10 +11,11 @@ description: |
|
|||||||
pending
|
pending
|
||||||
esid: pending
|
esid: pending
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
// Array.from throws if the argument is undefined or null.
|
// Array.from throws if the argument is undefined or null.
|
||||||
assertThrowsInstanceOf(() => Array.from(), TypeError);
|
assert.throws(TypeError, () => Array.from());
|
||||||
assertThrowsInstanceOf(() => Array.from(undefined), TypeError);
|
assert.throws(TypeError, () => Array.from(undefined));
|
||||||
assertThrowsInstanceOf(() => Array.from(null), TypeError);
|
assert.throws(TypeError, () => Array.from(null));
|
||||||
|
|
||||||
// Array.from throws if an element can't be defined on the new object.
|
// Array.from throws if an element can't be defined on the new object.
|
||||||
function ObjectWithReadOnlyElement() {
|
function ObjectWithReadOnlyElement() {
|
||||||
@ -23,14 +24,14 @@ function ObjectWithReadOnlyElement() {
|
|||||||
}
|
}
|
||||||
ObjectWithReadOnlyElement.from = Array.from;
|
ObjectWithReadOnlyElement.from = Array.from;
|
||||||
assert.deepEqual(ObjectWithReadOnlyElement.from([]), new ObjectWithReadOnlyElement);
|
assert.deepEqual(ObjectWithReadOnlyElement.from([]), new ObjectWithReadOnlyElement);
|
||||||
assertThrowsInstanceOf(() => ObjectWithReadOnlyElement.from([1]), TypeError);
|
assert.throws(TypeError, () => ObjectWithReadOnlyElement.from([1]));
|
||||||
|
|
||||||
// The same, but via preventExtensions.
|
// The same, but via preventExtensions.
|
||||||
function InextensibleObject() {
|
function InextensibleObject() {
|
||||||
Object.preventExtensions(this);
|
Object.preventExtensions(this);
|
||||||
}
|
}
|
||||||
InextensibleObject.from = Array.from;
|
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
|
// We will now test this property, that Array.from throws if the .length can't
|
||||||
// be assigned, using several different kinds of object.
|
// be assigned, using several different kinds of object.
|
||||||
@ -46,13 +47,13 @@ function testUnsettableLength(C, Exc) {
|
|||||||
C.from = Array.from;
|
C.from = Array.from;
|
||||||
|
|
||||||
obj = null;
|
obj = null;
|
||||||
assertThrowsInstanceOf(() => C.from([]), Exc);
|
assert.throws(Exc, () => C.from([]));
|
||||||
assert.sameValue(obj instanceof C, true);
|
assert.sameValue(obj instanceof C, true);
|
||||||
for (var i = 0; i < 4; i++)
|
for (var i = 0; i < 4; i++)
|
||||||
assert.sameValue(obj[0], 0);
|
assert.sameValue(obj[0], 0);
|
||||||
|
|
||||||
obj = null;
|
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);
|
assert.sameValue(obj instanceof C, true);
|
||||||
for (var i = 0; i < 4; i++)
|
for (var i = 0; i < 4; i++)
|
||||||
assert.sameValue(obj[i], i * 10);
|
assert.sameValue(obj[i], i * 10);
|
||||||
@ -76,7 +77,7 @@ testUnsettableLength(ObjectWithReadOnlyLength);
|
|||||||
|
|
||||||
// The same, but using a builtin type.
|
// The same, but using a builtin type.
|
||||||
Uint8Array.from = Array.from;
|
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
|
// Array.from throws if the new object's .length can't be assigned because it
|
||||||
// inherits a readonly .length along the prototype chain.
|
// inherits a readonly .length along the prototype chain.
|
||||||
@ -107,12 +108,12 @@ function ObjectWithThrowingLengthSetter() {
|
|||||||
testUnsettableLength(ObjectWithThrowingLengthSetter, RangeError);
|
testUnsettableLength(ObjectWithThrowingLengthSetter, RangeError);
|
||||||
|
|
||||||
// Array.from throws if mapfn is neither callable nor undefined.
|
// Array.from throws if mapfn is neither callable nor undefined.
|
||||||
assertThrowsInstanceOf(() => Array.from([3, 4, 5], {}), TypeError);
|
assert.throws(TypeError, () => Array.from([3, 4, 5], {}));
|
||||||
assertThrowsInstanceOf(() => Array.from([3, 4, 5], "also not a function"), TypeError);
|
assert.throws(TypeError, () => Array.from([3, 4, 5], "also not a function"));
|
||||||
assertThrowsInstanceOf(() => Array.from([3, 4, 5], null), TypeError);
|
assert.throws(TypeError, () => Array.from([3, 4, 5], null));
|
||||||
|
|
||||||
// Even if the function would not have been called.
|
// 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.
|
// If mapfn is not undefined and not callable, the error happens before anything else.
|
||||||
// Before calling the constructor, before touching the arrayLike.
|
// Before calling the constructor, before touching the arrayLike.
|
||||||
@ -126,7 +127,7 @@ var p = new Proxy({}, {
|
|||||||
get: function () { log += "2"; },
|
get: function () { log += "2"; },
|
||||||
getOwnPropertyDescriptor: function () { log += "3"; }
|
getOwnPropertyDescriptor: function () { log += "3"; }
|
||||||
});
|
});
|
||||||
assertThrowsInstanceOf(() => Array.from.call(C, p, {}), TypeError);
|
assert.throws(TypeError, () => Array.from.call(C, p, {}));
|
||||||
assert.sameValue(log, "");
|
assert.sameValue(log, "");
|
||||||
|
|
||||||
// If mapfn throws, the new object has already been created.
|
// 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).
|
// It's a TypeError if the @@iterator property is a primitive (except null and undefined).
|
||||||
for (var primitive of ["foo", 17, Symbol(), true]) {
|
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]: null}), []);
|
||||||
assert.deepEqual(Array.from({[Symbol.iterator]: undefined}), []);
|
assert.deepEqual(Array.from({[Symbol.iterator]: undefined}), []);
|
||||||
|
|
||||||
// It's a TypeError if the iterator's .next() method returns a primitive.
|
// It's a TypeError if the iterator's .next() method returns a primitive.
|
||||||
for (var primitive of [undefined, null, 17]) {
|
for (var primitive of [undefined, null, 17]) {
|
||||||
assertThrowsInstanceOf(
|
assert.throws(
|
||||||
|
TypeError,
|
||||||
() => Array.from({
|
() => Array.from({
|
||||||
[Symbol.iterator]() {
|
[Symbol.iterator]() {
|
||||||
return {next() { return primitive; }};
|
return {next() { return primitive; }};
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
TypeError);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,5 +17,5 @@ assert.sameValue(desc.configurable, true);
|
|||||||
assert.sameValue(desc.enumerable, false);
|
assert.sameValue(desc.enumerable, false);
|
||||||
assert.sameValue(desc.writable, true);
|
assert.sameValue(desc.writable, true);
|
||||||
assert.sameValue(Array.from.length, 1);
|
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);
|
assert.sameValue(a[2], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThrowsInstanceOf(() => a.reverse(), TypeError);
|
assert.throws(TypeError, () => a.reverse());
|
||||||
assertThrowsInstanceOf(() => a.shift(), TypeError);
|
assert.throws(TypeError, () => a.shift());
|
||||||
assertThrowsInstanceOf(() => a.unshift(0), TypeError);
|
assert.throws(TypeError, () => a.unshift(0));
|
||||||
assertThrowsInstanceOf(() => a.sort(function() {}), TypeError);
|
assert.throws(TypeError, () => a.sort(function() {}));
|
||||||
assertThrowsInstanceOf(() => a.pop(), TypeError);
|
assert.throws(TypeError, () => a.pop());
|
||||||
assertThrowsInstanceOf(() => a.fill(0), TypeError);
|
assert.throws(TypeError, () => a.fill(0));
|
||||||
assertThrowsInstanceOf(() => a.splice(0, 1, 1), TypeError);
|
assert.throws(TypeError, () => a.splice(0, 1, 1));
|
||||||
assertThrowsInstanceOf(() => a.push("foo"), TypeError);
|
assert.throws(TypeError, () => a.push("foo"));
|
||||||
assertThrowsInstanceOf(() => { "use strict"; a.length = 5; }, TypeError);
|
assert.throws(TypeError, () => { "use strict"; a.length = 5; });
|
||||||
assertThrowsInstanceOf(() => { "use strict"; a[2] = "foo"; }, TypeError);
|
assert.throws(TypeError, () => { "use strict"; a[2] = "foo"; });
|
||||||
assertThrowsInstanceOf(() => { "use strict"; delete a[0]; }, TypeError);
|
assert.throws(TypeError, () => { "use strict"; delete a[0]; });
|
||||||
assertThrowsInstanceOf(() => a.splice(Math.a), TypeError);
|
assert.throws(TypeError, () => a.splice(Math.a));
|
||||||
|
|
||||||
// Shouldn't throw, since this is not strict mode, but shouldn't change the
|
// Shouldn't throw, since this is not strict mode, but shouldn't change the
|
||||||
// value of the property.
|
// value of the property.
|
||||||
|
|||||||
@ -41,14 +41,14 @@ function isNeg(x) {
|
|||||||
assert.deepEqual(negMappedArray.get(0), a1);
|
assert.deepEqual(negMappedArray.get(0), a1);
|
||||||
assert.deepEqual(negMappedArray.size, 1);
|
assert.deepEqual(negMappedArray.size, 1);
|
||||||
|
|
||||||
assertThrowsInstanceOf(() => Object.groupBy([], undefined), TypeError);
|
assert.throws(TypeError, () => Object.groupBy([], undefined));
|
||||||
assertThrowsInstanceOf(() => Object.groupBy([], null), TypeError);
|
assert.throws(TypeError, () => Object.groupBy([], null));
|
||||||
assertThrowsInstanceOf(() => Object.groupBy([], 0), TypeError);
|
assert.throws(TypeError, () => Object.groupBy([], 0));
|
||||||
assertThrowsInstanceOf(() => Object.groupBy([], ""), TypeError);
|
assert.throws(TypeError, () => Object.groupBy([], ""));
|
||||||
assertThrowsInstanceOf(() => Map.groupBy([], undefined), TypeError);
|
assert.throws(TypeError, () => Map.groupBy([], undefined));
|
||||||
assertThrowsInstanceOf(() => Map.groupBy([], null), TypeError);
|
assert.throws(TypeError, () => Map.groupBy([], null));
|
||||||
assertThrowsInstanceOf(() => Map.groupBy([], 0), TypeError);
|
assert.throws(TypeError, () => Map.groupBy([], 0));
|
||||||
assertThrowsInstanceOf(() => Map.groupBy([], ""), TypeError);
|
assert.throws(TypeError, () => Map.groupBy([], ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
const array = [ 'test' ];
|
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: 3, get 0(){delete this[1]}, 1: 2}, 2));
|
||||||
assertFalse(staticIncludes({length: -100, 0: 1}, 1));
|
assertFalse(staticIncludes({length: -100, 0: 1}, 1));
|
||||||
|
|
||||||
assertThrowsInstanceOf(() => staticIncludes(), TypeError);
|
assert.throws(TypeError, () => staticIncludes());
|
||||||
assertThrowsInstanceOf(() => staticIncludes(null), TypeError);
|
assert.throws(TypeError, () => staticIncludes(null));
|
||||||
assertThrowsInstanceOf(() => staticIncludes({get length(){throw TypeError()}}), TypeError);
|
assert.throws(TypeError, () => staticIncludes({get length(){throw TypeError()}}));
|
||||||
assertThrowsInstanceOf(() => staticIncludes({length: 3, get 1() {throw TypeError()}}, 2), TypeError);
|
assert.throws(TypeError, () => staticIncludes({length: 3, get 1() {throw TypeError()}}, 2));
|
||||||
assertThrowsInstanceOf(() => staticIncludes({__proto__: {get 1() {throw TypeError()}}, length: 3}, 2), TypeError);
|
assert.throws(TypeError, () => staticIncludes({__proto__: {get 1() {throw TypeError()}}, length: 3}, 2));
|
||||||
assertThrowsInstanceOf(() => staticIncludes(new Proxy([1], {get(){throw TypeError()}})), TypeError);
|
assert.throws(TypeError, () => staticIncludes(new Proxy([1], {get(){throw TypeError()}})));
|
||||||
|
|
||||||
function assertTrue(v) {
|
function assertTrue(v) {
|
||||||
assert.sameValue(v, true);
|
assert.sameValue(v, true);
|
||||||
|
|||||||
@ -47,10 +47,10 @@ function performTests(pickGlobal)
|
|||||||
|
|
||||||
// Revoked proxy to (formerly) an array.
|
// Revoked proxy to (formerly) an array.
|
||||||
revocable.revoke();
|
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.
|
// 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.
|
// Throws if the comparator is neither undefined nor callable.
|
||||||
for (let invalidComparator of [null, 0, true, Symbol(), {}, []]) {
|
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.
|
// Doesn't throw if the comparator is undefined or a callable object.
|
||||||
|
|||||||
@ -97,7 +97,7 @@ function test(funcName, args, expectedLength, expectedLogs) {
|
|||||||
a.constructor = {
|
a.constructor = {
|
||||||
[Symbol.species]: species
|
[Symbol.species]: species
|
||||||
};
|
};
|
||||||
assertThrowsInstanceOf(() => a[funcName](...args), TypeError);
|
assert.throws(TypeError, () => a[funcName](...args));
|
||||||
}
|
}
|
||||||
|
|
||||||
// undefined constructor
|
// 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]) {
|
for (var ctor of [null, 0, 1.1, true, false, "a", Symbol.iterator]) {
|
||||||
a = [1, 2, 3, 4, 5];
|
a = [1, 2, 3, 4, 5];
|
||||||
a.constructor = ctor;
|
a.constructor = ctor;
|
||||||
assertThrowsInstanceOf(() => a[funcName](...args), TypeError);
|
assert.throws(TypeError, () => a[funcName](...args));
|
||||||
}
|
}
|
||||||
|
|
||||||
// not an array
|
// 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.sameValue(array.length, 6);
|
||||||
assert.compareArray(array, [1, 2, /* hole */, 3, 4, 5]);
|
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.sameValue(array.length, 6);
|
||||||
assert.compareArray(array, [123, 0, 1, 2, 4, 5]);
|
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);
|
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
|
// 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
|
// Make sure ArraySpeciesCreate is called with ToLength applied to the length property
|
||||||
var proxy = new Proxy([], {
|
var proxy = new Proxy([], {
|
||||||
|
|||||||
@ -56,11 +56,11 @@ for (let key of keys)
|
|||||||
assert.sameValue(Array_unscopables[key], true);
|
assert.sameValue(Array_unscopables[key], true);
|
||||||
|
|
||||||
// Test that it actually works
|
// Test that it actually works
|
||||||
assertThrowsInstanceOf(() => {
|
assert.throws(ReferenceError, () => {
|
||||||
with ([]) {
|
with ([]) {
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
}, ReferenceError);
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
let fill = 33;
|
let fill = 33;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user