Replace assertThrowsInstanceOf with assert.throws in sm/TypedArray

This commit is contained in:
André Bargull 2025-04-30 14:15:44 +02:00 committed by Philip Chimento
parent 23d9d1ad9d
commit 68acce80ed
49 changed files with 282 additions and 283 deletions

View File

@ -41,9 +41,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.at.call(invalidReceiver); constructor.prototype.at.call(invalidReceiver);
}, TypeError, "Assert that 'at' fails if this value is not a TypedArray"); }, "Assert that 'at' fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -11,7 +11,7 @@ esid: pending
---*/ ---*/
const testArray = [1n]; const testArray = [1n];
for (const constructor of anyTypedArrayConstructors) { for (const constructor of anyTypedArrayConstructors) {
assertThrowsInstanceOf(() => new constructor(testArray), TypeError); assert.throws(TypeError, () => new constructor(testArray));
assertThrowsInstanceOf(() => new constructor(testArray.values()), TypeError); assert.throws(TypeError, () => new constructor(testArray.values()));
} }

View File

@ -70,8 +70,8 @@ function ValueReturning(value, detach) {
for (let {buffer} of createBuffers()) { for (let {buffer} of createBuffers()) {
let constructor = ConstructorWithThrowingPrototype(); let constructor = ConstructorWithThrowingPrototype();
assertThrowsInstanceOf(() => assert.throws(ExpectedError, () =>
Reflect.construct(Int32Array, [buffer, poisonedValue, 0], constructor), ExpectedError); Reflect.construct(Int32Array, [buffer, poisonedValue, 0], constructor));
} }
// Ensure step 4 |AllocateTypedArray| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 4 |AllocateTypedArray| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -79,8 +79,8 @@ for (let {buffer, detach} of createBuffers()) {
let constructor = ConstructorWithThrowingPrototype(); let constructor = ConstructorWithThrowingPrototype();
detach(); detach();
assertThrowsInstanceOf(() => assert.throws(ExpectedError, () =>
Reflect.construct(Int32Array, [buffer, 0, 0], constructor), ExpectedError); Reflect.construct(Int32Array, [buffer, 0, 0], constructor));
} }
// Ensure step 4 |AllocateTypedArray| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 4 |AllocateTypedArray| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -88,16 +88,16 @@ for (let {buffer, detach} of createBuffers()) {
for (let {buffer, detach} of createBuffers()) { for (let {buffer, detach} of createBuffers()) {
let constructor = ConstructorWithThrowingPrototype(detach); let constructor = ConstructorWithThrowingPrototype(detach);
assertThrowsInstanceOf(() => assert.throws(ExpectedError, () =>
Reflect.construct(Int32Array, [buffer, 0, 0], constructor), ExpectedError); Reflect.construct(Int32Array, [buffer, 0, 0], constructor));
} }
// Ensure step 4 |AllocateTypedArray| is executed before step 8.a |ToIndex(length)|. // Ensure step 4 |AllocateTypedArray| is executed before step 8.a |ToIndex(length)|.
for (let {buffer} of createBuffers()) { for (let {buffer} of createBuffers()) {
let constructor = ConstructorWithThrowingPrototype(); let constructor = ConstructorWithThrowingPrototype();
assertThrowsInstanceOf(() => assert.throws(ExpectedError, () =>
Reflect.construct(Int32Array, [buffer, 0, poisonedValue], constructor), ExpectedError); Reflect.construct(Int32Array, [buffer, 0, poisonedValue], constructor));
} }
// Ensure step 6 |ToIndex(byteOffset)| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 6 |ToIndex(byteOffset)| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -105,7 +105,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = ValueThrowing(); let byteOffset = ValueThrowing();
detach(); detach();
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, 0), ExpectedError); assert.throws(ExpectedError, () => new Int32Array(buffer, byteOffset, 0));
} }
// Ensure step 6 |ToIndex(byteOffset)| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 6 |ToIndex(byteOffset)| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -113,14 +113,14 @@ for (let {buffer, detach} of createBuffers()) {
for (let {buffer, detach} of createBuffers()) { for (let {buffer, detach} of createBuffers()) {
let byteOffset = ValueThrowing(detach); let byteOffset = ValueThrowing(detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, 0), ExpectedError); assert.throws(ExpectedError, () => new Int32Array(buffer, byteOffset, 0));
} }
// Ensure step 6 |ToIndex(byteOffset)| is executed before step 8.a |ToIndex(length)|. // Ensure step 6 |ToIndex(byteOffset)| is executed before step 8.a |ToIndex(length)|.
for (let {buffer} of createBuffers()) { for (let {buffer} of createBuffers()) {
let byteOffset = ValueThrowing(); let byteOffset = ValueThrowing();
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, poisonedValue), ExpectedError); assert.throws(ExpectedError, () => new Int32Array(buffer, byteOffset, poisonedValue));
} }
// Ensure step 7 |offset modulo elementSize ≠ 0| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 7 |offset modulo elementSize ≠ 0| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -128,7 +128,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = 1; let byteOffset = 1;
detach(); detach();
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, 0), RangeError); assert.throws(RangeError, () => new Int32Array(buffer, byteOffset, 0));
} }
// Ensure step 7 |offset modulo elementSize ≠ 0| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 7 |offset modulo elementSize ≠ 0| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -136,12 +136,12 @@ for (let {buffer, detach} of createBuffers()) {
for (let {buffer, detach} of createBuffers()) { for (let {buffer, detach} of createBuffers()) {
let byteOffset = ValueReturning(1, detach); let byteOffset = ValueReturning(1, detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, 0), RangeError); assert.throws(RangeError, () => new Int32Array(buffer, byteOffset, 0));
} }
// Ensure step 7 |offset modulo elementSize ≠ 0| is executed before step 8.a |ToIndex(length)|. // Ensure step 7 |offset modulo elementSize ≠ 0| is executed before step 8.a |ToIndex(length)|.
for (let {buffer} of createBuffers()) { for (let {buffer} of createBuffers()) {
assertThrowsInstanceOf(() => new Int32Array(buffer, 1, poisonedValue), RangeError); assert.throws(RangeError, () => new Int32Array(buffer, 1, poisonedValue));
} }
// Ensure step 8.a |ToIndex(length)| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 8.a |ToIndex(length)| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -150,7 +150,7 @@ for (let {buffer, detach} of createBuffers()) {
let length = ValueThrowing(); let length = ValueThrowing();
detach(); detach();
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, length), ExpectedError); assert.throws(ExpectedError, () => new Int32Array(buffer, byteOffset, length));
} }
// Ensure step 8.a |ToIndex(length)| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 8.a |ToIndex(length)| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -159,7 +159,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = ValueReturning(0, detach); let byteOffset = ValueReturning(0, detach);
let length = ValueThrowing(); let length = ValueThrowing();
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, length), ExpectedError); assert.throws(ExpectedError, () => new Int32Array(buffer, byteOffset, length));
} }
// Ensure step 8.a |ToIndex(length)| is executed before step 9 |IsDetachedBuffer(buffer)|. // Ensure step 8.a |ToIndex(length)| is executed before step 9 |IsDetachedBuffer(buffer)|.
@ -168,7 +168,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = 0; let byteOffset = 0;
let length = ValueThrowing(detach); let length = ValueThrowing(detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, length), ExpectedError); assert.throws(ExpectedError, () => new Int32Array(buffer, byteOffset, length));
} }
// Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.a |bufferByteLength modulo elementSize ≠ 0|. // Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.a |bufferByteLength modulo elementSize ≠ 0|.
@ -176,7 +176,7 @@ for (let {buffer, detach} of createBuffers([1, 9])) {
let byteOffset = 0; let byteOffset = 0;
detach(); detach();
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset));
} }
// Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.a |bufferByteLength modulo elementSize ≠ 0|. // Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.a |bufferByteLength modulo elementSize ≠ 0|.
@ -184,7 +184,7 @@ for (let {buffer, detach} of createBuffers([1, 9])) {
for (let {buffer, detach} of createBuffers([1, 9])) { for (let {buffer, detach} of createBuffers([1, 9])) {
let byteOffset = ValueReturning(0, detach); let byteOffset = ValueReturning(0, detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset));
} }
// Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.c |newByteLength < 0|. // Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.c |newByteLength < 0|.
@ -192,7 +192,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = 64; let byteOffset = 64;
detach(); detach();
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset));
} }
// Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.c |newByteLength < 0|. // Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 11.c |newByteLength < 0|.
@ -200,7 +200,7 @@ for (let {buffer, detach} of createBuffers()) {
for (let {buffer, detach} of createBuffers()) { for (let {buffer, detach} of createBuffers()) {
let byteOffset = ValueReturning(64, detach); let byteOffset = ValueReturning(64, detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset));
} }
// Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 12.b |offset+newByteLength > bufferByteLength|. // Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 12.b |offset+newByteLength > bufferByteLength|.
@ -209,7 +209,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = 64; let byteOffset = 64;
let length = ValueReturning(0, detach); let length = ValueReturning(0, detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, length), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset, length));
} }
// Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 12.b |offset+newByteLength > bufferByteLength|. // Ensure step 9 |IsDetachedBuffer(buffer)| is executed before step 12.b |offset+newByteLength > bufferByteLength|.
@ -218,7 +218,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = 0; let byteOffset = 0;
let length = ValueReturning(64, detach); let length = ValueReturning(64, detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, length), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset, length));
} }
// Ensure we handle the case when ToIndex(byteOffset) detaches the array buffer. // Ensure we handle the case when ToIndex(byteOffset) detaches the array buffer.
@ -226,7 +226,7 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = ValueReturning(0, detach); let byteOffset = ValueReturning(0, detach);
let length = 0; let length = 0;
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, length), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset, length));
} }
// Ensure we handle the case when ToIndex(length) detaches the array buffer. // Ensure we handle the case when ToIndex(length) detaches the array buffer.
@ -234,6 +234,6 @@ for (let {buffer, detach} of createBuffers()) {
let byteOffset = 0; let byteOffset = 0;
let length = ValueReturning(0, detach); let length = ValueReturning(0, detach);
assertThrowsInstanceOf(() => new Int32Array(buffer, byteOffset, length), TypeError); assert.throws(TypeError, () => new Int32Array(buffer, byteOffset, length));
} }

