summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/map
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/map')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/arraylength-internal.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js30
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js27
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js24
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js45
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/callbackfn-this.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/detached-buffer.js34
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-abrupt-from-this-out-of-bounds.js62
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js36
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/shell.js42
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-abrupt.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-inherited.js66
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor-returns-throws.js67
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-ctor.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-abrupt.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-invocation.js61
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length-throws.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-length.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor-throws.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-custom-ctor.js58
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-returns-throws.js68
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species-use-default-ctor.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/speciesctor-get-species.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/BigInt/values-are-not-cached.js30
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/arraylength-internal.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js50
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-detachbuffer.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-is-not-callable.js49
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js30
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-resize.js79
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js27
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-returns-abrupt.js24
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js45
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-this.js52
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/detached-buffer.js34
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/invoked-as-func.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/invoked-as-method.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/length.js32
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/name.js29
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/prop-desc.js21
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds.js62
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js73
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js63
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js40
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js36
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/shell.js24
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-abrupt.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-inherited.js66
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-returns-throws.js67
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-abrupt.js47
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-invocation.js61
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws.js43
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-returns-another-instance.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-throws.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor.js58
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-returns-throws.js68
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-use-default-ctor.js56
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species.js48
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-object.js53
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-typedarray-instance.js45
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/map/values-are-not-cached.js30
79 files changed, 3556 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);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/arraylength-internal.js
new file mode 100644
index 0000000000..4d50955331
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample1 = new TA(42);
+ var loop = 0;
+
+ Object.defineProperty(sample1, "length", {value: 1});
+
+ sample1.map(function() {
+ loop++;
+ return 0;
+ });
+ 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 0;
+ });
+ assert.sameValue(loop, 4, "accessor descriptor");
+});
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js
new file mode 100644
index 0000000000..dd2f599d91
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 44]);
+
+ var results = [];
+ var thisArg = ["test262", 0, "ecma262", 0];
+
+ sample.map(function() {
+ results.push(arguments);
+ return 0;
+ }, 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], 42, "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], 43, "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], 44, "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/callbackfn-arguments-without-thisarg.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js
new file mode 100644
index 0000000000..14e593c926
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 44]);
+
+ var results = [];
+
+ sample.map(function() {
+ results.push(arguments);
+ return 0;
+ });
+
+ assert.sameValue(results.length, 3, "results.length");
+
+ assert.sameValue(results[0].length, 3, "results[0].length");
+ assert.sameValue(results[0][0], 42, "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], 43, "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], 44, "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/callbackfn-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-detachbuffer.js
new file mode 100644
index 0000000000..cead041854
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/callbackfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-is-not-callable.js
new file mode 100644
index 0000000000..c6ca42907e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/callbackfn-no-interaction-over-non-integer-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js
new file mode 100644
index 0000000000..4bbceeac78
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([7, 8]);
+
+ var results = [];
+
+ sample.foo = 42;
+ sample[Symbol("1")] = 43;
+
+ sample.map(function() {
+ results.push(arguments);
+ return 0;
+ });
+
+ 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], 7, "results[0][0] - kValue");
+ assert.sameValue(results[1][0], 8, "results[1][0] - kValue");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js
new file mode 100644
index 0000000000..d2c14b4635
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/callbackfn-resize.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-resize.js
new file mode 100644
index 0000000000..9d3ba7229a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-resize.js
@@ -0,0 +1,79 @@
+// |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: Instance buffer can be resized during iteration
+includes: [testTypedArray.js, compareArray.js]
+features: [TypedArray, resizable-arraybuffer]
+---*/
+
+// If the host chooses to throw as allowed by the specification, the observed
+// behavior will be identical to the case where `ArrayBuffer.prototype.resize`
+// has not been implemented. The following assertion prevents this test from
+// passing in runtimes which have not implemented the method.
+assert.sameValue(typeof ArrayBuffer.prototype.resize, 'function');
+
+testWithTypedArrayConstructors(function(TA) {
+ var BPE = TA.BYTES_PER_ELEMENT;
+ var NaNvalue = (TA === Float32Array || TA === Float64Array) ? NaN : 0;
+ var buffer = new ArrayBuffer(BPE * 3, {maxByteLength: BPE * 4});
+ var sample = new TA(buffer);
+ var finalElement, expectedElements, expectedIndices, expectedArrays;
+ var elements, indices, arrays, result;
+
+ elements = [];
+ indices = [];
+ arrays = [];
+ result = sample.map(function(element, index, array) {
+ if (elements.length === 0) {
+ try {
+ buffer.resize(2 * BPE);
+ finalElement = undefined;
+ expectedElements = [0, 0];
+ expectedIndices = [0, 1];
+ expectedArrays = [sample, sample];
+ } catch (_) {
+ finalElement = 0;
+ expectedElements = [0, 0, 0];
+ expectedIndices = [0, 1, 2];
+ expectedArrays = [sample, sample, sample];
+ }
+ }
+
+ elements.push(element);
+ indices.push(index);
+ arrays.push(array);
+
+ return index;
+ });
+
+ assert.compareArray(elements, [0, 0, finalElement], 'elements (shrink)');
+ assert.compareArray(indices, [0, 1, 2], 'indices (shrink)');
+ assert.compareArray(arrays, [sample, sample, sample], 'arrays (shrink)');
+ assert.compareArray(result, [0, 1, 2], 'result (shrink)');
+
+ elements = [];
+ indices = [];
+ arrays = [];
+ result = sample.map(function(element, index, array) {
+ if (elements.length === 0) {
+ try {
+ buffer.resize(4 * BPE);
+ } catch (_) {}
+ }
+
+ elements.push(element);
+ indices.push(index);
+ arrays.push(array);
+
+ return index;
+ });
+
+ assert.compareArray(elements, expectedElements, 'elements (grow)');
+ assert.compareArray(indices, expectedIndices, 'indices (grow)');
+ assert.compareArray(arrays, expectedArrays, 'arrays (grow)');
+ assert.compareArray(result, expectedIndices, 'result (grow)');
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js
new file mode 100644
index 0000000000..8627c187a3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 2, 4]);
+ var result = sample.map(function(v) {
+ return v * 3;
+ });
+
+ assert.sameValue(result[0], 3, "result[0] == 3");
+ assert.sameValue(result[1], 6, "result[1] == 6");
+ assert.sameValue(result[2], 12, "result[2] == 12");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js
new file mode 100644
index 0000000000..a386d40389
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample1 = new TA(3);
+
+ sample1[1] = 1;
+
+ sample1.map(function() {
+ return 42;
+ });
+
+ assert.sameValue(sample1[0], 0, "[0] == 0");
+ assert.sameValue(sample1[1], 1, "[1] == 1");
+ assert.sameValue(sample1[2], 0, "[2] == 0");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js
new file mode 100644
index 0000000000..228d5fca0b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([7, 8]);
+ var bar = Symbol("1");
+
+ sample.foo = 42;
+ sample[bar] = 1;
+
+ var result = sample.map(function() {
+ return 0;
+ });
+
+ 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/callbackfn-returns-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-returns-abrupt.js
new file mode 100644
index 0000000000..1849feee03
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/callbackfn-set-value-during-interaction.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js
new file mode 100644
index 0000000000..3367d09ed7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Reflect.set, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 44]);
+ var newVal = 0;
+
+ sample.map(function(val, i) {
+ if (i > 0) {
+ assert.sameValue(
+ sample[i - 1], newVal - 1,
+ "get the changed value during the loop"
+ );
+ assert.sameValue(
+ Reflect.set(sample, 0, 7),
+ true,
+ "re-set a value for sample[0]"
+ );
+ }
+ assert.sameValue(
+ Reflect.set(sample, i, newVal),
+ true,
+ "set value during iteration"
+ );
+
+ newVal++;
+ return 0;
+ });
+
+ assert.sameValue(sample[0], 7, "changed values after iteration [0] == 7");
+ assert.sameValue(sample[1], 1, "changed values after iteration [1] == 1");
+ assert.sameValue(sample[2], 2, "changed values after iteration [2] == 2");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-this.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/callbackfn-this.js
new file mode 100644
index 0000000000..f32ca0efa0
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var expected = (function() { return this; })();
+var thisArg = {};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(3);
+
+ var results1 = [];
+
+ sample.map(function() {
+ results1.push(this);
+ return 0;
+ });
+
+ 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 0;
+ }, 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/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/detached-buffer.js
new file mode 100644
index 0000000000..91ae25122b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js, detachArrayBuffer.js]
+features: [TypedArray]
+---*/
+
+var callbackfn = function() {
+ throw new Test262Error();
+};
+
+testWithTypedArrayConstructors(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/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/invoked-as-func.js
new file mode 100644
index 0000000000..390cc0f907
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/invoked-as-func.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.map
+description: Throws a TypeError exception when invoked as a function
+info: |
+ 22.2.3.18 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )
+
+ 1. Let O be the this value.
+ 2. Let valid be ValidateTypedArray(O).
+ 3. ReturnIfAbrupt(valid).
+ ...
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var map = TypedArray.prototype.map;
+
+assert.sameValue(typeof map, 'function');
+
+assert.throws(TypeError, function() {
+ map();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/invoked-as-method.js
new file mode 100644
index 0000000000..412ec13842
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/invoked-as-method.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.map
+description: Requires a [[TypedArrayName]] internal slot.
+info: |
+ 22.2.3.18 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )
+
+ 1. Let O be the this value.
+ 2. Let valid be ValidateTypedArray(O).
+ 3. ReturnIfAbrupt(valid).
+ ...
+
+ 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+
+assert.sameValue(typeof TypedArrayPrototype.map, 'function');
+
+assert.throws(TypeError, function() {
+ TypedArrayPrototype.map();
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/length.js
new file mode 100644
index 0000000000..005f678a2a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/length.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.map
+description: >
+ %TypedArray%.prototype.map.length is 1.
+info: |
+ %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, has a length
+ property whose value is an integer. Unless otherwise specified, this
+ value is equal to the largest number of named arguments shown in the
+ subclause headings for the function description, including optional
+ parameters. However, rest parameters shown using the form “...name”
+ are not included in the default argument count.
+
+ Unless otherwise specified, the length property of a built-in Function
+ object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
+ [[Configurable]]: true }.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+assert.sameValue(TypedArray.prototype.map.length, 1);
+
+verifyNotEnumerable(TypedArray.prototype.map, "length");
+verifyNotWritable(TypedArray.prototype.map, "length");
+verifyConfigurable(TypedArray.prototype.map, "length");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/name.js
new file mode 100644
index 0000000000..318e83fc91
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/name.js
@@ -0,0 +1,29 @@
+// Copyright (C) 2015 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-%typedarray%.prototype.map
+description: >
+ %TypedArray%.prototype.map.name is "map".
+info: |
+ %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every built-in Function object, including constructors, that is not
+ identified as an anonymous function has a name property whose value
+ is a String.
+
+ Unless otherwise specified, the name property of a built-in Function
+ object, if it exists, has the attributes { [[Writable]]: false,
+ [[Enumerable]]: false, [[Configurable]]: true }.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+assert.sameValue(TypedArray.prototype.map.name, "map");
+
+verifyNotEnumerable(TypedArray.prototype.map, "name");
+verifyNotWritable(TypedArray.prototype.map, "name");
+verifyConfigurable(TypedArray.prototype.map, "name");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/not-a-constructor.js
new file mode 100644
index 0000000000..c4f000f14d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/not-a-constructor.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-ecmascript-standard-built-in-objects
+description: >
+ TypedArray.prototype.map does not implement [[Construct]], is not new-able
+info: |
+ ECMAScript Function Objects
+
+ Built-in function objects that are not identified as constructors do not
+ implement the [[Construct]] internal method unless otherwise specified in
+ the description of a particular function.
+
+ sec-evaluatenew
+
+ ...
+ 7. If IsConstructor(constructor) is false, throw a TypeError exception.
+ ...
+includes: [isConstructor.js, testTypedArray.js]
+features: [Reflect.construct, arrow-function, TypedArray]
+---*/
+
+assert.sameValue(
+ isConstructor(TypedArray.prototype.map),
+ false,
+ 'isConstructor(TypedArray.prototype.map) must return false'
+);
+
+assert.throws(TypeError, () => {
+ let u8 = new Uint8Array(1); new u8.map(() => {});
+}, '`let u8 = new Uint8Array(1); new u8.map(() => {})` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/prop-desc.js
new file mode 100644
index 0000000000..4aff20321f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/prop-desc.js
@@ -0,0 +1,21 @@
+// 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: >
+ "map" property of TypedArrayPrototype
+info: |
+ ES6 section 17: Every other data property described in clauses 18 through 26
+ and in Annex B.2 has the attributes { [[Writable]]: true,
+ [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified.
+includes: [propertyHelper.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var TypedArrayPrototype = TypedArray.prototype;
+
+verifyNotEnumerable(TypedArrayPrototype, 'map');
+verifyWritable(TypedArrayPrototype, 'map');
+verifyConfigurable(TypedArrayPrototype, 'map');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-abrupt-from-this-out-of-bounds.js
new file mode 100644
index 0000000000..266cbd5320
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [ArrayBuffer, 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'
+);
+
+testWithTypedArrayConstructors(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(() => {});
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ // no error following shrink (within bounds):
+ array.map(() => {});
+
+ 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(() => {});
+ throw new Test262Error('map completed successfully');
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js
new file mode 100644
index 0000000000..ae26889ad9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation-consistent-nan.js
@@ -0,0 +1,73 @@
+// 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: Consistent canonicalization of NaN values
+info: |
+ 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )
+
+ ...
+ 8. Repeat, while k < len
+ ...
+ d. Perform ? Set(A, Pk, mappedValue, true).
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ ,
+ isLittleEndian ] )
+
+ ...
+ 8. If type is "Float32", then
+ a. Set rawBytes to a List containing the 4 bytes that are the result
+ of converting value to IEEE 754-2008 binary32 format using “Round to
+ nearest, ties to even” rounding mode. If isLittleEndian is false, the
+ bytes are arranged in big endian order. Otherwise, the bytes are
+ arranged in little endian order. If value is NaN, rawValue may be set
+ to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number
+ encoding. An implementation must always choose the same encoding for
+ each implementation distinguishable NaN value.
+ 9. Else, if type is "Float64", then
+ a. Set rawBytes to a List containing the 8 bytes that are the IEEE
+ 754-2008 binary64 format encoding of value. If isLittleEndian is false,
+ the bytes are arranged in big endian order. Otherwise, the bytes are
+ arranged in little endian order. If value is NaN, rawValue may be set
+ to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number
+ encoding. An implementation must always choose the same encoding for
+ each implementation distinguishable NaN value.
+ ...
+includes: [nans.js, testTypedArray.js, compareArray.js]
+features: [TypedArray]
+---*/
+
+function body(FloatArray) {
+ var sample = new FloatArray(NaNs);
+ var sampleBytes, resultBytes;
+ var i = 0;
+
+ var result = sample.map(function() {
+ return NaNs[i++];
+ });
+
+ sampleBytes = new Uint8Array(sample.buffer);
+ resultBytes = new Uint8Array(result.buffer);
+
+ assert(compareArray(sampleBytes, resultBytes));
+}
+
+testWithTypedArrayConstructors(body, [Float32Array, Float64Array]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js
new file mode 100644
index 0000000000..95607e6bf6
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-conversion-operation.js
@@ -0,0 +1,63 @@
+// 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: >
+ Verify conversion values on returned instance
+info: |
+ 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] )
+
+ ...
+ 8. Repeat, while k < len
+ ...
+ d. Perform ? Set(A, Pk, mappedValue, true).
+ ...
+
+ IntegerIndexedElementSet ( O, index, value )
+
+ Assert: O is an Integer-Indexed exotic object.
+ If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
+ Otherwise, let numValue be ? ToNumber(value).
+ Let buffer be O.[[ViewedArrayBuffer]].
+ If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
+ Let offset be O.[[ByteOffset]].
+ Let arrayTypeName be the String value of O.[[TypedArrayName]].
+ Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
+ Let indexedPosition be (ℝ(index) × elementSize) + offset.
+ Let elementType be the Element Type value in Table 62 for arrayTypeName.
+ Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
+ Return NormalCompletion(undefined).
+
+ 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ ,
+ isLittleEndian ] )
+
+ ...
+ 8. If type is "Float32", then
+ ...
+ 9. Else, if type is "Float64", then
+ ...
+ 10. Else,
+ ...
+ b. Let convOp be the abstract operation named in the Conversion Operation
+ column in Table 50 for Element Type type.
+ c. Let intValue be convOp(value).
+ d. If intValue ≥ 0, then
+ ...
+ e. Else,
+ ...
+includes: [byteConversionValues.js, testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) {
+ var sample = new TA([initial]);
+
+ var result = sample.map(function() {
+ return value;
+ });
+
+ assert.sameValue(result[0], expected, value + " converts to " + expected);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js
new file mode 100644
index 0000000000..caf14ee0e7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/return-new-typedarray-from-positive-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js
new file mode 100644
index 0000000000..781e95ed79
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/shell.js
new file mode 100644
index 0000000000..eda1477282
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/shell.js
@@ -0,0 +1,24 @@
+// GENERATED, DO NOT EDIT
+// file: isConstructor.js
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: |
+ Test if a given function is a constructor function.
+defines: [isConstructor]
+features: [Reflect.construct]
+---*/
+
+function isConstructor(f) {
+ if (typeof f !== "function") {
+ throw new Test262Error("isConstructor invoked with a non-function value");
+ }
+
+ try {
+ Reflect.construct(function(){}, [], f);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-abrupt.js
new file mode 100644
index 0000000000..8cb024e74f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([40, 41, 42, 43]);
+ 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/speciesctor-get-ctor-inherited.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-inherited.js
new file mode 100644
index 0000000000..69461a29bc
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([40, 41, 42, 43]);
+ var calls = 0;
+ var result;
+
+ Object.defineProperty(TA.prototype, "constructor", {
+ get: function() {
+ calls++;
+ }
+ });
+
+ result = sample.map(function() {
+ return 0;
+ });
+
+ 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/speciesctor-get-ctor-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor-returns-throws.js
new file mode 100644
index 0000000000..5f2498a20b
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var callbackfn = function() { return 0; };
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([40, 41, 42, 43]);
+
+ 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/speciesctor-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-ctor.js
new file mode 100644
index 0000000000..867e80d95e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([40, 41, 42, 43]);
+ var calls = 0;
+ var result;
+
+ Object.defineProperty(sample, "constructor", {
+ get: function() {
+ calls++;
+ }
+ });
+
+ result = sample.map(function() { return 0; });
+
+ 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/speciesctor-get-species-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-abrupt.js
new file mode 100644
index 0000000000..e13dc1fa89
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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 0; });
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-invocation.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-invocation.js
new file mode 100644
index 0000000000..31f2b4e2c1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([40, 42, 42]);
+ 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 === 42; });
+
+ 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/speciesctor-get-species-custom-ctor-length-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length-throws.js
new file mode 100644
index 0000000000..cfee782837
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/speciesctor-get-species-custom-ctor-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-length.js
new file mode 100644
index 0000000000..adaf755194
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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 0; });
+ assert.sameValue(result.length, customCount, "length == count");
+
+ customCount = 5;
+ result = sample.map(function() { return 0; });
+ assert.sameValue(result.length, customCount, "length > count");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-returns-another-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-returns-another-instance.js
new file mode 100644
index 0000000000..5891ee6291
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js, compareArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([40]);
+ var otherTA = TA === Int8Array ? Int16Array : Int8Array;
+ var other = new otherTA([1, 0, 1]);
+ var result;
+
+ sample.constructor = {};
+ sample.constructor[Symbol.species] = function() {
+ return other;
+ };
+
+ result = sample.map(function(a) { return a + 7; });
+
+ assert.sameValue(result, other, "returned another typedarray");
+ assert(compareArray(result, [47, 0, 1]), "values are set on returned typedarray");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor-throws.js
new file mode 100644
index 0000000000..cc914eb35c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/speciesctor-get-species-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-custom-ctor.js
new file mode 100644
index 0000000000..cc5cd4a718
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js, compareArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([40, 41, 42]);
+ 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 + 7; });
+
+ assert.sameValue(calls, 1, "ctor called once");
+ assert.sameValue(result, other, "return is instance of custom constructor");
+ assert(compareArray(result, [47, 48, 49]), "values are set on the new obj");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-returns-throws.js
new file mode 100644
index 0000000000..7c2d50f58a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(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/speciesctor-get-species-use-default-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species-use-default-ctor.js
new file mode 100644
index 0000000000..1f69a5f099
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+ var result;
+
+ sample.constructor = {};
+
+ result = sample.map(function() {});
+
+ 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() {});
+
+ 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/speciesctor-get-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/speciesctor-get-species.js
new file mode 100644
index 0000000000..ebb6be8c28
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [Symbol.species, TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(2);
+ var calls = 0;
+
+ sample.constructor = {};
+
+ Object.defineProperty(sample.constructor, Symbol.species, {
+ get: function() {
+ calls++;
+ }
+ });
+
+ sample.map(function() {});
+
+ assert.sameValue(calls, 1);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-object.js
new file mode 100644
index 0000000000..5ffe12583d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-object.js
@@ -0,0 +1,53 @@
+// 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 exception when `this` is not Object
+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 )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ ...
+includes: [testTypedArray.js]
+features: [Symbol, TypedArray]
+---*/
+
+var map = TypedArray.prototype.map;
+var callbackfn = function() {};
+
+assert.throws(TypeError, function() {
+ map.call(undefined, callbackfn);
+}, "this is undefined");
+
+assert.throws(TypeError, function() {
+ map.call(null, callbackfn);
+}, "this is null");
+
+assert.throws(TypeError, function() {
+ map.call(42, callbackfn);
+}, "this is 42");
+
+assert.throws(TypeError, function() {
+ map.call("1", callbackfn);
+}, "this is a string");
+
+assert.throws(TypeError, function() {
+ map.call(true, callbackfn);
+}, "this is true");
+
+assert.throws(TypeError, function() {
+ map.call(false, callbackfn);
+}, "this is false");
+
+var s = Symbol("s");
+assert.throws(TypeError, function() {
+ map.call(s, callbackfn);
+}, "this is a Symbol");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-typedarray-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-typedarray-instance.js
new file mode 100644
index 0000000000..214354fa23
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/this-is-not-typedarray-instance.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: >
+ Throws a TypeError exception when `this` is not a TypedArray instance
+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 )
+
+ 1. If Type(O) is not Object, throw a TypeError exception.
+ 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError
+ exception.
+ ...
+includes: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+var map = TypedArray.prototype.map;
+var callbackfn = function() {};
+
+assert.throws(TypeError, function() {
+ map.call({}, callbackfn);
+}, "this is an Object");
+
+assert.throws(TypeError, function() {
+ map.call([], callbackfn);
+}, "this is an Array");
+
+var ab = new ArrayBuffer(8);
+assert.throws(TypeError, function() {
+ map.call(ab, callbackfn);
+}, "this is an ArrayBuffer instance");
+
+var dv = new DataView(new ArrayBuffer(8), 0, 1);
+assert.throws(TypeError, function() {
+ map.call(dv, callbackfn);
+}, "this is a DataView instance");
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/map/values-are-not-cached.js b/js/src/tests/test262/built-ins/TypedArray/prototype/map/values-are-not-cached.js
new file mode 100644
index 0000000000..b65af8329f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/map/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: [testTypedArray.js]
+features: [TypedArray]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43, 44]);
+
+ sample.map(function(v, i) {
+ if (i < sample.length - 1) {
+ sample[i+1] = 42;
+ }
+
+ assert.sameValue(
+ v, 42, "method does not cache values before callbackfn calls"
+ );
+
+ return 0;
+ });
+});
+
+reportCompare(0, 0);