diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt')
17 files changed, 724 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js new file mode 100644 index 0000000000..c3d44249c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/arraylength-internal.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.foreach +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 42, "data descriptor"); + + var sample2 = new TA(7); + loop = 0; + + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 7, "accessor descriptor"); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000..0ba64a9ded --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,57 @@ +// 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.foreach +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? 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.forEach(function() { + results.push(arguments); + }, 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/forEach/BigInt/callbackfn-arguments-without-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000..fcde28dc17 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,55 @@ +// 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.foreach +description: > + callbackfn arguments +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? 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.forEach(function() { + results.push(arguments); + }); + + 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/forEach/BigInt/callbackfn-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000..5be9f05476 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,42 @@ +// 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.foreach +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? 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.forEach(function() { + if (loops === 0) { + $DETACHBUFFER(sample.buffer); + } + loops++; + }); + + assert.sameValue(loops, 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.js new file mode 100644 index 0000000000..662b26068e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.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.foreach +description: > + callbackfn is not callable +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(TypeError, function() { + sample.forEach(); + }); + + assert.throws(TypeError, function() { + sample.forEach(undefined); + }); + + assert.throws(TypeError, function() { + sample.forEach(null); + }); + + assert.throws(TypeError, function() { + sample.forEach({}); + }); + + assert.throws(TypeError, function() { + sample.forEach(1); + }); + + assert.throws(TypeError, function() { + sample.forEach(""); + }); + + assert.throws(TypeError, function() { + sample.forEach(false); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 0000000000..d94513f649 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/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.foreach +description: > + Does not interact over non-integer properties +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? 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.forEach(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], 7n, "results[0][0] - kValue"); + assert.sameValue(results[1][0], 8n, "results[1][0] - kValue"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000..c4be5838d5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/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.foreach +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().forEach(function() { + called++; + }); + + assert.sameValue(called, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000..052146907d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,32 @@ +// 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.foreach +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1n; + + sample1.forEach(function() { + return 42; + }); + + assert.sameValue(sample1[0], 0n, "[0] == 0"); + assert.sameValue(sample1[1], 1n, "[1] == 1"); + assert.sameValue(sample1[2], 0n, "[2] == 0"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000..2405024122 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.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.foreach +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? 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.forEach(function() { + throw new Test262Error(); + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000..208be545a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.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.foreach +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.forEach(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++; + }); + + 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/forEach/BigInt/callbackfn-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js new file mode 100644 index 0000000000..25e4abc0f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js @@ -0,0 +1,59 @@ +// 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.foreach +description: > + callbackfn `this` value +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( 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. Perform ? 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.forEach(function() { + results1.push(this); + }); + + 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.forEach(function() { + results2.push(this); + }, 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/forEach/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/detached-buffer.js new file mode 100644 index 0000000000..3a72de57aa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/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.foreach +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( 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.forEach(callbackfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..f1b50900c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| shell-option(--enable-arraybuffer-resizable) skip-if(!ArrayBuffer.prototype.resize||!xulRuntime.shell) -- resizable-arraybuffer is not enabled unconditionally, requires shell-options +// 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.foreach +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.forEach, + 'function', + 'implements TypedArray.prototype.forEach' +); + +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.forEach(() => {}); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.forEach(() => {}); + + 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 forEach operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.forEach(() => {}); + throw new Test262Error('forEach completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/returns-undefined.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/returns-undefined.js new file mode 100644 index 0000000000..b9e14e8695 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/returns-undefined.js @@ -0,0 +1,35 @@ +// 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.foreach +description: > + Returns undefined +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + + var result1 = sample1.forEach(function() { + return 42; + }); + + assert.sameValue(result1, undefined, "result1"); + + var sample2 = new TA(1); + var result2 = sample2.forEach(function() { + return null; + }); + + assert.sameValue(result2, undefined, "result2"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/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/forEach/BigInt/values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000..f607b8e525 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.js @@ -0,0 +1,33 @@ +// 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.foreach +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.forEach(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = 42n; + } + + assert.sameValue( + v, 42n, "method does not cache values before callbackfn calls" + ); + }); +}); + +reportCompare(0, 0); |