View File

@ -17,27 +17,27 @@ const ab = new ArrayBuffer(0);
for (let TA of typedArrayConstructors) { for (let TA of typedArrayConstructors) {
// Test bound checks around INT32_MAX for |byteOffset| argument. // Test bound checks around INT32_MAX for |byteOffset| argument.
assertThrowsInstanceOf(() => new TA(ab, 2**31 - TA.BYTES_PER_ELEMENT), RangeError); assert.throws(RangeError, () => new TA(ab, 2**31 - TA.BYTES_PER_ELEMENT));
assertThrowsInstanceOf(() => new TA(ab, 2**31 - 1), RangeError); assert.throws(RangeError, () => new TA(ab, 2**31 - 1));
assertThrowsInstanceOf(() => new TA(ab, 2**31), RangeError); assert.throws(RangeError, () => new TA(ab, 2**31));
assertThrowsInstanceOf(() => new TA(ab, 2**31 + 1), RangeError); assert.throws(RangeError, () => new TA(ab, 2**31 + 1));
assertThrowsInstanceOf(() => new TA(ab, 2**31 + TA.BYTES_PER_ELEMENT), RangeError); assert.throws(RangeError, () => new TA(ab, 2**31 + TA.BYTES_PER_ELEMENT));
// Test bound checks around UINT32_MAX for |byteOffset| argument. // Test bound checks around UINT32_MAX for |byteOffset| argument.
assertThrowsInstanceOf(() => new TA(ab, 2**32 - TA.BYTES_PER_ELEMENT), RangeError); assert.throws(RangeError, () => new TA(ab, 2**32 - TA.BYTES_PER_ELEMENT));
assertThrowsInstanceOf(() => new TA(ab, 2**32 - 1), RangeError); assert.throws(RangeError, () => new TA(ab, 2**32 - 1));
assertThrowsInstanceOf(() => new TA(ab, 2**32), RangeError); assert.throws(RangeError, () => new TA(ab, 2**32));
assertThrowsInstanceOf(() => new TA(ab, 2**32 + 1), RangeError); assert.throws(RangeError, () => new TA(ab, 2**32 + 1));
assertThrowsInstanceOf(() => new TA(ab, 2**32 + TA.BYTES_PER_ELEMENT), RangeError); assert.throws(RangeError, () => new TA(ab, 2**32 + TA.BYTES_PER_ELEMENT));
// Test bound checks around INT32_MAX for |length| argument. // Test bound checks around INT32_MAX for |length| argument.
assertThrowsInstanceOf(() => new TA(ab, 0, 2**31 - 1), RangeError); assert.throws(RangeError, () => new TA(ab, 0, 2**31 - 1));
assertThrowsInstanceOf(() => new TA(ab, 0, 2**31), RangeError); assert.throws(RangeError, () => new TA(ab, 0, 2**31));
assertThrowsInstanceOf(() => new TA(ab, 0, 2**31 + 1), RangeError); assert.throws(RangeError, () => new TA(ab, 0, 2**31 + 1));
// Test bound checks around UINT32_MAX for |length| argument. // Test bound checks around UINT32_MAX for |length| argument.
assertThrowsInstanceOf(() => new TA(ab, 0, 2**32 - 1), RangeError); assert.throws(RangeError, () => new TA(ab, 0, 2**32 - 1));
assertThrowsInstanceOf(() => new TA(ab, 0, 2**32), RangeError); assert.throws(RangeError, () => new TA(ab, 0, 2**32));
assertThrowsInstanceOf(() => new TA(ab, 0, 2**32 + 1), RangeError); assert.throws(RangeError, () => new TA(ab, 0, 2**32 + 1));
} }

View File

@ -30,9 +30,9 @@ for (let ctor of typedArrayConstructors) {
return primitive; return primitive;
} }
}; };
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
new ctor(arg); new ctor(arg);
}, TypeError); });
} }
} }

View File

@ -12,11 +12,11 @@ esid: pending
for (var constructor of typedArrayConstructors) { for (var constructor of typedArrayConstructors) {
var buf = new constructor(); var buf = new constructor();
$262.detachArrayBuffer(buf.buffer); $262.detachArrayBuffer(buf.buffer);
assertThrowsInstanceOf(() => new constructor(buf), TypeError); assert.throws(TypeError, () => new constructor(buf));
var buffer = new ArrayBuffer(); var buffer = new ArrayBuffer();
$262.detachArrayBuffer(buffer); $262.detachArrayBuffer(buffer);
assertThrowsInstanceOf(() => new constructor(buffer), TypeError); assert.throws(TypeError, () => new constructor(buffer));
} }

View File

@ -10,10 +10,10 @@ description: |
esid: pending esid: pending
---*/ ---*/
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
assertThrowsInstanceOf(() => constructor(), TypeError); assert.throws(TypeError, () => constructor());
assertThrowsInstanceOf(() => constructor(1), TypeError); assert.throws(TypeError, () => constructor(1));
assertThrowsInstanceOf(() => constructor.call(null), TypeError); assert.throws(TypeError, () => constructor.call(null));
assertThrowsInstanceOf(() => constructor.apply(null, []), TypeError); assert.throws(TypeError, () => constructor.apply(null, []));
assertThrowsInstanceOf(() => Reflect.apply(constructor, null, []), TypeError); assert.throws(TypeError, () => Reflect.apply(constructor, null, []));
} }

View File

