From f3cc1fb983a44a0c524dd846698f19b276918057 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Wed, 23 Mar 2016 14:35:13 -0400 Subject: [PATCH] Add tests for TypedArrays map --- .../prototype/map/arraylength-internal.js | 42 ++++++++++++++++ .../map/callbackfn-arguments-with-thisarg.js | 46 +++++++++++++++++ .../callbackfn-arguments-without-thisarg.js | 44 +++++++++++++++++ .../prototype/map/callbackfn-detachbuffer.js | 34 +++++++++++++ .../map/callbackfn-is-not-callable.js | 46 +++++++++++++++++ ...interaction-over-non-integer-properties.js | 40 +++++++++++++++ .../map/callbackfn-not-called-on-empty.js | 27 ++++++++++ ...llbackfn-return-affects-returned-object.js | 30 ++++++++++++ ...lbackfn-return-does-not-change-instance.js | 24 +++++++++ ...rn-does-not-copy-non-integer-properties.js | 42 ++++++++++++++++ .../map/callbackfn-returns-abrupt.js | 21 ++++++++ ...callbackfn-set-value-during-interaction.js | 42 ++++++++++++++++ .../prototype/map/callbackfn-this.js | 49 +++++++++++++++++++ ...return-new-typedarray-from-empty-length.js | 37 ++++++++++++++ ...urn-new-typedarray-from-positive-length.js | 33 +++++++++++++ 15 files changed, 557 insertions(+) create mode 100644 test/built-ins/TypedArray/prototype/map/arraylength-internal.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-detachbuffer.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-is-not-callable.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-returns-abrupt.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js create mode 100644 test/built-ins/TypedArray/prototype/map/callbackfn-this.js create mode 100644 test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js create mode 100644 test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js diff --git a/test/built-ins/TypedArray/prototype/map/arraylength-internal.js b/test/built-ins/TypedArray/prototype/map/arraylength-internal.js new file mode 100644 index 0000000000..7e1d4025df --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/arraylength-internal.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.map(function() { + loop++; + }); + 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++; + }); + assert.sameValue(loop, 4, "accessor descriptor"); +}); + diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js b/test/built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js new file mode 100644 index 0000000000..42cda42def --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,46 @@ +// 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.map(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js b/test/built-ins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.js new file mode 100644 index 0000000000..ad239fa19d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-arguments-without-thisarg.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: > + 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43, 44]); + + var results = []; + + sample.map(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/map/callbackfn-detachbuffer.js new file mode 100644 index 0000000000..54beabf070 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-detachbuffer.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: > + 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.map(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + }); + }); + + assert.sameValue(loops, 1, "callbackfn called only once"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-is-not-callable.js b/test/built-ins/TypedArray/prototype/map/callbackfn-is-not-callable.js new file mode 100644 index 0000000000..644c814371 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-is-not-callable.js @@ -0,0 +1,46 @@ +// 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] +---*/ + +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); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js b/test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.js new file mode 100644 index 0000000000..fb3ebba661 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-no-interaction-over-non-integer-properties.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: > + 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, compareArray.js] +features: [Symbol] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.map(function(v, i) { + results.push([v, i]); + }); + + 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/map/callbackfn-not-called-on-empty.js new file mode 100644 index 0000000000..3a23c627ad --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-not-called-on-empty.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: > + 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().map(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js b/test/built-ins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.js new file mode 100644 index 0000000000..02e6b5f199 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-return-affects-returned-object.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: > + 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] +---*/ + +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"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.js new file mode 100644 index 0000000000..445f08f8e0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-change-instance.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: > + The callbackfn return does not change the `this` instance +info: > + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testTypedArray.js] +---*/ + +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"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js b/test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js new file mode 100644 index 0000000000..4a60410b00 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-return-does-not-copy-non-integer-properties.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([7, 8]); + var bar = Symbol("1"); + + sample.foo = 42; + sample[bar] + + 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" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/map/callbackfn-returns-abrupt.js new file mode 100644 index 0000000000..e19be449da --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-returns-abrupt.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: > + Returns abrupt from callbackfn +info: > + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.map(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js b/test/built-ins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js new file mode 100644 index 0000000000..692bddc4a9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-set-value-during-interaction.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Integer indexed values changed during iteration +info: > + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testTypedArray.js] +features: [Reflect.set] +---*/ + +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 interaction" + ); + + newVal++; + }); + + assert.sameValue(sample[0], 7, "changed values after interaction [0] == 7"); + assert.sameValue(sample[1], 1, "changed values after interaction [1] == 1"); + assert.sameValue(sample[2], 2, "changed values after interaction [2] == 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/callbackfn-this.js b/test/built-ins/TypedArray/prototype/map/callbackfn-this.js new file mode 100644 index 0000000000..f136a4bafb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/callbackfn-this.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 `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] +---*/ + +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]"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js b/test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js new file mode 100644 index 0000000000..8c1c938f14 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-empty-length.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.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] +---*/ + +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"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js b/test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.js new file mode 100644 index 0000000000..fb4151f773 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/return-new-typedarray-from-positive-length.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: | + 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] +---*/ + +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"); +});