diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt')
18 files changed, 834 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000..feb32a4e4b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,58 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.every(function() { + results.push(arguments); + return true; + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000..7539c73698 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + callbackfn arguments +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + var results = []; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 42n, "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], 43n, "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], 44n, "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000..dcd3209e2a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + sample.every(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + return true; + }); + + assert.sameValue(loops, 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000..44ad01e601 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - value"); + assert.sameValue(results[1][0], 8n, "results[1][0] - value"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 0000000000..d0146e81d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,71 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.every(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.every(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.every(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.every("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.every(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.every(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.every(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.every(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.every({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.every(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.every(Symbol("1")); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000..b933d0618e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().every(function() { + called++; + }); + + assert.sameValue(called, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000..4de9055dca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + + sample.every(function() { + return 43; + }); + + assert.sameValue(sample[0], 40n, "[0] == 40"); + assert.sameValue(sample[1], 41n, "[1] == 41"); + assert.sameValue(sample[2], 42n, "[2] == 42"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000..13abf3af2b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: Returns abrupt from callbackfn +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.every(function() { + throw new Test262Error(); + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000..9681d5e39e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.every(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], newVal - 1n, + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, 7n), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, newVal), + true, + "set value during iteration" + ); + + newVal++; + + return true; + }); + + assert.sameValue(sample[0], 7n, "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], 1n, "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], 2n, "changed values after iteration [2] == 2"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-this.js new file mode 100644 index 0000000000..b0a04b738e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/callbackfn-this.js @@ -0,0 +1,61 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + callbackfn `this` value +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.every(function() { + results1.push(this); + return true; + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.every(function() { + results2.push(this); + return true; + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/detached-buffer.js new file mode 100644 index 0000000000..d90c073acb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.every(callbackfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..fabfb42348 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.every(function() { + calls++; + return true; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..7d9bf0d85f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: Return abrupt when "this" value fails buffer boundary checks +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.every, + 'function', + 'implements TypedArray.prototype.every' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.every(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.every(() => {}); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the every operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.every(() => {}); + throw new Test262Error('every completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js new file mode 100644 index 0000000000..20d55bc611 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + Returns false if any callbackfn call returns a coerced false. +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.every(function() { + called++; + if (called === 1) { + return true; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called until it returned " + val); + assert.sameValue(result, false, "result is false when it returned " + val); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js new file mode 100644 index 0000000000..ecd8112108 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + Returns true if every callbackfn returns a coerced true. +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + var values = [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ]; + var sample = new TA(values.length); + var result = sample.every(function() { + called++; + return values.unshift(); + }); + + assert.sameValue(called, sample.length, "callbackfn called for each index"); + assert.sameValue(result, true, "return is true"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000..bd074ea54e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/every/BigInt/values-are-not-cached.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.every +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.every(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + return true; + }); +}); + +reportCompare(0, 0); |