@ -14,9 +14,9 @@ esid: pending
var AB = new ArrayBuffer(12); // Length divides 4 var AB = new ArrayBuffer(12); // Length divides 4
var BC = new ArrayBuffer(14); // Length does not divide 4 var BC = new ArrayBuffer(14); // Length does not divide 4
assertThrowsInstanceOf(() => new Int32Array(AB, -1), RangeError); // 22.2.4.5 #8 assert.throws(RangeError, () => new Int32Array(AB, -1)); // 22.2.4.5 #8
assertThrowsInstanceOf(() => new Int32Array(AB, 2), RangeError); // 22.2.4.5 #10 assert.throws(RangeError, () => new Int32Array(AB, 2)); // 22.2.4.5 #10
assertThrowsInstanceOf(() => new Int32Array(BC), RangeError); // 22.2.4.5 #13.a assert.throws(RangeError, () => new Int32Array(BC)); // 22.2.4.5 #13.a
assertThrowsInstanceOf(() => new Int32Array(AB, 16), RangeError); // 22.2.4.5 #13.c assert.throws(RangeError, () => new Int32Array(AB, 16)); // 22.2.4.5 #13.c
assertThrowsInstanceOf(() => new Int32Array(AB, 0, 4), RangeError); // 22.2.4.5 #14.c assert.throws(RangeError, () => new Int32Array(AB, 0, 4)); // 22.2.4.5 #14.c

View File

@ -30,87 +30,87 @@ var POISON = (function() {
}); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.copyWithin(POISON); array.copyWithin(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.entries(); array.entries();
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.fill(POISON); array.fill(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.filter(POISON); array.filter(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.find(POISON); array.find(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.findIndex(POISON); array.findIndex(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.forEach(POISON); array.forEach(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.indexOf(POISON); array.indexOf(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.includes(POISON); array.includes(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.join(POISON); array.join(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.keys(); array.keys();
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.lastIndexOf(POISON); array.lastIndexOf(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.map(POISON); array.map(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.reduce(POISON); array.reduce(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.reduceRight(POISON); array.reduceRight(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.reverse(); array.reverse();
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.slice(POISON, POISON); array.slice(POISON, POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.some(POISON); array.some(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.values(); array.values();
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.every(POISON); array.every(POISON);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
array.sort(POISON); array.sort(POISON);
}, TypeError); });

View File

@ -39,9 +39,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.entries.call(invalidReceiver); constructor.prototype.entries.call(invalidReceiver);
}, TypeError, "Assert that entries fails if this value is not a TypedArray"); }, "Assert that entries fails if this value is not a TypedArray");
}); });
} }

View File

@ -86,14 +86,14 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(count, 3); assert.sameValue(count, 3);
// There is no callback or callback is not a function. // There is no callback or callback is not a function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.every(); arr.every();
}, TypeError); });
var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./]; var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./];
invalidCallbacks.forEach(callback => { invalidCallbacks.forEach(callback => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.every(callback); arr.every(callback);
}, TypeError); });
}) })
// Callback is a generator. // Callback is a generator.
@ -113,9 +113,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.every.call(invalidReceiver, () => true); constructor.prototype.every.call(invalidReceiver, () => true);
}, TypeError, "Assert that every fails if this value is not a TypedArray"); }, "Assert that every fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.
@ -209,14 +209,14 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(count, 3); assert.sameValue(count, 3);
// There is no callback or callback is not a function. // There is no callback or callback is not a function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.some(); arr.some();
}, TypeError); });
var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./]; var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./];
invalidCallbacks.forEach(callback => { invalidCallbacks.forEach(callback => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.some(callback); arr.some(callback);
}, TypeError); });
}) })
// Callback is a generator. // Callback is a generator.
@ -239,9 +239,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.some.call(invalidReceiver, () => true); constructor.prototype.some.call(invalidReceiver, () => true);
}, TypeError, "Assert that some fails if this value is not a TypedArray"); }, "Assert that some fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -33,13 +33,13 @@ function DetachTypedArrayValue(ta, value) {
for (let length of [0, 1, 10, 4096]) { for (let length of [0, 1, 10, 4096]) {
let ta = new Int32Array(length); let ta = new Int32Array(length);
let value = DetachArrayBufferValue(ta.buffer, 123); let value = DetachArrayBufferValue(ta.buffer, 123);
assertThrowsInstanceOf(() => ta.fill(value), TypeError); assert.throws(TypeError, () => ta.fill(value));
} }
// Test when ArrayBuffer is reified during the fill() call. // Test when ArrayBuffer is reified during the fill() call.
for (let length of [0, 1, 10, 4096]) { for (let length of [0, 1, 10, 4096]) {
let ta = new Int32Array(length); let ta = new Int32Array(length);
let value = DetachTypedArrayValue(ta, 123); let value = DetachTypedArrayValue(ta, 123);
assertThrowsInstanceOf(() => ta.fill(value), TypeError); assert.throws(TypeError, () => ta.fill(value));
} }

View File

@ -55,9 +55,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.fill.call(invalidReceiver, 1); constructor.prototype.fill.call(invalidReceiver, 1);
}, TypeError); });
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -35,11 +35,11 @@ anyTypedArrayConstructors.forEach(constructor => {
thisValues.push(Symbol()); thisValues.push(Symbol());
thisValues.forEach(thisArg => thisValues.forEach(thisArg =>
assertThrowsInstanceOf(() => arr[method].call(thisArg, () => true), TypeError) assert.throws(TypeError, () => arr[method].call(thisArg, () => true))
); );
assertThrowsInstanceOf(() => arr[method](), TypeError); assert.throws(TypeError, () => arr[method]());
assertThrowsInstanceOf(() => arr[method](1), TypeError); assert.throws(TypeError, () => arr[method](1));
}); });
}); });

View File

@ -35,11 +35,11 @@ anyTypedArrayConstructors.forEach(constructor => {
thisValues.push(Symbol()); thisValues.push(Symbol());
thisValues.forEach(thisArg => thisValues.forEach(thisArg =>
assertThrowsInstanceOf(() => arr[method].call(thisArg, () => true), TypeError) assert.throws(TypeError, () => arr[method].call(thisArg, () => true))
); );
assertThrowsInstanceOf(() => arr[method](), TypeError); assert.throws(TypeError, () => arr[method]());
assertThrowsInstanceOf(() => arr[method](1), TypeError); assert.throws(TypeError, () => arr[method](1));
}); });
}); });

View File

@ -65,14 +65,14 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(count, 3); assert.sameValue(count, 3);
// There is no callback or callback is not a function. // There is no callback or callback is not a function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.forEach(); arr.forEach();
}, TypeError); });
var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./]; var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./];
invalidCallbacks.forEach(callback => { invalidCallbacks.forEach(callback => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.forEach(callback); arr.forEach(callback);
}, TypeError); });
}) })
// Callback is a generator. // Callback is a generator.
@ -94,9 +94,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.forEach.call(invalidReceiver, () => true); constructor.prototype.forEach.call(invalidReceiver, () => true);
}, TypeError, "Assert that some fails if this value is not a TypedArray"); }, "Assert that some fails if this value is not a TypedArray");
}); });
} }

View File

@ -25,9 +25,9 @@ for (var constructor of anyTypedArrayConstructors) {
() => ({}) // arrow functions are not constructors () => ({}) // arrow functions are not constructors
]; ];
for (var v of nonconstructors) { for (var v of nonconstructors) {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.from.call(v, arr); constructor.from.call(v, arr);
}, TypeError); });
} }
// %TypedArray%.from does not get confused if global constructors for typed arrays // %TypedArray%.from does not get confused if global constructors for typed arrays

View File

