diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt')
34 files changed, 1540 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/arraylength-internal.js new file mode 100644 index 0000000000..e038d8da60 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/arraylength-internal.js @@ -0,0 +1,47 @@ +// 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.map +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.map(function() { + loop++; + return 0n; + }); + assert.sameValue(loop, 42, "data descriptor"); + + loop = 0; + var sample2 = new TA(4); + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.map(function() { + loop++; + return 0n; + }); + assert.sameValue(loop, 4, "accessor descriptor"); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000..136bace8bc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,50 @@ +// 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.map +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? 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.map(function() { + results.push(arguments); + return 0n; + }, 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/map/BigInt/callbackfn-arguments-without-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000..8d29b81a90 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.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.map +description: > + callbackfn arguments +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? 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.map(function() { + results.push(arguments); + return 0n; + }); + + 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/map/BigInt/callbackfn-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 0000000000..a21476ea34 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.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.map +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? 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.map(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/map/BigInt/callbackfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js new file mode 100644 index 0000000000..8a8f22473d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.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.map +description: > + callbackfn is not callable +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 4. 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.map(); + }); + + assert.throws(TypeError, function() { + sample.map(undefined); + }); + + assert.throws(TypeError, function() { + sample.map(null); + }); + + assert.throws(TypeError, function() { + sample.map({}); + }); + + assert.throws(TypeError, function() { + sample.map(1); + }); + + assert.throws(TypeError, function() { + sample.map(""); + }); + + assert.throws(TypeError, function() { + sample.map(false); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js new file mode 100644 index 0000000000..814b2dd35c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.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.map +description: > + Does not interact over non-integer properties +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? 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.map(function() { + results.push(arguments); + return 0n; + }); + + 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/map/BigInt/callbackfn-not-called-on-empty.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000..8405822991 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,30 @@ +// 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.map +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().map(function() { + called++; + }); + + assert.sameValue(called, 0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js new file mode 100644 index 0000000000..0f8fcf65ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.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.map +description: > + The callbackfn returned values are applied to the new instance +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + d. Perform ? Set(A, Pk, mappedValue, true). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([1n, 2n, 4n]); + var result = sample.map(function(v) { + return v * 3n; + }); + + assert.sameValue(result[0], 3n, "result[0] == 3"); + assert.sameValue(result[1], 6n, "result[1] == 6"); + assert.sameValue(result[2], 12n, "result[2] == 12"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000..9405e276f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,27 @@ +// 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.map +description: > + The callbackfn return does not change the `this` instance +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = 1n; + + sample1.map(function() { + return 42n; + }); + + 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/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js new file mode 100644 index 0000000000..3518e390b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.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.map +description: > + Does not copy non-integer properties to returned value +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([7n, 8n]); + var bar = Symbol("1"); + + sample.foo = 42; + sample[bar] = 1; + + var result = sample.map(function() { + return 0n; + }); + + assert.sameValue(result.length, 2, "result.length"); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, "foo"), + undefined, + "foo" + ); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, bar), + undefined, + "bar" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000..880d124eb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,24 @@ +// 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.map +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.map(function() { + throw new Test262Error(); + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000..55849c02da --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,45 @@ +// 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.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + var newVal = 0n; + + sample.map(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 0n; + }); + + 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/map/BigInt/callbackfn-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-this.js new file mode 100644 index 0000000000..c8aeffaa22 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-this.js @@ -0,0 +1,52 @@ +// 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.map +description: > + callbackfn `this` value +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 8. Repeat, while k < len + ... + c. Let mappedValue be ? 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.map(function() { + results1.push(this); + return 0n; + }); + + 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.map(function() { + results2.push(this); + return 0n; + }, 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/map/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/detached-buffer.js new file mode 100644 index 0000000000..d26dc3485b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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.map +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... + + 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.map(callbackfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..5ccc7ca1b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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.map +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.map, + 'function', + 'implements TypedArray.prototype.map' +); + +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.map(() => 0n); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.map(() => 0n); + + 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 map operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.map(() => 0n); + throw new Test262Error('map completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js new file mode 100644 index 0000000000..6b09264a29 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.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.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length == 0 +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(0); + + var result = sample.map(function() {}); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, TA, "same constructor"); + assert(result instanceof TA, "result is an instance of " + TA.name); + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "result has the same prototype of sample" + ); + assert.sameValue(result.length, 0, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js new file mode 100644 index 0000000000..712241641a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js @@ -0,0 +1,36 @@ +// 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.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length > 0 +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var result = sample.map(function(v) { + return v; + }); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, sample.constructor, "same constructor"); + assert.sameValue(result.length, 3, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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/map/BigInt/speciesctor-get-ctor-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000..d0a8044e66 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,47 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var callCount = 0; + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.map(function() { + callCount++; + }); + }); + assert.sameValue(callCount, 0, "callback should not be called"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-inherited.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000..cc3b73e3f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-inherited.js @@ -0,0 +1,66 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.map(function() { + return 0n; + }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000..f7a6a54e72 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,67 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var callbackfn = function() { return 0n; }; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.map(callbackfn); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor.js new file mode 100644 index 0000000000..6bbfca9989 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: get constructor on SpeciesConstructor +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.map(function() { return 0n; }); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000..dc36b88037 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-abrupt.js @@ -0,0 +1,47 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.map(function() { return 0n; }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000..8e1fc1b005 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newTypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 42n, 42n]); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.map(function(v) { return v === 42n; }); + + assert.sameValue(result.length, 1, "called with 1 argument"); + assert.sameValue(result[0], 3, "[0] is the length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000..127a1142fa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,43 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Throws a TypeError if new typedArray's length < len +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.map(function() { return 0; }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000..0e9e7a3fd7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length.js @@ -0,0 +1,48 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Does not throw a TypeError if new typedArray's length >= len +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.map(function() { return 0n; }); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.map(function() { return 0n; }); + assert.sameValue(result.length, customCount, "length > count"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000..82fa940644 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,56 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Custom @@species constructor may return a different TypedArray +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n]); + var otherTA = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var other = new otherTA([1n, 0n, 1n]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.map(function(a) { return a + 7n; }); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [47n, 0n, 1n]), "values are set on returned typedarray"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000..f56a8374a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,48 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = Array; + + assert.throws(TypeError, function() { + sample.map(function() {}); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000..25cd7e12b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,58 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Use custom @@species constructor if available +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n]); + var calls = 0; + var other, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(len) { + calls++; + other = new TA(len); + return other; + }; + + result = sample.map(function(a) { return a + 7n; }); + + assert.sameValue(calls, 1, "ctor called once"); + assert.sameValue(result, other, "return is instance of custom constructor"); + assert(compareArray(result, [47n, 48n, 49n]), "values are set on the new obj"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000..6431d37d25 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,68 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.map(function() {}); + }, "true"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-use-default-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000..5943e9b850 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.map(function() { return 0n; }); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.map(function() { return 0n; }); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species.js new file mode 100644 index 0000000000..30431bbf6a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species.js @@ -0,0 +1,48 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + get @@species from found constructor +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.map(function() { return 0n; }); + + assert.sameValue(calls, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/values-are-not-cached.js new file mode 100644 index 0000000000..73b72e7e3d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/values-are-not-cached.js @@ -0,0 +1,30 @@ +// 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.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n]); + + sample.map(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 0n; + }); +}); + +reportCompare(0, 0); |