diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/slice')
85 files changed, 3775 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/arraylength-internal.js new file mode 100644 index 0000000000..36be94c8a3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/arraylength-internal.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.slice +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.slice(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result.hasOwnProperty(2), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js new file mode 100644 index 0000000000..9bb42ed75b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.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.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during create with custom constructor (other targetType) +info: | + %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + + TypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? TypedArrayCreate(constructor, argumentList). + + TypedArrayCreate ( constructor, argumentList ) + + Let newTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateTypedArray(newTypedArray). + + ValidateTypedArray ( O ) + The abstract operation ValidateTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + var sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + counter++; + $DETACHBUFFER(sample.buffer); + return new other(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js new file mode 100644 index 0000000000..79ab4f121a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during create with custom constructor. +info: | + %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + + TypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? TypedArrayCreate(constructor, argumentList). + + TypedArrayCreate ( constructor, argumentList ) + + Let newTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateTypedArray(newTypedArray). + + ValidateTypedArray ( O ) + The abstract operation ValidateTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + return new TA(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js new file mode 100644 index 0000000000..91ae52dbe1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached during Get custom constructor. +info: | + %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + + TypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? TypedArrayCreate(constructor, argumentList). + + TypedArrayCreate ( constructor, argumentList ) + + Let newTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateTypedArray(newTypedArray). + + ValidateTypedArray ( O ) + The abstract operation ValidateTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + Object.defineProperty(sample, "constructor", { + get() { + counter++; + $DETACHBUFFER(sample.buffer); + } + }); + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000..61bf6aae07 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError if buffer of object created by custom constructor is detached. +info: | + %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + + TypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? TypedArrayCreate(constructor, argumentList). + + TypedArrayCreate ( constructor, argumentList ) + + Let newTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateTypedArray(newTypedArray). + + ValidateTypedArray ( O ) + The abstract operation ValidateTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + let other = new TA(count); + counter++; + $DETACHBUFFER(other.buffer); + return other; + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js new file mode 100644 index 0000000000..662fb476a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.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.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using other targetType. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, Other, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + Other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + $DETACHBUFFER(sample.buffer); + other = new Other(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result.constructor, Other, 'The value of result.constructor is expected to equal the value of Other'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + sample.slice(1, 1); // count = 0; + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js new file mode 100644 index 0000000000..3d322aedb8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js @@ -0,0 +1,51 @@ +// 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.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using same targetType. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + other = new TA(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + result = sample.slice(1, 1); // count = 0; + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue( + result.buffer, + sample.buffer, + 'The value of result.buffer is expected to not equal the value of `sample.buffer`' + ); + assert.sameValue(result.constructor, TA, 'The value of result.constructor is expected to equal the value of TA'); + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer.js new file mode 100644 index 0000000000..0836f833e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.slice(obj, obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/infinity.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/infinity.js new file mode 100644 index 0000000000..b0d3248970 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/infinity.js @@ -0,0 +1,31 @@ +// 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.slice +description: Infinity values on start and end +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.slice(-Infinity), [40n, 41n, 42n, 43n]), + "start == -Infinity" + ); + assert( + compareArray(sample.slice(Infinity), []), + "start == Infinity" + ); + assert( + compareArray(sample.slice(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.slice(0, Infinity), [40n, 41n, 42n, 43n]), + "end == Infinity" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/minus-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/minus-zero.js new file mode 100644 index 0000000000..75c7af3cef --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: -0 values on start and end +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([40n, 41n, 42n, 43n]); + + assert( + compareArray(sample.slice(-0), [40n, 41n, 42n, 43n]), + "start == -0" + ); + assert( + compareArray(sample.slice(-0, 4), [40n, 41n, 42n, 43n]), + "start == -0, end == length" + ); + assert( + compareArray(sample.slice(0, -0), []), + "start == 0, end == -0" + ); + assert( + compareArray(sample.slice(-0, -0), []), + "start == -0, end == -0" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000..9624a71553 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Result does not import own properties +info: | + 22.2.3.24 %TypedArray%.prototype.slice( start , end ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([41n, 42n, 43n, 44n]); + sample.foo = 42; + + var result = sample.slice(); + 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/slice/BigInt/results-with-different-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-different-length.js new file mode 100644 index 0000000000..734ff140d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-different-length.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.slice +description: slice may return a new instance with a smaller length +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.slice(1), [41n, 42n, 43n], "begin == 1"); + testRes(sample.slice(2), [42n, 43n], "begin == 2"); + testRes(sample.slice(3), [43n], "begin == 3"); + + testRes(sample.slice(1, 4), [41n, 42n, 43n], "begin == 1, end == length"); + testRes(sample.slice(2, 4), [42n, 43n], "begin == 2, end == length"); + testRes(sample.slice(3, 4), [43n], "begin == 3, end == length"); + + testRes(sample.slice(0, 1), [40n], "begin == 0, end == 1"); + testRes(sample.slice(0, 2), [40n, 41n], "begin == 0, end == 2"); + testRes(sample.slice(0, 3), [40n, 41n, 42n], "begin == 0, end == 3"); + + testRes(sample.slice(-1), [43n], "begin == -1"); + testRes(sample.slice(-2), [42n, 43n], "begin == -2"); + testRes(sample.slice(-3), [41n, 42n, 43n], "begin == -3"); + + testRes(sample.slice(-1, 4), [43n], "begin == -1, end == length"); + testRes(sample.slice(-2, 4), [42n, 43n], "begin == -2, end == length"); + testRes(sample.slice(-3, 4), [41n, 42n, 43n], "begin == -3, end == length"); + + testRes(sample.slice(0, -1), [40n, 41n, 42n], "begin == 0, end == -1"); + testRes(sample.slice(0, -2), [40n, 41n], "begin == 0, end == -2"); + testRes(sample.slice(0, -3), [40n], "begin == 0, end == -3"); + + testRes(sample.slice(-0, -1), [40n, 41n, 42n], "begin == -0, end == -1"); + testRes(sample.slice(-0, -2), [40n, 41n], "begin == -0, end == -2"); + testRes(sample.slice(-0, -3), [40n], "begin == -0, end == -3"); + + testRes(sample.slice(-2, -1), [42n], "length == 4, begin == -2, end == -1"); + testRes(sample.slice(1, -1), [41n, 42n], "length == 4, begin == 1, end == -1"); + testRes(sample.slice(1, -2), [41n], "length == 4, begin == 1, end == -2"); + testRes(sample.slice(2, -1), [42n], "length == 4, begin == 2, end == -1"); + + testRes(sample.slice(-1, 5), [43n], "begin == -1, end > length"); + testRes(sample.slice(-2, 4), [42n, 43n], "begin == -2, end > length"); + testRes(sample.slice(-3, 4), [41n, 42n, 43n], "begin == -3, end > length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-empty-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-empty-length.js new file mode 100644 index 0000000000..33b6407af3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-empty-length.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.slice +description: slice may return a new empty instance +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.slice(4), "begin == length"); + testRes(sample.slice(5), "begin > length"); + + testRes(sample.slice(4, 4), "begin == length, end == length"); + testRes(sample.slice(5, 4), "begin > length, end == length"); + + testRes(sample.slice(4, 5), "begin == length, end > length"); + testRes(sample.slice(5, 5), "begin > length, end > length"); + + testRes(sample.slice(0, 0), "begin == 0, end == 0"); + testRes(sample.slice(-0, -0), "begin == -0, end == -0"); + testRes(sample.slice(1, 0), "begin > 0, end == 0"); + testRes(sample.slice(-1, 0), "being < 0, end == 0"); + + testRes(sample.slice(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.slice(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.slice(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.slice(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.slice(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.slice(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.slice(0, -4), "begin == 0, end == -length"); + testRes(sample.slice(-4, -4), "begin == -length, end == -length"); + testRes(sample.slice(-5, -4), "begin < -length, end == -length"); + + testRes(sample.slice(0, -5), "begin == 0, end < -length"); + testRes(sample.slice(-4, -5), "begin == -length, end < -length"); + testRes(sample.slice(-5, -5), "begin < -length, end < -length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-same-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-same-length.js new file mode 100644 index 0000000000..ba42543f08 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/results-with-same-length.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: slice may return a new instance with the same length +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.slice(0), "begin == 0"); + testRes(sample.slice(-4), "begin == -srcLength"); + testRes(sample.slice(-5), "begin < -srcLength"); + + testRes(sample.slice(0, 4), "begin == 0, end == srcLength"); + testRes(sample.slice(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.slice(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.slice(0, 5), "begin == 0, end > srcLength"); + testRes(sample.slice(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.slice(-5, 5), "begin < -srcLength, end > srcLength"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000..248d77ca7c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; 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.slice(0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js new file mode 100644 index 0000000000..2f2464e217 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; 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.slice(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(0, o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.js new file mode 100644 index 0000000000..250acaeb77 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-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.slice +description: Return abrupt from ToInteger(start), start is symbol +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.slice(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js new file mode 100644 index 0000000000..c3a16ededd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.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.slice +description: Return abrupt from ToInteger(start) +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +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.slice(o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..fc66f5270d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Return abrupt when "this" value fails buffer boundary checks +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.slice, + 'function', + 'implements TypedArray.prototype.slice' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.slice(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.slice(0); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the slice operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.slice(0); + throw new Test262Error('slice completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.js new file mode 100644 index 0000000000..d8f5e282b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.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.slice +description: > + Perform regular set if target's uses a different element type +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + 10. Let srcName be the String value of O's [[TypedArrayName]] internal slot. + 11. Let srcType be the String value of the Element Type value in Table 50 for + srcName. + 12. Let targetName be the String value of A's [[TypedArrayName]] internal + slot. + 13. Let targetType be the String value of the Element Type value in Table 50 + for targetName. + 14. If SameValue(srcType, targetType) is false, then + a. Let n be 0. + b. Repeat, while k < final + i. Let Pk be ! ToString(k). + ii. Let kValue be ? Get(O, Pk). + iii. Perform ? Set(A, ! ToString(n), kValue, true). + iv. Increase k by 1. + v. Increase n by 1. + ... + 16. Return A +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +var arr = [42n, 43n, 44n]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + + sample.constructor = {}; + sample.constructor[Symbol.species] = other; + + var result = sample.slice(); + + assert(compareArray(result, arr), "values are set"); + assert.notSameValue(result.buffer, sample.buffer, "creates a new buffer"); + assert.sameValue(result.constructor, other, "used the custom ctor"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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/slice/BigInt/speciesctor-get-ctor-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000..54f18f7e15 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000..4d21693aff --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.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.slice +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + 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/slice/BigInt/speciesctor-get-ctor-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000..23f4362f5c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,65 @@ +// 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.slice +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.slice(); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.slice(); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js new file mode 100644 index 0000000000..ca47be61b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: get constructor on SpeciesConstructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + 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/slice/BigInt/speciesctor-get-species-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000..c7ac9ebbbc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.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.slice +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000..1473ac6565 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,61 @@ +// 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.slice +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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 result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.slice(1); + + assert.sameValue(result.length, 1, "called with 1 arguments"); + assert.sameValue(result[0], 2, "[0] is the new length count"); + + 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/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000..b04158435c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000..cc0710c91b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.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.slice +description: > + Does not throw a TypeError if new typedArray's length >= count +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length > count"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000..6958ed7c40 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.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.slice +description: > + Custom @@species constructor may return a totally different TypedArray +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(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/slice/BigInt/speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000..e7ba84ff89 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.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.slice +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000..4f0c14121e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Use custom @@species constructor if available +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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(count) { + calls++; + return new TA(count); + }; + + result = sample.slice(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41n, 42n]), "expected object"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000..79915087cd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,68 @@ +// 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.slice +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.slice(); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.slice(); + }, "true"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000..1d1a56e0fb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + 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.slice(); + + 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/slice/BigInt/speciesctor-get-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.js new file mode 100644 index 0000000000..91cc5e1409 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.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.slice +description: > + get @@species from found constructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + assert.sameValue(calls, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/tointeger-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/tointeger-end.js new file mode 100644 index 0000000000..9bcdadc845 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: ToInteger(end) +info: | + 22.2.3.24 %TypedArray%.prototype.slice( start , end ) + + ... + 6. If end is undefined, let relativeEnd be len; 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.slice(0, false), []), "false"); + assert(compareArray(sample.slice(0, true), [40n]), "true"); + + assert(compareArray(sample.slice(0, NaN), []), "NaN"); + assert(compareArray(sample.slice(0, null), []), "null"); + assert(compareArray(sample.slice(0, undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.slice(0, 0.6), []), "0.6"); + assert(compareArray(sample.slice(0, 1.1), [40n]), "1.1"); + assert(compareArray(sample.slice(0, 1.5), [40n]), "1.5"); + assert(compareArray(sample.slice(0, -0.6), []), "-0.6"); + assert(compareArray(sample.slice(0, -1.1), [40n, 41n, 42n]), "-1.1"); + assert(compareArray(sample.slice(0, -1.5), [40n, 41n, 42n]), "-1.5"); + + assert(compareArray(sample.slice(0, "3"), [40n, 41n, 42n]), "string"); + assert( + compareArray( + sample.slice(0, obj), + [40n, 41n] + ), + "object" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/tointeger-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/tointeger-start.js new file mode 100644 index 0000000000..fe474a8bcb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/BigInt/tointeger-start.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.slice +description: ToInteger(begin) +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +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.slice(false), [40n, 41n, 42n, 43n]), "false"); + assert(compareArray(sample.slice(true), [41n, 42n, 43n]), "true"); + + assert(compareArray(sample.slice(NaN), [40n, 41n, 42n, 43n]), "NaN"); + assert(compareArray(sample.slice(null), [40n, 41n, 42n, 43n]), "null"); + assert(compareArray(sample.slice(undefined), [40n, 41n, 42n, 43n]), "undefined"); + + assert(compareArray(sample.slice(1.1), [41n, 42n, 43n]), "1.1"); + assert(compareArray(sample.slice(1.5), [41n, 42n, 43n]), "1.5"); + assert(compareArray(sample.slice(0.6), [40n, 41n, 42n, 43n]), "0.6"); + + assert(compareArray(sample.slice(-1.5), [43n]), "-1.5"); + assert(compareArray(sample.slice(-1.1), [43n]), "-1.1"); + assert(compareArray(sample.slice(-0.6), [40n, 41n, 42n, 43n]), "-0.6"); + + assert(compareArray(sample.slice("3"), [43n]), "string"); + assert( + compareArray( + sample.slice(obj), + [42n, 43n] + ), + "object" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/arraylength-internal.js new file mode 100644 index 0000000000..6a7431fdd4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/arraylength-internal.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.slice +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.slice(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result.hasOwnProperty(2), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/bit-precision.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/bit-precision.js new file mode 100644 index 0000000000..1b4348e330 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/bit-precision.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.slice +description: Preservation of bit-level encoding +info: | + [...] + 15. Else if count > 0, then + [...] + e. NOTE: If srcType and targetType are the same, the transfer must be + performed in a manner that preserves the bit-level encoding of the + source data. + f. Let srcByteOffet be the value of O's [[ByteOffset]] internal slot. + g. Let targetByteIndex be A's [[ByteOffset]] internal slot. + h. Let srcByteIndex be (k × elementSize) + srcByteOffet. + i. Let limit be targetByteIndex + count × elementSize. + j. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + iii. Increase srcByteIndex by 1. + iv. Increase targetByteIndex by 1. +includes: [nans.js, compareArray.js, testTypedArray.js] +features: [TypedArray] +---*/ + +function body(FloatArray) { + var subject = new FloatArray(NaNs); + var sliced, subjectBytes, slicedBytes; + + sliced = subject.slice(); + + subjectBytes = new Uint8Array(subject.buffer); + slicedBytes = new Uint8Array(sliced.buffer); + + assert(compareArray(subjectBytes, slicedBytes)); +} + +testWithTypedArrayConstructors(body, [Float32Array, Float64Array]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.js new file mode 100644 index 0000000000..98e67832dd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-other-targettype.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.slice +description: > + Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached. Using other + targetType +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + Let A be ? TypedArraySpeciesCreate(O, « count »). + If count > 0, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + var sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + var other = TA === Int8Array ? Int16Array : Int8Array; + counter++; + $DETACHBUFFER(sample.buffer); + return new other(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.js new file mode 100644 index 0000000000..cff4bdfe80 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-custom-ctor-same-targettype.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.slice +description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached on Get custom constructor. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + Let A be ? TypedArraySpeciesCreate(O, « count »). + If count > 0, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + return new TA(count); + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-get-ctor.js new file mode 100644 index 0000000000..def685a2d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-get-ctor.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError if _O_.[[ViewedArrayBuffer]] is detached. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + Let A be ? TypedArraySpeciesCreate(O, « count »). + If count > 0, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + Object.defineProperty(sample, "constructor", { + get() { + counter++; + $DETACHBUFFER(sample.buffer); + } + }); + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000..bc4ddecd6e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError if buffer of object created by custom constructor is detached. +info: | + %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + + TypedArraySpeciesCreate ( exemplar, argumentList ) + + Let result be ? TypedArrayCreate(constructor, argumentList). + + TypedArrayCreate ( constructor, argumentList ) + + Let newTypedArray be ? Construct(constructor, argumentList). + Perform ? ValidateTypedArray(newTypedArray). + + ValidateTypedArray ( O ) + The abstract operation ValidateTypedArray takes argument O. It performs the following steps when called: + + Perform ? RequireInternalSlot(O, [[TypedArrayName]]). + Assert: O has a [[ViewedArrayBuffer]] internal slot. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + let other = new TA(count); + counter++; + $DETACHBUFFER(other.buffer); + return other; + }; + + assert.throws(TypeError, function() { + counter++; + sample.slice(); + }, '`sample.slice()` throws TypeError'); + + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.js new file mode 100644 index 0000000000..df223edad8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-other-targettype.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.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using other targetType. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, Other, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + Other = TA === Int16Array ? Int8Array : Int16Array; + $DETACHBUFFER(sample.buffer); + other = new Other(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result.constructor, Other, 'The value of result.constructor is expected to equal the value of Other'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + sample.slice(1, 1); // count = 0; + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js new file mode 100644 index 0000000000..d6e018010a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer-zero-count-custom-ctor-same-targettype.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + count <= 0. Using other targetType. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + Let A be ? TypedArraySpeciesCreate(O, « count »). + If count > 0, then + ... + Return A +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let sample, result, other; + let ctor = {}; + ctor[Symbol.species] = function(count) { + counter++; + $DETACHBUFFER(sample.buffer); + other = new TA(count); + return other; + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, 'The value of result.length is 0'); + assert.notSameValue(result.buffer, sample.buffer, 'The value of result.buffer is expected to not equal the value of `sample.buffer`'); + assert.sameValue(result, other, 'The value of `result` is expected to equal the value of other'); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + sample = new TA(4); + sample.constructor = ctor; + sample.slice(1, 1); // count = 0; + assert.sameValue(counter, 2, 'The value of `counter` is 2'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer.js new file mode 100644 index 0000000000..f89105dfce --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/detached-buffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.slice(obj, obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/infinity.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/infinity.js new file mode 100644 index 0000000000..4d4e53a76f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/infinity.js @@ -0,0 +1,31 @@ +// 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.slice +description: Infinity values on start and end +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.slice(-Infinity), [40, 41, 42, 43]), + "start == -Infinity" + ); + assert( + compareArray(sample.slice(Infinity), []), + "start == Infinity" + ); + assert( + compareArray(sample.slice(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.slice(0, Infinity), [40, 41, 42, 43]), + "end == Infinity" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/invoked-as-func.js new file mode 100644 index 0000000000..c41db512d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/invoked-as-func.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.23 %TypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Let valid be ValidateTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var slice = TypedArray.prototype.slice; + +assert.sameValue(typeof slice, 'function'); + +assert.throws(TypeError, function() { + slice(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/invoked-as-method.js new file mode 100644 index 0000000000..abbf41b1bb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/invoked-as-method.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.23 %TypedArray%.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. Let valid be ValidateTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.slice, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.slice(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/length.js new file mode 100644 index 0000000000..b4dc6292c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: > + %TypedArray%.prototype.slice.length is 2. +info: | + %TypedArray%.prototype.slice ( start, 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.slice.length, 2); + +verifyNotEnumerable(TypedArray.prototype.slice, "length"); +verifyNotWritable(TypedArray.prototype.slice, "length"); +verifyConfigurable(TypedArray.prototype.slice, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/minus-zero.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/minus-zero.js new file mode 100644 index 0000000000..cec3ea1260 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: -0 values on start and end +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([40, 41, 42, 43]); + + assert( + compareArray(sample.slice(-0), [40, 41, 42, 43]), + "start == -0" + ); + assert( + compareArray(sample.slice(-0, 4), [40, 41, 42, 43]), + "start == -0, end == length" + ); + assert( + compareArray(sample.slice(0, -0), []), + "start == 0, end == -0" + ); + assert( + compareArray(sample.slice(-0, -0), []), + "start == -0, end == -0" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/name.js new file mode 100644 index 0000000000..0065064c4f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: > + %TypedArray%.prototype.slice.name is "slice". +info: | + %TypedArray%.prototype.slice ( start, 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.slice.name, "slice"); + +verifyNotEnumerable(TypedArray.prototype.slice, "name"); +verifyNotWritable(TypedArray.prototype.slice, "name"); +verifyConfigurable(TypedArray.prototype.slice, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/not-a-constructor.js new file mode 100644 index 0000000000..c22277eea3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice 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.slice), + false, + 'isConstructor(TypedArray.prototype.slice) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.slice(); +}, '`let u8 = new Uint8Array(1); new u8.slice()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/prop-desc.js new file mode 100644 index 0000000000..7866448d95 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: > + "slice" 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, 'slice'); +verifyWritable(TypedArrayPrototype, 'slice'); +verifyConfigurable(TypedArrayPrototype, 'slice'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/result-does-not-copy-ordinary-properties.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/result-does-not-copy-ordinary-properties.js new file mode 100644 index 0000000000..ca5360e87e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Result does not import own properties +info: | + 22.2.3.24 %TypedArray%.prototype.slice( start , end ) +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([41, 42, 43, 44]); + sample.foo = 42; + + var result = sample.slice(); + 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/slice/results-with-different-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-different-length.js new file mode 100644 index 0000000000..21507d93fd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-different-length.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.slice +description: slice may return a new instance with a smaller length +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.slice(1), [41, 42, 43], "begin == 1"); + testRes(sample.slice(2), [42, 43], "begin == 2"); + testRes(sample.slice(3), [43], "begin == 3"); + + testRes(sample.slice(1, 4), [41, 42, 43], "begin == 1, end == length"); + testRes(sample.slice(2, 4), [42, 43], "begin == 2, end == length"); + testRes(sample.slice(3, 4), [43], "begin == 3, end == length"); + + testRes(sample.slice(0, 1), [40], "begin == 0, end == 1"); + testRes(sample.slice(0, 2), [40, 41], "begin == 0, end == 2"); + testRes(sample.slice(0, 3), [40, 41, 42], "begin == 0, end == 3"); + + testRes(sample.slice(-1), [43], "begin == -1"); + testRes(sample.slice(-2), [42, 43], "begin == -2"); + testRes(sample.slice(-3), [41, 42, 43], "begin == -3"); + + testRes(sample.slice(-1, 4), [43], "begin == -1, end == length"); + testRes(sample.slice(-2, 4), [42, 43], "begin == -2, end == length"); + testRes(sample.slice(-3, 4), [41, 42, 43], "begin == -3, end == length"); + + testRes(sample.slice(0, -1), [40, 41, 42], "begin == 0, end == -1"); + testRes(sample.slice(0, -2), [40, 41], "begin == 0, end == -2"); + testRes(sample.slice(0, -3), [40], "begin == 0, end == -3"); + + testRes(sample.slice(-0, -1), [40, 41, 42], "begin == -0, end == -1"); + testRes(sample.slice(-0, -2), [40, 41], "begin == -0, end == -2"); + testRes(sample.slice(-0, -3), [40], "begin == -0, end == -3"); + + testRes(sample.slice(-2, -1), [42], "length == 4, begin == -2, end == -1"); + testRes(sample.slice(1, -1), [41, 42], "length == 4, begin == 1, end == -1"); + testRes(sample.slice(1, -2), [41], "length == 4, begin == 1, end == -2"); + testRes(sample.slice(2, -1), [42], "length == 4, begin == 2, end == -1"); + + testRes(sample.slice(-1, 5), [43], "begin == -1, end > length"); + testRes(sample.slice(-2, 4), [42, 43], "begin == -2, end > length"); + testRes(sample.slice(-3, 4), [41, 42, 43], "begin == -3, end > length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-empty-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-empty-length.js new file mode 100644 index 0000000000..2b0610a11e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-empty-length.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.slice +description: slice may return a new empty instance +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.slice(4), "begin == length"); + testRes(sample.slice(5), "begin > length"); + + testRes(sample.slice(4, 4), "begin == length, end == length"); + testRes(sample.slice(5, 4), "begin > length, end == length"); + + testRes(sample.slice(4, 5), "begin == length, end > length"); + testRes(sample.slice(5, 5), "begin > length, end > length"); + + testRes(sample.slice(0, 0), "begin == 0, end == 0"); + testRes(sample.slice(-0, -0), "begin == -0, end == -0"); + testRes(sample.slice(1, 0), "begin > 0, end == 0"); + testRes(sample.slice(-1, 0), "being < 0, end == 0"); + + testRes(sample.slice(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.slice(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.slice(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.slice(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.slice(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.slice(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.slice(0, -4), "begin == 0, end == -length"); + testRes(sample.slice(-4, -4), "begin == -length, end == -length"); + testRes(sample.slice(-5, -4), "begin < -length, end == -length"); + + testRes(sample.slice(0, -5), "begin == 0, end < -length"); + testRes(sample.slice(-4, -5), "begin == -length, end < -length"); + testRes(sample.slice(-5, -5), "begin < -length, end < -length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-same-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-same-length.js new file mode 100644 index 0000000000..2d9cb4ac26 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/results-with-same-length.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: slice may return a new instance with the same length +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.slice(0), "begin == 0"); + testRes(sample.slice(-4), "begin == -srcLength"); + testRes(sample.slice(-5), "begin < -srcLength"); + + testRes(sample.slice(0, 4), "begin == 0, end == srcLength"); + testRes(sample.slice(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.slice(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.slice(0, 5), "begin == 0, end > srcLength"); + testRes(sample.slice(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.slice(-5, 5), "begin < -srcLength, end > srcLength"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-end-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-end-symbol.js new file mode 100644 index 0000000000..2d73a65949 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; 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.slice(0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-end.js new file mode 100644 index 0000000000..a0c21bf198 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 6. If end is undefined, let relativeEnd be len; 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.slice(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(0, o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-start-symbol.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-start-symbol.js new file mode 100644 index 0000000000..5e87198742 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-start-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.slice +description: Return abrupt from ToInteger(start), start is symbol +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.slice(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-start.js new file mode 100644 index 0000000000..5c9aa7c2d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-start.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.slice +description: Return abrupt from ToInteger(start) +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +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.slice(o1); + }); + + assert.throws(Test262Error, function() { + sample.slice(o2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..f2a0fa7b94 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Return abrupt when "this" value fails buffer boundary checks +includes: [testTypedArray.js] +features: [ArrayBuffer, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.slice, + 'function', + 'implements TypedArray.prototype.slice' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.slice(0); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.slice(0); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the slice operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.slice(0); + throw new Test262Error('slice completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/set-values-from-different-ctor-type.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/set-values-from-different-ctor-type.js new file mode 100644 index 0000000000..f9ad9584bd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/set-values-from-different-ctor-type.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.slice +description: > + Perform regular set if target's uses a different element type +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + 10. Let srcName be the String value of O's [[TypedArrayName]] internal slot. + 11. Let srcType be the String value of the Element Type value in Table 50 for + srcName. + 12. Let targetName be the String value of A's [[TypedArrayName]] internal + slot. + 13. Let targetType be the String value of the Element Type value in Table 50 + for targetName. + 14. If SameValue(srcType, targetType) is false, then + a. Let n be 0. + b. Repeat, while k < final + i. Let Pk be ! ToString(k). + ii. Let kValue be ? Get(O, Pk). + iii. Perform ? Set(A, ! ToString(n), kValue, true). + iv. Increase k by 1. + v. Increase n by 1. + ... + 16. Return A +includes: [testTypedArray.js, compareArray.js] +features: [Symbol.species, TypedArray] +---*/ + +var arr = [42, 43, 44]; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(arr); + var other = TA === Int8Array ? Uint8Array : Int8Array; + + sample.constructor = {}; + sample.constructor[Symbol.species] = other; + + var result = sample.slice(); + + assert(compareArray(result, arr), "values are set"); + assert.notSameValue(result.buffer, sample.buffer, "creates a new buffer"); + assert.sameValue(result.constructor, other, "used the custom ctor"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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/slice/speciesctor-get-ctor-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor-abrupt.js new file mode 100644 index 0000000000..dcf690fb8f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor-inherited.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor-inherited.js new file mode 100644 index 0000000000..66551be445 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor-inherited.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.slice +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + 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/slice/speciesctor-get-ctor-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 0000000000..6bb0dec7be --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,65 @@ +// 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.slice +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.slice(); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.slice(); + }, "symbol"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor.js new file mode 100644 index 0000000000..91abb251a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: get constructor on SpeciesConstructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + 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/slice/speciesctor-get-species-abrupt.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-abrupt.js new file mode 100644 index 0000000000..c5e87d9908 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-abrupt.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.slice +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-invocation.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 0000000000..ec10f87cec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,61 @@ +// 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.slice +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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 result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.slice(1); + + assert.sameValue(result.length, 1, "called with 1 arguments"); + assert.sameValue(result[0], 2, "[0] is the new length count"); + + 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/slice/speciesctor-get-species-custom-ctor-length-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 0000000000..c8544e8c00 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length-throws.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Throws a TypeError if new typedArray's length < count +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(); + }; + + assert.throws(TypeError, function() { + sample.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 0000000000..8b8f45205c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-length.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.slice +description: > + Does not throw a TypeError if new typedArray's length >= count +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + ... + 3. If argumentList is a List of a single Number, then + a. If the value of newTypedArray's [[ArrayLength]] internal slot < + argumentList[0], throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var customCount, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return new TA(customCount); + }; + + customCount = 2; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.slice(); + assert.sameValue(result.length, customCount, "length > count"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-returns-another-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 0000000000..fb5bf37410 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-returns-another-instance.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.slice +description: > + Custom @@species constructor may return a totally different TypedArray +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(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/slice/speciesctor-get-species-custom-ctor-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 0000000000..840a42a507 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor-throws.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.slice +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor.js new file mode 100644 index 0000000000..653a5aa24a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-custom-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Use custom @@species constructor if available +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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(count) { + calls++; + return new TA(count); + }; + + result = sample.slice(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, [41, 42]), "expected object"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-returns-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-returns-throws.js new file mode 100644 index 0000000000..c7a8bba242 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-returns-throws.js @@ -0,0 +1,68 @@ +// 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.slice +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.slice(); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.slice(); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.slice(); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.slice(); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.slice(); + }, "true"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-use-default-ctor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 0000000000..b50e582639 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species-use-default-ctor.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + 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.slice(); + + 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/slice/speciesctor-get-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species.js new file mode 100644 index 0000000000..0fd855cefd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/speciesctor-get-species.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.slice +description: > + get @@species from found constructor +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + + 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.slice(); + + assert.sameValue(calls, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/this-is-not-object.js new file mode 100644 index 0000000000..f47390fd8a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/this-is-not-object.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.slice +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var slice = TypedArray.prototype.slice; + +assert.throws(TypeError, function() { + slice.call(undefined, 0, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + slice.call(null, 0, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + slice.call(42, 0, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + slice.call("1", 0, 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + slice.call(true, 0, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + slice.call(false, 0, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + slice.call(s, 0, 0); +}, "this is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/this-is-not-typedarray-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000..8844744c09 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/this-is-not-typedarray-instance.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.slice +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var slice = TypedArray.prototype.slice; + +assert.throws(TypeError, function() { + slice.call({}, 0, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + slice.call([], 0, 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + slice.call(ab, 0, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + slice.call(dv, 0, 0); +}, "this is a DataView instance"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/tointeger-end.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/tointeger-end.js new file mode 100644 index 0000000000..ef3e1975d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/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.slice +description: ToInteger(end) +info: | + 22.2.3.24 %TypedArray%.prototype.slice( start , end ) + + ... + 6. If end is undefined, let relativeEnd be len; 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.slice(0, false), []), "false"); + assert(compareArray(sample.slice(0, true), [40]), "true"); + + assert(compareArray(sample.slice(0, NaN), []), "NaN"); + assert(compareArray(sample.slice(0, null), []), "null"); + assert(compareArray(sample.slice(0, undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.slice(0, 0.6), []), "0.6"); + assert(compareArray(sample.slice(0, 1.1), [40]), "1.1"); + assert(compareArray(sample.slice(0, 1.5), [40]), "1.5"); + assert(compareArray(sample.slice(0, -0.6), []), "-0.6"); + assert(compareArray(sample.slice(0, -1.1), [40, 41, 42]), "-1.1"); + assert(compareArray(sample.slice(0, -1.5), [40, 41, 42]), "-1.5"); + + assert(compareArray(sample.slice(0, "3"), [40, 41, 42]), "string"); + assert( + compareArray( + sample.slice(0, obj), + [40, 41] + ), + "object" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/slice/tointeger-start.js b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/tointeger-start.js new file mode 100644 index 0000000000..3ebf4087aa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/slice/tointeger-start.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.slice +description: ToInteger(begin) +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 4. Let relativeStart be ? ToInteger(start). + ... +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.slice(false), [40, 41, 42, 43]), "false"); + assert(compareArray(sample.slice(true), [41, 42, 43]), "true"); + + assert(compareArray(sample.slice(NaN), [40, 41, 42, 43]), "NaN"); + assert(compareArray(sample.slice(null), [40, 41, 42, 43]), "null"); + assert(compareArray(sample.slice(undefined), [40, 41, 42, 43]), "undefined"); + + assert(compareArray(sample.slice(1.1), [41, 42, 43]), "1.1"); + assert(compareArray(sample.slice(1.5), [41, 42, 43]), "1.5"); + assert(compareArray(sample.slice(0.6), [40, 41, 42, 43]), "0.6"); + + assert(compareArray(sample.slice(-1.5), [43]), "-1.5"); + assert(compareArray(sample.slice(-1.1), [43]), "-1.1"); + assert(compareArray(sample.slice(-0.6), [40, 41, 42, 43]), "-0.6"); + + assert(compareArray(sample.slice("3"), [43]), "string"); + assert( + compareArray( + sample.slice(obj), + [42, 43] + ), + "object" + ); +}); + +reportCompare(0, 0); |