@ -11,9 +11,9 @@ esid: pending
---*/ ---*/
for (var constructor of anyTypedArrayConstructors) { for (var constructor of anyTypedArrayConstructors) {
// %TypedArray%.from throws if the argument is undefined or null. // %TypedArray%.from throws if the argument is undefined or null.
assertThrowsInstanceOf(() => constructor.from(), TypeError); assert.throws(TypeError, () => constructor.from());
assertThrowsInstanceOf(() => constructor.from(undefined), TypeError); assert.throws(TypeError, () => constructor.from(undefined));
assertThrowsInstanceOf(() => constructor.from(null), TypeError); assert.throws(TypeError, () => constructor.from(null));
// Unlike Array.from, %TypedArray%.from doesn't get or set the length property. // Unlike Array.from, %TypedArray%.from doesn't get or set the length property.
function ObjectWithThrowingLengthGetterSetter(...rest) { function ObjectWithThrowingLengthGetterSetter(...rest) {
@ -29,12 +29,12 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(ObjectWithThrowingLengthGetterSetter.from([123])[0], 123); assert.sameValue(ObjectWithThrowingLengthGetterSetter.from([123])[0], 123);
// %TypedArray%.from throws if mapfn is neither callable nor undefined. // %TypedArray%.from throws if mapfn is neither callable nor undefined.
assertThrowsInstanceOf(() => constructor.from([3, 4, 5], {}), TypeError); assert.throws(TypeError, () => constructor.from([3, 4, 5], {}));
assertThrowsInstanceOf(() => constructor.from([3, 4, 5], "also not a function"), TypeError); assert.throws(TypeError, () => constructor.from([3, 4, 5], "also not a function"));
assertThrowsInstanceOf(() => constructor.from([3, 4, 5], null), TypeError); assert.throws(TypeError, () => constructor.from([3, 4, 5], null));
// Even if the function would not have been called. // Even if the function would not have been called.
assertThrowsInstanceOf(() => constructor.from([], JSON), TypeError); assert.throws(TypeError, () => constructor.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.
@ -50,7 +50,7 @@ for (var constructor of anyTypedArrayConstructors) {
get: function () { log += "2"; }, get: function () { log += "2"; },
getOwnPropertyDescriptor: function () { log += "3"; } getOwnPropertyDescriptor: function () { log += "3"; }
}); });
assertThrowsInstanceOf(() => constructor.from.call(C, p, {}), TypeError); assert.throws(TypeError, () => constructor.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.
@ -66,20 +66,19 @@ for (var constructor of anyTypedArrayConstructors) {
// 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(() => constructor.from({[Symbol.iterator] : primitive}), TypeError); assert.throws(TypeError, () => constructor.from({[Symbol.iterator] : primitive}));
} }
assert.deepEqual(constructor.from({[Symbol.iterator]: null}), new constructor()); assert.deepEqual(constructor.from({[Symbol.iterator]: null}), new constructor());
assert.deepEqual(constructor.from({[Symbol.iterator]: undefined}), new constructor()); assert.deepEqual(constructor.from({[Symbol.iterator]: undefined}), new constructor());
// 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, "foo", 17, Symbol(), true]) { for (var primitive of [undefined, null, "foo", 17, Symbol(), true]) {
assertThrowsInstanceOf( assert.throws(TypeError,
() => constructor.from({ () => constructor.from({
[Symbol.iterator]() { [Symbol.iterator]() {
return {next() { return primitive; }}; return {next() { return primitive; }};
} }
}), }));
TypeError);
} }
} }

View File

@ -16,6 +16,6 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(desc.enumerable, false); assert.sameValue(desc.enumerable, false);
assert.sameValue(desc.writable, true); assert.sameValue(desc.writable, true);
assert.sameValue(constructor.from.length, 1); assert.sameValue(constructor.from.length, 1);
assertThrowsInstanceOf(() => new constructor.from(), TypeError); // not a constructor assert.throws(TypeError, () => new constructor.from()); // not a constructor
} }

View File

@ -15,5 +15,5 @@ esid: pending
var ta = new Int32Array(4); var ta = new Int32Array(4);
$262.detachArrayBuffer(ta.buffer); $262.detachArrayBuffer(ta.buffer);
assertThrowsInstanceOf(() => Int32Array.from(ta), TypeError); assert.throws(TypeError, () => Int32Array.from(ta));

View File

@ -34,9 +34,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.includes.call(invalidReceiver); constructor.prototype.includes.call(invalidReceiver);
}, TypeError, "Assert that reverse fails if this value is not a TypedArray"); }, "Assert that reverse fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -43,9 +43,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.indexOf.call(invalidReceiver); constructor.prototype.indexOf.call(invalidReceiver);
}, TypeError, "Assert that indexOf fails if this value is not a TypedArray"); }, "Assert that indexOf fails if this value is not a TypedArray");
}); });
// test that this.length is never called // test that this.length is never called
@ -104,9 +104,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.lastIndexOf.call(invalidReceiver); constructor.prototype.lastIndexOf.call(invalidReceiver);
}, TypeError, "Assert that lastIndexOf fails if this value is not a TypedArray"); }, "Assert that lastIndexOf fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -68,14 +68,14 @@ if (typeof $262.detachArrayBuffer === "function" && typeof createNewGlobal === "
checkResult(thisNext.call(iterator), {value: 2, done: false}); checkResult(thisNext.call(iterator), {value: 2, done: false});
bufferGlobal.$262.detachArrayBuffer(buffer); bufferGlobal.$262.detachArrayBuffer(buffer);
assertThrowsInstanceOf(() => thisNext.call(iterator), TypeError); assert.throws(TypeError, () => thisNext.call(iterator));
// Test an unexhausted iterator. // Test an unexhausted iterator.
[arr, buffer, iterator] = arrayBufferIterator(); [arr, buffer, iterator] = arrayBufferIterator();
checkResult(thisNext.call(iterator), {value: 1, done: false}); checkResult(thisNext.call(iterator), {value: 1, done: false});
bufferGlobal.$262.detachArrayBuffer(buffer); bufferGlobal.$262.detachArrayBuffer(buffer);
assertThrowsInstanceOf(() => thisNext.call(iterator), TypeError); assert.throws(TypeError, () => thisNext.call(iterator));
} }
} }
} }

View File

@ -25,8 +25,8 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(new constructor(1).join(), "0"); assert.sameValue(new constructor(1).join(), "0");
assert.sameValue(new constructor(3).join(), "0,0,0"); assert.sameValue(new constructor(3).join(), "0,0,0");
assertThrowsInstanceOf(() => new constructor().join({toString(){throw new TypeError}}), TypeError); assert.throws(TypeError, () => new constructor().join({toString(){throw new TypeError}}));
assertThrowsInstanceOf(() => new constructor().join(Symbol()), TypeError); assert.throws(TypeError, () => new constructor().join(Symbol()));
// Called from other globals. // Called from other globals.
if (typeof createNewGlobal === "function") { if (typeof createNewGlobal === "function") {
@ -38,9 +38,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.join.call(invalidReceiver); constructor.prototype.join.call(invalidReceiver);
}, TypeError, "Assert that join fails if this value is not a TypedArray"); }, "Assert that join fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -37,9 +37,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.keys.call(invalidReceiver); constructor.prototype.keys.call(invalidReceiver);
}, TypeError, "Assert that keys fails if this value is not a TypedArray"); }, "Assert that keys fails if this value is not a TypedArray");
}); });
} }

View File

@ -94,14 +94,14 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(count, 3); assert.sameValue(count, 3);
// There is no callback or callback is not a function. // There is no callback or callback is not a function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.map(); arr.map();
}, TypeError); });
var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./]; var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./];
invalidCallbacks.forEach(callback => { invalidCallbacks.forEach(callback => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.map(callback); arr.map(callback);
}, TypeError); });
}) })
// Callback is a generator. // Callback is a generator.
@ -121,9 +121,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.filter.call(invalidReceiver, () => true); constructor.prototype.filter.call(invalidReceiver, () => true);
}, TypeError, "Assert that map fails if this value is not a TypedArray"); }, "Assert that map fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.
@ -218,14 +218,14 @@ for (var constructor of anyTypedArrayConstructors) {
assert.sameValue(count, 3); assert.sameValue(count, 3);
// There is no callback or callback is not a function. // There is no callback or callback is not a function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.filter(); arr.filter();
}, TypeError); });
var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./]; var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./];
invalidCallbacks.forEach(callback => { invalidCallbacks.forEach(callback => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.filter(callback); arr.filter(callback);
}, TypeError); });
}) })
// Callback is a generator. // Callback is a generator.
@ -246,9 +246,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.filter.call(invalidReceiver, () => true); constructor.prototype.filter.call(invalidReceiver, () => true);
}, TypeError, "Assert that filter fails if this value is not a TypedArray"); }, "Assert that filter fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -32,8 +32,8 @@ var throws = [
]; ];
for (var desc of throws) { for (var desc of throws) {
assertThrowsInstanceOf(function() { Object.defineProperty(obj, 0, desc); }, TypeError); assert.throws(TypeError, function() { Object.defineProperty(obj, 0, desc); });
assertThrowsInstanceOf(function() { Object.defineProperties(obj, {0: desc}); }, TypeError); assert.throws(TypeError, function() { Object.defineProperties(obj, {0: desc}); });
} }
Object.defineProperty(obj, 0, {}); Object.defineProperty(obj, 0, {});

