diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/TypedArray/prototype/subarray | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
66 files changed, 2891 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/detached-buffer.js new file mode 100644 index 0000000000..524f6858e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/detached-buffer.js @@ -0,0 +1,67 @@ +// 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.subarray +description: Throws a TypeError creating a new instance with a detached buffer +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + ... + + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 11. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var begin, end; + +var o1 = { + valueOf: function() { + begin = true; + return 0; + } +}; + +var o2 = { + valueOf: function() { + end = true; + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + begin = false; + end = false; + + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.subarray(o1, o2); + }); + + assert(begin, "observable ToInteger(begin)"); + assert(end, "observable ToInteger(end)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/infinity.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/infinity.js new file mode 100644 index 0000000000..cb1838bc27 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/infinity.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.subarray +description: Infinity values on begin and end +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.subarray(-Infinity), [40n, 41n, 42n, 43n]), + "begin == -Infinity" + ); + assert( + compareArray(sample.subarray(Infinity), []), + "being == Infinity" + ); + assert( + compareArray(sample.subarray(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.subarray(0, Infinity), [40n, 41n, 42n, 43n]), + "end == Infinity" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/minus-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/minus-zero.js new file mode 100644 index 0000000000..efdf9cca16 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/minus-zero.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.subarray +description: -0 values on begin and end +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.subarray(-0), [40n, 41n, 42n, 43n]), + "begin == -0" + ); + assert( + compareArray(sample.subarray(-0, 4), [40n, 41n, 42n, 43n]), + "being == -0, end == length" + ); + assert( + compareArray(sample.subarray(0, -0), []), + "being == 0, end == -0" + ); + assert( + compareArray(sample.subarray(-0, -0), []), + "being == -0, end == -0" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000..9be1b784d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,29 @@ +// 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.subarray +description: Subarray result does not import own property +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([41n, 42n, 43n, 44n]); + var result; + + sample.foo = 42; + + result = sample.subarray(0); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.js new file mode 100644 index 0000000000..4cefa6fd29 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.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.subarray +description: Returns a new instance from the same constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var result = sample.subarray(1); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "prototype" + ); + assert.sameValue(result.constructor, sample.constructor, "constructor"); + assert(result instanceof TA, "instanceof"); + + assert( + compareArray(sample, [40n, 41n, 42n, 43n]), + "original sample remains the same" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.js new file mode 100644 index 0000000000..3b8ea3c331 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.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.subarray +description: Returns a new instance sharing the same buffer +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + var buffer = sample.buffer; + var result = sample.subarray(1); + + assert.notSameValue(result, sample, "returns a new instance"); + assert.sameValue(result.buffer, sample.buffer, "shared buffer"); + assert.sameValue(sample.buffer, buffer, "original buffer is preserved"); + + sample[1] = 100n; + assert( + compareArray(result, [100n, 42n, 43n]), + "changes on the original sample values affect the new instance" + ); + + result[1] = 111n; + assert( + compareArray(sample, [40n, 100n, 111n, 43n]), + "changes on the new instance values affect the original sample" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js new file mode 100644 index 0000000000..f4153da597 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray may return a new instance with a smaller length +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.subarray(1), [41n, 42n, 43n], "begin == 1"); + testRes(sample.subarray(2), [42n, 43n], "begin == 2"); + testRes(sample.subarray(3), [43n], "begin == 3"); + + testRes(sample.subarray(1, 4), [41n, 42n, 43n], "begin == 1, end == length"); + testRes(sample.subarray(2, 4), [42n, 43n], "begin == 2, end == length"); + testRes(sample.subarray(3, 4), [43n], "begin == 3, end == length"); + + testRes(sample.subarray(0, 1), [40n], "begin == 0, end == 1"); + testRes(sample.subarray(0, 2), [40n, 41n], "begin == 0, end == 2"); + testRes(sample.subarray(0, 3), [40n, 41n, 42n], "begin == 0, end == 3"); + + testRes(sample.subarray(-1), [43n], "begin == -1"); + testRes(sample.subarray(-2), [42n, 43n], "begin == -2"); + testRes(sample.subarray(-3), [41n, 42n, 43n], "begin == -3"); + + testRes(sample.subarray(-1, 4), [43n], "begin == -1, end == length"); + testRes(sample.subarray(-2, 4), [42n, 43n], "begin == -2, end == length"); + testRes(sample.subarray(-3, 4), [41n, 42n, 43n], "begin == -3, end == length"); + + testRes(sample.subarray(0, -1), [40n, 41n, 42n], "begin == 0, end == -1"); + testRes(sample.subarray(0, -2), [40n, 41n], "begin == 0, end == -2"); + testRes(sample.subarray(0, -3), [40n], "begin == 0, end == -3"); + + testRes(sample.subarray(-0, -1), [40n, 41n, 42n], "begin == -0, end == -1"); + testRes(sample.subarray(-0, -2), [40n, 41n], "begin == -0, end == -2"); + testRes(sample.subarray(-0, -3), [40n], "begin == -0, end == -3"); + + testRes(sample.subarray(-2, -1), [42n], "length == 4, begin == -2, end == -1"); + testRes(sample.subarray(1, -1), [41n, 42n], "length == 4, begin == 1, end == -1"); + testRes(sample.subarray(1, -2), [41n], "length == 4, begin == 1, end == -2"); + testRes(sample.subarray(2, -1), [42n], "length == 4, begin == 2, end == -1"); + + testRes(sample.subarray(-1, 5), [43n], "begin == -1, end > length"); + testRes(sample.subarray(-2, 4), [42n, 43n], "begin == -2, end > length"); + testRes(sample.subarray(-3, 4), [41n, 42n, 43n], "begin == -3, end > length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js new file mode 100644 index 0000000000..33a3728bf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray may return a new empty instance +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, msg) { + assert.sameValue(result.length, 0, msg); + assert.sameValue( + result.hasOwnProperty(0), + false, + msg + " & result.hasOwnProperty(0) === false" + ); + } + + testRes(sample.subarray(4), "begin == length"); + testRes(sample.subarray(5), "begin > length"); + + testRes(sample.subarray(4, 4), "begin == length, end == length"); + testRes(sample.subarray(5, 4), "begin > length, end == length"); + + testRes(sample.subarray(4, 4), "begin == length, end > length"); + testRes(sample.subarray(5, 4), "begin > length, end > length"); + + testRes(sample.subarray(0, 0), "begin == 0, end == 0"); + testRes(sample.subarray(-0, -0), "begin == -0, end == -0"); + testRes(sample.subarray(1, 0), "begin > 0, end == 0"); + testRes(sample.subarray(-1, 0), "being < 0, end == 0"); + + testRes(sample.subarray(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.subarray(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.subarray(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.subarray(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.subarray(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.subarray(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.subarray(0, -4), "begin == 0, end == -length"); + testRes(sample.subarray(-4, -4), "begin == -length, end == -length"); + testRes(sample.subarray(-5, -4), "begin < -length, end == -length"); + + testRes(sample.subarray(0, -5), "begin == 0, end < -length"); + testRes(sample.subarray(-4, -5), "begin == -length, end < -length"); + testRes(sample.subarray(-5, -5), "begin < -length, end < -length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js new file mode 100644 index 0000000000..a74e0c3be6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js @@ -0,0 +1,39 @@ +// 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.subarray +description: Subarray may return a new instance with the same length +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], 40n, msg + " & result[0] === 40"); + assert.sameValue(result[1], 41n, msg + " & result[1] === 41"); + assert.sameValue(result[2], 42n, msg + " & result[2] === 42"); + assert.sameValue(result[3], 43n, msg + " & result[3] === 43"); + } + + testRes(sample.subarray(0), "begin == 0"); + testRes(sample.subarray(-4), "begin == -srcLength"); + testRes(sample.subarray(-5), "begin < -srcLength"); + + testRes(sample.subarray(0, 4), "begin == 0, end == srcLength"); + testRes(sample.subarray(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.subarray(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.subarray(0, 5), "begin == 0, end > srcLength"); + testRes(sample.subarray(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.subarray(-5, 5), "begin < -srcLength, end > srcLength"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js new file mode 100644 index 0000000000..83233be119 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js @@ -0,0 +1,26 @@ +// 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.subarray +description: Return abrupt from ToInteger(begin), begin is symbol +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js new file mode 100644 index 0000000000..0b5d84df83 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.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.subarray +description: Return abrupt from ToInteger(begin) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000..c68e1fbcb6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.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.subarray +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js new file mode 100644 index 0000000000..02ba53cd48 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js @@ -0,0 +1,41 @@ +// 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.subarray +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(0, o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/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/subarray/BigInt/speciesctor-get-ctor-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000..fadaf446a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.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.subarray +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000..68d4865a46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.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.subarray +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(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/subarray/BigInt/speciesctor-get-ctor-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000..07fec8bb54 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,64 @@ +// 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.subarray +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.subarray(0); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js new file mode 100644 index 0000000000..3b1687fd77 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: get constructor on SpeciesConstructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(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/subarray/BigInt/speciesctor-get-species-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000..94a903d30e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.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.subarray +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000..5afae1123e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.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.subarray +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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, 41n, 42n]); + var expectedOffset = TA.BYTES_PER_ELEMENT; + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + result = arguments; + ctorThis = this; + return new TA(buffer, offset, length); + }; + + sample.subarray(1); + + assert.sameValue(result.length, 3, "called with 3 arguments"); + assert.sameValue(result[0], sample.buffer, "[0] is sample.buffer"); + assert.sameValue(result[1], expectedOffset, "[1] is the byte offset pos"); + assert.sameValue(result[2], 2, "[2] is expected 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/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000..5ac5a191ce --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,54 @@ +// 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.subarray +description: > + Custom @@species constructor may return a totally different TypedArray +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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 other = new BigInt64Array([1n, 0n, 1n]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.subarray(0, 0); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1n, 0n, 1n]), "the returned object is preserved"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000..4350b76916 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.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.subarray +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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); + var ctor = function() {}; + + sample.constructor = {}; + sample.constructor[Symbol.species] = ctor; + + assert.throws(TypeError, function() { + sample.subarray(0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000..22f9502ae5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + Use custom @@species constructor if available +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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 result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + calls++; + return new TA(buffer, offset, length); + }; + + result = sample.subarray(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41n, 42n]), "expected subarray"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000..d568d39110 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,67 @@ +// 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.subarray +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "true"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000..e22fea84ad --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + + 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.subarray(0); + + 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/subarray/BigInt/speciesctor-get-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.js new file mode 100644 index 0000000000..358a88f259 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.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.subarray +description: > + get @@species from found constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + + assert.sameValue(calls, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js new file mode 100644 index 0000000000..4fcce8b780 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-begin.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.subarray +description: ToInteger(begin) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert(compareArray(sample.subarray(false), [40n, 41n, 42n, 43n]), "false"); + assert(compareArray(sample.subarray(true), [41n, 42n, 43n]), "true"); + + assert(compareArray(sample.subarray(NaN), [40n, 41n, 42n, 43n]), "NaN"); + assert(compareArray(sample.subarray(null), [40n, 41n, 42n, 43n]), "null"); + assert(compareArray(sample.subarray(undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.subarray(1.1), [41n, 42n, 43n]), "1.1"); + assert(compareArray(sample.subarray(1.5), [41n, 42n, 43n]), "1.5"); + assert(compareArray(sample.subarray(0.6), [40n, 41n, 42n, 43n]), "0.6"); + + assert(compareArray(sample.subarray(-1.5), [43n]), "-1.5"); + assert(compareArray(sample.subarray(-1.1), [43n]), "-1.1"); + assert(compareArray(sample.subarray(-0.6), [40n, 41n, 42n, 43n]), "-0.6"); + + assert(compareArray(sample.subarray("3"), [43n]), "string"); + assert( + compareArray( + sample.subarray(obj), + [42n, 43n] + ), + "object" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-end.js new file mode 100644 index 0000000000..2e3a74b14a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-end.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.subarray +description: ToInteger(end) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert(compareArray(sample.subarray(0, false), []), "false"); + assert(compareArray(sample.subarray(0, true), [40n]), "true"); + + assert(compareArray(sample.subarray(0, NaN), []), "NaN"); + assert(compareArray(sample.subarray(0, null), []), "null"); + assert(compareArray(sample.subarray(0, undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.subarray(0, 0.6), []), "0.6"); + assert(compareArray(sample.subarray(0, 1.1), [40n]), "1.1"); + assert(compareArray(sample.subarray(0, 1.5), [40n]), "1.5"); + assert(compareArray(sample.subarray(0, -0.6), []), "-0.6"); + assert(compareArray(sample.subarray(0, -1.1), [40n, 41n, 42n]), "-1.1"); + assert(compareArray(sample.subarray(0, -1.5), [40n, 41n, 42n]), "-1.5"); + + assert(compareArray(sample.subarray(0, "3"), [40n, 41n, 42n]), "string"); + assert( + compareArray( + sample.subarray(0, obj), + [40n, 41n] + ), + "object" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/detached-buffer.js new file mode 100644 index 0000000000..c65f6efff6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/detached-buffer.js @@ -0,0 +1,67 @@ +// 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.subarray +description: Throws a TypeError creating a new instance with a detached buffer +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + ... + + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 11. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var begin, end; + +var o1 = { + valueOf: function() { + begin = true; + return 0; + } +}; + +var o2 = { + valueOf: function() { + end = true; + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + begin = false; + end = false; + + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.subarray(o1, o2); + }); + + assert(begin, "observable ToInteger(begin)"); + assert(end, "observable ToInteger(end)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/infinity.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/infinity.js new file mode 100644 index 0000000000..283689ecea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/infinity.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.subarray +description: Infinity values on begin and end +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.subarray(-Infinity), [40, 41, 42, 43]), + "begin == -Infinity" + ); + assert( + compareArray(sample.subarray(Infinity), []), + "being == Infinity" + ); + assert( + compareArray(sample.subarray(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.subarray(0, Infinity), [40, 41, 42, 43]), + "end == Infinity" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/invoked-as-func.js new file mode 100644 index 0000000000..7bd0688838 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/invoked-as-func.js @@ -0,0 +1,26 @@ +// 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.subarray +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var subarray = TypedArray.prototype.subarray; + +assert.sameValue(typeof subarray, 'function'); + +assert.throws(TypeError, function() { + subarray(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/invoked-as-method.js new file mode 100644 index 0000000000..c5c39eb9e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/invoked-as-method.js @@ -0,0 +1,26 @@ +// 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.subarray +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. 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.subarray, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.subarray(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/length.js new file mode 100644 index 0000000000..7c29e2ff6b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/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.subarray +description: > + %TypedArray%.prototype.subarray.length is 2. +info: | + %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 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.subarray.length, 2); + +verifyNotEnumerable(TypedArray.prototype.subarray, "length"); +verifyNotWritable(TypedArray.prototype.subarray, "length"); +verifyConfigurable(TypedArray.prototype.subarray, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/minus-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/minus-zero.js new file mode 100644 index 0000000000..8c77ef6dd2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/minus-zero.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.subarray +description: -0 values on begin and end +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.subarray(-0), [40, 41, 42, 43]), + "begin == -0" + ); + assert( + compareArray(sample.subarray(-0, 4), [40, 41, 42, 43]), + "being == -0, end == length" + ); + assert( + compareArray(sample.subarray(0, -0), []), + "being == 0, end == -0" + ); + assert( + compareArray(sample.subarray(-0, -0), []), + "being == -0, end == -0" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/name.js new file mode 100644 index 0000000000..890fd6c7ce --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/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.subarray +description: > + %TypedArray%.prototype.subarray.name is "subarray". +info: | + %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 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.subarray.name, "subarray"); + +verifyNotEnumerable(TypedArray.prototype.subarray, "name"); +verifyNotWritable(TypedArray.prototype.subarray, "name"); +verifyConfigurable(TypedArray.prototype.subarray, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/not-a-constructor.js new file mode 100644 index 0000000000..1714a12b2a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/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.subarray 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.subarray), + false, + 'isConstructor(TypedArray.prototype.subarray) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.subarray(); +}, '`let u8 = new Uint8Array(1); new u8.subarray()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/prop-desc.js new file mode 100644 index 0000000000..e21769abed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/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.subarray +description: > + "subarray" 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, 'subarray'); +verifyWritable(TypedArrayPrototype, 'subarray'); +verifyConfigurable(TypedArrayPrototype, 'subarray'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-does-not-copy-ordinary-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000..6bd16f4c9b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,29 @@ +// 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.subarray +description: Subarray result does not import own property +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([41, 42, 43, 44]); + var result; + + sample.foo = 42; + + result = sample.subarray(0); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-is-new-instance-from-same-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-is-new-instance-from-same-ctor.js new file mode 100644 index 0000000000..48d9a3b490 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-is-new-instance-from-same-ctor.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.subarray +description: Returns a new instance from the same constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var result = sample.subarray(1); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "prototype" + ); + assert.sameValue(result.constructor, sample.constructor, "constructor"); + assert(result instanceof TA, "instanceof"); + + assert( + compareArray(sample, [40, 41, 42, 43]), + "original sample remains the same" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-is-new-instance-with-shared-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-is-new-instance-with-shared-buffer.js new file mode 100644 index 0000000000..223703aaa4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/result-is-new-instance-with-shared-buffer.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.subarray +description: Returns a new instance sharing the same buffer +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + var buffer = sample.buffer; + var result = sample.subarray(1); + + assert.notSameValue(result, sample, "returns a new instance"); + assert.sameValue(result.buffer, sample.buffer, "shared buffer"); + assert.sameValue(sample.buffer, buffer, "original buffer is preserved"); + + sample[1] = 100; + assert( + compareArray(result, [100, 42, 43]), + "changes on the original sample values affect the new instance" + ); + + result[1] = 111; + assert( + compareArray(sample, [40, 100, 111, 43]), + "changes on the new instance values affect the original sample" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-different-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-different-length.js new file mode 100644 index 0000000000..3445ae36be --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-different-length.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray may return a new instance with a smaller length +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.subarray(1), [41, 42, 43], "begin == 1"); + testRes(sample.subarray(2), [42, 43], "begin == 2"); + testRes(sample.subarray(3), [43], "begin == 3"); + + testRes(sample.subarray(1, 4), [41, 42, 43], "begin == 1, end == length"); + testRes(sample.subarray(2, 4), [42, 43], "begin == 2, end == length"); + testRes(sample.subarray(3, 4), [43], "begin == 3, end == length"); + + testRes(sample.subarray(0, 1), [40], "begin == 0, end == 1"); + testRes(sample.subarray(0, 2), [40, 41], "begin == 0, end == 2"); + testRes(sample.subarray(0, 3), [40, 41, 42], "begin == 0, end == 3"); + + testRes(sample.subarray(-1), [43], "begin == -1"); + testRes(sample.subarray(-2), [42, 43], "begin == -2"); + testRes(sample.subarray(-3), [41, 42, 43], "begin == -3"); + + testRes(sample.subarray(-1, 4), [43], "begin == -1, end == length"); + testRes(sample.subarray(-2, 4), [42, 43], "begin == -2, end == length"); + testRes(sample.subarray(-3, 4), [41, 42, 43], "begin == -3, end == length"); + + testRes(sample.subarray(0, -1), [40, 41, 42], "begin == 0, end == -1"); + testRes(sample.subarray(0, -2), [40, 41], "begin == 0, end == -2"); + testRes(sample.subarray(0, -3), [40], "begin == 0, end == -3"); + + testRes(sample.subarray(-0, -1), [40, 41, 42], "begin == -0, end == -1"); + testRes(sample.subarray(-0, -2), [40, 41], "begin == -0, end == -2"); + testRes(sample.subarray(-0, -3), [40], "begin == -0, end == -3"); + + testRes(sample.subarray(-2, -1), [42], "length == 4, begin == -2, end == -1"); + testRes(sample.subarray(1, -1), [41, 42], "length == 4, begin == 1, end == -1"); + testRes(sample.subarray(1, -2), [41], "length == 4, begin == 1, end == -2"); + testRes(sample.subarray(2, -1), [42], "length == 4, begin == 2, end == -1"); + + testRes(sample.subarray(-1, 5), [43], "begin == -1, end > length"); + testRes(sample.subarray(-2, 4), [42, 43], "begin == -2, end > length"); + testRes(sample.subarray(-3, 4), [41, 42, 43], "begin == -3, end > length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-empty-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-empty-length.js new file mode 100644 index 0000000000..204effe618 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-empty-length.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray may return a new empty instance +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, msg) { + assert.sameValue(result.length, 0, msg); + assert.sameValue( + result.hasOwnProperty(0), + false, + msg + " & result.hasOwnProperty(0) === false" + ); + } + + testRes(sample.subarray(4), "begin == length"); + testRes(sample.subarray(5), "begin > length"); + + testRes(sample.subarray(4, 4), "begin == length, end == length"); + testRes(sample.subarray(5, 4), "begin > length, end == length"); + + testRes(sample.subarray(4, 4), "begin == length, end > length"); + testRes(sample.subarray(5, 4), "begin > length, end > length"); + + testRes(sample.subarray(0, 0), "begin == 0, end == 0"); + testRes(sample.subarray(-0, -0), "begin == -0, end == -0"); + testRes(sample.subarray(1, 0), "begin > 0, end == 0"); + testRes(sample.subarray(-1, 0), "being < 0, end == 0"); + + testRes(sample.subarray(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.subarray(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.subarray(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.subarray(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.subarray(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.subarray(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.subarray(0, -4), "begin == 0, end == -length"); + testRes(sample.subarray(-4, -4), "begin == -length, end == -length"); + testRes(sample.subarray(-5, -4), "begin < -length, end == -length"); + + testRes(sample.subarray(0, -5), "begin == 0, end < -length"); + testRes(sample.subarray(-4, -5), "begin == -length, end < -length"); + testRes(sample.subarray(-5, -5), "begin < -length, end < -length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-same-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-same-length.js new file mode 100644 index 0000000000..614ad244ed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/results-with-same-length.js @@ -0,0 +1,39 @@ +// 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.subarray +description: Subarray may return a new instance with the same length +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], 40, msg + " & result[0] === 40"); + assert.sameValue(result[1], 41, msg + " & result[1] === 41"); + assert.sameValue(result[2], 42, msg + " & result[2] === 42"); + assert.sameValue(result[3], 43, msg + " & result[3] === 43"); + } + + testRes(sample.subarray(0), "begin == 0"); + testRes(sample.subarray(-4), "begin == -srcLength"); + testRes(sample.subarray(-5), "begin < -srcLength"); + + testRes(sample.subarray(0, 4), "begin == 0, end == srcLength"); + testRes(sample.subarray(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.subarray(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.subarray(0, 5), "begin == 0, end > srcLength"); + testRes(sample.subarray(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.subarray(-5, 5), "begin < -srcLength, end > srcLength"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js new file mode 100644 index 0000000000..650627c289 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin-symbol.js @@ -0,0 +1,26 @@ +// 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.subarray +description: Return abrupt from ToInteger(begin), begin is symbol +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin.js new file mode 100644 index 0000000000..9f8f28630b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-begin.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.subarray +description: Return abrupt from ToInteger(begin) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-end-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000..0e64f4ed39 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-end-symbol.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.subarray +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-end.js new file mode 100644 index 0000000000..3ab6a1c68c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/return-abrupt-from-end.js @@ -0,0 +1,41 @@ +// 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.subarray +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(0, o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/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/subarray/speciesctor-get-ctor-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000..c141c84747 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor-abrupt.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.subarray +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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]); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor-inherited.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000..b09d8759c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor-inherited.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.subarray +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(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/subarray/speciesctor-get-ctor-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000..7b96f3041c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,64 @@ +// 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.subarray +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.subarray(0); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor.js new file mode 100644 index 0000000000..a14d069528 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-ctor.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: get constructor on SpeciesConstructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(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/subarray/speciesctor-get-species-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000..7e40dbe686 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-abrupt.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.subarray +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-invocation.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000..1590a0c45b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-invocation.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.subarray +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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, 41, 42]); + var expectedOffset = TA.BYTES_PER_ELEMENT; + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + result = arguments; + ctorThis = this; + return new TA(buffer, offset, length); + }; + + sample.subarray(1); + + assert.sameValue(result.length, 3, "called with 3 arguments"); + assert.sameValue(result[0], sample.buffer, "[0] is sample.buffer"); + assert.sameValue(result[1], expectedOffset, "[1] is the byte offset pos"); + assert.sameValue(result[2], 2, "[2] is expected 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/subarray/speciesctor-get-species-custom-ctor-returns-another-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000..f86ed913db --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,54 @@ +// 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.subarray +description: > + Custom @@species constructor may return a totally different TypedArray +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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 other = new Int8Array([1, 0, 1]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.subarray(0, 0); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1, 0, 1]), "the returned object is preserved"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000..5e3d0d7be7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor-throws.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.subarray +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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); + var ctor = function() {}; + + sample.constructor = {}; + sample.constructor[Symbol.species] = ctor; + + assert.throws(TypeError, function() { + sample.subarray(0); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000..46e69712ee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + Use custom @@species constructor if available +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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 result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + calls++; + return new TA(buffer, offset, length); + }; + + result = sample.subarray(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41, 42]), "expected subarray"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000..01411d313c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-returns-throws.js @@ -0,0 +1,67 @@ +// 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.subarray +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "true"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-use-default-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000..cb21cd8f3c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + + 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.subarray(0); + + 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/subarray/speciesctor-get-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species.js new file mode 100644 index 0000000000..26bae75f03 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/speciesctor-get-species.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.subarray +description: > + get @@species from found constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 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.subarray(0); + + assert.sameValue(calls, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/this-is-not-object.js new file mode 100644 index 0000000000..e8aca60f7b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/this-is-not-object.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.subarray +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var subarray = TypedArray.prototype.subarray; + +assert.throws(TypeError, function() { + subarray.call(undefined, 0, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + subarray.call(null, 0, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + subarray.call(42, 0, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + subarray.call("1", 0, 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + subarray.call(true, 0, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + subarray.call(false, 0, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + subarray.call(s, 0, 0); +}, "this is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/this-is-not-typedarray-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000..da35e935f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/this-is-not-typedarray-instance.js @@ -0,0 +1,41 @@ +// 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.subarray +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.9 %TypedArray%.prototype.subarray( begin , end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var subarray = TypedArray.prototype.subarray; + +assert.throws(TypeError, function() { + subarray.call({}, 0, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + subarray.call([], 0, 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + subarray.call(ab, 0, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + subarray.call(dv, 0, 0); +}, "this is a DataView instance"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/tointeger-begin.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/tointeger-begin.js new file mode 100644 index 0000000000..de48a3d1a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/tointeger-begin.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.subarray +description: ToInteger(begin) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert(compareArray(sample.subarray(false), [40, 41, 42, 43]), "false"); + assert(compareArray(sample.subarray(true), [41, 42, 43]), "true"); + + assert(compareArray(sample.subarray(NaN), [40, 41, 42, 43]), "NaN"); + assert(compareArray(sample.subarray(null), [40, 41, 42, 43]), "null"); + assert(compareArray(sample.subarray(undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.subarray(1.1), [41, 42, 43]), "1.1"); + assert(compareArray(sample.subarray(1.5), [41, 42, 43]), "1.5"); + assert(compareArray(sample.subarray(0.6), [40, 41, 42, 43]), "0.6"); + + assert(compareArray(sample.subarray(-1.5), [43]), "-1.5"); + assert(compareArray(sample.subarray(-1.1), [43]), "-1.1"); + assert(compareArray(sample.subarray(-0.6), [40, 41, 42, 43]), "-0.6"); + + assert(compareArray(sample.subarray("3"), [43]), "string"); + assert( + compareArray( + sample.subarray(obj), + [42, 43] + ), + "object" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/tointeger-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/tointeger-end.js new file mode 100644 index 0000000000..a45c5258da --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/subarray/tointeger-end.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.subarray +description: ToInteger(end) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert(compareArray(sample.subarray(0, false), []), "false"); + assert(compareArray(sample.subarray(0, true), [40]), "true"); + + assert(compareArray(sample.subarray(0, NaN), []), "NaN"); + assert(compareArray(sample.subarray(0, null), []), "null"); + assert(compareArray(sample.subarray(0, undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.subarray(0, 0.6), []), "0.6"); + assert(compareArray(sample.subarray(0, 1.1), [40]), "1.1"); + assert(compareArray(sample.subarray(0, 1.5), [40]), "1.5"); + assert(compareArray(sample.subarray(0, -0.6), []), "-0.6"); + assert(compareArray(sample.subarray(0, -1.1), [40, 41, 42]), "-1.1"); + assert(compareArray(sample.subarray(0, -1.5), [40, 41, 42]), "-1.5"); + + assert(compareArray(sample.subarray(0, "3"), [40, 41, 42]), "string"); + assert( + compareArray( + sample.subarray(0, obj), + [40, 41] + ), + "object" + ); +}); + +reportCompare(0, 0); |