View File

@ -27,8 +27,8 @@ for (var constructor of anyTypedArrayConstructors) {
assert.deepEqual(constructor.of("1", "2", "3"), new constructor([1, 2, 3])); assert.deepEqual(constructor.of("1", "2", "3"), new constructor([1, 2, 3]));
// This method can't be transplanted to other constructors. // This method can't be transplanted to other constructors.
assertThrowsInstanceOf(() => constructor.of.call(Array), TypeError); assert.throws(TypeError, () => constructor.of.call(Array));
assertThrowsInstanceOf(() => constructor.of.call(Array, 1, 2, 3), TypeError); assert.throws(TypeError, () => constructor.of.call(Array, 1, 2, 3));
var hits = 0; var hits = 0;
assert.deepEqual(constructor.of.call(function(len) { assert.deepEqual(constructor.of.call(function(len) {
@ -51,40 +51,40 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidConstructors = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidConstructors = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
constructor.of, () => {}]; constructor.of, () => {}];
invalidConstructors.forEach(C => { invalidConstructors.forEach(C => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.of.call(C); constructor.of.call(C);
}, TypeError); });
}); });
// Throw if `this` is a method definition or a getter/setter function. // Throw if `this` is a method definition or a getter/setter function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.of.call({method() {}}.method); constructor.of.call({method() {}}.method);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.of.call(Object.getOwnPropertyDescriptor({get getter() {}}, "getter").get); constructor.of.call(Object.getOwnPropertyDescriptor({get getter() {}}, "getter").get);
}, TypeError); });
// Generators are not legal constructors. // Generators are not legal constructors.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.of.call(function*(len) { constructor.of.call(function*(len) {
return len; return len;
}, "a") }, "a")
}, TypeError); });
// An exception might be thrown in a strict assignment to the new object's indexed properties. // An exception might be thrown in a strict assignment to the new object's indexed properties.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.of.call(function() { constructor.of.call(function() {
return {get 0() {}}; return {get 0() {}};
}, "a"); }, "a");
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.of.call(function() { constructor.of.call(function() {
return Object("1"); return Object("1");
}, "a"); }, "a");
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.of.call(function() { constructor.of.call(function() {
return Object.create({ return Object.create({
set 0(v) { set 0(v) {
@ -92,7 +92,7 @@ for (var constructor of anyTypedArrayConstructors) {
} }
}); });
}, "a"); }, "a");
}, TypeError); });
} }
for (let constructor of anyTypedArrayConstructors.filter(isFloatConstructor)) { for (let constructor of anyTypedArrayConstructors.filter(isFloatConstructor)) {

View File

@ -51,7 +51,7 @@ for (var constructor of anyTypedArrayConstructors) {
// Throw an exception in the callback. // Throw an exception in the callback.
var count = 0; var count = 0;
var sum = 0; var sum = 0;
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.reduce((previous, current, index, array) => { arr.reduce((previous, current, index, array) => {
count++; count++;
sum += current; sum += current;
@ -59,19 +59,19 @@ for (var constructor of anyTypedArrayConstructors) {
throw TypeError("reduce"); throw TypeError("reduce");
} }
}) })
}, TypeError); });
assert.sameValue(count, 3); assert.sameValue(count, 3);
assert.sameValue(sum, 9); assert.sameValue(sum, 9);
// There is no callback or callback is not a function. // There is no callback or callback is not a function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.reduce(); arr.reduce();
}, TypeError); });
var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./]; var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./];
invalidCallbacks.forEach(callback => { invalidCallbacks.forEach(callback => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.reduce(callback); arr.reduce(callback);
}, TypeError); });
}) })
// Callback is a generator. // Callback is a generator.
@ -89,9 +89,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(3), {})]; new Proxy(new constructor(3), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.reduce.call(invalidReceiver, () => {}); constructor.prototype.reduce.call(invalidReceiver, () => {});
}, TypeError, "Assert that reduce fails if this value is not a TypedArray"); }, "Assert that reduce fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.
@ -144,7 +144,7 @@ for (var constructor of anyTypedArrayConstructors) {
// Throw an exception in the callback. // Throw an exception in the callback.
var count = 0; var count = 0;
var sum = 0; var sum = 0;
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.reduceRight((previous, current, index, array) => { arr.reduceRight((previous, current, index, array) => {
count++; count++;
sum += current; sum += current;
@ -152,19 +152,19 @@ for (var constructor of anyTypedArrayConstructors) {
throw TypeError("reduceRight"); throw TypeError("reduceRight");
} }
}) })
}, TypeError); });
assert.sameValue(count, 3); assert.sameValue(count, 3);
assert.sameValue(sum, 9); assert.sameValue(sum, 9);
// There is no callback or callback is not a function. // There is no callback or callback is not a function.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.reduceRight(); arr.reduceRight();
}, TypeError); });
var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./]; var invalidCallbacks = [undefined, null, 1, false, "", Symbol(), [], {}, /./];
invalidCallbacks.forEach(callback => { invalidCallbacks.forEach(callback => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
arr.reduceRight(callback); arr.reduceRight(callback);
}, TypeError); });
}) })
// Callback is a generator. // Callback is a generator.
@ -182,9 +182,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(3), {})]; new Proxy(new constructor(3), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.reduceRight.call(invalidReceiver, () => {}); constructor.prototype.reduceRight.call(invalidReceiver, () => {});
}, TypeError, "Assert that reduceRight fails if this value is not a TypedArray"); }, "Assert that reduceRight fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -32,9 +32,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.reverse.call(invalidReceiver); constructor.prototype.reverse.call(invalidReceiver);
}, TypeError, "Assert that reverse fails if this value is not a TypedArray"); }, "Assert that reverse fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -29,9 +29,9 @@ assert.sameValue(Object.isSealed(array), false);
array = new Int32Array(2); array = new Int32Array(2);
array.b = "test"; array.b = "test";
assertThrowsInstanceOf(() => Object.seal(array), TypeError); assert.throws(TypeError, () => Object.seal(array));
assert.sameValue(Object.isSealed(array), false); assert.sameValue(Object.isSealed(array), false);
assertThrowsInstanceOf(() => array.c = 15, TypeError); assert.throws(TypeError, () => array.c = 15);
// Freeze // Freeze
assert.sameValue(Object.isFrozen(new Int32Array(2)), false); assert.sameValue(Object.isFrozen(new Int32Array(2)), false);
@ -52,7 +52,7 @@ assert.sameValue(Object.isFrozen(array), true);
// Non-empty typed arrays can never be frozen, because the elements stay writable // Non-empty typed arrays can never be frozen, because the elements stay writable
array = new Int32Array(1); array = new Int32Array(1);
assertThrowsInstanceOf(() => Object.freeze(array), TypeError); assert.throws(TypeError, () => Object.freeze(array));
assert.sameValue(Object.isExtensible(array), false); assert.sameValue(Object.isExtensible(array), false);
assert.sameValue(Object.isFrozen(array), false); assert.sameValue(Object.isFrozen(array), false);

View File

@ -24,5 +24,5 @@ let obj = {
}; };
// Throws a SyntaxError, because "huzzah!" can't be parsed as a BigInt. // Throws a SyntaxError, because "huzzah!" can't be parsed as a BigInt.
assertThrowsInstanceOf(() => ta.set(obj), SyntaxError); assert.throws(SyntaxError, () => ta.set(obj));

View File

@ -27,11 +27,11 @@ if (typeof $262.detachArrayBuffer === "function") {
for (let {typedArray, buffer} of createTypedArrays()) { for (let {typedArray, buffer} of createTypedArrays()) {
$262.detachArrayBuffer(buffer); $262.detachArrayBuffer(buffer);
assertThrowsInstanceOf(() => typedArray.set(null, { assert.throws(ExpectedError, () => typedArray.set(null, {
valueOf() { valueOf() {
throw new ExpectedError(); throw new ExpectedError();
} }
}), ExpectedError); }));
} }
// Check for detached buffer after calling ToInteger(offset). Test with: // Check for detached buffer after calling ToInteger(offset). Test with:
@ -41,12 +41,12 @@ if (typeof $262.detachArrayBuffer === "function") {
for (let [offset, error] of [[0, TypeError], [1000000, TypeError], [-1, RangeError]]) { for (let [offset, error] of [[0, TypeError], [1000000, TypeError], [-1, RangeError]]) {
for (let source of [[], [0], new Int32Array(0), new Int32Array(1)]) { for (let source of [[], [0], new Int32Array(0), new Int32Array(1)]) {
for (let {typedArray, buffer} of createTypedArrays()) { for (let {typedArray, buffer} of createTypedArrays()) {
assertThrowsInstanceOf(() => typedArray.set(source, { assert.throws(error, () => typedArray.set(source, {
valueOf() { valueOf() {
$262.detachArrayBuffer(buffer); $262.detachArrayBuffer(buffer);
return offset; return offset;
} }
}), error); }));
} }
} }
} }
@ -56,11 +56,11 @@ if (typeof $262.detachArrayBuffer === "function") {
for (let {typedArray: source, buffer: sourceBuffer} of createTypedArrays()) { for (let {typedArray: source, buffer: sourceBuffer} of createTypedArrays()) {
$262.detachArrayBuffer(sourceBuffer); $262.detachArrayBuffer(sourceBuffer);
assertThrowsInstanceOf(() => typedArray.set(source, { assert.throws(ExpectedError, () => typedArray.set(source, {
valueOf() { valueOf() {
throw new ExpectedError(); throw new ExpectedError();
} }
}), ExpectedError); }));
} }
} }
@ -71,12 +71,12 @@ if (typeof $262.detachArrayBuffer === "function") {
for (let [offset, error] of [[0, TypeError], [1000000, TypeError], [-1, RangeError]]) { for (let [offset, error] of [[0, TypeError], [1000000, TypeError], [-1, RangeError]]) {
for (let {typedArray} of createTypedArrays()) { for (let {typedArray} of createTypedArrays()) {
for (let {typedArray: source, buffer: sourceBuffer} of createTypedArrays()) { for (let {typedArray: source, buffer: sourceBuffer} of createTypedArrays()) {
assertThrowsInstanceOf(() => typedArray.set(source, { assert.throws(error, () => typedArray.set(source, {
valueOf() { valueOf() {
$262.detachArrayBuffer(sourceBuffer); $262.detachArrayBuffer(sourceBuffer);
return offset; return offset;
} }
}), error); }));
} }
} }
} }
@ -89,12 +89,12 @@ if (typeof $262.detachArrayBuffer === "function") {
for (let src of [ta => ta, ta => new Int32Array(ta.buffer), ta => new Float32Array(ta.buffer)]) { for (let src of [ta => ta, ta => new Int32Array(ta.buffer), ta => new Float32Array(ta.buffer)]) {
for (let {typedArray, buffer} of createTypedArrays()) { for (let {typedArray, buffer} of createTypedArrays()) {
let source = src(typedArray); let source = src(typedArray);
assertThrowsInstanceOf(() => typedArray.set(source, { assert.throws(TypeError, () => typedArray.set(source, {
valueOf() { valueOf() {
$262.detachArrayBuffer(buffer); $262.detachArrayBuffer(buffer);
return 0; return 0;
} }
}), TypeError); }));
} }
} }
@ -142,7 +142,7 @@ if (typeof $262.detachArrayBuffer === "function") {
} }
}; };
if (typedArray.length === 0) { if (typedArray.length === 0) {
assertThrowsInstanceOf(() => typedArray.set(source), RangeError); assert.throws(RangeError, () => typedArray.set(source));
} else { } else {
typedArray.set(source); typedArray.set(source);
} }
@ -162,7 +162,7 @@ if (typeof $262.detachArrayBuffer === "function") {
} }
}; };
let err = typedArray.length === 0 ? RangeError : ExpectedError; let err = typedArray.length === 0 ? RangeError : ExpectedError;
assertThrowsInstanceOf(() => typedArray.set(source), err); assert.throws(err, () => typedArray.set(source));
} }
// Same as above, but with side-effect when executing ToNumber(Get(src, "0")). // Same as above, but with side-effect when executing ToNumber(Get(src, "0")).
@ -183,7 +183,7 @@ if (typeof $262.detachArrayBuffer === "function") {
} }
}; };
let err = typedArray.length === 0 ? RangeError : ExpectedError; let err = typedArray.length === 0 ? RangeError : ExpectedError;
assertThrowsInstanceOf(() => typedArray.set(source), err); assert.throws(err, () => typedArray.set(source));
} }
// Side-effects when getting the source elements detach the buffer. // Side-effects when getting the source elements detach the buffer.
@ -197,7 +197,7 @@ if (typeof $262.detachArrayBuffer === "function") {
} }
}); });
if (typedArray.length === 0) { if (typedArray.length === 0) {
assertThrowsInstanceOf(() => typedArray.set(source), RangeError); assert.throws(RangeError, () => typedArray.set(source));
} else { } else {
typedArray.set(source); typedArray.set(source);
} }
@ -223,7 +223,7 @@ if (typeof $262.detachArrayBuffer === "function") {
} }
}); });
if (typedArray.length <= 1) { if (typedArray.length <= 1) {
assertThrowsInstanceOf(() => typedArray.set(source), RangeError); assert.throws(RangeError, () => typedArray.set(source));
} else { } else {
assert.sameValue(accessed, false); assert.sameValue(accessed, false);
typedArray.set(source); typedArray.set(source);
@ -240,7 +240,7 @@ if (typeof $262.detachArrayBuffer === "function") {
} }
}]; }];
if (typedArray.length === 0) { if (typedArray.length === 0) {
assertThrowsInstanceOf(() => typedArray.set(source), RangeError); assert.throws(RangeError, () => typedArray.set(source));
} else { } else {
typedArray.set(source); typedArray.set(source);
} }
@ -263,7 +263,7 @@ if (typeof $262.detachArrayBuffer === "function") {
} }
}]; }];
if (typedArray.length <= 1) { if (typedArray.length <= 1) {
assertThrowsInstanceOf(() => typedArray.set(source), RangeError); assert.throws(RangeError, () => typedArray.set(source));
} else { } else {
assert.sameValue(accessed, false); assert.sameValue(accessed, false);
typedArray.set(source); typedArray.set(source);

View File

@ -83,7 +83,7 @@ let invalidOffsets = [
for (let offset of invalidOffsets) { for (let offset of invalidOffsets) {
for (let source of sources) { for (let source of sources) {
assertThrowsInstanceOf(() => ta.set(source, offset), RangeError); assert.throws(RangeError, () => ta.set(source, offset));
} }
} }
@ -93,12 +93,12 @@ for (let source of emptySources) {
ta.set(source, 4.9); ta.set(source, 4.9);
} }
for (let source of nonEmptySource) { for (let source of nonEmptySource) {
assertThrowsInstanceOf(() => ta.set(source, 4), RangeError); assert.throws(RangeError, () => ta.set(source, 4));
assertThrowsInstanceOf(() => ta.set(source, 4.9), RangeError); assert.throws(RangeError, () => ta.set(source, 4.9));
} }
// ToInteger(symbol value) throws a TypeError. // ToInteger(symbol value) throws a TypeError.
for (let source of sources) { for (let source of sources) {
assertThrowsInstanceOf(() => ta.set(source, Symbol()), TypeError); assert.throws(TypeError, () => ta.set(source, Symbol()));
} }

View File

@ -15,15 +15,15 @@ let ta = new Int32Array(4);
for (let nullOrUndefined of [null, undefined]) { for (let nullOrUndefined of [null, undefined]) {
// ToObject(array) throws a TypeError when |array| is null or undefined. // ToObject(array) throws a TypeError when |array| is null or undefined.
assertThrowsInstanceOf(() => ta.set(nullOrUndefined), TypeError); assert.throws(TypeError, () => ta.set(nullOrUndefined));
// ToInteger(offset) is called before ToObject(array). // ToInteger(offset) is called before ToObject(array).
class ExpectedError extends Error {} class ExpectedError extends Error {}
assertThrowsInstanceOf(() => ta.set(nullOrUndefined, { assert.throws(ExpectedError, () => ta.set(nullOrUndefined, {
valueOf() { valueOf() {
throw new ExpectedError(); throw new ExpectedError();
} }
}), ExpectedError); }));
} }
// Ensure ta is still initialized with zeros. // Ensure ta is still initialized with zeros.
@ -37,7 +37,7 @@ ta.set("123");
assert.compareArray(ta, [1, 2, 3, 0]); assert.compareArray(ta, [1, 2, 3, 0]);
// Throws a RangeError if the length is too large. // Throws a RangeError if the length is too large.
assertThrowsInstanceOf(() => ta.set("456789"), RangeError); assert.throws(RangeError, () => ta.set("456789"));
assert.compareArray(ta, [1, 2, 3, 0]); assert.compareArray(ta, [1, 2, 3, 0]);
// When called with other primitive values the typed array contents don't // When called with other primitive values the typed array contents don't

View File

@ -45,7 +45,7 @@ if (typeof createNewGlobal === "function") {
// Called with wrapped typed array, array buffer already detached. // Called with wrapped typed array, array buffer already detached.
otherGlobal.$262.detachArrayBuffer(source.buffer); otherGlobal.$262.detachArrayBuffer(source.buffer);
assertThrowsInstanceOf(() => target.set(source), TypeError); assert.throws(TypeError, () => target.set(source));
var source = new otherGlobal[TA.name](1); var source = new otherGlobal[TA.name](1);
taintLengthProperty(source); taintLengthProperty(source);
@ -58,7 +58,7 @@ if (typeof createNewGlobal === "function") {
return 0; return 0;
} }
}; };
assertThrowsInstanceOf(() => target.set(source, offset), TypeError); assert.throws(TypeError, () => target.set(source, offset));
} }
// Create typed array from different global (implictly created when // Create typed array from different global (implictly created when
@ -70,7 +70,7 @@ if (typeof createNewGlobal === "function") {
// Called with wrapped typed array, array buffer already detached. // Called with wrapped typed array, array buffer already detached.
otherGlobal.$262.detachArrayBuffer(source.buffer); otherGlobal.$262.detachArrayBuffer(source.buffer);
assertThrowsInstanceOf(() => target.set(source), TypeError); assert.throws(TypeError, () => target.set(source));
var source = new TA(new otherGlobal.ArrayBuffer(1 * TA.BYTES_PER_ELEMENT)); var source = new TA(new otherGlobal.ArrayBuffer(1 * TA.BYTES_PER_ELEMENT));
taintLengthProperty(source); taintLengthProperty(source);
@ -83,7 +83,7 @@ if (typeof createNewGlobal === "function") {
return 0; return 0;
} }
}; };
assertThrowsInstanceOf(() => target.set(source, offset), TypeError); assert.throws(TypeError, () => target.set(source, offset));
} }
} }
} }

View File

@ -32,9 +32,9 @@ if (typeof $262.detachArrayBuffer === "function") {
// ArrayBuffer is detached when entering slice(). // ArrayBuffer is detached when entering slice().
for (let {typedArray, buffer} of createTypedArrays()) { for (let {typedArray, buffer} of createTypedArrays()) {
$262.detachArrayBuffer(buffer()); $262.detachArrayBuffer(buffer());
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
typedArray.slice(0); typedArray.slice(0);
}, TypeError, "ArrayBuffer is detached on function entry"); }, "ArrayBuffer is detached on function entry");
} }
// ArrayBuffer is detached when computing ToInteger(start). // ArrayBuffer is detached when computing ToInteger(start).
@ -54,9 +54,9 @@ if (typeof $262.detachArrayBuffer === "function") {
if (length === 0) { if (length === 0) {
typedArray.slice(start); typedArray.slice(start);
} else { } else {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
typedArray.slice(start); typedArray.slice(start);
}, TypeError, "ArrayBuffer is detached in ToInteger(start)"); }, "ArrayBuffer is detached in ToInteger(start)");
} }
assert.sameValue(detached, true, "$262.detachArrayBuffer was called"); assert.sameValue(detached, true, "$262.detachArrayBuffer was called");
} }
@ -78,9 +78,9 @@ if (typeof $262.detachArrayBuffer === "function") {
if (length === 0) { if (length === 0) {
typedArray.slice(0, end); typedArray.slice(0, end);
} else { } else {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
typedArray.slice(0, end); typedArray.slice(0, end);
}, TypeError, "ArrayBuffer is detached in ToInteger(end)"); }, "ArrayBuffer is detached in ToInteger(end)");
} }
assert.sameValue(detached, true, "$262.detachArrayBuffer was called"); assert.sameValue(detached, true, "$262.detachArrayBuffer was called");
} }
@ -102,9 +102,9 @@ if (typeof $262.detachArrayBuffer === "function") {
if (length === 0) { if (length === 0) {
typedArray.slice(0); typedArray.slice(0);
} else { } else {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
typedArray.slice(0); typedArray.slice(0);
}, TypeError, "ArrayBuffer is detached in TypedArraySpeciesCreate(...)"); }, "ArrayBuffer is detached in TypedArraySpeciesCreate(...)");
} }
assert.sameValue(detached, true, "$262.detachArrayBuffer was called"); assert.sameValue(detached, true, "$262.detachArrayBuffer was called");
} }

View File

@ -15,11 +15,11 @@ for (var constructor of typedArrayConstructors) {
undefConstructor.constructor = undefined; undefConstructor.constructor = undefined;
assert.deepEqual(undefConstructor.slice(1), new constructor(1)); assert.deepEqual(undefConstructor.slice(1), new constructor(1));
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
var strConstructor = new constructor; var strConstructor = new constructor;
strConstructor.constructor = "not a constructor"; strConstructor.constructor = "not a constructor";
strConstructor.slice(123); strConstructor.slice(123);
}, TypeError, "Assert that we have an invalid constructor"); }, "Assert that we have an invalid constructor");
// If obj.constructor[@@species] is undefined or null then the default // If obj.constructor[@@species] is undefined or null then the default
// constructor is used. // constructor is used.
@ -49,10 +49,10 @@ for (var constructor of typedArrayConstructors) {
// If obj.constructor[@@species] is neither undefined nor null, and it's // If obj.constructor[@@species] is neither undefined nor null, and it's
// not a constructor, TypeError should be thrown. // not a constructor, TypeError should be thrown.
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
var strSpecies = new constructor; var strSpecies = new constructor;
strSpecies.constructor = { [Symbol.species]: "not a constructor" }; strSpecies.constructor = { [Symbol.species]: "not a constructor" };
strSpecies.slice(123); strSpecies.slice(123);
}, TypeError); });
} }

View File

@ -38,9 +38,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.slice.call(invalidReceiver, 0); constructor.prototype.slice.call(invalidReceiver, 0);
}, TypeError, "Assert that slice fails if this value is not a TypedArray"); }, "Assert that slice fails if this value is not a TypedArray");
}); });
// Test that the length getter is never called. // Test that the length getter is never called.

View File

@ -18,7 +18,7 @@ const typedArray = new Int32Array(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(() => typedArray.sort(invalidComparator), TypeError); assert.throws(TypeError, () => typedArray.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.

View File

@ -11,12 +11,12 @@ esid: pending
---*/ ---*/
// Ensure that TypedArrays throw when attempting to sort a detached ArrayBuffer // Ensure that TypedArrays throw when attempting to sort a detached ArrayBuffer
if (typeof $262.detachArrayBuffer === "function") { if (typeof $262.detachArrayBuffer === "function") {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
let buffer = new ArrayBuffer(32); let buffer = new ArrayBuffer(32);
let array = new Int32Array(buffer); let array = new Int32Array(buffer);
$262.detachArrayBuffer(buffer); $262.detachArrayBuffer(buffer);
array.sort(); array.sort();
}, TypeError); });
} }
// Ensure detaching buffer in comparator doesn't throw an error. // Ensure detaching buffer in comparator doesn't throw an error.
@ -58,23 +58,23 @@ if (typeof createNewGlobal === "function" && typeof $262.detachArrayBuffer === "
} }
// Ensure that TypedArray.prototype.sort will not sort non-TypedArrays // Ensure that TypedArray.prototype.sort will not sort non-TypedArrays
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
let array = [4, 3, 2, 1]; let array = [4, 3, 2, 1];
Int32Array.prototype.sort.call(array); Int32Array.prototype.sort.call(array);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
Int32Array.prototype.sort.call({a: 1, b: 2}); Int32Array.prototype.sort.call({a: 1, b: 2});
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
Int32Array.prototype.sort.call(Int32Array.prototype); Int32Array.prototype.sort.call(Int32Array.prototype);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
let buf = new ArrayBuffer(32); let buf = new ArrayBuffer(32);
Int32Array.prototype.sort.call(buf); Int32Array.prototype.sort.call(buf);
}, TypeError); });
// Ensure that comparator errors are propagataed // Ensure that comparator errors are propagataed
function badComparator(x, y) { function badComparator(x, y) {
@ -83,14 +83,14 @@ function badComparator(x, y) {
return x - y; return x - y;
} }
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
let array = new Uint8Array([99, 99, 99, 99]); let array = new Uint8Array([99, 99, 99, 99]);
array.sort(badComparator); array.sort(badComparator);
}, TypeError); });
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
let array = new Uint8Array([1, 99, 2, 99]); let array = new Uint8Array([1, 99, 2, 99]);
array.sort(badComparator); array.sort(badComparator);
}, TypeError); });

View File

@ -26,7 +26,7 @@ const NON_INLINE_STORAGE = 1024;
// Non-empty typed arrays cannot be sealed. // Non-empty typed arrays cannot be sealed.
for (let length of [INLINE_STORAGE, NON_INLINE_STORAGE]) { for (let length of [INLINE_STORAGE, NON_INLINE_STORAGE]) {
let ta = new Int32Array(length); let ta = new Int32Array(length);
assertThrowsInstanceOf(() => Object.seal(ta), TypeError); assert.throws(TypeError, () => Object.seal(ta));
assert.sameValue(Object.isExtensible(ta), false); assert.sameValue(Object.isExtensible(ta), false);
assert.sameValue(Object.isSealed(ta), false); assert.sameValue(Object.isSealed(ta), false);
@ -46,7 +46,7 @@ for (let length of [INLINE_STORAGE, NON_INLINE_STORAGE]) {
// Non-empty typed arrays cannot be frozen. // Non-empty typed arrays cannot be frozen.
for (let length of [INLINE_STORAGE, NON_INLINE_STORAGE]) { for (let length of [INLINE_STORAGE, NON_INLINE_STORAGE]) {
let ta = new Int32Array(length); let ta = new Int32Array(length);
assertThrowsInstanceOf(() => Object.freeze(ta), TypeError); assert.throws(TypeError, () => Object.freeze(ta));
assert.sameValue(Object.isExtensible(ta), false); assert.sameValue(Object.isExtensible(ta), false);
assert.sameValue(Object.isSealed(ta), false); assert.sameValue(Object.isSealed(ta), false);

View File

@ -16,7 +16,7 @@ if (typeof $262.detachArrayBuffer === "function") {
for (let constructor of typedArrayConstructors) { for (let constructor of typedArrayConstructors) {
let typedArray = new constructor(42); let typedArray = new constructor(42);
$262.detachArrayBuffer(typedArray.buffer); $262.detachArrayBuffer(typedArray.buffer);
assertThrowsInstanceOf(() => typedArray.toLocaleString(), TypeError); assert.throws(TypeError, () => typedArray.toLocaleString());
} }
// Doesn't throw a TypeError if detached in Number.prototype.toLocaleString. // Doesn't throw a TypeError if detached in Number.prototype.toLocaleString.

View File

@ -32,9 +32,9 @@ assert.sameValue(TypedArrayPrototype.toLocaleString.name, "toLocaleString");
assert.sameValue(TypedArrayPrototype.toLocaleString.length, 0); assert.sameValue(TypedArrayPrototype.toLocaleString.length, 0);
// It's not a generic method. // It's not a generic method.
assertThrowsInstanceOf(() => TypedArrayPrototype.toLocaleString.call(), TypeError); assert.throws(TypeError, () => TypedArrayPrototype.toLocaleString.call());
for (let invalid of [void 0, null, {}, [], function(){}, true, 0, "", Symbol()]) { for (let invalid of [void 0, null, {}, [], function(){}, true, 0, "", Symbol()]) {
assertThrowsInstanceOf(() => TypedArrayPrototype.toLocaleString.call(invalid), TypeError); assert.throws(TypeError, () => TypedArrayPrototype.toLocaleString.call(invalid));
} }
const localeOne = 1..toLocaleString(), const localeOne = 1..toLocaleString(),

View File

@ -14,5 +14,5 @@ var ta = new Int32Array([3, 2, 1]);
$262.detachArrayBuffer(ta.buffer); $262.detachArrayBuffer(ta.buffer);
assertThrowsInstanceOf(() => ta.toReversed(), TypeError); assert.throws(TypeError, () => ta.toReversed());

View File

@ -14,5 +14,5 @@ var ta = new Int32Array([3, 2, 1]);
$262.detachArrayBuffer(ta.buffer); $262.detachArrayBuffer(ta.buffer);
assertThrowsInstanceOf(() => ta.toSorted(), TypeError); assert.throws(TypeError, () => ta.toSorted());

View File

@ -38,9 +38,9 @@ for (var constructor of anyTypedArrayConstructors) {
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./, var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})]; new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => { invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => { assert.throws(TypeError, () => {
constructor.prototype.values.call(invalidReceiver); constructor.prototype.values.call(invalidReceiver);
}, TypeError, "Assert that values fails if this value is not a TypedArray"); }, "Assert that values fails if this value is not a TypedArray");
}); });
} }

View File

@ -14,5 +14,5 @@ var ta = new Int32Array([3, 2, 1]);
$262.detachArrayBuffer(ta.buffer); $262.detachArrayBuffer(ta.buffer);
assertThrowsInstanceOf(() => ta.with(0, 0), TypeError); assert.throws(TypeError, () => ta.with(0, 0));

View File

@ -24,7 +24,7 @@ let value = {
let ta = new Int32Array(5); let ta = new Int32Array(5);
for (let index of indices) { for (let index of indices) {
assertThrowsInstanceOf(() => ta.with(index, value), Err); assert.throws(Err, () => ta.with(index, value), Err);
} }
for (let index of indices) { for (let index of indices) {
@ -37,6 +37,6 @@ for (let index of indices) {
} }
}; };
assertThrowsInstanceOf(() => ta.with(index, value), RangeError); assert.throws(RangeError, () => ta.with(index, value));
} }