diff options
author | Leo Balter <leonardo.balter@gmail.com> | 2018-02-09 13:39:06 -0500 |
---|---|---|
committer | Leo Balter <leonardo.balter@gmail.com> | 2018-02-15 16:45:06 -0500 |
commit | c1bc43b1b10ec9d7c83ebee2af1837b78b784e52 (patch) | |
tree | 88aa3d799434cef567d2b1a8682b4fd6990c23d3 /test | |
parent | 5722ac494b89135cdcc406ec9ca3362920129346 (diff) |
Restore original tests for TypedArrays and optimize files
- optimize file names
- BigInt folder for TAs.from and of
- copy tests preparing for bigint
- copy ta prototype methods for bigint
- Use an exclusive harness for bigint typedarrays
- add features
- use proper harness
- use preper harness
- Restore original tests for TypedArrays
- final fixes
- fix includes
Diffstat (limited to 'test')
1037 files changed, 33865 insertions, 370 deletions
diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/detached-buffer.js new file mode 100644 index 000000000..3bfba3440 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/detached-buffer.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-get-%typedarray%.prototype-@@tostringtag +description: The getter method does not throw with a detached buffer +info: | + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample[Symbol.toStringTag], TA.name); +}); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-accessor.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-accessor.js new file mode 100644 index 000000000..a7f843337 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-accessor.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.31 +description: > + Return undefined if this value does not have a [[TypedArrayName]] internal slot +info: | + 22.2.3.31 get %TypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(TypedArrayPrototype[Symbol.toStringTag], undefined); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-func.js new file mode 100644 index 000000000..fee58c92f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/invoked-as-func.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. +/*--- +es6id: 22.2.3.31 +description: If this value is not Object, return undefined. +info: | + 22.2.3.31 get %TypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + 2. If Type(O) is not Object, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter(), undefined); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/length.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/length.js new file mode 100644 index 000000000..6b8e035cd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/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. + +/*--- +es6id: 22.2.3.31 +description: > + get %TypedArray%.prototype [ @@toStringTag ].length is 0. +info: | + get %TypedArray%.prototype [ @@toStringTag ] + + 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, testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(TypedArray.prototype, Symbol.toStringTag); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/name.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/name.js new file mode 100644 index 000000000..9b9342a72 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/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. + +/*--- +es6id: 22.2.3.31 +description: > + get %TypedArray%.prototype [ @@toStringTag ].name is "get [Symbol.toStringTag]". +info: | + get %TypedArray%.prototype [ @@toStringTag ] + + 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, testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(TypedArray.prototype, Symbol.toStringTag); + +assert.sameValue(desc.get.name, "get [Symbol.toStringTag]"); + +verifyNotEnumerable(desc.get, "name"); +verifyNotWritable(desc.get, "name"); +verifyConfigurable(desc.get, "name"); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/prop-desc.js new file mode 100644 index 000000000..bae8ca763 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/prop-desc.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.31 +description: > + "@@toStringTag" property of TypedArrayPrototype +info: | + 22.2.3.31 get %TypedArray%.prototype [ @@toStringTag ] + + %TypedArray%.prototype[@@toStringTag] is an accessor property whose set + accessor function is undefined. + ... + + This property has the attributes { [[Enumerable]]: false, [[Configurable]]: + true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, Symbol.toStringTag +); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); +verifyNotEnumerable(TypedArrayPrototype, Symbol.toStringTag); +verifyConfigurable(TypedArrayPrototype, Symbol.toStringTag); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/return-typedarrayname.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/return-typedarrayname.js new file mode 100644 index 000000000..80a3116b8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/return-typedarrayname.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-get-%typedarray%.prototype-@@tostringtag +description: > + Return value from the [[TypedArrayName]] internal slot +info: | + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + ... + 4. Let name be the value of O's [[TypedArrayName]] internal slot. + 5. Assert: name is a String value. + 6. Return name. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA(); + assert.sameValue(ta[Symbol.toStringTag], TA.name, "property value"); +}); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-has-no-typedarrayname-internal.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-has-no-typedarrayname-internal.js new file mode 100644 index 000000000..9414c2d00 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-has-no-typedarrayname-internal.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype-@@tostringtag +description: > + Return undefined when `this` does not have a [[TypedArrayName]] internal slot +info: | + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, DataView, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call({}), undefined); +assert.sameValue(getter.call([]), undefined); +assert.sameValue(getter.call(new ArrayBuffer(8)), undefined); + +var ab = new ArrayBuffer(8); +var dv = new DataView(ab, 0, 1); +assert.sameValue(getter.call(dv), undefined); diff --git a/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-is-not-object.js new file mode 100644 index 000000000..1ae3cf292 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/Symbol.toStringTag/BigInt/this-is-not-object.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-get-%typedarray%.prototype-@@tostringtag +description: Return undefined when `this` is not Object +info: | + 22.2.3.32 get %TypedArray%.prototype [ @@toStringTag ] + + 1. Let O be the this value. + 2. If Type(O) is not Object, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, Symbol.toStringTag, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, Symbol.toStringTag +).get; + +assert.sameValue(getter.call(undefined), undefined, "this is undefined"); +assert.sameValue(getter.call(42), undefined, "this is 42"); +assert.sameValue(getter.call("foo"), undefined, "this is a string"); +assert.sameValue(getter.call(true), undefined, "this is true"); +assert.sameValue(getter.call(false), undefined, "this is false"); +assert.sameValue(getter.call(Symbol("s")), undefined, "this is a Symbol"); +assert.sameValue(getter.call(null), undefined, "this is null"); diff --git a/test/built-ins/TypedArray/prototype/buffer/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/buffer/BigInt/detached-buffer.js new file mode 100644 index 000000000..3332f1a6c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/buffer/BigInt/detached-buffer.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-get-%typedarray%.prototype.buffer +description: The getter method does not throw with a detached buffer +info: | + 22.2.3.1 get %TypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer, 0, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.buffer, buffer); +}, [BigInt64Array, BigUint64Array]); diff --git a/test/built-ins/TypedArray/prototype/buffer/BigInt/return-buffer.js b/test/built-ins/TypedArray/prototype/buffer/BigInt/return-buffer.js new file mode 100644 index 000000000..c49a8df0a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/buffer/BigInt/return-buffer.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.1 +description: > + Return buffer from [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.1 get %TypedArray%.prototype.buffer + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. Return buffer. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(TA.BYTES_PER_ELEMENT); + var ta = new TA(buffer); + + assert.sameValue(ta.buffer, buffer); +}, [BigInt64Array, BigUint64Array]); diff --git a/test/built-ins/TypedArray/prototype/byteLength/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/byteLength/BigInt/detached-buffer.js new file mode 100644 index 000000000..16cfcd434 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteLength/BigInt/detached-buffer.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-get-%typedarray%.prototype.bytelength +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.2 get %TypedArray%.prototype.byteLength + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteLength, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/byteLength/BigInt/return-bytelength.js b/test/built-ins/TypedArray/prototype/byteLength/BigInt/return-bytelength.js new file mode 100644 index 000000000..c60a40801 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteLength/BigInt/return-bytelength.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. +/*--- +es6id: 22.2.3.2 +description: > + Return value from [[ByteLength]] internal slot +info: | + 22.2.3.2 get %TypedArray%.prototype.byteLength + + ... + 6. Let size be the value of O's [[ByteLength]] internal slot. + 7. Return size. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bytesPerElement = TA.BYTES_PER_ELEMENT; + var ta1 = new TA(); + assert.sameValue(ta1.byteLength, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.byteLength, 42 * bytesPerElement); +}); diff --git a/test/built-ins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js new file mode 100644 index 000000000..74710e488 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteOffset/BigInt/detached-buffer.js @@ -0,0 +1,22 @@ +// 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-get-%typedarray%.prototype.byteoffset +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.3 get %TypedArray%.prototype.byteOffset + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(128); + var sample = new TA(buffer, 8, 1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.byteOffset, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js b/test/built-ins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.js new file mode 100644 index 000000000..692d5ee56 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/byteOffset/BigInt/return-byteoffset.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. +/*--- +es6id: 22.2.3.3 +description: > + Return value from [[ByteOffset]] internal slot +info: | + 22.2.3.3 get %TypedArray%.prototype.byteOffset + + ... + 6. Let offset be the value of O's [[ByteOffset]] internal slot. + 7. Return size. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.byteOffset, 0, "Regular typedArray"); + + var offset = 4 * TA.BYTES_PER_ELEMENT; + + var buffer1 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var ta2 = new TA(buffer1, offset); + assert.sameValue(ta2.byteOffset, offset, "TA(buffer, offset)"); + + var buffer2 = new ArrayBuffer(8 * TA.BYTES_PER_ELEMENT); + var sample = new TA(buffer2, offset); + var ta3 = new TA(sample); + assert.sameValue(ta3.byteOffset, 0, "TA(typedArray)"); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js new file mode 100644 index 000000000..709166c7e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-end.js @@ -0,0 +1,77 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + end argument is coerced to an integer values. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0, null), + convertToBigInt([0, 1, 2, 3]) + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0, NaN), + convertToBigInt([0, 1, 2, 3]) + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0, false), + convertToBigInt([0, 1, 2, 3]) + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0, true), + convertToBigInt([0, 0, 2, 3]) + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0, '-2'), + convertToBigInt([0, 0, 1, 3]) + ), + 'string "-2" value coerced to integer -2' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0, -2.5), + convertToBigInt([0, 0, 1, 3]) + ), + 'float -2.5 value coerced to integer -2' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js new file mode 100644 index 000000000..c91d0c883 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-start.js @@ -0,0 +1,92 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + start argument is coerced to an integer value. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, undefined), + convertToBigInt([0, 0, 1, 2]) + ), + 'undefined value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, false), + convertToBigInt([0, 0, 1, 2]) + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, NaN), + convertToBigInt([0, 0, 1, 2]) + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, null), + convertToBigInt([0, 0, 1, 2]) + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, true), + convertToBigInt([1, 2, 3, 3]) + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, '1'), + convertToBigInt([1, 2, 3, 3]) + ), + 'string "1" value coerced to 1' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0.5), + convertToBigInt([0, 0, 1, 2]) + ), + '0.5 float value coerced to integer 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 1.5), + convertToBigInt([1, 2, 3, 3]) + ), + '1.5 float value coerced to integer 1' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js new file mode 100644 index 000000000..7b7baf7d3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/coerced-values-target.js @@ -0,0 +1,92 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + target argument is coerced to an integer value. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(undefined, 1), + convertToBigInt([1, 2, 3, 3]) + ), + 'undefined value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(false, 1), + convertToBigInt([1, 2, 3, 3]) + ), + 'false value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(NaN, 1), + convertToBigInt([1, 2, 3, 3]) + ), + 'NaN value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(null, 1), + convertToBigInt([1, 2, 3, 3]) + ), + 'null value coerced to 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(true, 0), + convertToBigInt([0, 0, 1, 2]) + ), + 'true value coerced to 1' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin('1', 0), + convertToBigInt([0, 0, 1, 2]) + ), + 'string "1" value coerced to 1' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0.5, 1), + convertToBigInt([1, 2, 3, 3]) + ), + '0.5 float value coerced to integer 0' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1.5, 0), + convertToBigInt([0, 0, 1, 2]) + ), + '1.5 float value coerced to integer 1' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js new file mode 100644 index 000000000..0014ea674 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.copywithin +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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.copyWithin(obj, obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 000000000..0b02e6462 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/get-length-ignores-length-prop.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.copywithin +es6id: 22.2.3.5 +description: > + Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(); + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + } + }); + + assert.sameValue(sample.copyWithin(0, 0), sample); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/invoked-as-func.js new file mode 100644 index 000000000..9b2836c2d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.5 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var copyWithin = TypedArray.prototype.copyWithin; + +assert.sameValue(typeof copyWithin, 'function'); + +assert.throws(TypeError, function() { + copyWithin(); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/invoked-as-method.js new file mode 100644 index 000000000..fdc3f22eb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.5 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [, end ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.copyWithin, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.copyWithin(); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/length.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/length.js new file mode 100644 index 000000000..56ed9e312 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/length.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. + +/*--- +es6id: 22.2.3.5 +description: > + %TypedArray%.prototype.copyWithin.length is 2. +info: | + %TypedArray%.prototype.copyWithin (target, 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.copyWithin.length, 2); + +verifyNotEnumerable(TypedArray.prototype.copyWithin, "length"); +verifyNotWritable(TypedArray.prototype.copyWithin, "length"); +verifyConfigurable(TypedArray.prototype.copyWithin, "length"); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/name.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/name.js new file mode 100644 index 000000000..f1eaecc38 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.5 +description: > + %TypedArray%.prototype.copyWithin.name is "copyWithin". +info: | + %TypedArray%.prototype.copyWithin (target, 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.copyWithin.name, "copyWithin"); + +verifyNotEnumerable(TypedArray.prototype.copyWithin, "name"); +verifyNotWritable(TypedArray.prototype.copyWithin, "name"); +verifyConfigurable(TypedArray.prototype.copyWithin, "name"); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-end.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-end.js new file mode 100644 index 000000000..45fd8f36d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-end.js @@ -0,0 +1,95 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + Set values with negative end argument. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 1, -1), + convertToBigInt([1, 2, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 1, -1) -> [1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(2, 0, -1), + convertToBigInt([0, 1, 0, 1, 2]) + ), + '[0, 1, 2, 3, 4].copyWithin(2, 0, -1) -> [0, 1, 0, 1, 2]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(1, 2, -2), + convertToBigInt([0, 2, 2, 3, 4]) + ), + '[0, 1, 2, 3, 4].copyWithin(1, 2, -2) -> [0, 2, 2, 3, 4]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, -2, -1), + convertToBigInt([2, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, -2, -1) -> [2, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(2, -2, -1), + convertToBigInt([0, 1, 3, 3, 4]) + ), + '[0, 1, 2, 3, 4].copyWithin(2, -2, 1) -> [0, 1, 3, 3, 4]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-3, -2, -1), + convertToBigInt([0, 2, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(-3, -2, -1) -> [0, 2, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(-2, -3, -1), + convertToBigInt([0, 1, 2, 2, 3]) + ), + '[0, 1, 2, 3, 4].copyWithin(-2, -3, -1) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(-5, -2, -1), + convertToBigInt([3, 1, 2, 3, 4]) + ), + '[0, 1, 2, 3, 4].copyWithin(-5, -2, -1) -> [3, 1, 2, 3, 4]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js new file mode 100644 index 000000000..17c08eea3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-end.js @@ -0,0 +1,111 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + Set values with negative out of bounds end argument. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 8. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 1, -10), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 1, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(0, 1, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, -2, -10), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, -2, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(0, -2, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, -9, -10), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, -9, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(0, -9, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-3, -2, -10), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(-3, -2, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(-3, -2, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-7, -8, -9), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(-7, -8, -9) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(-7, -8, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js new file mode 100644 index 000000000..84ee0dcca --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-start.js @@ -0,0 +1,93 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + Set values with out of bounds negative start argument. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let + from be min(relativeStart, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, -10), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3]).copyWithin(0, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(0, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(2, -10), + convertToBigInt([0, 1, 0, 1, 2]) + ), + '[0, 1, 2, 3, 4]).copyWithin(2, -2) -> [0, 1, 0, 1, 2]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(2, -Infinity), + convertToBigInt([1, 2, 1, 2, 3]) + ), + '[1, 2, 3, 4, 5]).copyWithin(2, -Infinity) -> [1, 2, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(10, -10), + convertToBigInt([0, 1, 2, 3, 4]) + ), + '[0, 1, 2, 3, 4]).copyWithin(10, -10) -> [0, 1, 2, 3, 4]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(10, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5]).copyWithin(10, -Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-9, -10), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(-9, -10) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(-9, -Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.js new file mode 100644 index 000000000..613f4f50c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-out-of-bounds-target.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.copywithin +es6id: 22.2.3.5 +description: > + Set values with out of bounds negative target argument. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let + to be min(relativeTarget, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-10, 0), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(-10, 0) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(-Infinity, 0), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(-10, 2), + convertToBigInt([2, 3, 4, 3, 4]) + ), + '[0, 1, 2, 3, 4].copyWithin(-10, 2) -> [2, 3, 4, 3, 4]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(-Infinity, 2), + convertToBigInt([3, 4, 5, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) -> [3, 4, 5, 4, 5]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-start.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-start.js new file mode 100644 index 000000000..928d349d3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-start.js @@ -0,0 +1,77 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + Set values with negative start argument. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 6. If relativeStart < 0, let from be max((len + relativeStart), 0); else let + from be min(relativeStart, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, -1), + convertToBigInt([3, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, -1) -> [3, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(2, -2), + convertToBigInt([0, 1, 3, 4, 4]) + ), + '[0, 1, 2, 3, 4].copyWithin(2, -2) -> [0, 1, 3, 4, 4]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(1, -2), + convertToBigInt([0, 3, 4, 3, 4]) + ), + '[0, 1, 2, 3, 4].copyWithin(1, -2) -> [0, 3, 4, 3, 4]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-1, -2), + convertToBigInt([0, 1, 2, 2]) + ), + '[0, 1, 2, 3].copyWithin(-1, -2) -> [ 0, 1, 2, 2 ]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(-2, -3), + convertToBigInt([0, 1, 2, 2, 3]) + ), + '[0, 1, 2, 3, 4].copyWithin(-2, -3) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(-5, -2), + convertToBigInt([3, 4, 2, 3, 4]) + ), + '[0, 1, 2, 3, 4].copyWithin(-5, -2) -> [3, 4, 2, 3, 4]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-target.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-target.js new file mode 100644 index 000000000..e7e08504b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/negative-target.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.copywithin +es6id: 22.2.3.5 +description: > + Set values with negative target argument. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 4. If relativeTarget < 0, let to be max((len + relativeTarget), 0); else let + to be min(relativeTarget, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-1, 0), + convertToBigInt([0, 1, 2, 0]) + ), + '[0, 1, 2, 3].copyWithin(-1, 0) -> [0, 1, 2, 0]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4])).copyWithin(-2, 2), + convertToBigInt([0, 1, 2, 2, 3]) + ), + '[0, 1, 2, 3, 4].copyWithin(-2, 2) -> [0, 1, 2, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(-1, 2), + convertToBigInt([0, 1, 2, 2]) + ), + '[0, 1, 2, 3].copyWithin(-1, 2) -> [0, 1, 2, 2]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.js new file mode 100644 index 000000000..a921443c4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-end.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.copywithin +es6id: 22.2.3.5 +description: > + Max value of end position is the this.length. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 1, 6), + convertToBigInt([1, 2, 3, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 1, 6) -> [1, 2, 3, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(0, 1, Infinity), + convertToBigInt([2, 3, 4, 5, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(0, 1, Infinity) -> [2, 3, 4, 5, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4, 5])).copyWithin(1, 3, 6), + convertToBigInt([0, 3, 4, 5, 4, 5]) + ), + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) -> [0, 3, 4, 5, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(1, 3, Infinity), + convertToBigInt([1, 4, 5, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) -> [1, 4, 5, 4, 5]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js new file mode 100644 index 000000000..8782ea76a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-out-of-bounds-target-and-start.js @@ -0,0 +1,74 @@ +// 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.copywithin +es6id: 22.2.3.5 +description: > + Max values of target and start positions are this.length. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4, 5])).copyWithin(6, 0), + convertToBigInt([0, 1, 2, 3, 4, 5]) + ) + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(Infinity, 0), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4, 5])).copyWithin(0, 6), + convertToBigInt([0, 1, 2, 3, 4, 5]) + ) + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(0, Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(0, Infinity) -> [1, 2, 3, 4, 5]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4, 5])).copyWithin(6, 6), + convertToBigInt([0, 1, 2, 3, 4, 5]) + ) + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4, 5])).copyWithin(10, 10), + convertToBigInt([0, 1, 2, 3, 4, 5]) + ) + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5])).copyWithin(Infinity, Infinity), + convertToBigInt([1, 2, 3, 4, 5]) + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) -> [1, 2, 3, 4, 5]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-start.js new file mode 100644 index 000000000..f958bc6e0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-and-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.copywithin +es6id: 22.2.3.5 +description: > + Copy values with non-negative target and start positions. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5, 6])).copyWithin(0, 0), + convertToBigInt([1, 2, 3, 4, 5, 6]) + ) + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5, 6])).copyWithin(0, 2), + convertToBigInt([3, 4, 5, 6, 5, 6]) + ) + ); + + assert( + compareArray( + new TA(convertToBigInt([1, 2, 3, 4, 5, 6])).copyWithin(3, 0), + convertToBigInt([1, 2, 3, 1, 2, 3]) + ) + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4, 5])).copyWithin(1, 4), + convertToBigInt([0, 4, 5, 3, 4, 5]) + ) + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js new file mode 100644 index 000000000..cda7b0e03 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/non-negative-target-start-and-end.js @@ -0,0 +1,73 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.copywithin +es6id: 22.2.3.5 +description: > + Copy values with non-negative target, start and end positions. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 0, 0), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 0, 0) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 0, 2), + convertToBigInt([0, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 0, 2) -> [0, 1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 1, 2), + convertToBigInt([1, 1, 2, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 1, 2) -> [1, 1, 2, 3]' + ); + + /* + * 10. If from<to and to<from+count, then + * a. Let direction be - 1. + * b. Let from be from + count - 1. + * c. Let to be to + count - 1. + * + * 0 < 1, 1 < 0 + 2 + * direction = -1 + * from = 0 + 2 - 1 + * to = 1 + 2 - 1 + */ + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(1, 0, 2), + convertToBigInt([0, 0, 1, 3]) + ), + '[0, 1, 2, 3].copyWithin(1, 0, 2) -> [0, 0, 1, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3, 4, 5])).copyWithin(1, 3, 5), + convertToBigInt([0, 3, 4, 3, 4, 5]) + ), + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 5) -> [0, 3, 4, 3, 4, 5]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/prop-desc.js new file mode 100644 index 000000000..c3e90369a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.5 +description: > + "copyWithin" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'copyWithin'); +verifyWritable(TypedArrayPrototype, 'copyWithin'); +verifyConfigurable(TypedArrayPrototype, 'copyWithin'); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.js new file mode 100644 index 000000000..adcbf5318 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end-is-symbol.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.copywithin +es6id: 22.2.3.5 +description: > + Return abrupt if end is a Symbol. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. 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.copyWithin(0, 0, s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.js new file mode 100644 index 000000000..bd4fd5bc1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-end.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.copywithin +es6id: 22.2.3.5 +description: > + Return abrupt from ToInteger(end). +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var o1 = { + valueOf: function() { + throw new Test262Error(); + } + }; + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(0, 0, o1); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.js new file mode 100644 index 000000000..196600a8a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start-is-symbol.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.copywithin +es6id: 22.2.3.5 +description: > + Return abrupt if start is a Symbol. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. 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.copyWithin(0, s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.js new file mode 100644 index 000000000..788473453 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-start.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.copywithin +es6id: 22.2.3.5 +description: > + Return abrupt from ToInteger(start). +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 5. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var err = { + valueOf: function() { + throw new Error("ToInteger(start) runs before ToInteger(end)"); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(0, o, err); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.js new file mode 100644 index 000000000..20e8bf58a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target-is-symbol.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.copywithin +es6id: 22.2.3.5 +description: > + Return abrupt if target is a Symbol. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.copyWithin(s, 0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.js new file mode 100644 index 000000000..9c8b00b4c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-abrupt-from-target.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.copywithin +es6id: 22.2.3.5 +description: > + Return abrupt from ToInteger(target). +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 3. Let relativeTarget be ? ToInteger(target). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.copyWithin(o); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-this.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-this.js new file mode 100644 index 000000000..62a3f69a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/return-this.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.copywithin +es6id: 22.2.3.5 +description: > + Returns `this`. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + 13. Return O. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(); + var result1 = sample1.copyWithin(0, 0); + + assert.sameValue(result1, sample1); + + var sample2 = new TA(convertToBigInt([1, 2, 3])); + var result2 = sample2.copyWithin(1, 0); + + assert.sameValue(result2, sample2); +}); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/this-is-not-object.js new file mode 100644 index 000000000..3c1b7c435 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/this-is-not-object.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.copywithin +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var copyWithin = TypedArray.prototype.copyWithin; + +assert.throws(TypeError, function() { + copyWithin.call(undefined, 0, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + copyWithin.call(null, 0, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + copyWithin.call(42, 0, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + copyWithin.call("1", 0, 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + copyWithin.call(true, 0, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + copyWithin.call(false, 0, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + copyWithin.call(s, 0, 0); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..95d9bfd12 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.copywithin +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var copyWithin = TypedArray.prototype.copyWithin; + +assert.throws(TypeError, function() { + copyWithin.call({}, 0, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + copyWithin.call([], 0, 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + copyWithin.call(ab, 0, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + copyWithin.call(dv, 0, 0); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js new file mode 100644 index 000000000..3a0d5df7d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/copyWithin/BigInt/undefined-end.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.copywithin +es6id: 22.2.3.5 +description: > + If `end` is undefined, set final position to `this.length`. +info: | + 22.2.3.5 %TypedArray%.prototype.copyWithin (target, start [ , end ] ) + + %TypedArray%.prototype.copyWithin is a distinct function that implements the + same algorithm as Array.prototype.copyWithin as defined in 22.1.3.3 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length" and the actual copying of values in step 12 + must be performed in a manner that preserves the bit-level encoding of the + source data. + + ... + + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 7. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 1, undefined), + convertToBigInt([1, 2, 3, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 1, undefined) -> [1, 2, 3]' + ); + + assert( + compareArray( + new TA(convertToBigInt([0, 1, 2, 3])).copyWithin(0, 1), + convertToBigInt([1, 2, 3, 3]) + ), + '[0, 1, 2, 3].copyWithin(0, 1) -> [1, 2, 3, 3]' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/entries/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/entries/BigInt/detached-buffer.js new file mode 100644 index 000000000..ead1ec4bf --- /dev/null +++ b/test/built-ins/TypedArray/prototype/entries/BigInt/detached-buffer.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.entries +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.6 %TypedArray%.prototype.entries ( ) + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.entries(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/entries/BigInt/iter-prototype.js b/test/built-ins/TypedArray/prototype/entries/BigInt/iter-prototype.js new file mode 100644 index 000000000..ae795bb04 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/entries/BigInt/iter-prototype.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.6 +esid: sec-%typedarray%.prototype.entries +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.6 %TypedArray%.prototype.entries ( ) + + ... + 3. Return CreateArrayIterator(O, "key+value"). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([0, 42, 64])); + var iter = sample.entries(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/built-ins/TypedArray/prototype/entries/BigInt/return-itor.js b/test/built-ins/TypedArray/prototype/entries/BigInt/return-itor.js new file mode 100644 index 000000000..2c2b47cd4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/entries/BigInt/return-itor.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. +/*--- +es6id: 22.2.3.6 +esid: sec-%typedarray%.prototype.entries +description: Return an iterator for the entries. +info: | + 22.2.3.6 %TypedArray%.prototype.entries ( ) + + ... + 3. Return CreateArrayIterator(O, "key+value"). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var sample = [0, 42, 64]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(convertToBigInt(sample)); + var itor = typedArray.entries(); + + var next = itor.next(); + assert(compareArray(next.value, [0, convertToBigInt(0)])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert(compareArray(next.value, [1, convertToBigInt(42)])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert(compareArray(next.value, [2, convertToBigInt(64)])); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 000000000..e6a878b01 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-with-thisarg.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.every +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.every(function() { + results.push(arguments); + return true; + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 000000000..1f2dce111 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-arguments-without-thisarg.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.every +description: > + callbackfn arguments +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 000000000..13660264f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-detachbuffer.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.every +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.every(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + return true; + }); + }); + + assert.sameValue(loops, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 000000000..678605aef --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-no-interaction-over-non-integer.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.every +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.every(function() { + results.push(arguments); + return true; + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], convertToBigInt(7), "results[0][0] - value"); + assert.sameValue(results[1][0], convertToBigInt(8), "results[1][0] - value"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 000000000..49827a5ca --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,69 @@ +// 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.every +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.every(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.every(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.every(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.every("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.every(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.every(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.every(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.every(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.every({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.every(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.every(Symbol("1")); + }, "symbol"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 000000000..07c599fd7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-not-called-on-empty.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.every +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().every(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 000000000..b46f77ad0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,38 @@ +// 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.every +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42])); + + sample.every(function() { + return 43; + }); + + assert.sameValue(sample[0], convertToBigInt(40), "[0] == 40"); + assert.sameValue(sample[1], convertToBigInt(41), "[1] == 41"); + assert.sameValue(sample[2], convertToBigInt(42), "[2] == 42"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 000000000..d165d7be7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-returns-abrupt.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.every +description: Returns abrupt from callbackfn +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.every(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 000000000..8949bb2f1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,58 @@ +// 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.every +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + var newVal = 0; + + sample.every(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], convertToBigInt(newVal - 1), + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, convertToBigInt(7)), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, convertToBigInt(newVal)), + true, + "set value during iteration" + ); + + newVal++; + + return true; + }); + + assert.sameValue(sample[0], convertToBigInt(7), "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], convertToBigInt(1), "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], convertToBigInt(2), "changed values after iteration [2] == 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-this.js b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-this.js new file mode 100644 index 000000000..589cfec30 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/callbackfn-this.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.every +description: > + callbackfn `this` value +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.every(function() { + results1.push(this); + return true; + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.every(function() { + results2.push(this); + return true; + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/every/BigInt/detached-buffer.js new file mode 100644 index 000000000..5c622dc6a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/detached-buffer.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.every +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.every(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..af887bf1e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/get-length-uses-internal-arraylength.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.every +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +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(convertToBigInt([42, 43])); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.every(function() { + calls++; + return true; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/every/BigInt/invoked-as-func.js new file mode 100644 index 000000000..1ae892380 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.7 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var every = TypedArray.prototype.every; + +assert.sameValue(typeof every, 'function'); + +assert.throws(TypeError, function() { + every(); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/every/BigInt/invoked-as-method.js new file mode 100644 index 000000000..24d9fd6fd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.7 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.every, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.every(); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/length.js b/test/built-ins/TypedArray/prototype/every/BigInt/length.js new file mode 100644 index 000000000..ee523a260 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/length.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. + +/*--- +es6id: 22.2.3.7 +description: > + %TypedArray%.prototype.every.length is 1. +info: | + %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.every.length, 1); + +verifyNotEnumerable(TypedArray.prototype.every, "length"); +verifyNotWritable(TypedArray.prototype.every, "length"); +verifyConfigurable(TypedArray.prototype.every, "length"); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/name.js b/test/built-ins/TypedArray/prototype/every/BigInt/name.js new file mode 100644 index 000000000..0bd6cc255 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.7 +description: > + %TypedArray%.prototype.every.name is "every". +info: | + %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.every.name, "every"); + +verifyNotEnumerable(TypedArray.prototype.every, "name"); +verifyNotWritable(TypedArray.prototype.every, "name"); +verifyConfigurable(TypedArray.prototype.every, "name"); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/every/BigInt/prop-desc.js new file mode 100644 index 000000000..cd6a80a3a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.7 +description: > + "every" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'every'); +verifyWritable(TypedArrayPrototype, 'every'); +verifyConfigurable(TypedArrayPrototype, 'every'); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js b/test/built-ins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.js new file mode 100644 index 000000000..8271e5109 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/returns-false-if-any-cb-returns-false.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.every +description: > + Returns false if any callbackfn call returns a coerced false. +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.every(function() { + called++; + if (called === 1) { + return true; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called until it returned " + val); + assert.sameValue(result, false, "result is false when it returned " + val); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js b/test/built-ins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.js new file mode 100644 index 000000000..761b8784b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/returns-true-if-every-cb-returns-true.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.every +description: > + Returns true if every callbackfn returns a coerced true. +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + var values = [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ]; + var sample = new TA(values.length); + var result = sample.every(function() { + called++; + return values.unshift(); + }); + + assert.sameValue(called, sample.length, "callbackfn called for each index"); + assert.sameValue(result, true, "return is true"); +}); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/every/BigInt/this-is-not-object.js new file mode 100644 index 000000000..af9557ea0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/this-is-not-object.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.every +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var every = TypedArray.prototype.every; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + every.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + every.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + every.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + every.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + every.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + every.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + every.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/every/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..21ff576b5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/this-is-not-typedarray-instance.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.every +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var every = TypedArray.prototype.every; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + every.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + every.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + every.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + every.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/every/BigInt/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/every/BigInt/values-are-not-cached.js new file mode 100644 index 000000000..5be553d1d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/every/BigInt/values-are-not-cached.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.every +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.7 %TypedArray%.prototype.every ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.every is a distinct function that implements the same + algorithm as Array.prototype.every as defined in 22.1.3.5 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.5 Array.prototype.every ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + sample.every(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = convertToBigInt(42); + } + + assert.sameValue( + v, convertToBigInt(42), "method does not cache values before callbackfn calls" + ); + return true; + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/coerced-indexes.js b/test/built-ins/TypedArray/prototype/fill/BigInt/coerced-indexes.js new file mode 100644 index 000000000..9a53f55a4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/coerced-indexes.js @@ -0,0 +1,104 @@ +// 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.fill +es6id: 22.2.3.8 +description: > + Fills elements from coerced to Integer `start` and `end` values +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), undefined), convertToBigInt([1, 1])), + '`undefined` start coerced to 0' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 0, undefined), convertToBigInt([1, 1])), + 'If end is undefined, let relativeEnd be len' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), null), convertToBigInt([1, 1])), + '`null` start coerced to 0' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 0, null), convertToBigInt([0, 0])), + '`null` end coerced to 0' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), true), convertToBigInt([0, 1])), + '`true` start coerced to 1' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 0, true), convertToBigInt([1, 0])), + '`true` end coerced to 1' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), false), convertToBigInt([1, 1])), + '`false` start coerced to 0' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 0, false), convertToBigInt([0, 0])), + '`false` end coerced to 0' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), NaN), convertToBigInt([1, 1])), + '`NaN` start coerced to 0' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 0, NaN), convertToBigInt([0, 0])), + '`NaN` end coerced to 0' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), '1'), convertToBigInt([0, 1])), + 'string start coerced' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 0, '1'), convertToBigInt([1, 0])), + 'string end coerced' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 1.5), convertToBigInt([0, 1])), + 'start as a float number coerced' + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0])).fill(convertToBigInt(1), 0, 1.5), convertToBigInt([1, 0])), + 'end as a float number coerced' + ); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/fill/BigInt/detached-buffer.js new file mode 100644 index 000000000..96e7980ac --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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.fill(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js new file mode 100644 index 000000000..f26998f76 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-once.js @@ -0,0 +1,27 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +description: > + Fills all the elements with non numeric values values. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let _value_ be ? ToNumber(_value_). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + var n = 1; + sample.fill({ valueOf() { return convertToBigInt(n++); } }); + + assert.sameValue(n, 2, "additional unexpected ToNumber() calls"); + assert.sameValue(sample[0], convertToBigInt(1), "incorrect ToNumber result in index 0"); + assert.sameValue(sample[1], convertToBigInt(1), "incorrect ToNumber result in index 1"); +}); + diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-operations-consistent-nan.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-operations-consistent-nan.js new file mode 100644 index 000000000..827dc9344 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-operations-consistent-nan.js @@ -0,0 +1,70 @@ +// 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.fill +es6id: 22.2.3.8 +description: Consistent canonicalization of NaN values +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + 9. Else, if type is "Float64", then + a. Set rawBytes to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of value. If isLittleEndian is false, + the bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + ... +includes: [nans.js, testBigIntTypedArray.js, compareArray.js] +---*/ + +function body(FloatArray) { + var sample = new FloatArray(3); + var control, idx, someNaN, sampleBytes, controlBytes; + + for (idx = 0; idx < distinctNaNs.length; ++idx) { + someNaN = distinctNaNs[idx]; + control = new FloatArray([someNaN, someNaN, someNaN]); + + sample.fill(someNaN); + + sampleBytes = new Uint8Array(sample.buffer); + controlBytes = new Uint8Array(control.buffer); + assert(compareArray(sampleBytes, controlBytes), 'NaN value #' + idx); + } +} + +testWithBigIntTypedArrayConstructors(body, [Float32Array, Float64Array]); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-operations.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-operations.js new file mode 100644 index 000000000..40e9e3fe9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-conversion-operations.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.fill +es6id: 22.2.3.8 +description: > + Fills all the elements with non numeric values values. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testBigIntTypedArray.js] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample.fill(value); + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-custom-start-and-end.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-custom-start-and-end.js new file mode 100644 index 000000000..48602ea11 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-custom-start-and-end.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +es6id: 22.2.3.8 +description: > + Fills all the elements from a with a custom start and end indexes. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert(compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), 1, 2), convertToBigInt([0, 8, 0]))); + assert(compareArray(new TA(convertToBigInt([0, 0, 0, 0, 0])).fill(convertToBigInt(8), -3, 4), convertToBigInt([0, 0, 8, 8, 0]))); + assert(compareArray(new TA(convertToBigInt([0, 0, 0, 0, 0])).fill(convertToBigInt(8), -2, -1), convertToBigInt([0, 0, 0, 8, 0]))); + assert(compareArray(new TA(convertToBigInt([0, 0, 0, 0, 0])).fill(convertToBigInt(8), -1, -3), convertToBigInt([0, 0, 0, 0, 0]))); + assert(compareArray(new TA(convertToBigInt([0, 0, 0, 0, 0])).fill(convertToBigInt(8), 1, 3), convertToBigInt([0, 8, 8, 0, 0]))); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js new file mode 100644 index 000000000..c4a97bfc9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-non-numeric.js @@ -0,0 +1,73 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +es6id: 22.2.3.8 +description: > + Fills all the elements with non numeric values values. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42])); + sample.fill(false); + assert.sameValue(sample[0], convertToBigInt(0), "false => 0"); + + sample = new TA(convertToBigInt([42])); + sample.fill(true); + assert.sameValue(sample[0], convertToBigInt(1), "true => 1"); + + sample = new TA(convertToBigInt([42])); + sample.fill("7"); + assert.sameValue(sample[0], convertToBigInt(7), "string conversion"); + + sample = new TA(convertToBigInt([42])); + sample.fill({ + toString: function() { + return "1"; + }, + valueOf: function() { + return convertToBigInt(7); + } + }); + assert.sameValue(sample[0], convertToBigInt(7), "object valueOf conversion before toString"); + + sample = new TA(convertToBigInt([42])); + sample.fill({ + toString: function() { + return "7"; + } + }); + assert.sameValue(sample[0], convertToBigInt(7), "object toString when valueOf is absent"); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-relative-end.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-relative-end.js new file mode 100644 index 000000000..b5bbe59da --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-relative-end.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.fill +es6id: 22.2.3.8 +description: > + Fills all the elements from a with a custom end index. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + 6. If relativeEnd < 0, let final be max((len + relativeEnd), 0); else let + final be min(relativeEnd, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), 0, 1), convertToBigInt([8, 0, 0])), + "Fill elements from custom end position" + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), 0, -1), convertToBigInt([8, 8, 0])), + "negative end sets final position to max((length + relativeEnd), 0)" + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), 0, 5), convertToBigInt([8, 8, 8])), + "end position is never higher than of length" + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), 0, -4), convertToBigInt([0, 0, 0])), + "end position is 0 when (len + relativeEnd) < 0" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-relative-start.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-relative-start.js new file mode 100644 index 000000000..674cf1490 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-relative-start.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.fill +es6id: 22.2.3.8 +description: > + Fills all the elements from a with a custom start index. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 4. If relativeStart < 0, let k be max((len + relativeStart), 0); else let k be + min(relativeStart, len). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), 1), convertToBigInt([0, 8, 8])), + "Fill elements from custom start position" + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), 4), convertToBigInt([0, 0, 0])), + "start position is never higher than length" + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), -1), convertToBigInt([0, 0, 8])), + "start < 0 sets initial position to max((len + relativeStart), 0)" + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8), -5), convertToBigInt([8, 8, 8])), + "start position is 0 when (len + relativeStart) < 0" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-symbol-throws.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-symbol-throws.js new file mode 100644 index 000000000..687db856d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values-symbol-throws.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +es6id: 22.2.3.8 +description: > + Throws a TypeError if value is a Symbol +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol('1'); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.fill(s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values.js b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values.js new file mode 100644 index 000000000..83a2bbd7a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/fill-values.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.fill +es6id: 22.2.3.8 +description: > + Fills all the elements with `value` from a default start and index. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert( + compareArray( + new TA().fill(convertToBigInt(8)), + [] + ), + "does not fill an empty instance" + ); + + assert( + compareArray(new TA(convertToBigInt([0, 0, 0])).fill(convertToBigInt(8)), convertToBigInt([8, 8, 8])), + "Default start and end indexes are 0 and this.length" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/get-length-ignores-length-prop.js b/test/built-ins/TypedArray/prototype/fill/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 000000000..36ca60566 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/get-length-ignores-length-prop.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.fill +es6id: 22.2.3.8 +description: > + Unreachable abrupt from Get(O, "length") as [[ArrayLength]] is returned. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(1); + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + } + }); + + assert.sameValue(sample.fill(convertToBigInt(1), 0), sample); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/fill/BigInt/invoked-as-func.js new file mode 100644 index 000000000..363ba5180 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.8 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fill = TypedArray.prototype.fill; + +assert.sameValue(typeof fill, 'function'); + +assert.throws(TypeError, function() { + fill(); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/fill/BigInt/invoked-as-method.js new file mode 100644 index 000000000..20dc89a17 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.8 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.fill, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.fill(); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/length.js b/test/built-ins/TypedArray/prototype/fill/BigInt/length.js new file mode 100644 index 000000000..17bf26159 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/length.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. + +/*--- +es6id: 22.2.3.8 +description: > + %TypedArray%.prototype.fill.length is 1. +info: | + %TypedArray%.prototype.fill (value [ , 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.fill.length, 1); + +verifyNotEnumerable(TypedArray.prototype.fill, "length"); +verifyNotWritable(TypedArray.prototype.fill, "length"); +verifyConfigurable(TypedArray.prototype.fill, "length"); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/name.js b/test/built-ins/TypedArray/prototype/fill/BigInt/name.js new file mode 100644 index 000000000..99c9ec2b4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.8 +description: > + %TypedArray%.prototype.fill.name is "fill". +info: | + %TypedArray%.prototype.fill (value [ , 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.fill.name, "fill"); + +verifyNotEnumerable(TypedArray.prototype.fill, "name"); +verifyNotWritable(TypedArray.prototype.fill, "name"); +verifyConfigurable(TypedArray.prototype.fill, "name"); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/fill/BigInt/prop-desc.js new file mode 100644 index 000000000..b3f039205 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.8 +description: > + "fill" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'fill'); +verifyWritable(TypedArrayPrototype, 'fill'); +verifyConfigurable(TypedArrayPrototype, 'fill'); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end-as-symbol.js b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end-as-symbol.js new file mode 100644 index 000000000..1ad1b898c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end-as-symbol.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +es6id: 22.2.3.8 +description: > + Return abrupt if end is a Symbol. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var end = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.fill(1, 0, end); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end.js b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end.js new file mode 100644 index 000000000..3a2aa9285 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-end.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.fill +es6id: 22.2.3.8 +description: > + Return abrupt from ToInteger(end). +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 5. If end is undefined, let relativeEnd be len; else let relativeEnd be ? + ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var end = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.fill(convertToBigInt(1), 0, end); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-set-value.js b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-set-value.js new file mode 100644 index 000000000..5133dac24 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-set-value.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.fill +es6id: 22.2.3.8 +description: > + Returns abrupt from value set +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 7. Repeat, while k < final + a. Let Pk be ! ToString(k). + b. Perform ? Set(O, Pk, value, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + var obj = { + valueOf: function() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample.fill(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start-as-symbol.js b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start-as-symbol.js new file mode 100644 index 000000000..69749d03c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start-as-symbol.js @@ -0,0 +1,38 @@ +// 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.fill +es6id: 22.2.3.8 +description: > + Return abrupt from ToInteger(start) as a Symbol. +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var start = Symbol(1); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.fill(1, start); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start.js b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start.js new file mode 100644 index 000000000..37bed7f7a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/return-abrupt-from-start.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +es6id: 22.2.3.8 +description: > + Return abrupt from ToInteger(start). +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + %TypedArray%.prototype.fill is a distinct function that implements the same + algorithm as Array.prototype.fill as defined in 22.1.3.6 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. However, such optimization + must not introduce any observable changes in the specified behaviour of the + algorithm. + + ... + + 22.1.3.6 Array.prototype.fill (value [ , start [ , end ] ] ) + + ... + 3. Let relativeStart be ? ToInteger(start). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var start = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(Test262Error, function() { + sample.fill(convertToBigInt(1), start); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/return-this.js b/test/built-ins/TypedArray/prototype/fill/BigInt/return-this.js new file mode 100644 index 000000000..b9b93eed4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/return-this.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.fill +es6id: 22.2.3.8 +description: > + Returns `this`. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(); + var result1 = sample1.fill(convertToBigInt(1)); + + assert.sameValue(result1, sample1); + + var sample2 = new TA(42); + var result2 = sample2.fill(convertToBigInt(7)); + assert.sameValue(result2, sample2); +}); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/fill/BigInt/this-is-not-object.js new file mode 100644 index 000000000..5846bbcae --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/this-is-not-object.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.fill +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fill = TypedArray.prototype.fill; + +assert.throws(TypeError, function() { + fill.call(undefined, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + fill.call(null, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + fill.call(42, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + fill.call("1", 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + fill.call(true, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + fill.call(false, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + fill.call(s, 0); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/fill/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/fill/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..8cb012108 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/fill/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.fill +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.8 %TypedArray%.prototype.fill (value [ , start [ , end ] ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fill = TypedArray.prototype.fill; + +assert.throws(TypeError, function() { + fill.call({}, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + fill.call([], 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + fill.call(ab, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + fill.call(dv, 0); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/fill/fill-values-non-numeric.js b/test/built-ins/TypedArray/prototype/fill/fill-values-non-numeric.js index 0b935fd44..52b4e53c4 100644 --- a/test/built-ins/TypedArray/prototype/fill/fill-values-non-numeric.js +++ b/test/built-ins/TypedArray/prototype/fill/fill-values-non-numeric.js @@ -40,11 +40,9 @@ features: [TypedArray] testWithTypedArrayConstructors(function(TA, N) { var sample; - if (numericTypedArrayConstructors.includes(TA)) { - sample = new TA(N([42])); - sample.fill(null); - assert.sameValue(sample[0], 0, "null => 0"); - } + sample = new TA(N([42])); + sample.fill(null); + assert.sameValue(sample[0], 0, "null => 0"); sample = new TA(N([42])); sample.fill(false); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/arraylength-internal.js b/test/built-ins/TypedArray/prototype/filter/BigInt/arraylength-internal.js new file mode 100644 index 000000000..ecd36aa8a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/arraylength-internal.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: Uses internal ArrayLength instead of length property +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 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(4); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 4, "interactions are not affected by custom length"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-with-thisarg.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 000000000..d0d796be5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.filter(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-without-thisarg.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 000000000..ca3e078d2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + callbackfn arguments +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.filter(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-ctor.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-ctor.js new file mode 100644 index 000000000..56c07c040 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-ctor.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: callbackfn is called for each item before TypedArraySpeciesCreate +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var length = 42; + var sample = new TA(length); + var calls = 0; + var before = false; + + sample.constructor = {}; + Object.defineProperty(sample, "constructor", { + get: function() { + before = calls === length; + } + }); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(calls, 42, "callbackfn called for each item"); + assert.sameValue(before, true, "all callbackfn called before"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-species.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-species.js new file mode 100644 index 000000000..e99e1b715 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-called-before-species.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: callbackfn is called for each item before TypedArraySpeciesCreate +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var length = 42; + var sample = new TA(length); + var calls = 0; + var before = false; + + sample.constructor = {}; + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + before = calls === length; + } + }); + + sample.filter(function() { + calls++; + }); + + assert.sameValue(calls, 42, "callbackfn called for each item"); + assert.sameValue(before, true, "all callbackfn called before"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 000000000..ff563cd3a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.filter(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + }); + }); + + assert.sameValue(loops, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-no-iteration-over-non-integer.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-no-iteration-over-non-integer.js new file mode 100644 index 000000000..b980efe72 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-no-iteration-over-non-integer.js @@ -0,0 +1,38 @@ +// 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.filter +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.filter(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], convertToBigInt(7), "results[0][0] - kValue"); + assert.sameValue(results[1][0], convertToBigInt(8), "results[1][0] - kValue"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-not-callable-throws.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 000000000..6d2c4a71a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,58 @@ +// 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.filter +description: Throws TypeError if callbackfn is not callable +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert.throws(TypeError, function() { + sample.filter(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.filter(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.filter(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.filter(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.filter(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.filter({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.filter([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.filter(1); + }, "Number"); + + assert.throws(TypeError, function() { + sample.filter(Symbol("")); + }, "symbol"); + + assert.throws(TypeError, function() { + sample.filter(""); + }, "string"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 000000000..47cc032e0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().filter(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 000000000..4bac77886 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,23 @@ +// 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.filter +description: > + The callbackfn return does not change the instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = convertToBigInt(1); + + sample1.filter(function() { + return 42; + }); + + assert.sameValue(sample1[0], convertToBigInt(0), "[0] == 0"); + assert.sameValue(sample1[1], convertToBigInt(1), "[1] == 1"); + assert.sameValue(sample1[2], convertToBigInt(0), "[2] == 0"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 000000000..411b5ef8c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-returns-abrupt.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.filter +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.filter(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-set-value-during-iteration.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-set-value-during-iteration.js new file mode 100644 index 000000000..a4e86b427 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-set-value-during-iteration.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.filter +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + var newVal = 0; + + sample.filter(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], convertToBigInt(newVal - 1), + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, convertToBigInt(7)), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, convertToBigInt(newVal)), + true, + "set value during interaction" + ); + + newVal++; + }); + + assert.sameValue(sample[0], convertToBigInt(7), "changed values after interaction [0] == 7"); + assert.sameValue(sample[1], convertToBigInt(1), "changed values after interaction [1] == 1"); + assert.sameValue(sample[2], convertToBigInt(2), "changed values after interaction [2] == 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-this.js b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-this.js new file mode 100644 index 000000000..fc7e0bccb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/callbackfn-this.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.filter +description: > + callbackfn `this` value +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.filter(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.filter(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/filter/BigInt/detached-buffer.js new file mode 100644 index 000000000..19539b599 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/detached-buffer.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.filter +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/filter/BigInt/invoked-as-func.js new file mode 100644 index 000000000..86c878c88 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.9 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var filter = TypedArray.prototype.filter; + +assert.sameValue(typeof filter, 'function'); + +assert.throws(TypeError, function() { + filter(); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/filter/BigInt/invoked-as-method.js new file mode 100644 index 000000000..0c70719e1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.9 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.filter, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.filter(); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/length.js b/test/built-ins/TypedArray/prototype/filter/BigInt/length.js new file mode 100644 index 000000000..2b5d020a3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/length.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. + +/*--- +es6id: 22.2.3.9 +description: > + %TypedArray%.prototype.filter.length is 1. +info: | + %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.filter.length, 1); + +verifyNotEnumerable(TypedArray.prototype.filter, "length"); +verifyNotWritable(TypedArray.prototype.filter, "length"); +verifyConfigurable(TypedArray.prototype.filter, "length"); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/name.js b/test/built-ins/TypedArray/prototype/filter/BigInt/name.js new file mode 100644 index 000000000..f582e69dd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.9 +description: > + %TypedArray%.prototype.filter.name is "filter". +info: | + %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.filter.name, "filter"); + +verifyNotEnumerable(TypedArray.prototype.filter, "name"); +verifyNotWritable(TypedArray.prototype.filter, "name"); +verifyConfigurable(TypedArray.prototype.filter, "name"); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/filter/BigInt/prop-desc.js new file mode 100644 index 000000000..898755704 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.9 +description: > + "filter" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'filter'); +verifyWritable(TypedArrayPrototype, 'filter'); +verifyConfigurable(TypedArrayPrototype, 'filter'); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/result-does-not-share-buffer.js b/test/built-ins/TypedArray/prototype/filter/BigInt/result-does-not-share-buffer.js new file mode 100644 index 000000000..1a84196dc --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/result-does-not-share-buffer.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.filter +description: > + Return does not share buffer +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + 13. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42])); + var result; + + result = sample.filter(function() { return true; }); + assert.notSameValue(result.buffer, sample.buffer); + + result = sample.filter(function() { return false; }); + assert.notSameValue(result.buffer, sample.buffer); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/result-empty-callbackfn-returns-false.js b/test/built-ins/TypedArray/prototype/filter/BigInt/result-empty-callbackfn-returns-false.js new file mode 100644 index 000000000..34058a260 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/result-empty-callbackfn-returns-false.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.filter +description: > + Returns empty if every callbackfn returns boolean false +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var result = sample.filter(function() { + return val; + }); + assert.sameValue(result.length, 0, val); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/result-full-callbackfn-returns-true.js b/test/built-ins/TypedArray/prototype/filter/BigInt/result-full-callbackfn-returns-true.js new file mode 100644 index 000000000..d63ba8691 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/result-full-callbackfn-returns-true.js @@ -0,0 +1,38 @@ +// 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.filter +description: > + Returns full length result if every callbackfn returns boolean false +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42])); + + [ + true, + 1, + "test262", + Symbol("1"), + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ].forEach(function(val) { + var result = sample.filter(function() { return val; }); + assert(compareArray(result, sample), val); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-abrupt.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 000000000..9b7bc9dfc --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/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.filter +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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(convertToBigInt([40, 41, 42, 43])); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.filter(function() { + return true; + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-inherited.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 000000000..35fe965b0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/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.filter +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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(convertToBigInt([40, 41, 42, 43])); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.filter(function() { + return true; + }); + + 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" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-returns-throws.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 000000000..79e40b47c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/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.filter +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var callbackfn = function() { return true; }; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.filter(callbackfn); + }, "symbol"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor.js new file mode 100644 index 000000000..0b64ac3ca --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-ctor.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.filter +description: get constructor on SpeciesConstructor +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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(convertToBigInt([40, 41, 42, 43])); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.filter(function() { return true; }); + + 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" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-abrupt.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 000000000..eb585beb7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-abrupt.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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.filter(function() { return true; }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 000000000..1efefe1be --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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(convertToBigInt([40, 42, 42])); + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + result = arguments; + ctorThis = this; + return new TA(count); + }; + + sample.filter(function(v) { return v === convertToBigInt(42); }); + + assert.sameValue(result.length, 1, "called with 1 argument"); + assert.sameValue(result[0], 2, "[0] is the new captured length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 000000000..80b0ea9f9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length-throws.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.filter +description: > + Throws a TypeError if new typedArray's length < captured +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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.filter(function() { return true; }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 000000000..38af74b53 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-length.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.filter +description: > + Does not throw a TypeError if new typedArray's length >= captured +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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.filter(function() { return true; }); + assert.sameValue(result.length, customCount, "length == count"); + + customCount = 5; + result = sample.filter(function() { return true; }); + assert.sameValue(result.length, customCount, "length > count"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 000000000..31f2887b3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + Custom @@species constructor may return a different TypedArray +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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(convertToBigInt([40])); + var otherTA = TA === Int8Array ? Int16Array : Int8Array; + var other = new otherTA([1, 0, 1]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.filter(function() {}); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1, 0, 1]), "the returned object is preserved"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-throws.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 000000000..ae5d33183 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor-throws.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.filter +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + sample.constructor[Symbol.species] = Array; + + assert.throws(TypeError, function() { + sample.filter(function() {}); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 000000000..f881f792d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/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.filter +description: > + Use custom @@species constructor if available +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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(convertToBigInt([40, 41, 42])); + var calls = 0; + var other, result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(captured) { + calls++; + other = new TA(captured); + return other; + }; + + result = sample.filter(function() { return true; }); + + assert.sameValue(calls, 1, "ctor called once"); + assert.sameValue(result, other, "return is instance of custom constructor"); + assert(compareArray(result, convertToBigInt([40, 41, 42])), "values are set on the new obj"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-returns-throws.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 000000000..12a76cdda --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,66 @@ +// 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.filter +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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.filter(function() {}); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.filter(function() {}); + }, "true"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-use-default-ctor.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 000000000..9ecb72b05 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species-use-default-ctor.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.filter +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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.filter(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.filter(function() {}); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species.js b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species.js new file mode 100644 index 000000000..04e413a38 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/speciesctor-get-species.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.filter +description: > + get @@species from found constructor +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 10. Let A be ? TypedArraySpeciesCreate(O, « captured »). + ... + + 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.filter(function() {}); + + assert.sameValue(calls, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/filter/BigInt/this-is-not-object.js new file mode 100644 index 000000000..0a8a31a27 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/this-is-not-object.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var filter = TypedArray.prototype.filter; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + filter.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + filter.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + filter.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + filter.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + filter.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + filter.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + filter.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/filter/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..4bb60e605 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var filter = TypedArray.prototype.filter; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + filter.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + filter.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + filter.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + filter.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/filter/BigInt/values-are-not-cached.js new file mode 100644 index 000000000..25b7eb24a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/values-are-not-cached.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.filter +description: > + Integer indexed values are not cached before interaction +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 9. Repeat, while k < len + ... + c. Let selected be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + sample.filter(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = convertToBigInt(42); + } + + assert.sameValue( + v, convertToBigInt(42), "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/filter/BigInt/values-are-set.js b/test/built-ins/TypedArray/prototype/filter/BigInt/values-are-set.js new file mode 100644 index 000000000..b7f2775f2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/filter/BigInt/values-are-set.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.filter +description: > + Returned instance with filtered values set on it +info: | + 22.2.3.9 %TypedArray%.prototype.filter ( callbackfn [ , thisArg ] ) + + ... + 12. For each element e of kept + a. Perform ! Set(A, ! ToString(n), e, true). + b. Increment n by 1. + 13. Return A. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([41, 1, 42, 7])); + var result; + + result = sample.filter(function() { return true; }); + assert(compareArray(result, convertToBigInt([41, 1, 42, 7])), "values are set #1"); + + result = sample.filter(function(v) { + return v > convertToBigInt(40); + }); + assert(compareArray(result, convertToBigInt([41, 42])), "values are set #2"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/find/BigInt/detached-buffer.js new file mode 100644 index 000000000..f3cfaeb3e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/detached-buffer.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.find +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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 predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.find(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js b/test/built-ins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 000000000..790de25db --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/get-length-ignores-length-prop.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.find +es6id: 22.2.3.10 +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(convertToBigInt([42])); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.find(function() { return true; }), + convertToBigInt(42) + ); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/find/BigInt/invoked-as-func.js new file mode 100644 index 000000000..eea7537b2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.10 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var find = TypedArray.prototype.find; + +assert.sameValue(typeof find, 'function'); + +assert.throws(TypeError, function() { + find(); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/find/BigInt/invoked-as-method.js new file mode 100644 index 000000000..ed0d1a9a2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.10 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.find, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.find(); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/length.js b/test/built-ins/TypedArray/prototype/find/BigInt/length.js new file mode 100644 index 000000000..e61e1c21e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/length.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. + +/*--- +es6id: 22.2.3.10 +description: > + %TypedArray%.prototype.find.length is 1. +info: | + %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.find.length, 1); + +verifyNotEnumerable(TypedArray.prototype.find, "length"); +verifyNotWritable(TypedArray.prototype.find, "length"); +verifyConfigurable(TypedArray.prototype.find, "length"); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/name.js b/test/built-ins/TypedArray/prototype/find/BigInt/name.js new file mode 100644 index 000000000..ab18751c2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.10 +description: > + %TypedArray%.prototype.find.name is "find". +info: | + %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.find.name, "find"); + +verifyNotEnumerable(TypedArray.prototype.find, "name"); +verifyNotWritable(TypedArray.prototype.find, "name"); +verifyConfigurable(TypedArray.prototype.find, "name"); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js new file mode 100644 index 000000000..6ed966f70 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-changes-value.js @@ -0,0 +1,78 @@ +// 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.find +es6id: 22.2.3.10 +description: > + Change values during predicate call +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = convertToBigInt([1, 2, 3]); + var sample; + var result; + + sample = new TA(3); + sample.find(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, convertToBigInt(0), "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i === 0 ) { + sample[2] = convertToBigInt(7); + } + return val === convertToBigInt(7); + }); + assert.sameValue(result, convertToBigInt(7), "value found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i === 0 ) { + sample[2] = convertToBigInt(7); + } + return val === convertToBigInt(3); + }); + assert.sameValue(result, undefined, "value not found"); + + sample = new TA(arr); + result = sample.find(function(val, i) { + if ( i > 0 ) { + sample[0] = convertToBigInt(7); + } + return val === convertToBigInt(7); + }); + assert.sameValue(result, undefined, "value not found - changed after call"); + + sample = new TA(arr); + result = sample.find(function() { + sample[0] = convertToBigInt(7); + return true; + }); + assert.sameValue(result, convertToBigInt(1), "find() returns previous found value"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js new file mode 100644 index 000000000..fd69894e6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-parameters.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.find +es6id: 22.2.3.10 +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([39, 2, 62])); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.find(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], convertToBigInt(39), "results[0][0] === 39, value"); + assert.sameValue(result[1], 0, "results[0][1] === 0, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3 arguments"); + + result = results[1]; + assert.sameValue(result[0], convertToBigInt(2), "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3 arguments"); + + result = results[2]; + assert.sameValue(result[0], convertToBigInt(62), "results[2][0] === 62, value"); + assert.sameValue(result[1], 2, "results[2][1] === 2, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3 arguments"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 000000000..538bd26ac --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.find +es6id: 22.2.3.10 +description: > + Verify predicate this on non-strict mode +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var T = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.find(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.find(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-strict.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-strict.js new file mode 100644 index 000000000..414440969 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-call-this-strict.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.find +es6id: 22.2.3.10 +description: > + Verify predicate this on strict mode +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.find(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.find(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 000000000..c9b0f5ace --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-is-not-callable-throws.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.find +es6id: 22.2.3.10 +description: > + Throws a TypeError exception if predicate is not callable. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 3. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.find({}); + }, "object"); + + assert.throws(TypeError, function() { + sample.find(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.find(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.find(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.find(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.find(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.find(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.find([]); + }, "array"); + + assert.throws(TypeError, function() { + sample.find(/./); + }, "regexp"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 000000000..fafed535e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-may-detach-buffer.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.find +es6id: 22.2.3.10 +description: > + Predicate may detach the buffer +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 + + ... + + However, such optimization must not introduce any observable changes in the + specified behaviour of the algorithm and must take into account the + possibility that calls to predicate may cause the this value to become + detached. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var loops = 0; + var completion = false; + + assert.throws(TypeError, function() { + sample.find(function() { + loops++; + $DETACHBUFFER(sample.buffer); + completion = true; + }); + }, "throws a TypeError getting a value from the detached buffer"); + + assert.sameValue(loops, 1, "predicate is called once"); + assert(completion, "abrupt completion does not come from DETACHBUFFER"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 000000000..029c16522 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/predicate-not-called-on-empty-array.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.find +es6id: 22.2.3.10 +description: > + Predicate is not called on empty instances +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var result = sample.find(function() { + called = true; + return true; + }); + + assert.sameValue( + called, + false, + "empty instance does not call predicate" + ); + assert.sameValue( + result, + undefined, + "find returns undefined when predicate is not called" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/find/BigInt/prop-desc.js new file mode 100644 index 000000000..13af89a56 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.10 +description: > + "find" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'find'); +verifyWritable(TypedArrayPrototype, 'find'); +verifyConfigurable(TypedArrayPrototype, 'find'); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js b/test/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 000000000..0942d004d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/return-abrupt-from-predicate-call.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.find +es6id: 22.2.3.10 +description: > + Return abrupt from predicate call. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + var predicate = function() { + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.find(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js b/test/built-ins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js new file mode 100644 index 000000000..63fda9413 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/return-found-value-predicate-result-is-true.js @@ -0,0 +1,66 @@ +// 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.find +es6id: 22.2.3.10 +description: > + Return found value if predicate return a boolean true value. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return kValue. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([39, 2, 62])); + var called, result; + + called = 0; + result = sample.find(function() { + called++; + return true; + }); + assert.sameValue(result, convertToBigInt(39), "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.find(function(val) { + called++; + return val === convertToBigInt(62); + }); + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, convertToBigInt(62), "returned true on sample[3]"); + + result = sample.find(function() { return "string"; }); + assert.sameValue(result, convertToBigInt(39), "ToBoolean(string)"); + + result = sample.find(function() { return {}; }); + assert.sameValue(result, convertToBigInt(39), "ToBoolean(object)"); + + result = sample.find(function() { return Symbol(""); }); + assert.sameValue(result, convertToBigInt(39), "ToBoolean(symbol)"); + + result = sample.find(function() { return 1; }); + assert.sameValue(result, convertToBigInt(39), "ToBoolean(number)"); + + result = sample.find(function() { return -1; }); + assert.sameValue(result, convertToBigInt(39), "ToBoolean(negative number)"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js b/test/built-ins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.js new file mode 100644 index 000000000..86f3f6cd3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/return-undefined-if-predicate-returns-false-value.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.find +es6id: 22.2.3.10 +description: > + Return undefined if predicate always returns a boolean false value. +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + %TypedArray%.prototype.find is a distinct function that implements the same + algorithm as Array.prototype.find as defined in 22.1.3.8 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". The implementation of the algorithm may be optimized with + the knowledge that the this value is an object that has a fixed length and + whose integer indexed properties are not sparse. + + ... + + 22.1.3.8 Array.prototype.find ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return undefined. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + var called = 0; + + var result = sample.find(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, undefined); + + result = sample.find(function() { return ""; }); + assert.sameValue(result, undefined, "ToBoolean(empty string)"); + + result = sample.find(function() { return undefined; }); + assert.sameValue(result, undefined, "ToBoolean(undefined)"); + + result = sample.find(function() { return null; }); + assert.sameValue(result, undefined, "ToBoolean(null)"); + + result = sample.find(function() { return 0; }); + assert.sameValue(result, undefined, "ToBoolean(0)"); + + result = sample.find(function() { return -0; }); + assert.sameValue(result, undefined, "ToBoolean(-0)"); + + result = sample.find(function() { return NaN; }); + assert.sameValue(result, undefined, "ToBoolean(NaN)"); +}); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/find/BigInt/this-is-not-object.js new file mode 100644 index 000000000..149306352 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/this-is-not-object.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.find +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var find = TypedArray.prototype.find; +var predicate = function() {}; + +assert.throws(TypeError, function() { + find.call(undefined, predicate); +}, "this is undefined"); + +assert.throws(TypeError, function() { + find.call(null, predicate); +}, "this is null"); + +assert.throws(TypeError, function() { + find.call(42, predicate); +}, "this is 42"); + +assert.throws(TypeError, function() { + find.call("1", predicate); +}, "this is a string"); + +assert.throws(TypeError, function() { + find.call(true, predicate); +}, "this is true"); + +assert.throws(TypeError, function() { + find.call(false, predicate); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + find.call(s, predicate); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/find/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/find/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..957be1152 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/find/BigInt/this-is-not-typedarray-instance.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.find +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.10 %TypedArray%.prototype.find (predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var find = TypedArray.prototype.find; +var predicate = function() {}; + +assert.throws(TypeError, function() { + find.call({}, predicate); +}, "this is an Object"); + +assert.throws(TypeError, function() { + find.call([], predicate); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + find.call(ab, predicate); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + find.call(dv, predicate); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/detached-buffer.js new file mode 100644 index 000000000..f8e8ed449 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/detached-buffer.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.findindex +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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 predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.js new file mode 100644 index 000000000..64ba1216f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/get-length-ignores-length-prop.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.findindex +es6id: 22.2.3.11 +description: > + [[Get]] of "length" uses [[ArrayLength]] +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + Object.defineProperty(TA.prototype, "length", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(convertToBigInt([42])); + + Object.defineProperty(sample, "length", { + get: function() { + throw new Test262Error(); + }, + configurable: true + }); + + assert.sameValue( + sample.findIndex(function() { return true; }), + 0 + ); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-func.js new file mode 100644 index 000000000..eec6d6341 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.11 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var findIndex = TypedArray.prototype.findIndex; + +assert.sameValue(typeof findIndex, 'function'); + +assert.throws(TypeError, function() { + findIndex(); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-method.js new file mode 100644 index 000000000..73197eb1d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.11 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.findIndex, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.findIndex(); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/length.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/length.js new file mode 100644 index 000000000..aeab6fc8e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/length.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. + +/*--- +es6id: 22.2.3.11 +description: > + %TypedArray%.prototype.findIndex.length is 1. +info: | + %TypedArray%.prototype.findIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.findIndex.length, 1); + +verifyNotEnumerable(TypedArray.prototype.findIndex, "length"); +verifyNotWritable(TypedArray.prototype.findIndex, "length"); +verifyConfigurable(TypedArray.prototype.findIndex, "length"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/name.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/name.js new file mode 100644 index 000000000..a0cc1c772 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.11 +description: > + %TypedArray%.prototype.findIndex.name is "findIndex". +info: | + %TypedArray%.prototype.findIndex (predicate [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.findIndex.name, "findIndex"); + +verifyNotEnumerable(TypedArray.prototype.findIndex, "name"); +verifyNotWritable(TypedArray.prototype.findIndex, "name"); +verifyConfigurable(TypedArray.prototype.findIndex, "name"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js new file mode 100644 index 000000000..0dc15c76e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-changes-value.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.findindex +es6id: 22.2.3.11 +description: > + Change values during predicate call +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [compareArray.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = convertToBigInt([10, 20, 30]); + var sample; + var result; + + sample = new TA(3); + sample.findIndex(function(val, i) { + sample[i] = arr[i]; + + assert.sameValue(val, convertToBigInt(0), "value is not mapped to instance"); + }); + assert(compareArray(sample, arr), "values set during each predicate call"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i === 0 ) { + sample[2] = convertToBigInt(7); + } + return val === convertToBigInt(7); + }); + assert.sameValue(result, 2, "value found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i === 0 ) { + sample[2] = convertToBigInt(7); + } + return val === convertToBigInt(30); + }); + assert.sameValue(result, -1, "value not found"); + + sample = new TA(arr); + result = sample.findIndex(function(val, i) { + if ( i > 0 ) { + sample[0] = convertToBigInt(7); + } + return val === convertToBigInt(7); + }); + assert.sameValue(result, -1, "value not found - changed after call"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.js new file mode 100644 index 000000000..e63adf53f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-parameters.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.findindex +es6id: 22.2.3.11 +description: > + Predicate called as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([39, 2, 62])); + var results = []; + var result; + + sample.foo = "bar"; // Ignores non integer index properties + + sample.findIndex(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "predicate is called for each index"); + + result = results[0]; + assert.sameValue(result[0], convertToBigInt(39), "results[0][0] === 39, value"); + assert.sameValue(result[1], 0, "results[0][1] === 0, index"); + assert.sameValue(result[2], sample, "results[0][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[0].length === 3, arguments"); + + result = results[1]; + assert.sameValue(result[0], convertToBigInt(2), "results[1][0] === 2, value"); + assert.sameValue(result[1], 1, "results[1][1] === 1, index"); + assert.sameValue(result[2], sample, "results[1][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[1].length === 3, arguments"); + + result = results[2]; + assert.sameValue(result[0], convertToBigInt(62), "results[2][0] === 62, value"); + assert.sameValue(result[1], 2, "results[2][1] === 2, index"); + assert.sameValue(result[2], sample, "results[2][2] === sample, instance"); + assert.sameValue(result.length, 3, "results[2].length === 3, arguments"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js new file mode 100644 index 000000000..a4a8ab7eb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-non-strict.js @@ -0,0 +1,58 @@ +// 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.findindex +es6id: 22.2.3.11 +description: > + Verify predicate this on non-strict mode +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var T = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue(result, T, "without thisArg, predicate this is the global"); + + result = null; + sample.findIndex(function() { + result = this; + }, undefined); + + assert.sameValue(result, T, "predicate this is the global when thisArg is undefined"); + + var o = {}; + result = null; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.js new file mode 100644 index 000000000..554a55aa0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-call-this-strict.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.findindex +es6id: 22.2.3.11 +description: > + Predicate thisArg as F.call( thisArg, kValue, k, O ) for each array entry. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + var result; + + sample.findIndex(function() { + result = this; + }); + + assert.sameValue( + result, + undefined, + "without thisArg, predicate this is undefined" + ); + + var o = {}; + sample.findIndex(function() { + result = this; + }, o); + + assert.sameValue(result, o, "thisArg becomes the predicate this"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-throws.js new file mode 100644 index 000000000..3a2143101 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-is-not-callable-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.findindex +es6id: 22.2.3.11 +description: > + Throws a TypeError exception if predicate is not callable. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 3. If IsCallable(predicate) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.throws(TypeError, function() { + sample.findIndex({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.findIndex(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.findIndex(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.findIndex(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.findIndex(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.findIndex(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.findIndex(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.findIndex([]); + }, "[]"); + + assert.throws(TypeError, function() { + sample.findIndex(/./); + }, "/./"); +}); + diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.js new file mode 100644 index 000000000..3bf9014ff --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-may-detach-buffer.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.findindex +es6id: 22.2.3.11 +description: > + Predicate may detach the buffer +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var loops = 0; + var completion = false; + + assert.throws(TypeError, function() { + sample.findIndex(function() { + loops++; + $DETACHBUFFER(sample.buffer); + completion = true; + }); + }, "throws a TypeError getting a value from the detached buffer"); + + assert.sameValue(loops, 1, "predicated is called once"); + assert(completion, "abrupt completion does not come from DETACHBUFFER"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.js new file mode 100644 index 000000000..a58100f03 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/predicate-not-called-on-empty-array.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.findindex +es6id: 22.2.3.11 +description: > + Predicate is not called on an empty instance +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var called = false; + + var predicate = function() { + called = true; + return true; + }; + + var result = sample.findIndex(predicate); + + assert.sameValue( + called, false, + "does not call predicate" + ); + assert.sameValue( + result, -1, + "returns -1 on an empty instance" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/prop-desc.js new file mode 100644 index 000000000..a4bf542d7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.11 +description: > + "findIndex" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'findIndex'); +verifyWritable(TypedArrayPrototype, 'findIndex'); +verifyConfigurable(TypedArrayPrototype, 'findIndex'); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js new file mode 100644 index 000000000..6994a7954 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-abrupt-from-predicate-call.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.findindex +es6id: 22.2.3.11 +description: > + Return abrupt from predicate call. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var predicate = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + assert.throws(Test262Error, function() { + sample.findIndex(predicate); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js new file mode 100644 index 000000000..0c979bd4f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-index-predicate-result-is-true.js @@ -0,0 +1,66 @@ +// 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.findindex +es6id: 22.2.3.11 +description: > + Return index if predicate return a boolean true value. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 5. Let k be 0. + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + d. If testResult is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([39, 3, 9])); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return true; + }); + + assert.sameValue(result, 0, "returned true on sample[0]"); + assert.sameValue(called, 1, "predicate was called once"); + + called = 0; + result = sample.findIndex(function(val) { + called++; + return val === convertToBigInt(9); + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, 2, "returned true on sample[3]"); + + result = sample.findIndex(function() { return "string"; }); + assert.sameValue(result, 0, "ToBoolean(string)"); + + result = sample.findIndex(function() { return {}; }); + assert.sameValue(result, 0, "ToBoolean(object)"); + + result = sample.findIndex(function() { return Symbol(""); }); + assert.sameValue(result, 0, "ToBoolean(symbol)"); + + result = sample.findIndex(function() { return 1; }); + assert.sameValue(result, 0, "ToBoolean(number)"); + + result = sample.findIndex(function() { return -1; }); + assert.sameValue(result, 0, "ToBoolean(negative number)"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js new file mode 100644 index 000000000..28001d77c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/return-negative-one-if-predicate-returns-false-value.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.findindex +es6id: 22.2.3.11 +description: > + Return -1 if predicate always returns a boolean false value. +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + %TypedArray%.prototype.findIndex is a distinct function that implements the + same algorithm as Array.prototype.findIndex as defined in 22.1.3.9 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + ... + + 22.1.3.9 Array.prototype.findIndex ( predicate[ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)). + ... + 7. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 2, 3])); + var called = 0; + + var result = sample.findIndex(function() { + called++; + return false; + }); + + assert.sameValue(called, 3, "predicate was called three times"); + assert.sameValue(result, -1, "result is -1 when predicate returns are false"); + + result = sample.findIndex(function() { return ""; }); + assert.sameValue(result, -1, "ToBoolean(string)"); + + result = sample.findIndex(function() { return undefined; }); + assert.sameValue(result, -1, "ToBoolean(undefined)"); + + result = sample.findIndex(function() { return null; }); + assert.sameValue(result, -1, "ToBoolean(null)"); + + result = sample.findIndex(function() { return 0; }); + assert.sameValue(result, -1, "ToBoolean(0)"); + + result = sample.findIndex(function() { return -0; }); + assert.sameValue(result, -1, "ToBoolean(-0)"); + + result = sample.findIndex(function() { return NaN; }); + assert.sameValue(result, -1, "ToBoolean(NaN)"); +}); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-object.js new file mode 100644 index 000000000..fedede8b0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-object.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.findindex +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var findIndex = TypedArray.prototype.findIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findIndex.call(undefined, predicate); +}, "this is undefined"); + +assert.throws(TypeError, function() { + findIndex.call(null, predicate); +}, "this is null"); + +assert.throws(TypeError, function() { + findIndex.call(42, predicate); +}, "this is 42"); + +assert.throws(TypeError, function() { + findIndex.call("1", predicate); +}, "this is a string"); + +assert.throws(TypeError, function() { + findIndex.call(true, predicate); +}, "this is true"); + +assert.throws(TypeError, function() { + findIndex.call(false, predicate); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + findIndex.call(s, predicate); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..0c1bbab00 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/findIndex/BigInt/this-is-not-typedarray-instance.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.findindex +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var findIndex = TypedArray.prototype.findIndex; +var predicate = function() {}; + +assert.throws(TypeError, function() { + findIndex.call({}, predicate); +}, "this is an Object"); + +assert.throws(TypeError, function() { + findIndex.call([], predicate); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + findIndex.call(ab, predicate); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + findIndex.call(dv, predicate); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js new file mode 100644 index 000000000..c5d14f29e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/arraylength-internal.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.foreach +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 42, "data descriptor"); + + var sample2 = new TA(7); + loop = 0; + + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.forEach(function() { + loop++; + }); + + assert.sameValue(loop, 7, "accessor descriptor"); +}); + diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 000000000..ada379de2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-with-thisarg.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.foreach +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.forEach(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 000000000..81011139e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-arguments-without-thisarg.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.foreach +description: > + callbackfn arguments +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.forEach(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 000000000..0f7725e4f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.foreach +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.forEach(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + }); + }); + + assert.sameValue(loops, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.js new file mode 100644 index 000000000..219872510 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-is-not-callable.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.foreach +description: > + callbackfn is not callable +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(TypeError, function() { + sample.forEach(); + }); + + assert.throws(TypeError, function() { + sample.forEach(undefined); + }); + + assert.throws(TypeError, function() { + sample.forEach(null); + }); + + assert.throws(TypeError, function() { + sample.forEach({}); + }); + + assert.throws(TypeError, function() { + sample.forEach(1); + }); + + assert.throws(TypeError, function() { + sample.forEach(""); + }); + + assert.throws(TypeError, function() { + sample.forEach(false); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 000000000..95c7e4b37 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-no-interaction-over-non-integer.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.foreach +description: > + Does not interact over non-integer properties +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.forEach(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], convertToBigInt(7), "results[0][0] - kValue"); + assert.sameValue(results[1][0], convertToBigInt(8), "results[1][0] - kValue"); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 000000000..f81f5ac40 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-not-called-on-empty.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.foreach +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().forEach(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 000000000..82da435a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.foreach +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = convertToBigInt(1); + + sample1.forEach(function() { + return 42; + }); + + assert.sameValue(sample1[0], convertToBigInt(0), "[0] == 0"); + assert.sameValue(sample1[1], convertToBigInt(1), "[1] == 1"); + assert.sameValue(sample1[2], convertToBigInt(0), "[2] == 0"); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 000000000..fb9c58a20 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-returns-abrupt.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.foreach +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.forEach(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 000000000..2b2865b4c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-set-value-during-interaction.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.foreach +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + var newVal = 0; + + sample.forEach(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], convertToBigInt(newVal - 1), + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, convertToBigInt(7)), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, convertToBigInt(newVal)), + true, + "set value during iteration" + ); + + newVal++; + }); + + assert.sameValue(sample[0], convertToBigInt(7), "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], convertToBigInt(1), "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], convertToBigInt(2), "changed values after iteration [2] == 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js new file mode 100644 index 000000000..df900d125 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/callbackfn-this.js @@ -0,0 +1,57 @@ +// 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.foreach +description: > + callbackfn `this` value +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" + + 22.1.3.10 Array.prototype.forEach ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Perform ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.forEach(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.forEach(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/detached-buffer.js new file mode 100644 index 000000000..fe196e0cb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/detached-buffer.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.foreach +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.forEach(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/invoked-as-func.js new file mode 100644 index 000000000..6ea0a324c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.12 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var forEach = TypedArray.prototype.forEach; + +assert.sameValue(typeof forEach, 'function'); + +assert.throws(TypeError, function() { + forEach(); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/invoked-as-method.js new file mode 100644 index 000000000..7062e8b1d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.12 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.forEach, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.forEach(); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/length.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/length.js new file mode 100644 index 000000000..bb291f677 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/length.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. + +/*--- +es6id: 22.2.3.12 +description: > + %TypedArray%.prototype.forEach.length is 1. +info: | + %TypedArray%.prototype.forEach (callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.forEach.length, 1); + +verifyNotEnumerable(TypedArray.prototype.forEach, "length"); +verifyNotWritable(TypedArray.prototype.forEach, "length"); +verifyConfigurable(TypedArray.prototype.forEach, "length"); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/name.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/name.js new file mode 100644 index 000000000..6adfd3c6b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.12 +description: > + %TypedArray%.prototype.forEach.name is "forEach". +info: | + %TypedArray%.prototype.forEach (callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.forEach.name, "forEach"); + +verifyNotEnumerable(TypedArray.prototype.forEach, "name"); +verifyNotWritable(TypedArray.prototype.forEach, "name"); +verifyConfigurable(TypedArray.prototype.forEach, "name"); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/prop-desc.js new file mode 100644 index 000000000..56bafc356 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.12 +description: > + "forEach" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'forEach'); +verifyWritable(TypedArrayPrototype, 'forEach'); +verifyConfigurable(TypedArrayPrototype, 'forEach'); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/returns-undefined.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/returns-undefined.js new file mode 100644 index 000000000..467825d27 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/returns-undefined.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.foreach +description: > + Returns undefined +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + + var result1 = sample1.forEach(function() { + return 42; + }); + + assert.sameValue(result1, undefined, "result1"); + + var sample2 = new TA(1); + var result2 = sample2.forEach(function() { + return null; + }); + + assert.sameValue(result2, undefined, "result2"); +}); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/this-is-not-object.js new file mode 100644 index 000000000..6317c05d5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/this-is-not-object.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.foreach +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var forEach = TypedArray.prototype.forEach; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + forEach.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + forEach.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + forEach.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + forEach.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + forEach.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + forEach.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + forEach.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..33db208c9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/this-is-not-typedarray-instance.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.foreach +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var forEach = TypedArray.prototype.forEach; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + forEach.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + forEach.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + forEach.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + forEach.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.js new file mode 100644 index 000000000..d937cf44f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/forEach/BigInt/values-are-not-cached.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.foreach +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.12 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.forEach is a distinct function that implements the same + algorithm as Array.prototype.forEach as defined in 22.1.3.10 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length" +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + sample.forEach(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = convertToBigInt(42); + } + + assert.sameValue( + v, convertToBigInt(42), "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer.js new file mode 100644 index 000000000..990e4b01a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/detached-buffer.js @@ -0,0 +1,28 @@ +// 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.includes +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.includes(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js b/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.js new file mode 100644 index 000000000..a59b7084a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-equal-or-greater-length-returns-false.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.includes +description: Return false if fromIndex >= ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.includes(0, 42), false); + assert.sameValue(sample.includes(0, 43), false); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js b/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.js new file mode 100644 index 000000000..0d44d7a65 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-infinity.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.includes +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + ... + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 43, 41])); + + assert.sameValue( + sample.includes(convertToBigInt(43), Infinity), + false, + "includes(43, Infinity)" + ); + assert.sameValue( + sample.includes(convertToBigInt(43), -Infinity), + true, + "includes(43, -Infinity)"); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js b/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.js new file mode 100644 index 000000000..285a7c316 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/fromIndex-minus-zero.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.includes +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43])); + assert.sameValue(sample.includes(convertToBigInt(42), -0), true, "-0 [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), -0), true, "-0 [1]"); + assert.sameValue(sample.includes(convertToBigInt(44), -0), false, "-0 [2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..85ab71b09 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/get-length-uses-internal-arraylength.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.includes +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", {value: 0}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7])); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.includes(convertToBigInt(7)), true); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/includes/BigInt/invoked-as-func.js new file mode 100644 index 000000000..cb8069bc3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var includes = TypedArray.prototype.includes; + +assert.sameValue(typeof includes, "function"); + +assert.throws(TypeError, function() { + includes(); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/includes/BigInt/invoked-as-method.js new file mode 100644 index 000000000..78f7428a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.includes, "function"); + +assert.throws(TypeError, function() { + TypedArrayPrototype.includes(); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js b/test/built-ins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js new file mode 100644 index 000000000..9c06fa6c1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/length-zero-returns-false.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.includes +description: Returns false if length is 0 +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.includes(0), false, "returns false"); + assert.sameValue(sample.includes(), false, "returns false - no arg"); + assert.sameValue( + sample.includes(0, fromIndex), false, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/length.js b/test/built-ins/TypedArray/prototype/includes/BigInt/length.js new file mode 100644 index 000000000..9f7938791 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/length.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.includes +description: > + %TypedArray%.prototype.includes.length is 1. +info: | + %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.includes.length, 1); + +verifyNotEnumerable(TypedArray.prototype.includes, "length"); +verifyNotWritable(TypedArray.prototype.includes, "length"); +verifyConfigurable(TypedArray.prototype.includes, "length"); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/name.js b/test/built-ins/TypedArray/prototype/includes/BigInt/name.js new file mode 100644 index 000000000..fdc316989 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/name.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.includes +description: > + %TypedArray%.prototype.includes.name is "includes". +info: | + %TypedArray%.prototype.includes (searchElement [ , fromIndex ] ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.includes.name, "includes"); + +verifyNotEnumerable(TypedArray.prototype.includes, "name"); +verifyNotWritable(TypedArray.prototype.includes, "name"); +verifyConfigurable(TypedArray.prototype.includes, "name"); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/includes/BigInt/prop-desc.js new file mode 100644 index 000000000..fcdef18da --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// 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.includes +description: > + "includes" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, "includes"); +verifyWritable(TypedArrayPrototype, "includes"); +verifyConfigurable(TypedArrayPrototype, "includes"); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.js b/test/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 000000000..33c8861ab --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex-symbol.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.includes +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7])); + + assert.throws(TypeError, function() { + sample.includes(convertToBigInt(7), fromIndex); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.js new file mode 100644 index 000000000..6ddcb1f70 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/return-abrupt-tointeger-fromindex.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.includes +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7])); + + assert.throws(Test262Error, function() { + sample.includes(convertToBigInt(7), fromIndex); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js b/test/built-ins/TypedArray/prototype/includes/BigInt/search-found-returns-true.js new file mode 100644 index 000000000..f11212ce4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/search-found-returns-true.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.includes +description: returns true for found index +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 42, 41])); + assert.sameValue(sample.includes(convertToBigInt(42)), true, "includes(42)"); + assert.sameValue(sample.includes(convertToBigInt(43)), true, "includes(43)"); + assert.sameValue(sample.includes(convertToBigInt(43), 1), true, "includes(43, 1)"); + assert.sameValue(sample.includes(convertToBigInt(42), 1), true, "includes(42, 1)"); + assert.sameValue(sample.includes(convertToBigInt(42), 2), true, "includes(42, 2)"); + + assert.sameValue(sample.includes(convertToBigInt(42), -4), true, "includes(42, -4)"); + assert.sameValue(sample.includes(convertToBigInt(42), -3), true, "includes(42, -3)"); + assert.sameValue(sample.includes(convertToBigInt(42), -2), true, "includes(42, -2)"); + assert.sameValue(sample.includes(convertToBigInt(42), -5), true, "includes(42, -5)"); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js b/test/built-ins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js new file mode 100644 index 000000000..5bf3b9086 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/search-not-found-returns-false.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.includes +description: returns false if the element is not found +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. Let k be n. + 6. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43, 42, 41])); + assert.sameValue(sample.includes(convertToBigInt(44)), false, "includes(44)"); + assert.sameValue(sample.includes(convertToBigInt(43), 2), false, "includes(43, 2)"); + assert.sameValue(sample.includes(convertToBigInt(42), 3), false, "includes(42, 3)"); + assert.sameValue(sample.includes(convertToBigInt(44), -4), false, "includes(44, -4)"); + assert.sameValue(sample.includes(convertToBigInt(44), -5), false, "includes(44, -5)"); + assert.sameValue(sample.includes(convertToBigInt(42), -1), false, "includes(42, -1)"); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/includes/BigInt/this-is-not-object.js new file mode 100644 index 000000000..2bee1f2f3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/this-is-not-object.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. +/*--- +es6id: 22.2.3.14 +esid: sec-%typedarray%.prototype.includes +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var includes = TypedArray.prototype.includes; + +assert.throws(TypeError, function() { + includes.call(undefined, 42); +}, "this is undefined"); + +assert.throws(TypeError, function() { + includes.call(null, 42); +}, "this is null"); + +assert.throws(TypeError, function() { + includes.call(42, 42); +}, "this is 42"); + +assert.throws(TypeError, function() { + includes.call("1", 42); +}, "this is a string"); + +assert.throws(TypeError, function() { + includes.call(true, 42); +}, "this is true"); + +assert.throws(TypeError, function() { + includes.call(false, 42); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + includes.call(s, 42); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/includes/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..713fe26dd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.includes +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.14 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var includes = TypedArray.prototype.includes; + +assert.throws(TypeError, function() { + includes.call({}, 42); +}, "this is an Object"); + +assert.throws(TypeError, function() { + includes.call([], 42); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + includes.call(ab, 42); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + includes.call(dv, 42); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.js new file mode 100644 index 000000000..67fbd38da --- /dev/null +++ b/test/built-ins/TypedArray/prototype/includes/BigInt/tointeger-fromindex.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.includes +description: get the integer value from fromIndex +info: | + 22.2.3.13 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.includes is a distinct function that implements the + same algorithm as Array.prototype.includes as defined in 22.1.3.11 except that + the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + 5. If n ≥ 0, then + a. Let k be n. + ... + 7. Repeat, while k < len + a. Let elementK be the result of ? Get(O, ! ToString(k)). + b. If SameValueZero(searchElement, elementK) is true, return true. + c. Increase k by 1. + 8. Return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43])); + assert.sameValue(sample.includes(convertToBigInt(42), "1"), false, "string [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), "1"), true, "string [1]"); + + assert.sameValue(sample.includes(convertToBigInt(42), true), false, "true [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), true), true, "true [1]"); + + assert.sameValue(sample.includes(convertToBigInt(42), false), true, "false [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), false), true, "false [1]"); + + assert.sameValue(sample.includes(convertToBigInt(42), NaN), true, "NaN [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), NaN), true, "NaN [1]"); + + assert.sameValue(sample.includes(convertToBigInt(42), null), true, "null [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), null), true, "null [1]"); + + assert.sameValue(sample.includes(convertToBigInt(42), undefined), true, "undefined [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), undefined), true, "undefined [1]"); + + assert.sameValue(sample.includes(convertToBigInt(42), null), true, "null [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), null), true, "null [1]"); + + assert.sameValue(sample.includes(convertToBigInt(42), obj), false, "object [0]"); + assert.sameValue(sample.includes(convertToBigInt(43), obj), true, "object [1]"); +}); diff --git a/test/built-ins/TypedArray/prototype/includes/samevaluezero.js b/test/built-ins/TypedArray/prototype/includes/samevaluezero.js index c06e20b1a..c6ad3785b 100644 --- a/test/built-ins/TypedArray/prototype/includes/samevaluezero.js +++ b/test/built-ins/TypedArray/prototype/includes/samevaluezero.js @@ -36,9 +36,7 @@ testWithTypedArrayConstructors(function(TA) { assert.sameValue(sample.includes(false), false, "false"); assert.sameValue(sample.includes(null), false, "null"); assert.sameValue(sample.includes(""), false, "empty string"); -}, - // ToBigInt(undefined) throws a TypeError exception. - numericTypedArrayConstructors); +}); testWithTypedArrayConstructors(function(FloatArray) { var sample = new FloatArray([42, 0, 1, undefined, NaN]); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer.js new file mode 100644 index 000000000..1d44ab16d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/detached-buffer.js @@ -0,0 +1,28 @@ +// 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.indexof +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.indexOf(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-equal-or-greater-length-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-equal-or-greater-length-returns-minus-one.js new file mode 100644 index 000000000..022f4a156 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-equal-or-greater-length-returns-minus-one.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.indexof +description: Return -1 if fromIndex >= ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(42); + assert.sameValue(sample.indexOf(0, 42), -1); + assert.sameValue(sample.indexOf(0, 43), -1); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-infinity.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-infinity.js new file mode 100644 index 000000000..38a6515cf --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-infinity.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.indexof +description: handle Infinity values for fromIndex +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 8. Repeat, while k < len + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 43, 41])); + + assert.sameValue(sample.indexOf(convertToBigInt(43), Infinity), -1, "indexOf(43, Infinity)"); + assert.sameValue(sample.indexOf(convertToBigInt(43), -Infinity), 1, "indexOf(43, -Infinity)"); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-minus-zero.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-minus-zero.js new file mode 100644 index 000000000..bd141027d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/fromIndex-minus-zero.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.indexof +description: -0 fromIndex becomes 0 +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43])); + assert.sameValue(sample.indexOf(convertToBigInt(42), -0), 0, "-0 [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), -0), 1, "-0 [1]"); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..61a961bd4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/get-length-uses-internal-arraylength.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.indexof +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", {value: 0}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7])); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.indexOf(convertToBigInt(7)), 0); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/invoked-as-func.js new file mode 100644 index 000000000..8134bac14 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.13 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var indexOf = TypedArray.prototype.indexOf; + +assert.sameValue(typeof indexOf, 'function'); + +assert.throws(TypeError, function() { + indexOf(); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/invoked-as-method.js new file mode 100644 index 000000000..6a87487b7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.13 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.indexOf, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.indexOf(); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/length-zero-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/length-zero-returns-minus-one.js new file mode 100644 index 000000000..510a58f7b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/length-zero-returns-minus-one.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.indexof +description: Returns -1 if length is 0 +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return -1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.indexOf(0), -1, "returns -1"); + assert.sameValue( + sample.indexOf(0, fromIndex), -1, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/length.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/length.js new file mode 100644 index 000000000..fc4a0303d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/length.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. + +/*--- +es6id: 22.2.3.13 +description: > + %TypedArray%.prototype.indexOf.length is 1. +info: | + %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.indexOf.length, 1); + +verifyNotEnumerable(TypedArray.prototype.indexOf, "length"); +verifyNotWritable(TypedArray.prototype.indexOf, "length"); +verifyConfigurable(TypedArray.prototype.indexOf, "length"); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/name.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/name.js new file mode 100644 index 000000000..594595344 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.13 +description: > + %TypedArray%.prototype.indexOf.name is "indexOf". +info: | + %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.indexOf.name, "indexOf"); + +verifyNotEnumerable(TypedArray.prototype.indexOf, "name"); +verifyNotWritable(TypedArray.prototype.indexOf, "name"); +verifyConfigurable(TypedArray.prototype.indexOf, "name"); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/prop-desc.js new file mode 100644 index 000000000..a9454f493 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.13 +description: > + "indexOf" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'indexOf'); +verifyWritable(TypedArrayPrototype, 'indexOf'); +verifyConfigurable(TypedArrayPrototype, 'indexOf'); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 000000000..843a22a29 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.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.indexof +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.indexOf(7, fromIndex); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex.js new file mode 100644 index 000000000..751b482b9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/return-abrupt-tointeger-fromindex.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.indexof +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(Test262Error, function() { + sample.indexOf(7, fromIndex); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/search-found-returns-index.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/search-found-returns-index.js new file mode 100644 index 000000000..e932c2689 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/search-found-returns-index.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.indexof +description: returns index for the first found element +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + 8. Repeat, while k < len + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 42, 41])); + assert.sameValue(sample.indexOf(convertToBigInt(42)), 0, "indexOf(42)"); + assert.sameValue(sample.indexOf(convertToBigInt(43)), 1, "indexOf(43)"); + assert.sameValue(sample.indexOf(convertToBigInt(43), 1), 1, "indexOf(43, 1)"); + assert.sameValue(sample.indexOf(convertToBigInt(42), 1), 2, "indexOf(42, 1)"); + assert.sameValue(sample.indexOf(convertToBigInt(42), 2), 2, "indexOf(42, 2)"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), -4), 0, "indexOf(42, -4)"); + assert.sameValue(sample.indexOf(convertToBigInt(42), -3), 2, "indexOf(42, -3)"); + assert.sameValue(sample.indexOf(convertToBigInt(42), -2), 2, "indexOf(42, -2)"); + assert.sameValue(sample.indexOf(convertToBigInt(42), -5), 0, "indexOf(42, -5)"); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/search-not-found-returns-minus-one.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/search-not-found-returns-minus-one.js new file mode 100644 index 000000000..94dc9285e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/search-not-found-returns-minus-one.js @@ -0,0 +1,38 @@ +// 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.indexof +description: returns -1 if the element if not found +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 6. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be n. + 7. Else n < 0, + a. Let k be len + n. + b. If k < 0, let k be 0. + ... + 9. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43, 42, 41])); + assert.sameValue(sample.indexOf(convertToBigInt(44)), -1, "indexOf(44)"); + assert.sameValue(sample.indexOf(convertToBigInt(43), 2), -1, "indexOf(43, 2)"); + assert.sameValue(sample.indexOf(convertToBigInt(42), 3), -1, "indexOf(42, 3)"); + assert.sameValue(sample.indexOf(convertToBigInt(44), -4), -1, "indexOf(44, -4)"); + assert.sameValue(sample.indexOf(convertToBigInt(44), -5), -1, "indexOf(44, -5)"); + assert.sameValue(sample.indexOf(convertToBigInt(42), -1), -1, "indexOf(42, -1)"); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/this-is-not-object.js new file mode 100644 index 000000000..c572d7dd3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/this-is-not-object.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.indexof +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var indexOf = TypedArray.prototype.indexOf; + +assert.throws(TypeError, function() { + indexOf.call(undefined, 42); +}, "this is undefined"); + +assert.throws(TypeError, function() { + indexOf.call(null, 42); +}, "this is null"); + +assert.throws(TypeError, function() { + indexOf.call(42, 42); +}, "this is 42"); + +assert.throws(TypeError, function() { + indexOf.call("1", 42); +}, "this is a string"); + +assert.throws(TypeError, function() { + indexOf.call(true, 42); +}, "this is true"); + +assert.throws(TypeError, function() { + indexOf.call(false, 42); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + indexOf.call(s, 42); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..753fc3f79 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.indexof +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var indexOf = TypedArray.prototype.indexOf; + +assert.throws(TypeError, function() { + indexOf.call({}, 42); +}, "this is an Object"); + +assert.throws(TypeError, function() { + indexOf.call([], 42); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + indexOf.call(ab, 42); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + indexOf.call(dv, 42); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/indexOf/BigInt/tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/indexOf/BigInt/tointeger-fromindex.js new file mode 100644 index 000000000..e338bf1a4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/indexOf/BigInt/tointeger-fromindex.js @@ -0,0 +1,57 @@ +// 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.indexof +description: Return -1 if fromIndex >= ArrayLength - converted values +info: | + 22.2.3.13 %TypedArray%.prototype.indexOf (searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.indexOf is a distinct function that implements the same + algorithm as Array.prototype.indexOf as defined in 22.1.3.12 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.12 Array.prototype.indexOf ( searchElement [ , fromIndex ] ) + + ... + 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step + produces the value 0.) + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43])); + assert.sameValue(sample.indexOf(convertToBigInt(42), "1"), -1, "string [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), "1"), 1, "string [1]"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), true), -1, "true [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), true), 1, "true [1]"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), false), 0, "false [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), false), 1, "false [1]"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), NaN), 0, "NaN [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), NaN), 1, "NaN [1]"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), null), 0, "null [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), null), 1, "null [1]"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), undefined), 0, "undefined [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), undefined), 1, "undefined [1]"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), null), 0, "null [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), null), 1, "null [1]"); + + assert.sameValue(sample.indexOf(convertToBigInt(42), obj), -1, "object [0]"); + assert.sameValue(sample.indexOf(convertToBigInt(43), obj), 1, "object [1]"); +}); diff --git a/test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js b/test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js index ddd3540f8..5a7883f97 100644 --- a/test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js +++ b/test/built-ins/TypedArray/prototype/indexOf/strict-comparison.js @@ -38,6 +38,4 @@ testWithTypedArrayConstructors(function(TA) { assert.sameValue(sample.indexOf(null), -1, "null"); assert.sameValue(sample.indexOf(undefined), -1, "undefined"); assert.sameValue(sample.indexOf(""), -1, "empty string"); -}, - // Cannot create Big*64Arrays from non-safe integers. - numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js b/test/built-ins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js new file mode 100644 index 000000000..2f611e46f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/custom-separator-result-from-tostring-on-each-simple-value.js @@ -0,0 +1,78 @@ +// 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.join +description: > + Concatenates the result of toString for each value with custom separator +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 0, 2, 3, 42, 127])); + + var result; + + result = sample.join(","); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(undefined); + assert.sameValue(result, "1,0,2,3,42,127"); + + result = sample.join(null); + assert.sameValue(result, "1null0null2null3null42null127"); + + result = sample.join(",,"); + assert.sameValue(result, "1,,0,,2,,3,,42,,127"); + + result = sample.join(0); + assert.sameValue(result, "10002030420127"); + + result = sample.join(""); + assert.sameValue(result, "102342127"); + + result = sample.join(" a b c "); + assert.sameValue(result, "1 a b c 0 a b c 2 a b c 3 a b c 42 a b c 127"); + + result = sample.join({}); + assert.sameValue(result, "1[object Object]0[object Object]2[object Object]3[object Object]42[object Object]127"); + + result = sample.join(true); + assert.sameValue(result, "1true0true2true3true42true127"); + + result = sample.join({ toString: function() { return "foo"; }}); + assert.sameValue(result, "1foo0foo2foo3foo42foo127"); + + result = sample.join({ toString: undefined, valueOf: function() { return "bar"; }}); + assert.sameValue(result, "1bar0bar2bar3bar42bar127"); + + result = sample.join(false); + assert.sameValue(result, "1false0false2false3false42false127"); + + result = sample.join(-1); + assert.sameValue(result, "1-10-12-13-142-1127"); + + result = sample.join(-0); + assert.sameValue(result, "10002030420127"); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js new file mode 100644 index 000000000..1af7ae94c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/detached-buffer.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.join +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.join(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js b/test/built-ins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js new file mode 100644 index 000000000..a7103a83e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/empty-instance-empty-string.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.join +description: Return the empty String if length is 0 +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.sameValue(sample.join(), ""); + assert.sameValue(sample.join("test262"), ""); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..24ca6f0e3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.join +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... + 5. If len is zero, return the empty String. + ... +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(convertToBigInt([42, 43])); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.join(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.notSameValue(result, "", "result is not affected but custom length 0"); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/join/BigInt/invoked-as-func.js new file mode 100644 index 000000000..f2bab1f7f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.14 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.14 %TypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var join = TypedArray.prototype.join; + +assert.sameValue(typeof join, 'function'); + +assert.throws(TypeError, function() { + join(); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/join/BigInt/invoked-as-method.js new file mode 100644 index 000000000..11bf0beda --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.14 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.14 %TypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.join, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.join(); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/length.js b/test/built-ins/TypedArray/prototype/join/BigInt/length.js new file mode 100644 index 000000000..540d1aba3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/length.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. + +/*--- +es6id: 22.2.3.14 +description: > + %TypedArray%.prototype.join.length is 1. +info: | + %TypedArray%.prototype.join ( separator ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.join.length, 1); + +verifyNotEnumerable(TypedArray.prototype.join, "length"); +verifyNotWritable(TypedArray.prototype.join, "length"); +verifyConfigurable(TypedArray.prototype.join, "length"); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/name.js b/test/built-ins/TypedArray/prototype/join/BigInt/name.js new file mode 100644 index 000000000..dea31a3c7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.14 +description: > + %TypedArray%.prototype.join.name is "join". +info: | + %TypedArray%.prototype.join ( separator ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.join.name, "join"); + +verifyNotEnumerable(TypedArray.prototype.join, "name"); +verifyNotWritable(TypedArray.prototype.join, "name"); +verifyConfigurable(TypedArray.prototype.join, "name"); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/join/BigInt/prop-desc.js new file mode 100644 index 000000000..2102a0b24 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.14 +description: > + "join" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'join'); +verifyWritable(TypedArrayPrototype, 'join'); +verifyConfigurable(TypedArrayPrototype, 'join'); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js b/test/built-ins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.js new file mode 100644 index 000000000..186585603 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/result-from-tostring-on-each-simple-value.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.join +description: Concatenates the result of toString for each simple value +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 7. If element0 is undefined or null, let R be the empty String; otherwise, let + R be ? ToString(element0). + 8. Let k be 1. + 9. Repeat, while k < len + a. Let S be the String value produced by concatenating R and sep. + b. Let element be ? Get(O, ! ToString(k)). + c. If element is undefined or null, let next be the empty String; otherwise, + let next be ? ToString(element). + d. Let R be a String value produced by concatenating S and next. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 0, 2, 3, 42, 127])); + + var result = sample.join(); + + assert.sameValue(result, "1,0,2,3,42,127"); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js b/test/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.js new file mode 100644 index 000000000..fe27585b2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator-symbol.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.join +description: Return abrupt from ToString(Symbol separator) +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol(""); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.join(s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js b/test/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.js new file mode 100644 index 000000000..beb8d16b0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/return-abrupt-from-separator.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.join +description: Return abrupt from ToString(separator) +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + %TypedArray%.prototype.join is a distinct function that implements the same + algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.13 Array.prototype.join (separator) + + ... + 4. Let sep be ? ToString(separator). + 5. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.join(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/join/BigInt/this-is-not-object.js new file mode 100644 index 000000000..6f04ef810 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/this-is-not-object.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.join +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var join = TypedArray.prototype.join; + +assert.throws(TypeError, function() { + join.call(undefined, ""); +}, "this is undefined"); + +assert.throws(TypeError, function() { + join.call(null, ""); +}, "this is null"); + +assert.throws(TypeError, function() { + join.call(42, ""); +}, "this is 42"); + +assert.throws(TypeError, function() { + join.call("1", ""); +}, "this is a string"); + +assert.throws(TypeError, function() { + join.call(true, ""); +}, "this is true"); + +assert.throws(TypeError, function() { + join.call(false, ""); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + join.call(s, ""); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/join/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/join/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..582c99f3d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/join/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.join +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var join = TypedArray.prototype.join; + +assert.throws(TypeError, function() { + join.call({}, ""); +}, "this is an Object"); + +assert.throws(TypeError, function() { + join.call([], ""); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + join.call(ab, ""); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + join.call(dv, ""); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js b/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js index d135c173f..94caedf65 100644 --- a/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js +++ b/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js @@ -132,6 +132,4 @@ testWithTypedArrayConstructors(function(TA) { }).join(separator); result = sample.join(separator); assert.sameValue(result, expected, "using: " + separator); -}, - // Cannot create Big*64Arrays from non-safe integers. - numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js b/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js index df27d079c..d3d699ffa 100644 --- a/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js +++ b/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js @@ -41,6 +41,4 @@ testWithTypedArrayConstructors(function(TA) { var result = sample.join(); assert.sameValue(result, expected); -}, - // Cannot construct Big*64Arrays from non-safe integers. - numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/keys/BigInt/detached-buffer.js new file mode 100644 index 000000000..90189e441 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/detached-buffer.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.keys +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.16 %TypedArray%.prototype.keys ( ) + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.keys(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/keys/BigInt/invoked-as-func.js new file mode 100644 index 000000000..f96271997 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.15 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.15 %TypedArray%.prototype.keys ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var keys = TypedArray.prototype.keys; + +assert.sameValue(typeof keys, 'function'); + +assert.throws(TypeError, function() { + keys(); +}); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/keys/BigInt/invoked-as-method.js new file mode 100644 index 000000000..ca9b0d663 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.15 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.15 %TypedArray%.prototype.keys ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.keys, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.keys(); +}); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/iter-prototype.js b/test/built-ins/TypedArray/prototype/keys/BigInt/iter-prototype.js new file mode 100644 index 000000000..fd5e0a5ec --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/iter-prototype.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.16 +esid: sec-%typedarray%.prototype.keys +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.16 %TypedArray%.prototype.keys ( ) + + ... + 3. Return CreateArrayIterator(O, "key"). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([0, 42, 64])); + var iter = sample.keys(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/length.js b/test/built-ins/TypedArray/prototype/keys/BigInt/length.js new file mode 100644 index 000000000..39d20e5e2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/length.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. + +/*--- +es6id: 22.2.3.15 +description: > + %TypedArray%.prototype.keys.length is 0. +info: | + %TypedArray%.prototype.keys ( ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.keys.length, 0); + +verifyNotEnumerable(TypedArray.prototype.keys, "length"); +verifyNotWritable(TypedArray.prototype.keys, "length"); +verifyConfigurable(TypedArray.prototype.keys, "length"); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/name.js b/test/built-ins/TypedArray/prototype/keys/BigInt/name.js new file mode 100644 index 000000000..2cd9e67d4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.15 +description: > + %TypedArray%.prototype.keys.name is "keys". +info: | + %TypedArray%.prototype.keys ( ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.keys.name, "keys"); + +verifyNotEnumerable(TypedArray.prototype.keys, "name"); +verifyNotWritable(TypedArray.prototype.keys, "name"); +verifyConfigurable(TypedArray.prototype.keys, "name"); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/keys/BigInt/prop-desc.js new file mode 100644 index 000000000..669d27257 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.15 +description: > + "keys" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'keys'); +verifyWritable(TypedArrayPrototype, 'keys'); +verifyConfigurable(TypedArrayPrototype, 'keys'); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/return-itor.js b/test/built-ins/TypedArray/prototype/keys/BigInt/return-itor.js new file mode 100644 index 000000000..e4bc1b0ba --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/return-itor.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. +/*--- +es6id: 22.2.3.16 +esid: sec-%typedarray%.prototype.keys +description: Return an iterator for the keys. +info: | + 22.2.3.16 %TypedArray%.prototype.keys ( ) + + ... + 3. Return CreateArrayIterator(O, "key"). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sample = [0, 42, 64]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(convertToBigInt(sample)); + var itor = typedArray.keys(); + + var next = itor.next(); + assert.sameValue(next.value, 0); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 1); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, 2); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/keys/BigInt/this-is-not-object.js new file mode 100644 index 000000000..7fd0c8f05 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/this-is-not-object.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.keys +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.16 %TypedArray%.prototype.keys ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var keys = TypedArray.prototype.keys; + +assert.throws(TypeError, function() { + keys.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + keys.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + keys.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + keys.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + keys.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + keys.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + keys.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/keys/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/keys/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..6978bfb3d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/keys/BigInt/this-is-not-typedarray-instance.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.keys +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.16 %TypedArray%.prototype.keys ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var keys = TypedArray.prototype.keys; + +assert.throws(TypeError, function() { + keys.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + keys.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + keys.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + keys.call(dv); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer.js new file mode 100644 index 000000000..616f96ce5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/detached-buffer.js @@ -0,0 +1,28 @@ +// 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.lastindexof +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.lastIndexOf(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-infinity.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-infinity.js new file mode 100644 index 000000000..d7c28b130 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-infinity.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.lastindexof +description: handle Infinity values for fromIndex +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 43, 41])); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), Infinity), 2, "lastIndexOf(43, Infinity)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), -Infinity), -1, "lastIndexOf(43, -Infinity)"); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-minus-zero.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-minus-zero.js new file mode 100644 index 000000000..284d49930 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/fromIndex-minus-zero.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.lastindexof +description: -0 fromIndex becomes 0 +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43])); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), -0), 0, "-0 [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), -0), -1, "-0 [1]"); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..2b4daf2dd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/get-length-uses-internal-arraylength.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.lastindexof +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +Object.defineProperty(TypedArray.prototype, "length", {value: 0}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7])); + + Object.defineProperty(TA.prototype, "length", {value: 0}); + Object.defineProperty(sample, "length", {value: 0}); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(7)), 0); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/invoked-as-func.js new file mode 100644 index 000000000..d36811f90 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.16 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.16 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var lastIndexOf = TypedArray.prototype.lastIndexOf; + +assert.sameValue(typeof lastIndexOf, 'function'); + +assert.throws(TypeError, function() { + lastIndexOf(); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/invoked-as-method.js new file mode 100644 index 000000000..ec03407bb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.16 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.16 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.lastIndexOf, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.lastIndexOf(); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/length-zero-returns-minus-one.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/length-zero-returns-minus-one.js new file mode 100644 index 000000000..07fc5da72 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/length-zero-returns-minus-one.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.lastindexof +description: Returns -1 if length is 0 +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. If len is 0, return -1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.lastIndexOf(0), -1, "returns -1"); + assert.sameValue( + sample.lastIndexOf(0, fromIndex), -1, + "length is checked before ToInteger(fromIndex)" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/length.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/length.js new file mode 100644 index 000000000..809454a16 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/length.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. + +/*--- +es6id: 22.2.3.16 +description: > + %TypedArray%.prototype.lastIndexOf.length is 1. +info: | + %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.lastIndexOf.length, 1); + +verifyNotEnumerable(TypedArray.prototype.lastIndexOf, "length"); +verifyNotWritable(TypedArray.prototype.lastIndexOf, "length"); +verifyConfigurable(TypedArray.prototype.lastIndexOf, "length"); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/name.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/name.js new file mode 100644 index 000000000..4e500aaf4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.16 +description: > + %TypedArray%.prototype.lastIndexOf.name is "lastIndexOf". +info: | + %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.lastIndexOf.name, "lastIndexOf"); + +verifyNotEnumerable(TypedArray.prototype.lastIndexOf, "name"); +verifyNotWritable(TypedArray.prototype.lastIndexOf, "name"); +verifyConfigurable(TypedArray.prototype.lastIndexOf, "name"); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/prop-desc.js new file mode 100644 index 000000000..0b5ab2e59 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.16 +description: > + "lastIndexOf" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'lastIndexOf'); +verifyWritable(TypedArrayPrototype, 'lastIndexOf'); +verifyConfigurable(TypedArrayPrototype, 'lastIndexOf'); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.js new file mode 100644 index 000000000..67c1ea4c6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex-symbol.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.lastindexof +description: Return abrupt from ToInteger(fromIndex) - using symbol +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var fromIndex = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.lastIndexOf(7, fromIndex); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex.js new file mode 100644 index 000000000..2f3465b34 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/return-abrupt-tointeger-fromindex.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.lastindexof +description: Return abrupt from ToInteger(fromIndex) +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var fromIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(Test262Error, function() { + sample.lastIndexOf(7, fromIndex); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/search-found-returns-index.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/search-found-returns-index.js new file mode 100644 index 000000000..255672fa4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/search-found-returns-index.js @@ -0,0 +1,57 @@ +// 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.lastindexof +description: returns index for the first found element +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + a. Let kPresent be ? HasProperty(O, ! ToString(k)). + b. If kPresent is true, then + i. Let elementK be ? Get(O, ! ToString(k)). + ii. Let same be the result of performing Strict Equality Comparison + searchElement === elementK. + iii. If same is true, return k. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 42, 41])); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42)), 2, "lastIndexOf(42)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43)), 1, "lastIndexOf(43)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(41)), 3, "lastIndexOf(41)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(41), 3), 3, "lastIndexOf(41, 3)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(41), 4), 3, "lastIndexOf(41, 4)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), 1), 1, "lastIndexOf(43, 1)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), 2), 1, "lastIndexOf(43, 2)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), 3), 1, "lastIndexOf(43, 3)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), 4), 1, "lastIndexOf(43, 4)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), 0), 0, "lastIndexOf(42, 0)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), 1), 0, "lastIndexOf(42, 1)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), 2), 2, "lastIndexOf(42, 2)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), 3), 2, "lastIndexOf(42, 3)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), 4), 2, "lastIndexOf(42, 4)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), -4), 0, "lastIndexOf(42, -4)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), -3), 0, "lastIndexOf(42, -3)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), -2), 2, "lastIndexOf(42, -2)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), -1), 2, "lastIndexOf(42, -1)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), -3), 1, "lastIndexOf(43, -3)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), -2), 1, "lastIndexOf(43, -2)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), -1), 1, "lastIndexOf(43, -1)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(41), -1), 3, "lastIndexOf(41, -1)"); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/search-not-found-returns-minus-one.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/search-not-found-returns-minus-one.js new file mode 100644 index 000000000..d53260ab8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/search-not-found-returns-minus-one.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.lastindexof +description: returns -1 if the element if not found +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 5. If n ≥ 0, then + a. If n is -0, let k be +0; else let k be min(n, len - 1). + 6. Else n < 0, + a. Let k be len + n. + 7. Repeat, while k ≥ 0 + ... + 8. Return -1. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43, 42, 41])); + assert.sameValue(sample.lastIndexOf(convertToBigInt(44)), -1, "lastIndexOf(44)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(44), -4), -1, "lastIndexOf(44, -4)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(44), -5), -1, "lastIndexOf(44, -5)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), -5), -1, "lastIndexOf(42, -5)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), -4), -1, "lastIndexOf(43, -4)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), -5), -1, "lastIndexOf(43, -5)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(41), 0), -1, "lastIndexOf(41, 0)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(41), 1), -1, "lastIndexOf(41, 1)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(41), 2), -1, "lastIndexOf(41, 2)"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), 0), -1, "lastIndexOf(43, 0)"); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/this-is-not-object.js new file mode 100644 index 000000000..02a4312c0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/this-is-not-object.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.lastindexof +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var lastIndexOf = TypedArray.prototype.lastIndexOf; + +assert.throws(TypeError, function() { + lastIndexOf.call(undefined, 42); +}, "this is undefined"); + +assert.throws(TypeError, function() { + lastIndexOf.call(null, 42); +}, "this is null"); + +assert.throws(TypeError, function() { + lastIndexOf.call(42, 42); +}, "this is 42"); + +assert.throws(TypeError, function() { + lastIndexOf.call("1", 42); +}, "this is a string"); + +assert.throws(TypeError, function() { + lastIndexOf.call(true, 42); +}, "this is true"); + +assert.throws(TypeError, function() { + lastIndexOf.call(false, 42); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + lastIndexOf.call(s, 42); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..e59dc5c53 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.lastindexof +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var lastIndexOf = TypedArray.prototype.lastIndexOf; + +assert.throws(TypeError, function() { + lastIndexOf.call({}, 42); +}, "this is an Object"); + +assert.throws(TypeError, function() { + lastIndexOf.call([], 42); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + lastIndexOf.call(ab, 42); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + lastIndexOf.call(dv, 42); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/tointeger-fromindex.js b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/tointeger-fromindex.js new file mode 100644 index 000000000..8c591c1a7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/BigInt/tointeger-fromindex.js @@ -0,0 +1,57 @@ +// 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.lastindexof +description: Return -1 if fromIndex >= ArrayLength - converted values +info: | + 22.2.3.17 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + %TypedArray%.prototype.lastIndexOf is a distinct function that implements the + same algorithm as Array.prototype.lastIndexOf as defined in 22.1.3.15 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] ) + + ... + 4. If argument fromIndex was passed, let n be ? ToInteger(fromIndex); else let + n be len-1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 1; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([42, 43])); + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), "1"), 0, "string [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), "1"), 1, "string [1]"); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), true), 0, "true [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), true), 1, "true [1]"); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), false), 0, "false [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), false), -1, "false [1]"); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), NaN), 0, "NaN [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), NaN), -1, "NaN [1]"); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), null), 0, "null [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), null), -1, "null [1]"); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), undefined), 0, "undefined [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), undefined), -1, "undefined [1]"); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), null), 0, "null [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), null), -1, "null [1]"); + + assert.sameValue(sample.lastIndexOf(convertToBigInt(42), obj), 0, "object [0]"); + assert.sameValue(sample.lastIndexOf(convertToBigInt(43), obj), 1, "object [1]"); +}); diff --git a/test/built-ins/TypedArray/prototype/lastIndexOf/strict-comparison.js b/test/built-ins/TypedArray/prototype/lastIndexOf/strict-comparison.js index 1adeec42f..374cebfa5 100644 --- a/test/built-ins/TypedArray/prototype/lastIndexOf/strict-comparison.js +++ b/test/built-ins/TypedArray/prototype/lastIndexOf/strict-comparison.js @@ -38,6 +38,4 @@ testWithTypedArrayConstructors(function(TA) { assert.sameValue(sample.lastIndexOf(null), -1, "null"); assert.sameValue(sample.lastIndexOf(undefined), -1, "undefined"); assert.sameValue(sample.lastIndexOf(""), -1, "empty string"); -}, - // Cannot create Big*64Arrays from non-safe integers. - numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/length/BigInt/detached-buffer.js new file mode 100644 index 000000000..31ee55484 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/detached-buffer.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-get-%typedarray%.prototype.length +description: Returns 0 if the instance has a detached buffer +info: | + 22.2.3.18 get %TypedArray%.prototype.length + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. If IsDetachedBuffer(buffer) is true, return 0. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + assert.sameValue(sample.length, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/invoked-as-accessor.js b/test/built-ins/TypedArray/prototype/length/BigInt/invoked-as-accessor.js new file mode 100644 index 000000000..e8f07cb68 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/invoked-as-accessor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.17 +description: > + Requires this value to have a [[ViewedArrayBuffer]] internal slot +info: | + 22.2.3.17 get %TypedArray%.prototype.length + + 1. Let O be the this value. + ... + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.throws(TypeError, function() { + TypedArrayPrototype.length; +}); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/length/BigInt/invoked-as-func.js new file mode 100644 index 000000000..0e3283914 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/invoked-as-func.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.17 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.17 get %TypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, 'length' +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/length.js b/test/built-ins/TypedArray/prototype/length/BigInt/length.js new file mode 100644 index 000000000..873bf7d57 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.17 +description: > + get %TypedArray%.prototype.length.length is 0. +info: | + get %TypedArray%.prototype.length + + 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, testBigIntTypedArray.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(TypedArray.prototype, "length"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/name.js b/test/built-ins/TypedArray/prototype/length/BigInt/name.js new file mode 100644 index 000000000..168a579c7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.17 +description: > + get %TypedArray%.prototype.length.name is "get length". +info: | + get %TypedArray%.prototype.length + + 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, testBigIntTypedArray.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(TypedArray.prototype, "length"); + +assert.sameValue(desc.get.name, "get length"); + +verifyNotEnumerable(desc.get, "name"); +verifyNotWritable(desc.get, "name"); +verifyConfigurable(desc.get, "name"); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/length/BigInt/prop-desc.js new file mode 100644 index 000000000..be321d354 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/prop-desc.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.17 +description: > + "length" property of TypedArrayPrototype +info: | + %TypedArray%.prototype.length is an accessor property whose set accessor + function is undefined. + + Section 17: Every accessor property described in clauses 18 through 26 and in + Annex B.2 has the attributes {[[Enumerable]]: false, [[Configurable]]: true } +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var desc = Object.getOwnPropertyDescriptor(TypedArrayPrototype, "length"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(TypedArrayPrototype, "length"); +verifyConfigurable(TypedArrayPrototype, "length"); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/return-length.js b/test/built-ins/TypedArray/prototype/length/BigInt/return-length.js new file mode 100644 index 000000000..419acd0f6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/return-length.js @@ -0,0 +1,28 @@ +// 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-get-%typedarray%.prototype.length +description: > + Return value from the [[ArrayLength]] internal slot +info: | + 22.2.3.18 get %TypedArray%.prototype.length + + ... + 6. Let length be the value of O's [[ArrayLength]] internal slot. + 7. Return length. + + --- + + The current tests on `prop-desc.js` and `length.js` already assert `length` is + not a dynamic property as in regular arrays. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta1 = new TA(); + assert.sameValue(ta1.length, 0); + + var ta2 = new TA(42); + assert.sameValue(ta2.length, 42); +}); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/this-has-no-typedarrayname-internal.js b/test/built-ins/TypedArray/prototype/length/BigInt/this-has-no-typedarrayname-internal.js new file mode 100644 index 000000000..1dd1d7696 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/this-has-no-typedarrayname-internal.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-get-%typedarray%.prototype.length +description: > + Throws a TypeError exception when `this` does not have a [[TypedArrayName]] + internal slot +info: | + 22.2.3.18 get %TypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, DataView, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "length" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}); + +var dv = new DataView(new ArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/built-ins/TypedArray/prototype/length/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/length/BigInt/this-is-not-object.js new file mode 100644 index 000000000..663a6402b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/length/BigInt/this-is-not-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-%typedarray%.prototype.length +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.18 get %TypedArray%.prototype.length + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; +var getter = Object.getOwnPropertyDescriptor( + TypedArrayPrototype, "length" +).get; + + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "number"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "symbol"); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/arraylength-internal.js b/test/built-ins/TypedArray/prototype/map/BigInt/arraylength-internal.js new file mode 100644 index 000000000..c74501315 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/arraylength-internal.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + [[ArrayLength]] is accessed in place of performing a [[Get]] of "length" +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(42); + var loop = 0; + + Object.defineProperty(sample1, "length", {value: 1}); + + sample1.map(function() { + loop++; + return convertToBigInt(0); + }); + assert.sameValue(loop, 42, "data descriptor"); + + loop = 0; + var sample2 = new TA(4); + Object.defineProperty(sample2, "length", { + get: function() { + throw new Test262Error( + "Does not return abrupt getting length property" + ); + } + }); + + sample2.map(function() { + loop++; + return convertToBigInt(0); + }); + assert.sameValue(loop, 4, "accessor descriptor"); +}); + diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 000000000..85ff13e4e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.map(function() { + results.push(arguments); + return convertToBigInt(0); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 000000000..1e12f5551 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-arguments-without-thisarg.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + callbackfn arguments +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.map(function() { + results.push(arguments); + return convertToBigInt(0); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 000000000..59971da1e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.map(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + return convertToBigInt(0); + }); + }); + + assert.sameValue(loops, 1, "callbackfn called only once"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js new file mode 100644 index 000000000..4f30cdf50 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-is-not-callable.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + callbackfn is not callable +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 4. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(TypeError, function() { + sample.map(); + }); + + assert.throws(TypeError, function() { + sample.map(undefined); + }); + + assert.throws(TypeError, function() { + sample.map(null); + }); + + assert.throws(TypeError, function() { + sample.map({}); + }); + + assert.throws(TypeError, function() { + sample.map(1); + }); + + assert.throws(TypeError, function() { + sample.map(""); + }); + + assert.throws(TypeError, function() { + sample.map(false); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.js new file mode 100644 index 000000000..a1b5639f1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-no-interaction-over-non-integer-properties.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.map +description: > + Does not interact over non-integer properties +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.map(function() { + results.push(arguments); + return convertToBigInt(0); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + + assert.sameValue(results[0][0], convertToBigInt(7), "results[0][0] - kValue"); + assert.sameValue(results[1][0], convertToBigInt(8), "results[1][0] - kValue"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 000000000..3e7a82aeb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().map(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.js new file mode 100644 index 000000000..cfd180d1f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-affects-returned-object.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.map +description: > + The callbackfn returned values are applied to the new instance +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + d. Perform ? Set(A, Pk, mappedValue, true). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 2, 4])); + var result = sample.map(function(v) { + return v * convertToBigInt(3); + }); + + assert.sameValue(result[0], convertToBigInt(3), "result[0] == 3"); + assert.sameValue(result[1], convertToBigInt(6), "result[1] == 6"); + assert.sameValue(result[2], convertToBigInt(12), "result[2] == 12"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 000000000..bc0f6f32b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + The callbackfn return does not change the `this` instance +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(3); + + sample1[1] = convertToBigInt(1); + + sample1.map(function() { + return convertToBigInt(42); + }); + + assert.sameValue(sample1[0], convertToBigInt(0), "[0] == 0"); + assert.sameValue(sample1[1], convertToBigInt(1), "[1] == 1"); + assert.sameValue(sample1[2], convertToBigInt(0), "[2] == 0"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js new file mode 100644 index 000000000..a672b35bd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-return-does-not-copy-non-integer-properties.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Does not copy non-integer properties to returned value +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + a. Let Pk be ! ToString(k). + b. Let kValue be ? Get(O, Pk). + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + var bar = Symbol("1"); + + sample.foo = 42; + sample[bar] = 1; + + var result = sample.map(function() { + return convertToBigInt(0); + }); + + assert.sameValue(result.length, 2, "result.length"); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, "foo"), + undefined, + "foo" + ); + assert.sameValue( + Object.getOwnPropertyDescriptor(result, bar), + undefined, + "bar" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 000000000..c8080729d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-returns-abrupt.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.map(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 000000000..2e0f7eed1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-set-value-during-interaction.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + var newVal = 0; + + sample.map(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], convertToBigInt(newVal - 1), + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, convertToBigInt(7)), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, convertToBigInt(newVal)), + true, + "set value during iteration" + ); + + newVal++; + return convertToBigInt(0); + }); + + assert.sameValue(sample[0], convertToBigInt(7), "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], convertToBigInt(1), "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], convertToBigInt(2), "changed values after iteration [2] == 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-this.js b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-this.js new file mode 100644 index 000000000..e5ee5393c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/callbackfn-this.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + callbackfn `this` value +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.map(function() { + results1.push(this); + return convertToBigInt(0); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.map(function() { + results2.push(this); + return convertToBigInt(0); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/map/BigInt/detached-buffer.js new file mode 100644 index 000000000..c7039bd1d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/detached-buffer.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.map(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/map/BigInt/invoked-as-func.js new file mode 100644 index 000000000..1c07da18e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.18 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.18 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var map = TypedArray.prototype.map; + +assert.sameValue(typeof map, 'function'); + +assert.throws(TypeError, function() { + map(); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/map/BigInt/invoked-as-method.js new file mode 100644 index 000000000..3d5bb1f8f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.18 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.18 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Let valid be ValidateTypedArray(O). + 3. ReturnIfAbrupt(valid). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.map, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.map(); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/length.js b/test/built-ins/TypedArray/prototype/map/BigInt/length.js new file mode 100644 index 000000000..75c9a5ace --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/length.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. + +/*--- +es6id: 22.2.3.18 +description: > + %TypedArray%.prototype.map.length is 1. +info: | + %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.map.length, 1); + +verifyNotEnumerable(TypedArray.prototype.map, "length"); +verifyNotWritable(TypedArray.prototype.map, "length"); +verifyConfigurable(TypedArray.prototype.map, "length"); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/name.js b/test/built-ins/TypedArray/prototype/map/BigInt/name.js new file mode 100644 index 000000000..bd5237b2d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.18 +description: > + %TypedArray%.prototype.map.name is "map". +info: | + %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.map.name, "map"); + +verifyNotEnumerable(TypedArray.prototype.map, "name"); +verifyNotWritable(TypedArray.prototype.map, "name"); +verifyConfigurable(TypedArray.prototype.map, "name"); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/map/BigInt/prop-desc.js new file mode 100644 index 000000000..c68afe481 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.18 +description: > + "map" property of TypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'map'); +verifyWritable(TypedArrayPrototype, 'map'); +verifyConfigurable(TypedArrayPrototype, 'map'); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-conversion-operation-consistent-nan.js b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-conversion-operation-consistent-nan.js new file mode 100644 index 000000000..a8c3cb62e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-conversion-operation-consistent-nan.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.map +description: Consistent canonicalization of NaN values +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Perform ? Set(A, Pk, mappedValue, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + 9. Else, if type is "Float64", then + a. Set rawBytes to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of value. If isLittleEndian is false, + the bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + ... +includes: [nans.js, testBigIntTypedArray.js, compareArray.js] +---*/ + +function body(FloatArray) { + var sample = new FloatArray(distinctNaNs); + var sampleBytes, resultBytes; + var i = 0; + + var result = sample.map(function() { + return distinctNaNs[i++]; + }); + + sampleBytes = new Uint8Array(sample.buffer); + resultBytes = new Uint8Array(result.buffer); + + assert(compareArray(sampleBytes, resultBytes)); +} + +testWithBigIntTypedArrayConstructors(body, [Float32Array, Float64Array]); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-conversion-operation.js b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-conversion-operation.js new file mode 100644 index 000000000..fdc16e2ab --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-conversion-operation.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.map +description: > + Verify conversion values on returned instance +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 8. Repeat, while k < len + ... + d. Perform ? Set(A, Pk, mappedValue, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testBigIntTypedArray.js] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + var result = sample.map(function() { + return value; + }); + + assert.sameValue(result[0], expected, value + " converts to " + expected); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js new file mode 100644 index 000000000..957bb7cdd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-empty-length.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length == 0 +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(0); + + var result = sample.map(function() {}); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, TA, "same constructor"); + assert(result instanceof TA, "result is an instance of " + TA.name); + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "result has the same prototype of sample" + ); + assert.sameValue(result.length, 0, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-length.js new file mode 100644 index 000000000..e7ba97709 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/return-new-typedarray-from-positive-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.map +description: > + Returns a new typedArray instance from the same constructor with the same + length and a new buffer object - testing on an instance with length > 0 +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + ... + 6. Let A be ? TypedArraySpeciesCreate(O, « len »). + 7. Let k be 0. + 8. Repeat, while k < len + ... + c. Let mappedValue be ? Call(callbackfn, T, « kValue, k, O »). + ... + 9. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var result = sample.map(function(v) { + return v; + }); + + assert.notSameValue(result, sample, "new typedArray object"); + assert.sameValue(result.constructor, sample.constructor, "same constructor"); + assert.sameValue(result.length, 3, "same length"); + assert.notSameValue(result.buffer, sample.buffer, "new buffer"); +}); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/map/BigInt/this-is-not-object.js new file mode 100644 index 000000000..50fa543a6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/this-is-not-object.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.map +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var map = TypedArray.prototype.map; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + map.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + map.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + map.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + map.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + map.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + map.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + map.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/map/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..97266d749 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var map = TypedArray.prototype.map; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + map.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + map.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + map.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + map.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/map/BigInt/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/map/BigInt/values-are-not-cached.js new file mode 100644 index 000000000..a8665d931 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/map/BigInt/values-are-not-cached.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.map +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.19 %TypedArray%.prototype.map ( callbackfn [ , thisArg ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + sample.map(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = convertToBigInt(42); + } + + assert.sameValue( + v, convertToBigInt(42), "method does not cache values before callbackfn calls" + ); + + return convertToBigInt(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-custom-accumulator.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-custom-accumulator.js new file mode 100644 index 000000000..8527302fd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-custom-accumulator.js @@ -0,0 +1,58 @@ +// 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.reduce +description: > + callbackfn arguments using custom accumulator +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.reduce(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }, 7); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 4, "results[0].length"); + assert.sameValue(results[0][0], 7, "results[0][0] - accumulator"); + assert.sameValue(results[0][1], convertToBigInt(42), "results[0][1] - kValue"); + assert.sameValue(results[0][2], 0, "results[0][2] - k"); + assert.sameValue(results[0][3], sample, "results[0][3] - this"); + + assert.sameValue(results[1].length, 4, "results[1].length"); + assert.sameValue(results[1][0], 8, "results[1][0] - accumulator"); + assert.sameValue(results[1][1], convertToBigInt(43), "results[1][1] - kValue"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + assert.sameValue(results[1][3], sample, "results[1][3] - this"); + + assert.sameValue(results[2].length, 4, "results[2].length"); + assert.sameValue(results[2][0], 9, "results[2][0] - accumulator"); + assert.sameValue(results[2][1], convertToBigInt(44), "results[2][1] - kValue"); + assert.sameValue(results[2][2], 2, "results[2][2] - k"); + assert.sameValue(results[2][3], sample, "results[2][3] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-default-accumulator.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-default-accumulator.js new file mode 100644 index 000000000..b4514895a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-arguments-default-accumulator.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduce +description: > + callbackfn arguments using default accumulator (value at index 0) +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + a. Let kPresent be false. + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.reduce(function(accumulator) { + results.push(arguments); + return accumulator - convertToBigInt(1); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0].length, 4, "results[1].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[1][0] - accumulator"); + assert.sameValue(results[0][1], convertToBigInt(43), "results[1][1] - kValue"); + assert.sameValue(results[0][2], 1, "results[1][2] - k"); + assert.sameValue(results[0][3], sample, "results[1][3] - this"); + + assert.sameValue(results[1].length, 4, "results[2].length"); + assert.sameValue(results[1][0], convertToBigInt(41), "results[2][0] - accumulator"); + assert.sameValue(results[1][1], convertToBigInt(44), "results[2][1] - kValue"); + assert.sameValue(results[1][2], 2, "results[2][2] - k"); + assert.sameValue(results[1][3], sample, "results[2][3] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 000000000..60ce57fe7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-detachbuffer.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.reduce +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.reduce(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + }, 0); + }); + + assert.sameValue(loops, 1, "callbackfn called only once"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-is-not-callable-throws.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-is-not-callable-throws.js new file mode 100644 index 000000000..36b147501 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-is-not-callable-throws.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduce +description: > + Throws TypeError if callbackfn is not callable +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.reduce(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.reduce(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.reduce(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.reduce({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.reduce(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.reduce(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.reduce(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.reduce(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.reduce(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.reduce(Symbol("")); + }, "symbol"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-no-iteration-over-non-integer-properties.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-no-iteration-over-non-integer-properties.js new file mode 100644 index 000000000..b230de900 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-no-iteration-over-non-integer-properties.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.reduce +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.reduce(function() { + results.push(arguments); + }, 0); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][2], 0, "results[0][2] - k"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + + assert.sameValue(results[0][1], convertToBigInt(7), "results[0][1] - kValue"); + assert.sameValue(results[1][1], convertToBigInt(8), "results[1][1] - kValue"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 000000000..8bcbcfd43 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-not-called-on-empty.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduce +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().reduce(function() { + called++; + }, undefined); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 000000000..05a8adddf --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-return-does-not-change-instance.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.reduce +description: > + The callbackfn return does not change the `this` instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([0, 1, 0])); + + sample.reduce(function() { + return 42; + }, 7); + + assert.sameValue(sample[0], convertToBigInt(0), "[0] == 0"); + assert.sameValue(sample[1], convertToBigInt(1), "[1] == 1"); + assert.sameValue(sample[2], convertToBigInt(0), "[2] == 0"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 000000000..25470aff7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-returns-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.reduce +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(Test262Error, function() { + sample.reduce(function() { + throw new Test262Error(); + }); + }); + + assert.throws(Test262Error, function() { + sample.reduce(function() { + throw new Test262Error(); + }, 0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-set-value-during-iteration.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-set-value-during-iteration.js new file mode 100644 index 000000000..395a5aea7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-set-value-during-iteration.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.reduce +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + var newVal = 0; + + sample.reduce(function(acc, val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], convertToBigInt(newVal - 1), + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, convertToBigInt(7)), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, convertToBigInt(newVal)), + true, + "set value during iteration" + ); + + newVal++; + }, 0); + + assert.sameValue(sample[0], convertToBigInt(7), "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], convertToBigInt(1), "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], convertToBigInt(2), "changed values after iteration [2] == 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-this.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-this.js new file mode 100644 index 000000000..fe364eeac --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/callbackfn-this.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.reduce +description: > + callbackfn `this` value +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results = []; + + sample.reduce(function() { + results.push(this); + }, 0); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(results[0], expected, "[0]"); + assert.sameValue(results[1], expected, "[1]"); + assert.sameValue(results[2], expected, "[2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/detached-buffer.js new file mode 100644 index 000000000..91763bcfb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/detached-buffer.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.reduce +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduce(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/empty-instance-return-initialvalue.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/empty-instance-return-initialvalue.js new file mode 100644 index 000000000..34ed97d79 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/empty-instance-return-initialvalue.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.reduce +description: > + Returns given initialValue on empty instances without calling callbackfn +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA().reduce(function() { + called = true; + }, 42); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/empty-instance-with-no-initialvalue-throws.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/empty-instance-with-no-initialvalue-throws.js new file mode 100644 index 000000000..f903b32a0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/empty-instance-with-no-initialvalue-throws.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.reduce +description: > + If len is 0 and initialValue is not present, throw a TypeError exception. +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + assert.throws(TypeError, function() { + new TA().reduce(function() { + called++; + }); + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..a4f6c763e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/get-length-uses-internal-arraylength.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.reduce +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +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(convertToBigInt([42, 43])); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reduce(function() { + calls++; + }, 0); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/invoked-as-func.js new file mode 100644 index 000000000..32441ea61 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.19 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.19 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var reduce = TypedArray.prototype.reduce; + +assert.sameValue(typeof reduce, 'function'); + +assert.throws(TypeError, function() { + reduce(); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/invoked-as-method.js new file mode 100644 index 000000000..fcc586259 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.19 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.19 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.reduce, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.reduce(); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/length.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/length.js new file mode 100644 index 000000000..03b80a145 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/length.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. + +/*--- +es6id: 22.2.3.19 +description: > + %TypedArray%.prototype.reduce.length is 1. +info: | + %TypedArray%.prototype.reduce ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.reduce.length, 1); + +verifyNotEnumerable(TypedArray.prototype.reduce, "length"); +verifyNotWritable(TypedArray.prototype.reduce, "length"); +verifyConfigurable(TypedArray.prototype.reduce, "length"); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/name.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/name.js new file mode 100644 index 000000000..86ad9f3d4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.19 +description: > + %TypedArray%.prototype.reduce.name is "reduce". +info: | + %TypedArray%.prototype.reduce ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.reduce.name, "reduce"); + +verifyNotEnumerable(TypedArray.prototype.reduce, "name"); +verifyNotWritable(TypedArray.prototype.reduce, "name"); +verifyConfigurable(TypedArray.prototype.reduce, "name"); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/prop-desc.js new file mode 100644 index 000000000..6b53a2630 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.19 +description: > + "reduce" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'reduce'); +verifyWritable(TypedArrayPrototype, 'reduce'); +verifyConfigurable(TypedArrayPrototype, 'reduce'); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/result-is-last-callbackfn-return.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/result-is-last-callbackfn-return.js new file mode 100644 index 000000000..83e9a723f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/result-is-last-callbackfn-return.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduce +description: > + Returns last accumulator value +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var calls, result; + + calls = 0; + result = new TA(convertToBigInt([1, 2, 3])).reduce(function() { + calls++; + + if (calls == 2) { + return 42; + } + }); + assert.sameValue(result, 42, "using default accumulator"); + + calls = 0; + result = new TA(convertToBigInt([1, 2, 3])).reduce(function() { + calls++; + + if (calls == 3) { + return 7; + } + }, 0); + assert.sameValue(result, 7, "using custom accumulator"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/result-of-any-type.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/result-of-any-type.js new file mode 100644 index 000000000..370a5b052 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/result-of-any-type.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduce +description: > + Result can be of any type without any number conversions +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + [ + ["test262", "string"], + ["", "empty string"], + [undefined, "undefined"], + [null, "null"], + [-0, "-0"], + [42, "integer"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [0.6, "float number"], + [true, "true"], + [false, "false"], + [Symbol(""), "symbol"], + [{}, "object"] + ].forEach(function(item) { + var result; + + result = sample.reduce(function() { + return item[0]; + }); + assert.sameValue(result, item[0], item[1] + " - using default accumulator"); + + result = sample.reduce(function() { + return item[0]; + }, 0); + + assert.sameValue(result, item[0], item[1] + " - using custom accumulator"); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/return-first-value-without-callbackfn.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/return-first-value-without-callbackfn.js new file mode 100644 index 000000000..7fbd76fa0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/return-first-value-without-callbackfn.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduce +description: > + Returns [0] without calling callbackfn if length is 1 and initialValue is not + present. +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k < len + ... + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Increase k by 1. + ... + 8. Repeat, while k < len + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA(convertToBigInt([42])).reduce(function() { + called = true; + }); + + assert.sameValue(result, convertToBigInt(42)); + assert.sameValue(called, false); +}); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/this-is-not-object.js new file mode 100644 index 000000000..14680f3d4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/this-is-not-object.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.reduce +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var reduce = TypedArray.prototype.reduce; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduce.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + reduce.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + reduce.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + reduce.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + reduce.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + reduce.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + reduce.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..6dedc8cd2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/this-is-not-typedarray-instance.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.reduce +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var reduce = TypedArray.prototype.reduce; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduce.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + reduce.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + reduce.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + reduce.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/reduce/BigInt/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/reduce/BigInt/values-are-not-cached.js new file mode 100644 index 000000000..7b602dd9d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduce/BigInt/values-are-not-cached.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.reduce +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.20 %TypedArray%.prototype.reduce ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduce is a distinct function that implements the same + algorithm as Array.prototype.reduce as defined in 22.1.3.19 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.19 Array.prototype.reduce ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + sample.reduce(function(a, v, i) { + if (i < sample.length - 1) { + sample[i+1] = convertToBigInt(42); + } + + assert.sameValue( + v, convertToBigInt(42), "method does not cache values before callbackfn calls" + ); + }, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js new file mode 100644 index 000000000..8ecb1ff4f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-custom-accumulator.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduceright +description: > + callbackfn arguments using custom accumulator +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + 1; + }, 7); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 4, "results[0].length"); + assert.sameValue(results[0][0], 7, "results[0][0] - accumulator"); + assert.sameValue(results[0][1], convertToBigInt(44), "results[0][1] - kValue"); + assert.sameValue(results[0][2], 2, "results[0][2] - k"); + assert.sameValue(results[0][3], sample, "results[0][3] - this"); + + assert.sameValue(results[1].length, 4, "results[1].length"); + assert.sameValue(results[1][0], 8, "results[1][0] - accumulator"); + assert.sameValue(results[1][1], convertToBigInt(43), "results[1][1] - kValue"); + assert.sameValue(results[1][2], 1, "results[1][2] - k"); + assert.sameValue(results[1][3], sample, "results[1][3] - this"); + + assert.sameValue(results[2].length, 4, "results[2].length"); + assert.sameValue(results[2][0], 9, "results[2][0] - accumulator"); + assert.sameValue(results[2][1], convertToBigInt(42), "results[2][1] - kValue"); + assert.sameValue(results[2][2], 0, "results[2][2] - k"); + assert.sameValue(results[2][3], sample, "results[2][3] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js new file mode 100644 index 000000000..d80202ebc --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-arguments-default-accumulator.js @@ -0,0 +1,62 @@ +// 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.reduceright +description: > + callbackfn arguments using default accumulator (value at last index) +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.reduceRight(function(accumulator) { + results.push(arguments); + return accumulator + convertToBigInt(1); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0].length, 4, "results[1].length"); + assert.sameValue(results[0][0], convertToBigInt(44), "results[1][0] - accumulator"); + assert.sameValue(results[0][1], convertToBigInt(43), "results[1][1] - kValue"); + assert.sameValue(results[0][2], 1, "results[1][2] - k"); + assert.sameValue(results[0][3], sample, "results[1][3] - this"); + + assert.sameValue(results[1].length, 4, "results[2].length"); + assert.sameValue(results[1][0], convertToBigInt(45), "results[2][0] - accumulator"); + assert.sameValue(results[1][1], convertToBigInt(42), "results[2][1] - kValue"); + assert.sameValue(results[1][2], 0, "results[2][2] - k"); + assert.sameValue(results[1][3], sample, "results[2][3] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 000000000..c484769f4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-detachbuffer.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.reduceright +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.reduceRight(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + }, 0); + }); + + assert.sameValue(loops, 1, "callbackfn called only once"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js new file mode 100644 index 000000000..880e1a1a9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-is-not-callable-throws.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduceright +description: > + Throws TypeError if callbackfn is not callable +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.throws(TypeError, function() { + sample.reduceRight(); + }, "no arg"); + + assert.throws(TypeError, function() { + sample.reduceRight(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.reduceRight(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.reduceRight({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.reduceRight(1); + }, "1"); + + assert.throws(TypeError, function() { + sample.reduceRight(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.reduceRight(""); + }, "string"); + + assert.throws(TypeError, function() { + sample.reduceRight(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.reduceRight(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.reduceRight(Symbol("")); + }, "symbol"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.js new file mode 100644 index 000000000..a0f2fb513 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-no-iteration-over-non-integer-properties.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.reduceright +description: > + Does not iterate over non-integer properties +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.reduceRight(function() { + results.push(arguments); + }, 0); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][2], 1, "results[0][2] - k"); + assert.sameValue(results[1][2], 0, "results[1][2] - k"); + + assert.sameValue(results[0][1], convertToBigInt(8), "results[0][1] - kValue"); + assert.sameValue(results[1][1], convertToBigInt(7), "results[1][1] - kValue"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 000000000..ce9dc4b05 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-not-called-on-empty.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.reduceright +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().reduceRight(function() { + called++; + }, undefined); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 000000000..2bf7460bf --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-return-does-not-change-instance.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.reduceright +description: > + The callbackfn return does not change the `this` instance +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([0, 1, 0])); + + sample.reduceRight(function() { + return 42; + }, 7); + + assert.sameValue(sample[0], convertToBigInt(0), "[0] == 0"); + assert.sameValue(sample[1], convertToBigInt(1), "[1] == 1"); + assert.sameValue(sample[2], convertToBigInt(0), "[2] == 0"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 000000000..ce1cc6d0e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-returns-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.reduceright +description: > + Returns abrupt from callbackfn +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k < len + ... + c. If kPresent is true, then + ... + i. Let accumulator be ? Call(callbackfn, undefined, « accumulator, kValue, + k, O »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }); + }); + + assert.throws(Test262Error, function() { + sample.reduceRight(function() { + throw new Test262Error(); + }, 0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.js new file mode 100644 index 000000000..d0fd3510f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-set-value-during-iteration.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.reduceright +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + var newVal = 0; + + sample.reduceRight(function(acc, val, i) { + if (i < sample.length - 1) { + assert.sameValue( + sample[i + 1], convertToBigInt(newVal - 1), + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 2, convertToBigInt(7)), + true, + "re-set a value for sample[2]" + ); + } + assert.sameValue( + Reflect.set(sample, i, convertToBigInt(newVal)), + true, + "set value during iteration" + ); + + newVal++; + }, 0); + + assert.sameValue(sample[0], convertToBigInt(2), "changed values after iteration [0] == 2"); + assert.sameValue(sample[1], convertToBigInt(1), "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], convertToBigInt(7), "changed values after iteration [2] == 7"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js new file mode 100644 index 000000000..6210eea50 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/callbackfn-this.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduceright +description: > + callbackfn `this` value +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results = []; + + sample.reduceRight(function() { + results.push(this); + }, 0); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(results[0], expected, "[0]"); + assert.sameValue(results[1], expected, "[1]"); + assert.sameValue(results[2], expected, "[2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.js new file mode 100644 index 000000000..08e635433 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/detached-buffer.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.reduceright +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reduceRight(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js new file mode 100644 index 000000000..2818b78b1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-return-initialvalue.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduceright +description: > + Returns given initialValue on empty instances without calling callbackfn +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA().reduceRight(function() { + called = true; + }, 42); + + assert.sameValue(result, 42); + assert.sameValue(called, false); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.js new file mode 100644 index 000000000..65b07a1ce --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/empty-instance-with-no-initialvalue-throws.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.reduceright +description: > + If len is 0 and initialValue is not present, throw a TypeError exception. +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 4. If len is 0 and initialValue is not present, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + assert.throws(TypeError, function() { + new TA().reduceRight(function() { + called++; + }); + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..e2cb704a0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/get-length-uses-internal-arraylength.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.reduceright +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +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(convertToBigInt([42, 43])); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reduceRight(function() { + calls++; + }, 0); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/invoked-as-func.js new file mode 100644 index 000000000..7bc30e60c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.20 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.20 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var reduceRight = TypedArray.prototype.reduceRight; + +assert.sameValue(typeof reduceRight, 'function'); + +assert.throws(TypeError, function() { + reduceRight(); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/invoked-as-method.js new file mode 100644 index 000000000..468ad5e36 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.20 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.20 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.reduceRight, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.reduceRight(); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/length.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/length.js new file mode 100644 index 000000000..cb857c2f5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/length.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. + +/*--- +es6id: 22.2.3.20 +description: > + %TypedArray%.prototype.reduceRight.length is 1. +info: | + %TypedArray%.prototype.reduceRight ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.reduceRight.length, 1); + +verifyNotEnumerable(TypedArray.prototype.reduceRight, "length"); +verifyNotWritable(TypedArray.prototype.reduceRight, "length"); +verifyConfigurable(TypedArray.prototype.reduceRight, "length"); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/name.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/name.js new file mode 100644 index 000000000..fa94ac119 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.20 +description: > + %TypedArray%.prototype.reduceRight.name is "reduceRight". +info: | + %TypedArray%.prototype.reduceRight ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.reduceRight.name, "reduceRight"); + +verifyNotEnumerable(TypedArray.prototype.reduceRight, "name"); +verifyNotWritable(TypedArray.prototype.reduceRight, "name"); +verifyConfigurable(TypedArray.prototype.reduceRight, "name"); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/prop-desc.js new file mode 100644 index 000000000..71eeecbbf --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.20 +description: > + "reduceRight" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'reduceRight'); +verifyWritable(TypedArrayPrototype, 'reduceRight'); +verifyConfigurable(TypedArrayPrototype, 'reduceRight'); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.js new file mode 100644 index 000000000..feeb92f0f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/result-is-last-callbackfn-return.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.reduceright +description: > + Returns last accumulator value +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var calls, result; + + calls = 0; + result = new TA(convertToBigInt([1, 2, 3])).reduceRight(function() { + calls++; + + if (calls == 2) { + return 42; + } + }); + assert.sameValue(result, 42, "using default accumulator"); + + calls = 0; + result = new TA(convertToBigInt([1, 2, 3])).reduceRight(function() { + calls++; + + if (calls == 3) { + return 7; + } + }, 0); + assert.sameValue(result, 7, "using custom accumulator"); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js new file mode 100644 index 000000000..d3731ab58 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/result-of-any-type.js @@ -0,0 +1,69 @@ +// 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.reduceright +description: > + Result can be of any type without any number conversions +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + [ + ["test262", "string"], + ["", "empty string"], + [undefined, "undefined"], + [null, "null"], + [-0, "-0"], + [42, "integer"], + [NaN, "NaN"], + [Infinity, "Infinity"], + [0.6, "float number"], + [true, "true"], + [false, "false"], + [Symbol(""), "symbol"], + [{}, "object"] + ].forEach(function(item) { + var result; + + result = sample.reduceRight(function() { + return item[0]; + }); + assert.sameValue(result, item[0], item[1] + " - using default accumulator"); + + result = sample.reduceRight(function() { + return item[0]; + }, 0); + + assert.sameValue(result, item[0], item[1] + " - using custom accumulator"); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.js new file mode 100644 index 000000000..3219fb682 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/return-first-value-without-callbackfn.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.reduceright +description: > + Returns [0] without calling callbackfn if length is 1 and initialValue is not + present. +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 7. Else initialValue is not present, + ... + b. Repeat, while kPresent is false and k ≥ 0 + ... + ii. Let kPresent be ? HasProperty(O, Pk). + iii. If kPresent is true, then + 1. Let accumulator be ? Get(O, Pk). + iv. Decrease k by 1. + ... + 8. Repeat, while k ≥ 0 + ... + 9. Return accumulator. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = false; + var result = new TA(convertToBigInt([42])).reduceRight(function() { + called = true; + }); + + assert.sameValue(result, convertToBigInt(42)); + assert.sameValue(called, false); +}); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/this-is-not-object.js new file mode 100644 index 000000000..fccf9de2b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/this-is-not-object.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.reduceright +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var reduceRight = TypedArray.prototype.reduceRight; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduceRight.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + reduceRight.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + reduceRight.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + reduceRight.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + reduceRight.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + reduceRight.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + reduceRight.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..8092e93e9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/this-is-not-typedarray-instance.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.reduceright +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var reduceRight = TypedArray.prototype.reduceRight; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + reduceRight.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + reduceRight.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + reduceRight.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + reduceRight.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js new file mode 100644 index 000000000..a7f5cda05 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reduceRight/BigInt/values-are-not-cached.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reduceright +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.21 %TypedArray%.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + %TypedArray%.prototype.reduceRight is a distinct function that implements the + same algorithm as Array.prototype.reduceRight as defined in 22.1.3.20 except + that the this object's [[ArrayLength]] internal slot is accessed in place of + performing a [[Get]] of "length". + + 22.1.3.20 Array.prototype.reduceRight ( callbackfn [ , initialValue ] ) + + ... + 8. Repeat, while k ≥ 0 + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let accumulator be ? Call(callbackfn, undefined, « accumulator, + kValue, k, O »). + d. Decrease k by 1. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([44, 43, 42])); + + sample.reduceRight(function(a, v, i) { + if (i > 0) { + sample[i-1] = convertToBigInt(42); + } + + assert.sameValue( + v, convertToBigInt(42), "method does not cache values before callbackfn calls" + ); + }, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/detached-buffer.js new file mode 100644 index 000000000..5067380d5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/detached-buffer.js @@ -0,0 +1,28 @@ +// 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.reverse +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.reverse(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..7acdfdfff --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reverse +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + %TypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +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(convertToBigInt([42, 43])); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.reverse(); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/invoked-as-func.js new file mode 100644 index 000000000..f8b4b6fde --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.21 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.21 %TypedArray%.prototype.reverse ( ) + + ... + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var reverse = TypedArray.prototype.reverse; + +assert.sameValue(typeof reverse, 'function'); + +assert.throws(TypeError, function() { + reverse(); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/invoked-as-method.js new file mode 100644 index 000000000..ec8dd5945 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.21 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.21 %TypedArray%.prototype.reverse ( ) + + ... + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.reverse, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.reverse(); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/length.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/length.js new file mode 100644 index 000000000..afb56f9e1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/length.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. + +/*--- +es6id: 22.2.3.21 +description: > + %TypedArray%.prototype.reverse.length is 0. +info: | + %TypedArray%.prototype.reverse ( ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.reverse.length, 0); + +verifyNotEnumerable(TypedArray.prototype.reverse, "length"); +verifyNotWritable(TypedArray.prototype.reverse, "length"); +verifyConfigurable(TypedArray.prototype.reverse, "length"); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/name.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/name.js new file mode 100644 index 000000000..9652d5a60 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.21 +description: > + %TypedArray%.prototype.reverse.name is "reverse". +info: | + %TypedArray%.prototype.reverse ( ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.reverse.name, "reverse"); + +verifyNotEnumerable(TypedArray.prototype.reverse, "name"); +verifyNotWritable(TypedArray.prototype.reverse, "name"); +verifyConfigurable(TypedArray.prototype.reverse, "name"); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/preserves-non-numeric-properties.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/preserves-non-numeric-properties.js new file mode 100644 index 000000000..a06d52f98 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/preserves-non-numeric-properties.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.reverse +description: Preserves non numeric properties +info: | + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + %TypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + + sample = new TA(2); + sample.foo = 42; + sample.bar = "bar"; + sample[s] = 1; + result = sample.reverse(); + assert.sameValue(result.foo, 42, "sample.foo === 42"); + assert.sameValue(result.bar, "bar", "sample.bar === 'bar'"); + assert.sameValue(result[s], 1, "sample[s] === 1"); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/prop-desc.js new file mode 100644 index 000000000..56c828f36 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.21 +description: > + "reverse" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'reverse'); +verifyWritable(TypedArrayPrototype, 'reverse'); +verifyConfigurable(TypedArrayPrototype, 'reverse'); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/returns-original-object.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/returns-original-object.js new file mode 100644 index 000000000..c9f8fdafd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/returns-original-object.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reverse +description: Returns the same object +info: | + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + %TypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(64); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result, expectedLength; + + sample = new TA(buffer, 0); + expectedLength = sample.length; + result = sample.reverse(); + assert.sameValue(result, sample, "returns the same object"); + assert.sameValue(sample.buffer, buffer, "keeps the same buffer"); + assert.sameValue(sample.length, expectedLength, "length is preserved"); + + sample = new TA(buffer, 0, 0); + result = sample.reverse(); + assert.sameValue(result, sample, "returns the same object (empty instance)"); + assert.sameValue(sample.buffer, buffer, "keeps the same buffer (empty instance)"); + assert.sameValue(sample.length, 0, "length is preserved (empty instance)"); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/reverts.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/reverts.js new file mode 100644 index 000000000..660088f02 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/reverts.js @@ -0,0 +1,57 @@ +// 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.reverse +description: Reverts values +info: | + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + %TypedArray%.prototype.reverse is a distinct function that implements the same + algorithm as Array.prototype.reverse as defined in 22.1.3.21 except that the + this object's [[ArrayLength]] internal slot is accessed in place of performing + a [[Get]] of "length". + + 22.1.3.21 Array.prototype.reverse ( ) + + ... + 6. Return O. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(64); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(buffer, 0, 4); + var other = new TA(buffer, 0, 5); + + sample[0] = convertToBigInt(42); + sample[1] = convertToBigInt(43); + sample[2] = convertToBigInt(2); + sample[3] = convertToBigInt(1); + other[4] = convertToBigInt(7); + + sample.reverse(); + assert( + compareArray(sample, convertToBigInt([1, 2, 43, 42])) + ); + + assert( + compareArray(other, convertToBigInt([1, 2, 43, 42, 7])) + ); + + sample[0] = convertToBigInt(7); + sample[1] = convertToBigInt(17); + sample[2] = convertToBigInt(1); + sample[3] = convertToBigInt(0); + other[4] = convertToBigInt(42); + + other.reverse(); + assert( + compareArray(other, convertToBigInt([42, 0, 1, 17, 7])) + ); + + assert( + compareArray(sample, convertToBigInt([42, 0, 1, 17])) + ); +}); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/this-is-not-object.js new file mode 100644 index 000000000..82255a345 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/this-is-not-object.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.reverse +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var reverse = TypedArray.prototype.reverse; + +assert.throws(TypeError, function() { + reverse.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + reverse.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + reverse.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + reverse.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + reverse.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + reverse.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + reverse.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/reverse/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/reverse/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..07b5138d9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/reverse/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.reverse +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.22 %TypedArray%.prototype.reverse ( ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var reverse = TypedArray.prototype.reverse; + +assert.throws(TypeError, function() { + reverse.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + reverse.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + reverse.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + reverse.call(dv); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.js new file mode 100644 index 000000000..a5896d24b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-negative-integer-offset-throws.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.set-array-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert.throws(RangeError, function() { + sample.set([1], -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set([1], -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set([1], -Infinity); + }, "-Infinity"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js new file mode 100644 index 000000000..b47dc9de6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-offset-tointeger.js @@ -0,0 +1,95 @@ +// 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.set-array-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], ""); + assert(compareArray(sample, convertToBigInt([42, 2])), "the empty string"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], "0"); + assert(compareArray(sample, convertToBigInt([42, 2])), "'0'"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], false); + assert(compareArray(sample, convertToBigInt([42, 2])), "false"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], 0.1); + assert(compareArray(sample, convertToBigInt([42, 2])), "0.1"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], 0.9); + assert(compareArray(sample, convertToBigInt([42, 2])), "0.9"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], -0.5); + assert(compareArray(sample, convertToBigInt([42, 2])), "-0.5"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], 1.1); + assert(compareArray(sample, convertToBigInt([1, 42])), "1.1"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], NaN); + assert(compareArray(sample, convertToBigInt([42, 2])), "NaN"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], null); + assert(compareArray(sample, convertToBigInt([42, 2])), "null"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], undefined); + assert(compareArray(sample, convertToBigInt([42, 2])), "undefined"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], {}); + assert(compareArray(sample, convertToBigInt([42, 2])), "{}"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], []); + assert(compareArray(sample, convertToBigInt([42, 2])), "[]"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], [0]); + assert(compareArray(sample, convertToBigInt([42, 2])), "[0]"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], true); + assert(compareArray(sample, convertToBigInt([1, 42])), "true"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], "1"); + assert(compareArray(sample, convertToBigInt([1, 42])), "'1'"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], [1]); + assert(compareArray(sample, convertToBigInt([1, 42])), "[1]"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], { valueOf: function() {return 1;} }); + assert(compareArray(sample, convertToBigInt([1, 42])), "valueOf"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set([convertToBigInt(42)], { toString: function() {return 1;} }); + assert(compareArray(sample, convertToBigInt([1, 42])), "toString"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js new file mode 100644 index 000000000..2dd5b23ea --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Return abrupt getting src "length" +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 2, 3])); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.js new file mode 100644 index 000000000..451e7bad1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-get-value.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.set-array-offset +description: > + Return abrupt from getting src property value +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": convertToBigInt(42), + "1": convertToBigInt(43), + "3": convertToBigInt(44) + }; + Object.defineProperty(obj, "2", { + get: function() { + throw new Test262Error(); + } + }); + + var sample = new TA(convertToBigInt([1, 2, 3, 4])); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, convertToBigInt([42, 43, 3, 4])), + "values are set until exception" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js new file mode 100644 index 000000000..f1a65b06e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Return abrupt getting src "length" as symbol +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var obj = { + length: Symbol("1") +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 2, 3])); + + assert.throws(TypeError, function() { + sample.set(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.js new file mode 100644 index 000000000..401a486db --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-length.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.set-array-offset +description: > + Return abrupt from ToLength(src "length") +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; + +var obj2 = { + length: { + toString: function() { + throw new Test262Error(); + } + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 2, 3])); + + assert.throws(Test262Error, function() { + sample.set(obj1); + }, "valueOf"); + + assert.throws(Test262Error, function() { + sample.set(obj2); + }, "toString"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.js new file mode 100644 index 000000000..fd9121934 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value-symbol.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.set-array-offset +description: > + Return abrupt from ToNumber(src property symbol value) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": convertToBigInt(42), + "1": convertToBigInt(43), + "2": Symbol("1"), + "3": convertToBigInt(44) + }; + + var sample = new TA(convertToBigInt([1, 2, 3, 4])); + + assert.throws(TypeError, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, convertToBigInt([42, 43, 3, 4])), + "values are set until exception" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.js new file mode 100644 index 000000000..af1f98349 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-src-tonumber-value.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.set-array-offset +description: > + Return abrupt from ToNumber(src property value) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + length: 4, + "0": convertToBigInt(42), + "1": convertToBigInt(43), + "2": { + valueOf: function() { + throw new Test262Error(); + } + }, + "3": convertToBigInt(44) + }; + + var sample = new TA(convertToBigInt([1, 2, 3, 4])); + + assert.throws(Test262Error, function() { + sample.set(obj); + }); + + assert( + compareArray(sample, convertToBigInt([42, 43, 3, 4])), + "values are set until exception" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 000000000..f9d8699ab --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset-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.set-array-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.set([1], s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 000000000..ca31811e5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-tointeger-offset.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.set-array-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set([], obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set([], obj2); + }, "abrupt from toString"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js new file mode 100644 index 000000000..8ee19ce7c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-return-abrupt-from-toobject-offset.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Return abrupt from ToObject(array) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 15. Let src be ? ToObject(array). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 2, 3])); + + assert.throws(TypeError, function() { + sample.set(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.set(null); + }, "null"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js new file mode 100644 index 000000000..7a5ed9850 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values-in-order.js @@ -0,0 +1,72 @@ +// 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.set-array-offset +description: > + Get and set each value in order +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var calls = []; + var obj = { + length: 3 + }; + Object.defineProperty(obj, 0, { + get: function() { + calls.push(0); + calls.push(sample.join()); + return convertToBigInt(42); + } + }); + + Object.defineProperty(obj, 1, { + get: function() { + calls.push(1); + calls.push(sample.join()); + return convertToBigInt(43); + } + }); + + Object.defineProperty(obj, 2, { + get: function() { + calls.push(2); + calls.push(sample.join()); + return convertToBigInt(44); + } + }); + + Object.defineProperty(obj, 3, { + get: function() { + throw new Test262Error("Should not call obj[3]"); + } + }); + + sample.set(obj, 1); + + assert( + compareArray(sample, convertToBigInt([0, 42, 43, 44, 0])), + "values are set for src length" + ); + + assert( + compareArray(calls, [0, "0,0,0,0,0", 1, "0,42,0,0,0", 2, "0,42,43,0,0"]), + "values are set in order" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values.js new file mode 100644 index 000000000..3a5888726 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-set-values.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Set values to target and return undefined +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + Let Pk be ! ToString(k). + Let kNumber be ? ToNumber(? Get(src, Pk)). + If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, kNumber). + ... + 22. Return undefined. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var src = convertToBigInt([42, 43]); + var srcObj = { + length: 2, + '0': convertToBigInt(7), + '1': convertToBigInt(17) + }; + var sample, result; + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 0); + assert(compareArray(sample, convertToBigInt([42, 43, 3, 4])), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 1); + assert(compareArray(sample, convertToBigInt([1, 42, 43, 4])), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 2); + assert(compareArray(sample, convertToBigInt([1, 2, 42, 43])), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(srcObj, 0); + assert(compareArray(sample, convertToBigInt([7, 17, 3, 4])), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(srcObj, 1); + assert(compareArray(sample, convertToBigInt([1, 7, 17, 4])), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(srcObj, 2); + assert(compareArray(sample, convertToBigInt([1, 2, 7, 17])), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-conversions.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-conversions.js new file mode 100644 index 000000000..04d518689 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-conversions.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Values conversions on ToNumber(src property value) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [byteConversionValues.js, testBigIntTypedArray.js] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample.set([value]); + + assert.sameValue(sample[0], expected, "["+value+"] => ["+expected +"]"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.js new file mode 100644 index 000000000..a07ffab4f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-tonumber-value-type-conversions.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.set-array-offset +description: > + Type conversions on ToNumber(src property value) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj1 = { + valueOf: function() { + return convertToBigInt(42); + } + }; + + var obj2 = { + toString: function() { + return "42"; + } + }; + + // undefined and NaN covered on typedArrayConversions + var arr = ["1", "", false, true, nullish, obj1, obj2, [], [1]]; + + var sample = new TA(arr.length); + var expected = new TA(convertToBigInt([1, 0, 0, 1, 42, 42, 0, 1])); + + sample.set(arr); + + assert( + compareArray(sample, expected), + "sample: [" + sample + "], expected: [" + expected + "]" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.js new file mode 100644 index 000000000..3ad61f0b6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-src-values-are-not-cached.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.set-array-offset +description: > + Values from src array are not cached +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(5); + var obj = { + length: 5, + '1': convertToBigInt(7), + '2': convertToBigInt(7), + '3': convertToBigInt(7), + '4': convertToBigInt(7) + }; + Object.defineProperty(obj, 0, { + get: function() { + obj[1] = convertToBigInt(43); + obj[2] = convertToBigInt(44); + obj[3] = convertToBigInt(45); + obj[4] = convertToBigInt(46); + return convertToBigInt(42); + } + }); + + sample.set(obj); + + assert(compareArray(sample, convertToBigInt([42, 43, 44, 45, 46]))); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.js new file mode 100644 index 000000000..95c1a9776 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-target-arraylength-internal.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.set-array-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 17. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set(convertToBigInt([42, 43])); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-get-src-value-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-get-src-value-throws.js new file mode 100644 index 000000000..7e53f4221 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-get-src-value-throws.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Throws an error if buffer is detached before setting a value +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 21. Repeat, while targetByteIndex < limit + a. Let Pk be ! ToString(k). + b. Let kNumber be ? ToNumber(? Get(src, Pk)). + c. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + d. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + kNumber). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([1, 2, 3])); + var obj = { + length: 3, + "0": convertToBigInt(42) + }; + Object.defineProperty(obj, 1, { + get: function() { + $DETACHBUFFER(sample.buffer); + } + }); + Object.defineProperty(obj, 2, { + get: function() { + throw new Test262Error("Should not get other values"); + } + }); + + assert.throws(TypeError, function() { + sample.set(obj); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js new file mode 100644 index 000000000..a25113b5a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-on-tointeger-offset-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set([1], obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-throws.js new file mode 100644 index 000000000..9a2bd2531 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/array-arg-targetbuffer-detached-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.set-array-offset +description: > + Throws a TypeError if targetBuffer is detached +info: | + 22.2.3.23.1 %TypedArray%.prototype.set (array [ , offset ] ) + + 1. Assert: array is any ECMAScript language value other than an Object with a + [[TypedArrayName]] internal slot. If it is such an Object, the definition in + 22.2.3.23.2 applies. + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... + 15. Let src be ? ToObject(array). + 16. Let srcLength be ? ToLength(? Get(src, "length")). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var obj = {}; +Object.defineProperty(obj, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample.set([1]); + }, "regular check"); + + assert.throws(TypeError, function() { + sample.set(obj); + }, "IsDetachedBuffer happens before Get(src.length)"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/bit-precision.js b/test/built-ins/TypedArray/prototype/set/BigInt/bit-precision.js new file mode 100644 index 000000000..07ec82242 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/bit-precision.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.set +es6id: 22.2.3.22.2 +description: Preservation of bit-level encoding +info: | + [...] + 28. Else, + a. 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. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + iii. Set srcByteIndex to srcByteIndex + 1. + iv. Set targetByteIndex to targetByteIndex + 1. +includes: [nans.js, compareArray.js, testBigIntTypedArray.js] +---*/ + +function body(FloatArray) { + var source = new FloatArray(distinctNaNs); + var target = new FloatArray(distinctNaNs.length); + var sourceBytes, targetBytes; + + target.set(source); + + sourceBytes = new Uint8Array(source.buffer); + targetBytes = new Uint8Array(target.buffer); + + assert(compareArray(sourceBytes, targetBytes)) +} + +testWithBigIntTypedArrayConstructors(body, [Float32Array, Float64Array]); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/set/BigInt/invoked-as-func.js new file mode 100644 index 000000000..1826706ff --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/invoked-as-func.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. +/*--- +es6id: 22.2.3.22 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.22 %TypedArray%.prototype.set ( overloaded [ , offset ]) + + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var set = TypedArray.prototype.set; + +assert.sameValue(typeof set, 'function'); + +assert.throws(TypeError, function() { + set(); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/set/BigInt/invoked-as-method.js new file mode 100644 index 000000000..4f52624e7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/invoked-as-method.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. +/*--- +es6id: 22.2.3.22 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.22 %TypedArray%.prototype.set ( overloaded [ , offset ]) + + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.set, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.set(); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/length.js b/test/built-ins/TypedArray/prototype/set/BigInt/length.js new file mode 100644 index 000000000..a206e85a9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/length.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. + +/*--- +es6id: 22.2.3.22 +description: > + %TypedArray%.prototype.set.length is 1. +info: | + %TypedArray%.prototype.set ( overloaded [ , offset ]) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.set.length, 1); + +verifyNotEnumerable(TypedArray.prototype.set, "length"); +verifyNotWritable(TypedArray.prototype.set, "length"); +verifyConfigurable(TypedArray.prototype.set, "length"); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/name.js b/test/built-ins/TypedArray/prototype/set/BigInt/name.js new file mode 100644 index 000000000..2bb904d8f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.22 +description: > + %TypedArray%.prototype.set.name is "set". +info: | + %TypedArray%.prototype.set ( overloaded [ , offset ]) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.set.name, "set"); + +verifyNotEnumerable(TypedArray.prototype.set, "name"); +verifyNotWritable(TypedArray.prototype.set, "name"); +verifyConfigurable(TypedArray.prototype.set, "name"); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/set/BigInt/prop-desc.js new file mode 100644 index 000000000..6dabe5c1b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.22 +description: > + "set" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'set'); +verifyWritable(TypedArrayPrototype, 'set'); +verifyConfigurable(TypedArrayPrototype, 'set'); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/set/BigInt/this-is-not-object.js new file mode 100644 index 000000000..d1b6242e9 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/this-is-not-object.js @@ -0,0 +1,75 @@ +// 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.set-overloaded-offset +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.23 %TypedArray%.prototype.set + + ... + 2. Let target be the this value. + 3. If Type(target) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var set = TypedArray.prototype.set; + +assert.throws(TypeError, function() { + set.call(undefined, []); +}, "this is undefined"); + +assert.throws(TypeError, function() { + set.call(null, []); +}, "this is null"); + +assert.throws(TypeError, function() { + set.call(undefined, new Int8Array()); +}, "this is undefined"); + +assert.throws(TypeError, function() { + set.call(null, new Int8Array()); +}, "this is null"); + +assert.throws(TypeError, function() { + set.call(42, []); +}, "this is 42"); + +assert.throws(TypeError, function() { + set.call("1", []); +}, "this is a string"); + +assert.throws(TypeError, function() { + set.call(true, []); +}, "this is true"); + +assert.throws(TypeError, function() { + set.call(false, []); +}, "this is false"); + +var s1 = Symbol("s"); +assert.throws(TypeError, function() { + set.call(s1, []); +}, "this is a Symbol"); + +assert.throws(TypeError, function() { + set.call(42, new Int8Array(1)); +}, "this is 42"); + +assert.throws(TypeError, function() { + set.call("1", new Int8Array(1)); +}, "this is a string"); + +assert.throws(TypeError, function() { + set.call(true, new Int8Array(1)); +}, "this is true"); + +assert.throws(TypeError, function() { + set.call(false, new Int8Array(1)); +}, "this is false"); + +var s2 = Symbol("s"); +assert.throws(TypeError, function() { + set.call(s2, new Int8Array(1)); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/set/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..77220ea6a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/this-is-not-typedarray-instance.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.set-overloaded-offset +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.23 %TypedArray%.prototype.set + + ... + 2. Let target be the this value. + 3. If Type(target) is not Object, throw a TypeError exception. + 4. If target does not have a [[TypedArrayName]] internal slot, throw a + TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var set = TypedArray.prototype.set; + +assert.throws(TypeError, function() { + set.call({}, []); +}, "this is an Object"); + +assert.throws(TypeError, function() { + set.call([], []); +}, "this is an Array"); + +var ab1 = new ArrayBuffer(8); +assert.throws(TypeError, function() { + set.call(ab1, []); +}, "this is an ArrayBuffer instance"); + +var dv1 = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + set.call(dv1, []); +}, "this is a DataView instance"); + +assert.throws(TypeError, function() { + set.call({}, new Int8Array()); +}, "this is an Object"); + +assert.throws(TypeError, function() { + set.call([], new Int8Array()); +}, "this is an Array"); + +var ab2 = new ArrayBuffer(8); +assert.throws(TypeError, function() { + set.call(ab2, new Int8Array()); +}, "this is an ArrayBuffer instance"); + +var dv2 = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + set.call(dv2, new Int8Array()); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.js new file mode 100644 index 000000000..d5848d91a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-negative-integer-offset-throws.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.set-typedarray-offset +description: > + Throw a RangeError exception if targetOffset < 0 +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + 7. If targetOffset < 0, throw a RangeError exception. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(RangeError, function() { + sample.set(sample, -1); + }, "-1"); + + assert.throws(RangeError, function() { + sample.set(sample, -1.00001); + }, "-1.00001"); + + assert.throws(RangeError, function() { + sample.set(sample, -Infinity); + }, "-Infinity"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js new file mode 100644 index 000000000..9d5b2478f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-offset-tointeger.js @@ -0,0 +1,93 @@ +// 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.set-typedarray-offset +description: > + ToInteger(offset) operations +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + var src = new TA(convertToBigInt([42])); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, ""); + assert(compareArray(sample, convertToBigInt([42, 2])), "the empty string"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, "0"); + assert(compareArray(sample, convertToBigInt([42, 2])), "'0'"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, false); + assert(compareArray(sample, convertToBigInt([42, 2])), "false"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, 0.1); + assert(compareArray(sample, convertToBigInt([42, 2])), "0.1"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, 0.9); + assert(compareArray(sample, convertToBigInt([42, 2])), "0.9"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, -0.5); + assert(compareArray(sample, convertToBigInt([42, 2])), "-0.5"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, 1.1); + assert(compareArray(sample, convertToBigInt([1, 42])), "1.1"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, NaN); + assert(compareArray(sample, convertToBigInt([42, 2])), "NaN"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, null); + assert(compareArray(sample, convertToBigInt([42, 2])), "null"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, undefined); + assert(compareArray(sample, convertToBigInt([42, 2])), "undefined"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, {}); + assert(compareArray(sample, convertToBigInt([42, 2])), "{}"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, []); + assert(compareArray(sample, convertToBigInt([42, 2])), "[]"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, [0]); + assert(compareArray(sample, convertToBigInt([42, 2])), "[0]"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, true); + assert(compareArray(sample, convertToBigInt([1, 42])), "true"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, "1"); + assert(compareArray(sample, convertToBigInt([1, 42])), "'1'"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, [1]); + assert(compareArray(sample, convertToBigInt([1, 42])), "[1]"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, { valueOf: function() {return 1;} }); + assert(compareArray(sample, convertToBigInt([1, 42])), "valueOf"); + + sample = new TA(convertToBigInt([1, 2])); + sample.set(src, { toString: function() {return 1;} }); + assert(compareArray(sample, convertToBigInt([1, 42])), "toString"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-symbol.js new file mode 100644 index 000000000..1dd14da8c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset-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.set-typedarray-offset +description: > + Return abrupt from ToInteger(Symbol offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.set(sample, s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.js new file mode 100644 index 000000000..7f3c93ff3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-return-abrupt-from-tointeger-offset.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.set-typedarray-offset +description: > + Return abrupt from ToInteger(offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.set(sample, obj1); + }, "abrupt from valueOf"); + + assert.throws(Test262Error, function() { + sample.set(sample, obj2); + }, "abrupt from toString"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js new file mode 100644 index 000000000..7cf6f1111 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set converted values from different buffer of different types and different type instances +includes: [byteConversionValues.js, testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + if (TA === Float64Array || TA === Float32Array || TA === Uint8ClampedArray) { + return; + } + if (TA === Int32Array) { + return; + } + + var sab, src, target; + + sab = new SharedArrayBuffer(4); + src = new Int32Array(sab); + src[0] = value; + target = new TA([initial]); + + target.set(src); + + assert.sameValue(target[0], expected, "src is SAB-backed"); + + sab = new SharedArrayBuffer(4); + src = new Int32Array([value]); + target = new TA(sab); + target[0] = initial; + + target.set(src); + + assert.sameValue(target[0], expected, "target is SAB-backed"); + + var sab1 = new SharedArrayBuffer(4); + var sab2 = new SharedArrayBuffer(4); + src = new Int32Array(sab1); + src[0] = value; + target = new TA(sab2); + target[0] = initial; + + target.set(src); + + assert.sameValue(target[0], expected, "src and target are SAB-backed"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-conversions.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-conversions.js new file mode 100644 index 000000000..5e819db9c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-conversions.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.set-typedarray-offset +description: > + Set converted values from different buffer and different type instances +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + ... + 28. Else, + a. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + value). +includes: [byteConversionValues.js, testBigIntTypedArray.js] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + if (TA === Float64Array) { + return; + } + var src = new Float64Array([value]); + var target = new TA([initial]); + + target.set(src); + + assert.sameValue(target[0], expected); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js new file mode 100644 index 000000000..408633ced --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type-sab.js @@ -0,0 +1,107 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var other = Int32Array; + var sab = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT); + var src = new other(sab); + src[0] = 42; + src[1] = 43; + var sample, result; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + src = new other([42, 43]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + var sab1 = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT); + src = new other(sab1); + src[0] = 42; + src[1] = 43; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.js new file mode 100644 index 000000000..1b1869345 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-other-type.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.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + ... + 28. Else, + a. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, targetType, + value). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src = new other(convertToBigInt([42, 43])); + var sample, result; + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 0); + assert(compareArray(sample, convertToBigInt([42, 43, 3, 4])), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 1); + assert(compareArray(sample, convertToBigInt([1, 42, 43, 4])), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 2); + assert(compareArray(sample, convertToBigInt([1, 2, 42, 43])), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js new file mode 100644 index 000000000..6e1279ea4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type-sab.js @@ -0,0 +1,107 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + + var sab = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + var src = new TA(sab); + src[0] = 42; + src[1] = 43; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + src = new TA([42, 43]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + src = new TA(sab1); + src[0] = 42; + src[1] = 43; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.js new file mode 100644 index 000000000..be938ca51 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-diff-buffer-same-type.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.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + ... + 24. Else, let srcByteIndex be srcByteOffset. + ... + 27. If SameValue(srcType, targetType) is true, then, + a. 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. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). + ... + 29. Return undefined. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + var src = new TA(convertToBigInt([42, 43])); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 1); + assert(compareArray(sample, convertToBigInt([1, 42, 43, 4])), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 0); + assert(compareArray(sample, convertToBigInt([42, 43, 3, 4])), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + result = sample.set(src, 2); + assert(compareArray(sample, convertToBigInt([1, 2, 42, 43])), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js new file mode 100644 index 000000000..86c686e3b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type-sab.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src, result, sab; + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1, 2, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 1, 2, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 1, 2]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.js new file mode 100644 index 000000000..8daad3956 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-set-values-same-buffer-same-type.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.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 23. If SameValue(srcBuffer, targetBuffer) is true, then + a. Let srcBuffer be ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcLength, + %ArrayBuffer%). + b. NOTE: %ArrayBuffer% is used to clone srcBuffer because is it known to not + have any observable side-effects. + ... + ... + 27. If SameValue(srcType, targetType) is true, then, + a. 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. + b. Repeat, while targetByteIndex < limit + i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, "Uint8"). + ii. Perform SetValueInBuffer(targetBuffer, targetByteIndex, "Uint8", + value). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src, result; + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, convertToBigInt([1, 2, 3, 4])), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, convertToBigInt([1, 1, 2, 4])), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA(convertToBigInt([1, 2, 3, 4])); + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, convertToBigInt([1, 2, 1, 2])), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.js new file mode 100644 index 000000000..9da7cbdcf --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-arraylength-internal.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.set-typedarray-offset +description: > + Uses typedArray's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 42; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(convertToBigInt([42, 43])); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(src, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js new file mode 100644 index 000000000..b75cbbd8e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-byteoffset-internal.js @@ -0,0 +1,45 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Uses typedArray's internal [[ByteOffset]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 21. Let srcByteOffset be typedArray.[[ByteOffset]]. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "byteOffset", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(convertToBigInt([42, 43])); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src2 = new other(convertToBigInt([42, 43])); + var src3 = new other(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(src, "byteOffset", desc); + Object.defineProperty(src2, "byteOffset", desc); + Object.defineProperty(src3, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteOffset properties"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.js new file mode 100644 index 000000000..2a24d0990 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-src-range-greather-than-target-throws-rangeerror.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.set-typedarray-offset +description: > + If srcLength + targetOffset > targetLength, throw a RangeError exception. +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 20. Let srcLength be the value of typedArray's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, src; + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 1); + }, "2 + 1 > 2"); + + sample = new TA(1); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, 0); + }, "2 + 0 > 1"); + + sample = new TA(1); + src = new TA(0); + assert.throws(RangeError, function() { + sample.set(src, 2); + }, "0 + 2 > 1"); + + sample = new TA(2); + src = new TA(2); + assert.throws(RangeError, function() { + sample.set(src, Infinity); + }, "2 + Infinity > 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 000000000..98ae8b2fa --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-srcbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Throws a TypeError if srcBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 11. Let srcBuffer be the value of typedArray's [[ViewedArrayBuffer]] internal + slot. + 12. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + var target = new TA(); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(target.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(target, obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js new file mode 100644 index 000000000..7eed1fff1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-arraylength-internal.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 10. Let targetLength be the value of target's [[ArrayLength]] internal slot. + ... + 22. If srcLength + targetOffset > targetLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(convertToBigInt([42, 43])); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.set(src); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js new file mode 100644 index 000000000..ba1909dd5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-target-byteoffset-internal.js @@ -0,0 +1,44 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Uses target's internal [[ArrayLength]] +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + 2. Let target be the this value. + ... + 16. Let targetByteOffset be target.[[ByteOffset]]. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "byteOffset", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(convertToBigInt([42, 43])); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + var src2 = new other(convertToBigInt([42, 43])); + var src3 = new other(sample.buffer, 0, 2); + + Object.defineProperty(TA.prototype, "byteOffset", desc); + Object.defineProperty(sample, "byteOffset", desc); + + sample.set(src); + sample.set(src2); + sample.set(src3); + + assert.sameValue(getCalls, 0, "ignores byteoffset properties"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js new file mode 100644 index 000000000..b57c24551 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/BigInt/typedarray-arg-targetbuffer-detached-during-tointeger-offset-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Throws a TypeError if targetBuffer is detached on ToInteger(offset) +info: | + 22.2.3.23.2 %TypedArray%.prototype.set(typedArray [ , offset ] ) + + 1. Assert: typedArray has a [[TypedArrayName]] internal slot. If it does not, + the definition in 22.2.3.23.1 applies. + ... + 6. Let targetOffset be ? ToInteger(offset). + ... + 8. Let targetBuffer be the value of target's [[ViewedArrayBuffer]] internal + slot. + 9. If IsDetachedBuffer(targetBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var src = new TA(1); + var calledOffset = 0; + var obj = { + valueOf: function() { + $DETACHBUFFER(sample.buffer); + calledOffset += 1; + } + }; + + assert.throws(TypeError, function() { + sample.set(src, obj); + }); + + assert.sameValue(calledOffset, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js index 9ea3f3ef0..45d648c1a 100644 --- a/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js +++ b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-other-type.js @@ -56,4 +56,4 @@ testWithTypedArrayConstructors(function(TA) { assert(compareArray(sample, expected[TA.name]), sample); assert.sameValue(result, undefined, "returns undefined"); -}, numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/arraylength-internal.js b/test/built-ins/TypedArray/prototype/slice/BigInt/arraylength-internal.js new file mode 100644 index 000000000..9f97ab033 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/arraylength-internal.js @@ -0,0 +1,38 @@ +// 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(convertToBigInt([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], convertToBigInt(42)); + assert.sameValue(result[1], convertToBigInt(43)); + assert.sameValue(result.hasOwnProperty(2), false); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/bit-precision.js b/test/built-ins/TypedArray/prototype/slice/BigInt/bit-precision.js new file mode 100644 index 000000000..4c581eb60 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/bit-precision.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +es6id: 22.2.3.23 +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, testBigIntTypedArray.js] +---*/ + +function body(FloatArray) { + var subject = new FloatArray(distinctNaNs); + var sliced, subjectBytes, slicedBytes; + + sliced = subject.slice(); + + subjectBytes = new Uint8Array(subject.buffer); + slicedBytes = new Uint8Array(sliced.buffer); + + assert(compareArray(subjectBytes, slicedBytes)); +} + +testWithBigIntTypedArrayConstructors(body, [Float32Array, Float64Array]); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js new file mode 100644 index 000000000..5dee0faf7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-other-targettype.js @@ -0,0 +1,38 @@ +// 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 buffer is detached on Get custom constructor. Using other + targetType +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + 14. If SameValue(srcType, targetType) is false, then + a. Let n be 0. + b. Repeat, while k < final + ... + ii. Let kValue be ? Get(O, Pk). + ... + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + var other = TA === Int8Array ? Int16Array : Int8Array; + $DETACHBUFFER(sample.buffer); + return new other(count); + }; + + assert.throws(TypeError, function() { + sample.slice(); + }, "step 14.b.ii - ? Get(O, Pk), O has a detached buffer"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.js new file mode 100644 index 000000000..a5e64a7d1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-custom-ctor-same-targettype.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: Throws a TypeError buffer is detached on Get custom constructor. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + 14. If SameValue(srcType, targetType) is false, then + ... + 15. Else if count > 0, then + a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot. + b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + $DETACHBUFFER(sample.buffer); + return new TA(count); + }; + + assert.throws(TypeError, function() { + sample.slice(); + }, "step 15.b, IsDetachedBuffer(srcBuffer) is true"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js new file mode 100644 index 000000000..5ce258d5c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-get-ctor.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Throws a TypeError buffer is detached on Get constructor. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + 14. If SameValue(srcType, targetType) is false, then + ... + 15. Else if count > 0, then + a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot. + b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "constructor", { + get: function() { + $DETACHBUFFER(sample.buffer); + } + }); + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 000000000..29258266b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-speciesctor-get-species-custom-ctor-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: > + Custom @@species constructor throws if it returns an instance with a detached + buffer +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). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(count) { + var other = new TA(count); + $DETACHBUFFER(other.buffer); + return other; + }; + + assert.throws(TypeError, function() { + sample.slice(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.js new file mode 100644 index 000000000..adcd18b71 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-other-targettype.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 buffer is detached on custom constructor and + `k >= final`. Using other targetType. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + 14. If SameValue(srcType, targetType) is false, then + a. Let n be 0. + b. Repeat, while k < final + ... + ii. Let kValue be ? Get(O, Pk). + ... + ... + 16. Return A. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result, other; + var ctor = {}; + ctor[Symbol.species] = function(count) { + other = TA === Int8Array ? Int16Array : Int8Array; + $DETACHBUFFER(sample.buffer); + return new other(count); + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, "#1: result.length"); + assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer"); + assert.sameValue(result.constructor, other, "#1: ctor"); + + sample = new TA(4); + sample.constructor = ctor; + result = sample.slice(1, 1); + assert.sameValue(result.length, 0, "#2: result.length"); + assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer"); + assert.sameValue(result.constructor, other, "#2: ctor"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js new file mode 100644 index 000000000..67372bd73 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer-zero-count-custom-ctor-same-targettype.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: > + Does not throw a TypeError if buffer is detached on custom constructor and + `k >= final`. Using same targetType. +info: | + 22.2.3.24 %TypedArray%.prototype.slice ( start, end ) + + ... + 9. Let A be ? TypedArraySpeciesCreate(O, « count »). + ... + 14. If SameValue(srcType, targetType) is false, then + ... + 15. Else if count > 0, then + a. Let srcBuffer be the value of O's [[ViewedArrayBuffer]] internal slot. + b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample, result; + var ctor = {}; + ctor[Symbol.species] = function(count) { + $DETACHBUFFER(sample.buffer); + return new TA(count); + }; + + sample = new TA(0); + sample.constructor = ctor; + result = sample.slice(); + assert.sameValue(result.length, 0, "#1: result.length"); + assert.notSameValue(result.buffer, sample.buffer, "#1: creates a new buffer"); + assert.sameValue(result.constructor, TA, "#1: ctor"); + + sample = new TA(4); + sample.constructor = ctor; + result = sample.slice(1, 1); + assert.sameValue(result.length, 0, "#2: result.length"); + assert.notSameValue(result.buffer, sample.buffer, "#2: creates a new buffer"); + assert.sameValue(result.constructor, TA, "#2: ctor"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer.js new file mode 100644 index 000000000..846386175 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/detached-buffer.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: 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); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/infinity.js b/test/built-ins/TypedArray/prototype/slice/BigInt/infinity.js new file mode 100644 index 000000000..07f62263a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/infinity.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.slice +description: Infinity values on start and end +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + assert( + compareArray(sample.slice(-Infinity), convertToBigInt([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), convertToBigInt([40, 41, 42, 43])), + "end == Infinity" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/slice/BigInt/invoked-as-func.js new file mode 100644 index 000000000..d12fa6245 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.23 +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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var slice = TypedArray.prototype.slice; + +assert.sameValue(typeof slice, 'function'); + +assert.throws(TypeError, function() { + slice(); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/slice/BigInt/invoked-as-method.js new file mode 100644 index 000000000..c352bbaf6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.23 +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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.slice, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.slice(); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/length.js b/test/built-ins/TypedArray/prototype/slice/BigInt/length.js new file mode 100644 index 000000000..615fac7a2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/length.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. + +/*--- +es6id: 22.2.3.23 +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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.slice.length, 2); + +verifyNotEnumerable(TypedArray.prototype.slice, "length"); +verifyNotWritable(TypedArray.prototype.slice, "length"); +verifyConfigurable(TypedArray.prototype.slice, "length"); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/minus-zero.js b/test/built-ins/TypedArray/prototype/slice/BigInt/minus-zero.js new file mode 100644 index 000000000..19657957a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/minus-zero.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: -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(convertToBigInt([40, 41, 42, 43])); + + assert( + compareArray(sample.slice(-0), convertToBigInt([40, 41, 42, 43])), + "start == -0" + ); + assert( + compareArray(sample.slice(-0, 4), convertToBigInt([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" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/name.js b/test/built-ins/TypedArray/prototype/slice/BigInt/name.js new file mode 100644 index 000000000..e26ef197a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.23 +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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.slice.name, "slice"); + +verifyNotEnumerable(TypedArray.prototype.slice, "name"); +verifyNotWritable(TypedArray.prototype.slice, "name"); +verifyConfigurable(TypedArray.prototype.slice, "name"); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/slice/BigInt/prop-desc.js new file mode 100644 index 000000000..a750f3750 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.23 +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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'slice'); +verifyWritable(TypedArrayPrototype, 'slice'); +verifyConfigurable(TypedArrayPrototype, 'slice'); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js b/test/built-ins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js new file mode 100644 index 000000000..00b6132ac --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,22 @@ +// 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(convertToBigInt([41, 42, 43, 44])); + sample.foo = 42; + + var result = sample.slice(); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-different-length.js b/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-different-length.js new file mode 100644 index 000000000..22c8a0abe --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-different-length.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: 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(convertToBigInt([40, 41, 42, 43])); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.slice(1), convertToBigInt([41, 42, 43]), "begin == 1"); + testRes(sample.slice(2), convertToBigInt([42, 43]), "begin == 2"); + testRes(sample.slice(3), convertToBigInt([43]), "begin == 3"); + + testRes(sample.slice(1, 4), convertToBigInt([41, 42, 43]), "begin == 1, end == length"); + testRes(sample.slice(2, 4), convertToBigInt([42, 43]), "begin == 2, end == length"); + testRes(sample.slice(3, 4), convertToBigInt([43]), "begin == 3, end == length"); + + testRes(sample.slice(0, 1), convertToBigInt([40]), "begin == 0, end == 1"); + testRes(sample.slice(0, 2), convertToBigInt([40, 41]), "begin == 0, end == 2"); + testRes(sample.slice(0, 3), convertToBigInt([40, 41, 42]), "begin == 0, end == 3"); + + testRes(sample.slice(-1), convertToBigInt([43]), "begin == -1"); + testRes(sample.slice(-2), convertToBigInt([42, 43]), "begin == -2"); + testRes(sample.slice(-3), convertToBigInt([41, 42, 43]), "begin == -3"); + + testRes(sample.slice(-1, 4), convertToBigInt([43]), "begin == -1, end == length"); + testRes(sample.slice(-2, 4), convertToBigInt([42, 43]), "begin == -2, end == length"); + testRes(sample.slice(-3, 4), convertToBigInt([41, 42, 43]), "begin == -3, end == length"); + + testRes(sample.slice(0, -1), convertToBigInt([40, 41, 42]), "begin == 0, end == -1"); + testRes(sample.slice(0, -2), convertToBigInt([40, 41]), "begin == 0, end == -2"); + testRes(sample.slice(0, -3), convertToBigInt([40]), "begin == 0, end == -3"); + + testRes(sample.slice(-0, -1), convertToBigInt([40, 41, 42]), "begin == -0, end == -1"); + testRes(sample.slice(-0, -2), convertToBigInt([40, 41]), "begin == -0, end == -2"); + testRes(sample.slice(-0, -3), convertToBigInt([40]), "begin == -0, end == -3"); + + testRes(sample.slice(-2, -1), convertToBigInt([42]), "length == 4, begin == -2, end == -1"); + testRes(sample.slice(1, -1), convertToBigInt([41, 42]), "length == 4, begin == 1, end == -1"); + testRes(sample.slice(1, -2), convertToBigInt([41]), "length == 4, begin == 1, end == -2"); + testRes(sample.slice(2, -1), convertToBigInt([42]), "length == 4, begin == 2, end == -1"); + + testRes(sample.slice(-1, 5), convertToBigInt([43]), "begin == -1, end > length"); + testRes(sample.slice(-2, 4), convertToBigInt([42, 43]), "begin == -2, end > length"); + testRes(sample.slice(-3, 4), convertToBigInt([41, 42, 43]), "begin == -3, end > length"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-empty-length.js b/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-empty-length.js new file mode 100644 index 000000000..386149b45 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-empty-length.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: slice may return a new empty instance +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([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"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-same-length.js b/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-same-length.js new file mode 100644 index 000000000..a8cee48aa --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/results-with-same-length.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: slice may return a new instance with the same length +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], convertToBigInt(40), msg + " & result[0] === 40"); + assert.sameValue(result[1], convertToBigInt(41), msg + " & result[1] === 41"); + assert.sameValue(result[2], convertToBigInt(42), msg + " & result[2] === 42"); + assert.sameValue(result[3], convertToBigInt(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"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js new file mode 100644 index 000000000..c0ec87e5a --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end-symbol.js @@ -0,0 +1,25 @@ +// 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); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js new file mode 100644 index 000000000..9fa211798 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-end.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.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); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.js b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.js new file mode 100644 index 000000000..6e003f8df --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start-symbol.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: 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); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js new file mode 100644 index 000000000..3b79f1375 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/return-abrupt-from-start.js @@ -0,0 +1,38 @@ +// 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); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.js b/test/built-ins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.js new file mode 100644 index 000000000..93b074f1f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/set-values-from-different-ctor-type.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: > + 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 = [42, 43, 44]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + var other = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + + sample.constructor = {}; + sample.constructor[Symbol.species] = other; + + var result = sample.slice(); + + assert(compareArray(result, convertToBigInt(arr)), "values are set"); + assert.notSameValue(result.buffer, sample.buffer, "creates a new buffer"); + assert.sameValue(result.constructor, other, "used the custom ctor"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 000000000..6294fa6b1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-abrupt.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 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(convertToBigInt([40, 41, 42, 43])); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.slice(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 000000000..15f1e5765 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-inherited.js @@ -0,0 +1,62 @@ +// 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(convertToBigInt([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" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 000000000..7a742b9b8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.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(convertToBigInt([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"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.js new file mode 100644 index 000000000..967579071 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-ctor.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: 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(convertToBigInt([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" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 000000000..74de9aceb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-abrupt.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.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(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 000000000..5187a421f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-invocation.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.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(convertToBigInt([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" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.js new file mode 100644 index 000000000..6f699c2d3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length-throws.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: > + 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(); + }); +});
\ No newline at end of file diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.js new file mode 100644 index 000000000..5159487ae --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-length.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: > + 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"); +});
\ No newline at end of file diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 000000000..b323cc7ec --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.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: > + 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(convertToBigInt([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"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 000000000..e35f1af62 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor-throws.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: > + 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(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 000000000..00a426e10 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-custom-ctor.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: > + 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(convertToBigInt([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, convertToBigInt([41, 42])), "expected object"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 000000000..a24ba5a52 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-returns-throws.js @@ -0,0 +1,66 @@ +// 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 000000000..4429f6336 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species-use-default-ctor.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: > + 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"); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.js b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.js new file mode 100644 index 000000000..a2cf9e131 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/speciesctor-get-species.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: > + 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); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/slice/BigInt/this-is-not-object.js new file mode 100644 index 000000000..a16cf1c8c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/this-is-not-object.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 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: [testBigIntTypedArray.js] +features: [BigInt, 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"); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/slice/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..ad429c8a1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/this-is-not-typedarray-instance.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: > + 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: [testBigIntTypedArray.js] +features: [BigInt, 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"); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/tointeger-end.js b/test/built-ins/TypedArray/prototype/slice/BigInt/tointeger-end.js new file mode 100644 index 000000000..979b2df9f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/tointeger-end.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: 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(convertToBigInt([40, 41, 42, 43])); + + assert(compareArray(sample.slice(0, false), []), "false"); + assert(compareArray(sample.slice(0, true), convertToBigInt([40])), "true"); + + assert(compareArray(sample.slice(0, NaN), []), "NaN"); + assert(compareArray(sample.slice(0, null), []), "null"); + assert(compareArray(sample.slice(0, undefined), convertToBigInt([40, 41, 42, 43])), "undefined"); + + assert(compareArray(sample.slice(0, 0.6), []), "0.6"); + assert(compareArray(sample.slice(0, 1.1), convertToBigInt([40])), "1.1"); + assert(compareArray(sample.slice(0, 1.5), convertToBigInt([40])), "1.5"); + assert(compareArray(sample.slice(0, -0.6), []), "-0.6"); + assert(compareArray(sample.slice(0, -1.1), convertToBigInt([40, 41, 42])), "-1.1"); + assert(compareArray(sample.slice(0, -1.5), convertToBigInt([40, 41, 42])), "-1.5"); + + assert(compareArray(sample.slice(0, "3"), convertToBigInt([40, 41, 42])), "string"); + assert( + compareArray( + sample.slice(0, obj), + convertToBigInt([40, 41]) + ), + "object" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/slice/BigInt/tointeger-start.js b/test/built-ins/TypedArray/prototype/slice/BigInt/tointeger-start.js new file mode 100644 index 000000000..8ce0fde83 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/slice/BigInt/tointeger-start.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: 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(convertToBigInt([40, 41, 42, 43])); + + assert(compareArray(sample.slice(false), convertToBigInt([40, 41, 42, 43])), "false"); + assert(compareArray(sample.slice(true), convertToBigInt([41, 42, 43])), "true"); + + assert(compareArray(sample.slice(NaN), convertToBigInt([40, 41, 42, 43])), "NaN"); + assert(compareArray(sample.slice(null), convertToBigInt([40, 41, 42, 43])), "null"); + assert(compareArray(sample.slice(undefined), convertToBigInt([40, 41, 42, 43])), "undefined"); + + assert(compareArray(sample.slice(1.1), convertToBigInt([41, 42, 43])), "1.1"); + assert(compareArray(sample.slice(1.5), convertToBigInt([41, 42, 43])), "1.5"); + assert(compareArray(sample.slice(0.6), convertToBigInt([40, 41, 42, 43])), "0.6"); + + assert(compareArray(sample.slice(-1.5), convertToBigInt([43])), "-1.5"); + assert(compareArray(sample.slice(-1.1), convertToBigInt([43])), "-1.1"); + assert(compareArray(sample.slice(-0.6), convertToBigInt([40, 41, 42, 43])), "-0.6"); + + assert(compareArray(sample.slice("3"), convertToBigInt([43])), "string"); + assert( + compareArray( + sample.slice(obj), + convertToBigInt([42, 43]) + ), + "object" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js new file mode 100644 index 000000000..df0c06fc3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-with-thisarg.js @@ -0,0 +1,57 @@ +// 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.some +description: > + thisArg does not affect callbackfn arguments +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + var thisArg = ["test262", 0, "ecma262", 0]; + + sample.some(function() { + results.push(arguments); + }, thisArg); + + assert.sameValue(results.length, 3, "results.length"); + assert.sameValue(thisArg.length, 4, "thisArg.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.js new file mode 100644 index 000000000..4f52490ef --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-arguments-without-thisarg.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.some +description: > + callbackfn arguments +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + var results = []; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 3, "results.length"); + + assert.sameValue(results[0].length, 3, "results[0].length"); + assert.sameValue(results[0][0], convertToBigInt(42), "results[0][0] - kValue"); + assert.sameValue(results[0][1], 0, "results[0][1] - k"); + assert.sameValue(results[0][2], sample, "results[0][2] - this"); + + assert.sameValue(results[1].length, 3, "results[1].length"); + assert.sameValue(results[1][0], convertToBigInt(43), "results[1][0] - kValue"); + assert.sameValue(results[1][1], 1, "results[1][1] - k"); + assert.sameValue(results[1][2], sample, "results[1][2] - this"); + + assert.sameValue(results[2].length, 3, "results[2].length"); + assert.sameValue(results[2][0], convertToBigInt(44), "results[2][0] - kValue"); + assert.sameValue(results[2][1], 2, "results[2][1] - k"); + assert.sameValue(results[2][2], sample, "results[2][2] - this"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js new file mode 100644 index 000000000..9c92aed23 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-detachbuffer.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.some +description: > + Instance buffer can be detached during loop +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [detachArrayBuffer.js, testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var loops = 0; + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.some(function() { + if (loops === 1) { + throw new Test262Error("callbackfn called twice"); + } + $DETACHBUFFER(sample.buffer); + loops++; + }); + }); + + assert.sameValue(loops, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.js new file mode 100644 index 000000000..b01b5e621 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-no-interaction-over-non-integer.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.some +description: > + Does not interact over non-integer properties +info: | + 22.2.3.7 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([7, 8])); + + var results = []; + + sample.foo = 42; + sample[Symbol("1")] = 43; + + sample.some(function() { + results.push(arguments); + }); + + assert.sameValue(results.length, 2, "results.length"); + + assert.sameValue(results[0][1], 0, "results[0][1] - key"); + assert.sameValue(results[1][1], 1, "results[1][1] - key"); + + assert.sameValue(results[0][0], convertToBigInt(7), "results[0][0] - value"); + assert.sameValue(results[1][0], convertToBigInt(8), "results[1][0] - value"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js new file mode 100644 index 000000000..ce453a2c6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-callable-throws.js @@ -0,0 +1,69 @@ +// 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.some +description: Throws a TypeError if callbackfn is not callable +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 3. If IsCallable(callbackfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.throws(TypeError, function() { + sample.some(); + }, "no args"); + + assert.throws(TypeError, function() { + sample.some(null); + }, "null"); + + assert.throws(TypeError, function() { + sample.some(undefined); + }, "undefined"); + + assert.throws(TypeError, function() { + sample.some("abc"); + }, "string"); + + assert.throws(TypeError, function() { + sample.some(1); + }, "number"); + + assert.throws(TypeError, function() { + sample.some(NaN); + }, "NaN"); + + assert.throws(TypeError, function() { + sample.some(false); + }, "false"); + + assert.throws(TypeError, function() { + sample.some(true); + }, "true"); + + assert.throws(TypeError, function() { + sample.some({}); + }, "{}"); + + assert.throws(TypeError, function() { + sample.some(sample); + }, "same typedArray instance"); + + assert.throws(TypeError, function() { + sample.some(Symbol("1")); + }, "symbol"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.js new file mode 100644 index 000000000..4480beb4d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-not-called-on-empty.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.some +description: > + callbackfn is not called on empty instances +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + new TA().some(function() { + called++; + }); + + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js new file mode 100644 index 000000000..19a6337d0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-return-does-not-change-instance.js @@ -0,0 +1,38 @@ +// 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.some +description: > + The callbackfn return does not change the instance +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42])); + + sample.some(function() { + return 0; + }); + + assert.sameValue(sample[0], convertToBigInt(40), "[0] == 40"); + assert.sameValue(sample[1], convertToBigInt(41), "[1] == 41"); + assert.sameValue(sample[2], convertToBigInt(42), "[2] == 42"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.js new file mode 100644 index 000000000..eef277bfb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-returns-abrupt.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.some +description: Returns abrupt from callbackfn +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + assert.throws(Test262Error, function() { + sample.some(function() { + throw new Test262Error(); + }); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.js new file mode 100644 index 000000000..4a2331d42 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-set-value-during-interaction.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.some +description: > + Integer indexed values changed during iteration +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect.set, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + var newVal = 0; + + sample.some(function(val, i) { + if (i > 0) { + assert.sameValue( + sample[i - 1], convertToBigInt(newVal - 1), + "get the changed value during the loop" + ); + assert.sameValue( + Reflect.set(sample, 0, convertToBigInt(7)), + true, + "re-set a value for sample[0]" + ); + } + assert.sameValue( + Reflect.set(sample, i, convertToBigInt(newVal)), + true, + "set value during iteration" + ); + + newVal++; + }); + + assert.sameValue(sample[0], convertToBigInt(7), "changed values after iteration [0] == 7"); + assert.sameValue(sample[1], convertToBigInt(1), "changed values after iteration [1] == 1"); + assert.sameValue(sample[2], convertToBigInt(2), "changed values after iteration [2] == 2"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-this.js b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-this.js new file mode 100644 index 000000000..dc08ba4aa --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/callbackfn-this.js @@ -0,0 +1,57 @@ +// 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.some +description: > + callbackfn `this` value +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 4. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + ... + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expected = (function() { return this; })(); +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(3); + + var results1 = []; + + sample.some(function() { + results1.push(this); + }); + + assert.sameValue(results1.length, 3, "results1"); + assert.sameValue(results1[0], expected, "without thisArg - [0]"); + assert.sameValue(results1[1], expected, "without thisArg - [1]"); + assert.sameValue(results1[2], expected, "without thisArg - [2]"); + + var results2 = []; + + sample.some(function() { + results2.push(this); + }, thisArg); + + assert.sameValue(results2.length, 3, "results2"); + assert.sameValue(results2[0], thisArg, "using thisArg - [0]"); + assert.sameValue(results2[1], thisArg, "using thisArg - [1]"); + assert.sameValue(results2[2], thisArg, "using thisArg - [2]"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/some/BigInt/detached-buffer.js new file mode 100644 index 000000000..ec32a7df4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/detached-buffer.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.some +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var callbackfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.some(callbackfn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..2135d10ca --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/get-length-uses-internal-arraylength.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.some +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? ToLength(? Get(O, "length")). + ... +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(convertToBigInt([42, 43])); + var calls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.some(function() { + calls++; + }); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert.sameValue(calls, 2, "iterations are not affected by custom length"); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/some/BigInt/invoked-as-func.js new file mode 100644 index 000000000..f093afd9b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/invoked-as-func.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.24 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.24 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var some = TypedArray.prototype.some; + +assert.sameValue(typeof some, 'function'); + +assert.throws(TypeError, function() { + some(); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/some/BigInt/invoked-as-method.js new file mode 100644 index 000000000..7fc537318 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/invoked-as-method.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.24 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.24 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.some, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.some(); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/length.js b/test/built-ins/TypedArray/prototype/some/BigInt/length.js new file mode 100644 index 000000000..c1574968f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/length.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. + +/*--- +es6id: 22.2.3.24 +description: > + %TypedArray%.prototype.some.length is 1. +info: | + %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.some.length, 1); + +verifyNotEnumerable(TypedArray.prototype.some, "length"); +verifyNotWritable(TypedArray.prototype.some, "length"); +verifyConfigurable(TypedArray.prototype.some, "length"); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/name.js b/test/built-ins/TypedArray/prototype/some/BigInt/name.js new file mode 100644 index 000000000..e216ae780 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.24 +description: > + %TypedArray%.prototype.some.name is "some". +info: | + %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.some.name, "some"); + +verifyNotEnumerable(TypedArray.prototype.some, "name"); +verifyNotWritable(TypedArray.prototype.some, "name"); +verifyConfigurable(TypedArray.prototype.some, "name"); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/some/BigInt/prop-desc.js new file mode 100644 index 000000000..00de662ca --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.24 +description: > + "some" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'some'); +verifyWritable(TypedArrayPrototype, 'some'); +verifyConfigurable(TypedArrayPrototype, 'some'); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js b/test/built-ins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.js new file mode 100644 index 000000000..ef733a11e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/returns-false-if-every-cb-returns-false.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.some +description: > + Returns false if every callbackfn calls returns a coerced false. +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 7. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + + [ + false, + "", + 0, + -0, + NaN, + undefined, + null + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + return val; + }); + assert.sameValue(called, 42, "callbackfn called for each index property"); + assert.sameValue(result, false, "result is false - " + val); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js b/test/built-ins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js new file mode 100644 index 000000000..da956be06 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/returns-true-if-any-cb-returns-true.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.some +description: > + Returns true if any callbackfn returns a coerced true. +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + ... + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + iii. If testResult is true, return true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + [ + true, + 1, + "test262", + s, + {}, + [], + -1, + Infinity, + -Infinity, + 0.1, + -0.1 + ].forEach(function(val) { + var called = 0; + var result = sample.some(function() { + called++; + if (called == 1) { + return false; + } + return val; + }); + assert.sameValue(called, 2, "callbackfn called for each index property"); + + var msg = "result is true - " + (val === s ? "symbol" : val); + assert.sameValue(result, true, msg); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/some/BigInt/this-is-not-object.js new file mode 100644 index 000000000..cc7aba63f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/this-is-not-object.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.some +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var some = TypedArray.prototype.some; +var callbackfn = function() {}; + +assert.throws(TypeError, function() { + some.call(undefined, callbackfn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + some.call(null, callbackfn); +}, "this is null"); + +assert.throws(TypeError, function() { + some.call(42, callbackfn); +}, "this is 42"); + +assert.throws(TypeError, function() { + some.call("1", callbackfn); +}, "this is a string"); + +assert.throws(TypeError, function() { + some.call(true, callbackfn); +}, "this is true"); + +assert.throws(TypeError, function() { + some.call(false, callbackfn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + some.call(s, callbackfn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/some/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..3cc3bb41f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/this-is-not-typedarray-instance.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.some +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var some = TypedArray.prototype.some; +var callbackfn = function () {}; + +assert.throws(TypeError, function() { + some.call({}, callbackfn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + some.call([], callbackfn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + some.call(ab, callbackfn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + some.call(dv, callbackfn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/some/BigInt/values-are-not-cached.js b/test/built-ins/TypedArray/prototype/some/BigInt/values-are-not-cached.js new file mode 100644 index 000000000..bd1d209f8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/some/BigInt/values-are-not-cached.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.some +description: > + Integer indexed values are not cached before iteration +info: | + 22.2.3.25 %TypedArray%.prototype.some ( callbackfn [ , thisArg ] ) + + %TypedArray%.prototype.some is a distinct function that implements the same + algorithm as Array.prototype.some as defined in 22.1.3.24 except that the this + object's [[ArrayLength]] internal slot is accessed in place of performing a + [[Get]] of "length". + + 22.1.3.24 Array.prototype.some ( callbackfn [ , thisArg ] ) + + ... + 6. Repeat, while k < len + .. + c. If kPresent is true, then + i. Let kValue be ? Get(O, Pk). + ii. Let testResult be ToBoolean(? Call(callbackfn, T, « kValue, k, O »)). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44])); + + sample.some(function(v, i) { + if (i < sample.length - 1) { + sample[i+1] = convertToBigInt(42); + } + + assert.sameValue( + v, convertToBigInt(42), "method does not cache values before callbackfn calls" + ); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js b/test/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js new file mode 100644 index 000000000..b8436a5f3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.sort +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + ... + 3. Let len be the value of obj's [[ArrayLength]] internal slot. +includes: [testBigIntTypedArray.js, compareArray.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(convertToBigInt([42, 42, 42])); + getCalls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.sort(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert( + compareArray(result, sample), + "result is not affected by custom length" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js new file mode 100644 index 000000000..d319341a7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.sort +description: Returns abrupt from comparefn +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... + + 22.1.3.25 Array.prototype.sort (comparefn) + + The following steps are taken: + + - If an abrupt completion is returned from any of these operations, it is + immediately returned as the value of this function. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44, 45, 46])); + var calls = 0; + + var comparefn = function() { + calls += 1; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.sort(comparefn); + }); + + assert.sameValue(calls, 1, "immediately returned"); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js new file mode 100644 index 000000000..c058cddac --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.sort +description: comparefn is called if not undefined +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expectedThis = (function() { + return this; +})(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 42, 42, 42, 42])); + var calls = []; + + var comparefn = function() { + calls.push([this, arguments]); + }; + + sample.sort(comparefn); + + assert(calls.length > 0, "calls comparefn"); + calls.forEach(function(args) { + assert.sameValue(args[0], expectedThis, "comparefn is called no specific this"); + assert.sameValue(args[1].length, 2, "comparefn is always called with 2 args"); + assert.sameValue(args[1][0], convertToBigInt(42), "x is a listed value"); + assert.sameValue(args[1][0], convertToBigInt(42), "y is a listed value"); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js new file mode 100644 index 000000000..80f23f618 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js @@ -0,0 +1,55 @@ +// Copyright (C) 2017 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.sort +description: throws on a non-undefined non-function +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + Upon entry, the following steps are performed to initialize evaluation + of the sort function. These steps are used instead of the entry steps + in 22.1.3.25: + + ... + 1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception. + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43, 44, 45, 46])); + + assert.throws(TypeError, function() { + sample.sort(null); + }); + + assert.throws(TypeError, function() { + sample.sort(true); + }); + + assert.throws(TypeError, function() { + sample.sort(false); + }); + + assert.throws(TypeError, function() { + sample.sort(''); + }); + + assert.throws(TypeError, function() { + sample.sort(/a/g); + }); + + assert.throws(TypeError, function() { + sample.sort(42); + }); + + assert.throws(TypeError, function() { + sample.sort([]); + }); + + assert.throws(TypeError, function() { + sample.sort({}); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js new file mode 100644 index 000000000..caa7f80a2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js @@ -0,0 +1,38 @@ +// 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.sort +description: Throws a TypeError if comparefn detaches the object buffer +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + var calls = 0; + var comparefn = function() { + if (calls > 0) { + throw new Test262Error(); + } + calls++; + $DETACHBUFFER(sample.buffer); + }; + + assert.throws(TypeError, function() { + sample.sort(comparefn); + }); + + assert.sameValue(calls, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js new file mode 100644 index 000000000..e49bb0883 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.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.sort +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value. + 2. Let buffer be ? ValidateTypedArray(obj). + + 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 comparefn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.sort(comparefn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-func.js new file mode 100644 index 000000000..89e84fc27 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-func.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. +/*--- +es6id: 22.2.3.25 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.25 %TypedArray%.prototype.sort ( comparefn ) + + ... + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. + ... + + 1. Let obj be the this value as the argument. + 2. Let buffer be ValidateTypedArray(obj). + 3. ReturnIfAbrupt(buffer). + ... + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sort = TypedArray.prototype.sort; + +assert.sameValue(typeof sort, 'function'); + +assert.throws(TypeError, function() { + sort(); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-method.js new file mode 100644 index 000000000..fea2db35b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-method.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. +/*--- +es6id: 22.2.3.25 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.25 %TypedArray%.prototype.sort ( comparefn ) + + ... + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. + ... + + 1. Let obj be the this value as the argument. + 2. Let buffer be ValidateTypedArray(obj). + 3. ReturnIfAbrupt(buffer). + ... + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.sort, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.sort(); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/length.js b/test/built-ins/TypedArray/prototype/sort/BigInt/length.js new file mode 100644 index 000000000..028e2639b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/length.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. + +/*--- +es6id: 22.2.3.25 +description: > + %TypedArray%.prototype.sort.length is 1. +info: | + %TypedArray%.prototype.sort ( comparefn ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.sort.length, 1); + +verifyNotEnumerable(TypedArray.prototype.sort, "length"); +verifyNotWritable(TypedArray.prototype.sort, "length"); +verifyConfigurable(TypedArray.prototype.sort, "length"); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/name.js b/test/built-ins/TypedArray/prototype/sort/BigInt/name.js new file mode 100644 index 000000000..2214531a3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.25 +description: > + %TypedArray%.prototype.sort.name is "sort". +info: | + %TypedArray%.prototype.sort ( comparefn ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.sort.name, "sort"); + +verifyNotEnumerable(TypedArray.prototype.sort, "name"); +verifyNotWritable(TypedArray.prototype.sort, "name"); +verifyConfigurable(TypedArray.prototype.sort, "name"); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/sort/BigInt/prop-desc.js new file mode 100644 index 000000000..21f05def7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.25 +description: > + "sort" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'sort'); +verifyWritable(TypedArrayPrototype, 'sort'); +verifyConfigurable(TypedArrayPrototype, 'sort'); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js b/test/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js new file mode 100644 index 000000000..d3ad6056f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js @@ -0,0 +1,25 @@ +// 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.sort +description: Returns the same instance +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([2, 1])); + var result = sample.sort(); + + assert.sameValue(sample, result, "without comparefn"); + + result = sample.sort(function() { return 0; }); + assert.sameValue(sample, result, "with comparefn"); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js b/test/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js new file mode 100644 index 000000000..b7f73c650 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.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.sort +description: TypedArrays sort does not cast values to String +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var origToString = Number.prototype.toString; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([20, 100, 3])); + var result = sample.sort(); + assert(compareArray(result, convertToBigInt([3, 20, 100]))); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values-nan.js b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values-nan.js new file mode 100644 index 000000000..7a553b13e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values-nan.js @@ -0,0 +1,38 @@ +// 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.sort +description: Sort values to numeric ascending order +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + + NOTE: Because NaN always compares greater than any other value, NaN property + values always sort to the end of the result when comparefn is not provided. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([2, NaN, NaN, 0, 1]).sort(); + assert.sameValue(sample[0], 0, "#1 [0]"); + assert.sameValue(sample[1], 1, "#1 [1]"); + assert.sameValue(sample[2], 2, "#1 [2]"); + assert.sameValue(sample[3], NaN, "#1 [3]"); + assert.sameValue(sample[4], NaN, "#1 [4]"); + + sample = new TA([3, NaN, NaN, Infinity, 0, -Infinity, 2]).sort(); + assert.sameValue(sample[0], -Infinity, "#2 [0]"); + assert.sameValue(sample[1], 0, "#2 [1]"); + assert.sameValue(sample[2], 2, "#2 [2]"); + assert.sameValue(sample[3], 3, "#2 [3]"); + assert.sameValue(sample[4], Infinity, "#2 [4]"); + assert.sameValue(sample[5], NaN, "#2 [5]"); + assert.sameValue(sample[6], NaN, "#2 [6]"); +}, [Float64Array, Float32Array]); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js new file mode 100644 index 000000000..588f1b49f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.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.sort +description: Sort values to numeric ascending order +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA(convertToBigInt([4, 3, 2, 1])).sort(); + assert(compareArray(sample, convertToBigInt([1, 2, 3, 4])), "descending values"); + + sample = new TA(convertToBigInt([3, 4, 1, 2])).sort(); + assert(compareArray(sample, convertToBigInt([1, 2, 3, 4])), "mixed numbers"); + + sample = new TA(convertToBigInt([3, 4, 3, 1, 0, 1, 2])).sort(); + assert(compareArray(sample, convertToBigInt([0, 1, 1, 2, 3, 3, 4])), "repeating numbers"); + + sample = new TA(convertToBigInt([1, 0, -0, 2])).sort(); + assert(compareArray(sample, convertToBigInt([0, 0, 1, 2])), "0s"); +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([-4, 3, 4, -3, 2, -2, 1, 0]).sort(); + assert(compareArray(sample, [-4, -3, -2, 0, 1, 2, 3, 4]), "negative values"); +}, [Float64Array, Float32Array, Int8Array, Int16Array, Int32Array]); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([0.5, 0, 1.5, 1]).sort(); + assert(compareArray(sample, [0, 0.5, 1, 1.5]), "non integers"); + + sample = new TA([0.5, 0, 1.5, -0.5, -1, -1.5, 1]).sort(); + assert(compareArray(sample, [-1.5, -1, -0.5, 0, 0.5, 1, 1.5]), "non integers + negatives"); + + sample = new TA([1, 0, -0, 2]).sort(); + assert(compareArray(sample, [0, 0, 1, 2]), "0 and -0"); + + sample = new TA([3, 4, Infinity, -Infinity, 1, 2]).sort(); + assert(compareArray(sample, [-Infinity, 1, 2, 3, 4, Infinity]), "infinities"); + +}, [Float64Array, Float32Array]); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-object.js new file mode 100644 index 000000000..9c8a4c7fb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-object.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.sort +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value as the argument. + 2. Let buffer be ? ValidateTypedArray(obj). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var sort = TypedArray.prototype.sort; +var comparefn = function() {}; + +assert.throws(TypeError, function() { + sort.call(undefined, comparefn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + sort.call(null, comparefn); +}, "this is null"); + +assert.throws(TypeError, function() { + sort.call(42, comparefn); +}, "this is 42"); + +assert.throws(TypeError, function() { + sort.call("1", comparefn); +}, "this is a string"); + +assert.throws(TypeError, function() { + sort.call(true, comparefn); +}, "this is true"); + +assert.throws(TypeError, function() { + sort.call(false, comparefn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + sort.call(s, comparefn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..74e47bae5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-typedarray-instance.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.sort +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value as the argument. + 2. Let buffer be ? ValidateTypedArray(obj). + ... + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sort = TypedArray.prototype.sort; +var comparefn = function() {}; + +assert.throws(TypeError, function() { + sort.call({}, comparefn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + sort.call([], comparefn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + sort.call(ab, comparefn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + sort.call(dv, comparefn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/detached-buffer.js new file mode 100644 index 000000000..b8e4087e5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/detached-buffer.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.subarray +description: Throws a TypeError creating a new instance with a detached buffer +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + ... + + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 11. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +var begin, end; + +var o1 = { + valueOf: function() { + begin = true; + return 0; + } +}; + +var o2 = { + valueOf: function() { + end = true; + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + begin = false; + end = false; + + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.subarray(o1, o2); + }); + + assert(begin, "observable ToInteger(begin)"); + assert(end, "observable ToInteger(end)"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/infinity.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/infinity.js new file mode 100644 index 000000000..0ac7cb592 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/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.subarray +description: Infinity values on begin and end +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + assert( + compareArray(sample.subarray(-Infinity), convertToBigInt([40, 41, 42, 43])), + "begin == -Infinity" + ); + assert( + compareArray(sample.subarray(Infinity), []), + "being == Infinity" + ); + assert( + compareArray(sample.subarray(0, -Infinity), []), + "end == -Infinity" + ); + assert( + compareArray(sample.subarray(0, Infinity), convertToBigInt([40, 41, 42, 43])), + "end == Infinity" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/invoked-as-func.js new file mode 100644 index 000000000..ca9598644 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/invoked-as-func.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. +/*--- +es6id: 22.2.3.26 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var subarray = TypedArray.prototype.subarray; + +assert.sameValue(typeof subarray, 'function'); + +assert.throws(TypeError, function() { + subarray(); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/invoked-as-method.js new file mode 100644 index 000000000..abfefd8fc --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/invoked-as-method.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. +/*--- +es6id: 22.2.3.26 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.26 %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.subarray, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.subarray(); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/length.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/length.js new file mode 100644 index 000000000..7d6bb6297 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/length.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. + +/*--- +es6id: 22.2.3.26 +description: > + %TypedArray%.prototype.subarray.length is 2. +info: | + %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.subarray.length, 2); + +verifyNotEnumerable(TypedArray.prototype.subarray, "length"); +verifyNotWritable(TypedArray.prototype.subarray, "length"); +verifyConfigurable(TypedArray.prototype.subarray, "length"); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/minus-zero.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/minus-zero.js new file mode 100644 index 000000000..a0349c375 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/minus-zero.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.subarray +description: -0 values on begin and end +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + assert( + compareArray(sample.subarray(-0), convertToBigInt([40, 41, 42, 43])), + "begin == -0" + ); + assert( + compareArray(sample.subarray(-0, 4), convertToBigInt([40, 41, 42, 43])), + "being == -0, end == length" + ); + assert( + compareArray(sample.subarray(0, -0), []), + "being == 0, end == -0" + ); + assert( + compareArray(sample.subarray(-0, -0), []), + "being == -0, end == -0" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/name.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/name.js new file mode 100644 index 000000000..d5d11e1b5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.26 +description: > + %TypedArray%.prototype.subarray.name is "subarray". +info: | + %TypedArray%.prototype.subarray( [ begin [ , end ] ] ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.subarray.name, "subarray"); + +verifyNotEnumerable(TypedArray.prototype.subarray, "name"); +verifyNotWritable(TypedArray.prototype.subarray, "name"); +verifyConfigurable(TypedArray.prototype.subarray, "name"); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/prop-desc.js new file mode 100644 index 000000000..23353fadb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.26 +description: > + "subarray" property of TypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'subarray'); +verifyWritable(TypedArrayPrototype, 'subarray'); +verifyConfigurable(TypedArrayPrototype, 'subarray'); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js new file mode 100644 index 000000000..17f2b3a4c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/result-does-not-copy-ordinary-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray result does not import own property +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([41, 42, 43, 44])); + var result; + + sample.foo = 42; + + result = sample.subarray(0); + assert.sameValue( + result.hasOwnProperty("foo"), + false, + "does not import own property" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.js new file mode 100644 index 000000000..d4b9a09a7 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-from-same-ctor.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.subarray +description: Returns a new instance from the same constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + var result = sample.subarray(1); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "prototype" + ); + assert.sameValue(result.constructor, sample.constructor, "constructor"); + assert(result instanceof TA, "instanceof"); + + assert( + compareArray(sample, convertToBigInt([40, 41, 42, 43])), + "original sample remains the same" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-buffer.js new file mode 100644 index 000000000..87801c85e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/result-is-new-instance-with-shared-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.subarray +description: Returns a new instance sharing the same buffer +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + var buffer = sample.buffer; + var result = sample.subarray(1); + + assert.notSameValue(result, sample, "returns a new instance"); + assert.sameValue(result.buffer, sample.buffer, "shared buffer"); + assert.sameValue(sample.buffer, buffer, "original buffer is preserved"); + + sample[1] = convertToBigInt(100); + assert( + compareArray(result, convertToBigInt([100, 42, 43])), + "changes on the original sample values affect the new instance" + ); + + result[1] = convertToBigInt(111); + assert( + compareArray(sample, convertToBigInt([40, 100, 111, 43])), + "changes on the new instance values affect the original sample" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js new file mode 100644 index 000000000..3be58ad56 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-different-length.js @@ -0,0 +1,58 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray may return a new instance with a smaller length +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + function testRes(result, expected, msg) { + assert(compareArray(result, expected), msg + ", result: [" + result + "]"); + } + + testRes(sample.subarray(1), convertToBigInt([41, 42, 43]), "begin == 1"); + testRes(sample.subarray(2), convertToBigInt([42, 43]), "begin == 2"); + testRes(sample.subarray(3), convertToBigInt([43]), "begin == 3"); + + testRes(sample.subarray(1, 4), convertToBigInt([41, 42, 43]), "begin == 1, end == length"); + testRes(sample.subarray(2, 4), convertToBigInt([42, 43]), "begin == 2, end == length"); + testRes(sample.subarray(3, 4), convertToBigInt([43]), "begin == 3, end == length"); + + testRes(sample.subarray(0, 1), convertToBigInt([40]), "begin == 0, end == 1"); + testRes(sample.subarray(0, 2), convertToBigInt([40, 41]), "begin == 0, end == 2"); + testRes(sample.subarray(0, 3), convertToBigInt([40, 41, 42]), "begin == 0, end == 3"); + + testRes(sample.subarray(-1), convertToBigInt([43]), "begin == -1"); + testRes(sample.subarray(-2), convertToBigInt([42, 43]), "begin == -2"); + testRes(sample.subarray(-3), convertToBigInt([41, 42, 43]), "begin == -3"); + + testRes(sample.subarray(-1, 4), convertToBigInt([43]), "begin == -1, end == length"); + testRes(sample.subarray(-2, 4), convertToBigInt([42, 43]), "begin == -2, end == length"); + testRes(sample.subarray(-3, 4), convertToBigInt([41, 42, 43]), "begin == -3, end == length"); + + testRes(sample.subarray(0, -1), convertToBigInt([40, 41, 42]), "begin == 0, end == -1"); + testRes(sample.subarray(0, -2), convertToBigInt([40, 41]), "begin == 0, end == -2"); + testRes(sample.subarray(0, -3), convertToBigInt([40]), "begin == 0, end == -3"); + + testRes(sample.subarray(-0, -1), convertToBigInt([40, 41, 42]), "begin == -0, end == -1"); + testRes(sample.subarray(-0, -2), convertToBigInt([40, 41]), "begin == -0, end == -2"); + testRes(sample.subarray(-0, -3), convertToBigInt([40]), "begin == -0, end == -3"); + + testRes(sample.subarray(-2, -1), convertToBigInt([42]), "length == 4, begin == -2, end == -1"); + testRes(sample.subarray(1, -1), convertToBigInt([41, 42]), "length == 4, begin == 1, end == -1"); + testRes(sample.subarray(1, -2), convertToBigInt([41]), "length == 4, begin == 1, end == -2"); + testRes(sample.subarray(2, -1), convertToBigInt([42]), "length == 4, begin == 2, end == -1"); + + testRes(sample.subarray(-1, 5), convertToBigInt([43]), "begin == -1, end > length"); + testRes(sample.subarray(-2, 4), convertToBigInt([42, 43]), "begin == -2, end > length"); + testRes(sample.subarray(-3, 4), convertToBigInt([41, 42, 43]), "begin == -3, end > length"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js new file mode 100644 index 000000000..f31ec8448 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-empty-length.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray may return a new empty instance +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + function testRes(result, msg) { + assert.sameValue(result.length, 0, msg); + assert.sameValue( + result.hasOwnProperty(0), + false, + msg + " & result.hasOwnProperty(0) === false" + ); + } + + testRes(sample.subarray(4), "begin == length"); + testRes(sample.subarray(5), "begin > length"); + + testRes(sample.subarray(4, 4), "begin == length, end == length"); + testRes(sample.subarray(5, 4), "begin > length, end == length"); + + testRes(sample.subarray(4, 4), "begin == length, end > length"); + testRes(sample.subarray(5, 4), "begin > length, end > length"); + + testRes(sample.subarray(0, 0), "begin == 0, end == 0"); + testRes(sample.subarray(-0, -0), "begin == -0, end == -0"); + testRes(sample.subarray(1, 0), "begin > 0, end == 0"); + testRes(sample.subarray(-1, 0), "being < 0, end == 0"); + + testRes(sample.subarray(2, 1), "begin > 0, begin < length, begin > end, end > 0"); + testRes(sample.subarray(2, 2), "begin > 0, begin < length, begin == end"); + + testRes(sample.subarray(2, -2), "begin > 0, begin < length, end == -2"); + + testRes(sample.subarray(-1, -1), "length = 4, begin == -1, end == -1"); + testRes(sample.subarray(-1, -2), "length = 4, begin == -1, end == -2"); + testRes(sample.subarray(-2, -2), "length = 4, begin == -2, end == -2"); + + testRes(sample.subarray(0, -4), "begin == 0, end == -length"); + testRes(sample.subarray(-4, -4), "begin == -length, end == -length"); + testRes(sample.subarray(-5, -4), "begin < -length, end == -length"); + + testRes(sample.subarray(0, -5), "begin == 0, end < -length"); + testRes(sample.subarray(-4, -5), "begin == -length, end < -length"); + testRes(sample.subarray(-5, -5), "begin < -length, end < -length"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js new file mode 100644 index 000000000..8e51f899f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/results-with-same-length.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Subarray may return a new instance with the same length +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + function testRes(result, msg) { + assert.sameValue(result.length, 4, msg); + assert.sameValue(result[0], convertToBigInt(40), msg + " & result[0] === 40"); + assert.sameValue(result[1], convertToBigInt(41), msg + " & result[1] === 41"); + assert.sameValue(result[2], convertToBigInt(42), msg + " & result[2] === 42"); + assert.sameValue(result[3], convertToBigInt(43), msg + " & result[3] === 43"); + } + + testRes(sample.subarray(0), "begin == 0"); + testRes(sample.subarray(-4), "begin == -srcLength"); + testRes(sample.subarray(-5), "begin < -srcLength"); + + testRes(sample.subarray(0, 4), "begin == 0, end == srcLength"); + testRes(sample.subarray(-4, 4), "begin == -srcLength, end == srcLength"); + testRes(sample.subarray(-5, 4), "begin < -srcLength, end == srcLength"); + + testRes(sample.subarray(0, 5), "begin == 0, end > srcLength"); + testRes(sample.subarray(-4, 5), "begin == -srcLength, end > srcLength"); + testRes(sample.subarray(-5, 5), "begin < -srcLength, end > srcLength"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.js new file mode 100644 index 000000000..a05ad6261 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin-symbol.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.subarray +description: Return abrupt from ToInteger(begin), begin is symbol +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js new file mode 100644 index 000000000..edff4831f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-begin.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Return abrupt from ToInteger(begin) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(o2); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js new file mode 100644 index 000000000..29f517746 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end-symbol.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Return abrupt from ToInteger(end), end is symbol +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(TypeError, function() { + sample.subarray(0, s); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js new file mode 100644 index 000000000..d9f1bf3b5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/return-abrupt-from-end.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Return abrupt from ToInteger(end) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd + be ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var o1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var o2 = { + toString: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert.throws(Test262Error, function() { + sample.subarray(0, o1); + }); + + assert.throws(Test262Error, function() { + sample.subarray(0, o2); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.js new file mode 100644 index 000000000..5f66e654f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-abrupt.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Return abrupt from SpeciesConstructor's get Constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + Object.defineProperty(sample, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.js new file mode 100644 index 000000000..0e70b7051 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-inherited.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.subarray +description: get inherited constructor on SpeciesConstructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + var calls = 0; + var result; + + Object.defineProperty(TA.prototype, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.subarray(0); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + undefined, + "used defaultCtor but still checks the inherited .constructor" + ); + + calls = 6; + result.constructor; + assert.sameValue( + calls, + 7, + "result.constructor triggers the inherited accessor property" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js new file mode 100644 index 000000000..fc8c9cad0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor-returns-throws.js @@ -0,0 +1,62 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + Throws if O.constructor returns a non-Object and non-undefined value +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + sample.constructor = 42; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "42"); + + sample.constructor = "1"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor = null; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "null"); + + sample.constructor = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor = Symbol("1"); + assert.throws(TypeError, function() { + sample.subarray(0); + }, "symbol"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.js new file mode 100644 index 000000000..e552af771 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-ctor.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.subarray +description: get constructor on SpeciesConstructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + var calls = 0; + var result; + + Object.defineProperty(sample, "constructor", { + get: function() { + calls++; + } + }); + + result = sample.subarray(0); + + assert.sameValue(calls, 1, "called custom ctor get accessor once"); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "use defaultCtor on an undefined return - getPrototypeOf check" + ); + assert.sameValue( + result.constructor, + TA, + "use defaultCtor on an undefined return - .constructor check" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.js new file mode 100644 index 000000000..c1b64586d --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-abrupt.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.subarray +description: > + Returns abrupt from get @@species on found constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.subarray(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-invocation.js new file mode 100644 index 000000000..1747a44ea --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/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.subarray +description: > + Verify arguments on custom @@species construct call +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newTypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42])); + var expectedOffset = TA.BYTES_PER_ELEMENT; + var result, ctorThis; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + result = arguments; + ctorThis = this; + return new TA(buffer, offset, length); + }; + + sample.subarray(1); + + assert.sameValue(result.length, 3, "called with 3 arguments"); + assert.sameValue(result[0], sample.buffer, "[0] is sample.buffer"); + assert.sameValue(result[1], expectedOffset, "[1] is the byte offset pos"); + assert.sameValue(result[2], 2, "[2] is expected length"); + + assert( + ctorThis instanceof sample.constructor[Symbol.species], + "`this` value in the @@species fn is an instance of the function itself" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.js new file mode 100644 index 000000000..1993db3f6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-returns-another-instance.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.subarray +description: > + Custom @@species constructor may return a totally different TypedArray +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40])); + var other = new Int8Array([1, 0, 1]); + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function() { + return other; + }; + + result = sample.subarray(0, 0); + + assert.sameValue(result, other, "returned another typedarray"); + assert(compareArray(result, [1, 0, 1]), "the returned object is preserved"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js new file mode 100644 index 000000000..958378556 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + Custom @@species constructor throws if it does not return a compatible object +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var ctor = function() {}; + + sample.constructor = {}; + sample.constructor[Symbol.species] = ctor; + + assert.throws(TypeError, function() { + sample.subarray(0); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.js new file mode 100644 index 000000000..7b11bb596 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-custom-ctor.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.subarray +description: > + Use custom @@species constructor if available +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + 4. Return ? TypedArrayCreate(constructor, argumentList). + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... + 7. If IsConstructor(S) is true, return S. + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + 3. If argumentList is a List of a single Number, then + ... + 4. Return newTypedArray. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42])); + var calls = 0; + var result; + + sample.constructor = {}; + sample.constructor[Symbol.species] = function(buffer, offset, length) { + calls++; + return new TA(buffer, offset, length); + }; + + result = sample.subarray(1); + + assert.sameValue(calls, 1, "ctor called once"); + assert(compareArray(result, convertToBigInt([41, 42])), "expected subarray"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-returns-throws.js new file mode 100644 index 000000000..1a01c0460 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-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.subarray +description: > + Throws if returned @@species is not a constructor, null or undefined. +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + sample.constructor = {}; + + sample.constructor[Symbol.species] = 0; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "0"); + + sample.constructor[Symbol.species] = "string"; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "string"); + + sample.constructor[Symbol.species] = {}; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "{}"); + + sample.constructor[Symbol.species] = NaN; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "NaN"); + + sample.constructor[Symbol.species] = false; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "false"); + + sample.constructor[Symbol.species] = true; + assert.throws(TypeError, function() { + sample.subarray(0); + }, "true"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.js new file mode 100644 index 000000000..1b1a4e46f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species-use-default-ctor.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.subarray +description: > + Use defaultConstructor if @@species is either undefined or null +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var result; + + sample.constructor = {}; + + result = sample.subarray(0); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "undefined @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "undefined @@species - ctor check"); + + sample.constructor[Symbol.species] = null; + result = sample.subarray(0); + + assert.sameValue( + Object.getPrototypeOf(result), + Object.getPrototypeOf(sample), + "null @@species - prototype check " + ); + assert.sameValue(result.constructor, TA, "null @@species - ctor check"); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.js new file mode 100644 index 000000000..01f3427bf --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/speciesctor-get-species.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + get @@species from found constructor +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 17. Return ? TypedArraySpeciesCreate(O, argumentsList). + + 22.2.4.7 TypedArraySpeciesCreate ( exemplar, argumentList ) + + ... + 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be ? Get(O, "constructor"). + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + var calls = 0; + + sample.constructor = {}; + + Object.defineProperty(sample.constructor, Symbol.species, { + get: function() { + calls++; + } + }); + + sample.subarray(0); + + assert.sameValue(calls, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/this-is-not-object.js new file mode 100644 index 000000000..976731c66 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/this-is-not-object.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var subarray = TypedArray.prototype.subarray; + +assert.throws(TypeError, function() { + subarray.call(undefined, 0, 0); +}, "this is undefined"); + +assert.throws(TypeError, function() { + subarray.call(null, 0, 0); +}, "this is null"); + +assert.throws(TypeError, function() { + subarray.call(42, 0, 0); +}, "this is 42"); + +assert.throws(TypeError, function() { + subarray.call("1", 0, 0); +}, "this is a string"); + +assert.throws(TypeError, function() { + subarray.call(true, 0, 0); +}, "this is true"); + +assert.throws(TypeError, function() { + subarray.call(false, 0, 0); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + subarray.call(s, 0, 0); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..275f5e2bd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.9 %TypedArray%.prototype.subarray( begin , end ) + + The following steps are taken: + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var subarray = TypedArray.prototype.subarray; + +assert.throws(TypeError, function() { + subarray.call({}, 0, 0); +}, "this is an Object"); + +assert.throws(TypeError, function() { + subarray.call([], 0, 0); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + subarray.call(ab, 0, 0); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + subarray.call(dv, 0, 0); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js new file mode 100644 index 000000000..6a7885155 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-begin.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: ToInteger(begin) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 7. Let relativeBegin be ? ToInteger(begin). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + assert(compareArray(sample.subarray(false), convertToBigInt([40, 41, 42, 43])), "false"); + assert(compareArray(sample.subarray(true), convertToBigInt([41, 42, 43])), "true"); + + assert(compareArray(sample.subarray(NaN), convertToBigInt([40, 41, 42, 43])), "NaN"); + assert(compareArray(sample.subarray(null), convertToBigInt([40, 41, 42, 43])), "null"); + assert(compareArray(sample.subarray(undefined), convertToBigInt([40, 41, 42, 43])), "undefined"); + + assert(compareArray(sample.subarray(1.1), convertToBigInt([41, 42, 43])), "1.1"); + assert(compareArray(sample.subarray(1.5), convertToBigInt([41, 42, 43])), "1.5"); + assert(compareArray(sample.subarray(0.6), convertToBigInt([40, 41, 42, 43])), "0.6"); + + assert(compareArray(sample.subarray(-1.5), convertToBigInt([43])), "-1.5"); + assert(compareArray(sample.subarray(-1.1), convertToBigInt([43])), "-1.1"); + assert(compareArray(sample.subarray(-0.6), convertToBigInt([40, 41, 42, 43])), "-0.6"); + + assert(compareArray(sample.subarray("3"), convertToBigInt([43])), "string"); + assert( + compareArray( + sample.subarray(obj), + convertToBigInt([42, 43]) + ), + "object" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-end.js b/test/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-end.js new file mode 100644 index 000000000..f847b6d27 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/subarray/BigInt/tointeger-end.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: ToInteger(end) +info: | + 22.2.3.27 %TypedArray%.prototype.subarray( begin , end ) + + ... + 9. If end is undefined, let relativeEnd be srcLength; else, let relativeEnd be + ? ToInteger(end). + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + return 2; + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([40, 41, 42, 43])); + + assert(compareArray(sample.subarray(0, false), []), "false"); + assert(compareArray(sample.subarray(0, true), convertToBigInt([40])), "true"); + + assert(compareArray(sample.subarray(0, NaN), []), "NaN"); + assert(compareArray(sample.subarray(0, null), []), "null"); + assert(compareArray(sample.subarray(0, undefined), convertToBigInt([40, 41, 42, 43])), "undefined"); + + assert(compareArray(sample.subarray(0, 0.6), []), "0.6"); + assert(compareArray(sample.subarray(0, 1.1), convertToBigInt([40])), "1.1"); + assert(compareArray(sample.subarray(0, 1.5), convertToBigInt([40])), "1.5"); + assert(compareArray(sample.subarray(0, -0.6), []), "-0.6"); + assert(compareArray(sample.subarray(0, -1.1), convertToBigInt([40, 41, 42])), "-1.1"); + assert(compareArray(sample.subarray(0, -1.5), convertToBigInt([40, 41, 42])), "-1.5"); + + assert(compareArray(sample.subarray(0, "3"), convertToBigInt([40, 41, 42])), "string"); + assert( + compareArray( + sample.subarray(0, obj), + convertToBigInt([40, 41]) + ), + "object" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js new file mode 100644 index 000000000..c40f36561 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.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.tolocalestring +description: Calls toLocaleString from each property's value +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + calls.push(this); + return "hacks" + calls.length; +}; + +var arr = [42, 0]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + calls = []; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert( + compareArray(new TA(convertToBigInt(calls)), sample), + "toLocaleString called for each item" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js new file mode 100644 index 000000000..9a9fe93d0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js @@ -0,0 +1,58 @@ +// 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.tolocalestring +description: > + Calls toString from each property's value return from toLocaleString +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + return "hacks" + calls; + }, + valueOf: function() { + throw new Test262Error("should not call valueOf if toString is present"); + } + }; +}; + +var arr = [42, 0]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + calls = 0; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert.sameValue(calls, 2, "toString called once for each item"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js new file mode 100644 index 000000000..b01c60feb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.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.tolocalestring +description: > + Calls valueOf from each property's value return from toLocaleString +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + return "hacks" + calls; + } + }; +}; + +var arr = [42, 0]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + calls = 0; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert.sameValue(calls, 2, "valueOf called once for each item"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js new file mode 100644 index 000000000..debd112e6 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js @@ -0,0 +1,28 @@ +// 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.tolocalestring +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toLocaleString(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js new file mode 100644 index 000000000..e933bce82 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.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.tolocalestring +description: Returns an empty string if called on an empty instance +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 4. If len is zero, return the empty String. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.toLocaleString(), ""); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 000000000..f1662225c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.tolocalestring +description: Get "length" uses internal ArrayLength +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + 1. Let array be ? ToObject(this value). + 2.Let len be ? ToLength(? Get(array, "length")). + ... +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(convertToBigInt([42, 43])); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.toLocaleString(); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/invoked-as-func.js new file mode 100644 index 000000000..b124aaf26 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/invoked-as-func.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. +/*--- +es6id: 22.2.3.27 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.27 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + ... + + This function is not generic. ValidateTypedArray is applied to the this + value prior to evaluating the algorithm. If its result is an abrupt + completion that exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var toLocaleString = TypedArray.prototype.toLocaleString; + +assert.sameValue(typeof toLocaleString, 'function'); + +assert.throws(TypeError, function() { + toLocaleString(); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/invoked-as-method.js new file mode 100644 index 000000000..27ad4e2bc --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/invoked-as-method.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. +/*--- +es6id: 22.2.3.27 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.27 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + ... + + This function is not generic. ValidateTypedArray is applied to the this + value prior to evaluating the algorithm. If its result is an abrupt + completion that exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.toLocaleString, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.toLocaleString(); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/length.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/length.js new file mode 100644 index 000000000..20f6962ef --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/length.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. + +/*--- +es6id: 22.2.3.27 +description: > + %TypedArray%.prototype.toLocaleString.length is 0. +info: | + %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.toLocaleString.length, 0); + +verifyNotEnumerable(TypedArray.prototype.toLocaleString, "length"); +verifyNotWritable(TypedArray.prototype.toLocaleString, "length"); +verifyConfigurable(TypedArray.prototype.toLocaleString, "length"); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/name.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/name.js new file mode 100644 index 000000000..2899e7f6c --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.27 +description: > + %TypedArray%.prototype.toLocaleString.name is "toLocaleString". +info: | + %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.toLocaleString.name, "toLocaleString"); + +verifyNotEnumerable(TypedArray.prototype.toLocaleString, "name"); +verifyNotWritable(TypedArray.prototype.toLocaleString, "name"); +verifyConfigurable(TypedArray.prototype.toLocaleString, "name"); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/prop-desc.js new file mode 100644 index 000000000..784268170 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.27 +description: > + "toLocaleString" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'toLocaleString'); +verifyWritable(TypedArrayPrototype, 'toLocaleString'); +verifyConfigurable(TypedArrayPrototype, 'toLocaleString'); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js new file mode 100644 index 000000000..378b4e5b8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.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.tolocalestring +description: Returns abrupt from firstElement's toLocaleString +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 4. If len is zero, return the empty String. + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls; + +BigInt.prototype.toLocaleString = function() { + calls++; + throw new Test262Error(); +}; + +var arr = [42, 0]; + +testWithBigIntTypedArrayConstructors(function(TA) { + calls = 0; + var sample = new TA(convertToBigInt(arr)); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "abrupt from first element"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js new file mode 100644 index 000000000..3398b29ef --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.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.tolocalestring +description: > + Return abrupt from firstElement's toLocaleString => toString +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +var arr = [42, 0]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js new file mode 100644 index 000000000..fceea34ef --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.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.tolocalestring +description: > + Return abrupt from firstElement's toLocaleString => valueOf +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +var arr = [42, 0]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js new file mode 100644 index 000000000..1bac9b691 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.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.tolocalestring +description: Returns abrupt from a nextElement's toLocaleString +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } +}; + +var arr = [42, 0]; + +testWithBigIntTypedArrayConstructors(function(TA) { + calls = 0; + var sample = new TA(convertToBigInt(arr)); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a next element"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js new file mode 100644 index 000000000..3c45b81c1 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js @@ -0,0 +1,57 @@ +// 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.tolocalestring +description: > + Return abrupt from nextElement's toLocaleString => valueOf +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +var arr = [42, 0]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js new file mode 100644 index 000000000..f683ad285 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js @@ -0,0 +1,58 @@ +// 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.tolocalestring +description: > + Return abrupt from nextElement's toLocaleString => valueOf +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +var arr = [42, 0]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-result.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-result.js new file mode 100644 index 000000000..c3588c70f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-result.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.tolocalestring +description: Returns a string +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + %TypedArray%.prototype.toLocaleString is a distinct function that implements + the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27 + except that the this object's [[ArrayLength]] internal slot is accessed in + place of performing a [[Get]] of "length". + + 22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ) + + ... + 5. Let firstElement be ? Get(array, "0"). + 6. If firstElement is undefined or null, then + a. Let R be the empty String. + 7. Else, + a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")). + 8. Let k be 1. + 9.Repeat, while k < len + a. Let S be a String value produced by concatenating R and separator. + b. Let nextElement be ? Get(array, ! ToString(k)). + c. If nextElement is undefined or null, then + i. Let R be the empty String. + d. Else, + i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); + +var arr = [42, 0, 43]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt(arr)); + var expected = + sample[0].toLocaleString().toString() + + separator + + sample[1].toLocaleString().toString() + + separator + + sample[2].toLocaleString().toString(); + assert.sameValue(sample.toLocaleString(), expected); +}); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/this-is-not-object.js new file mode 100644 index 000000000..b67bf77c4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/this-is-not-object.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.tolocalestring +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var toLocaleString = TypedArray.prototype.toLocaleString; + +assert.throws(TypeError, function() { + toLocaleString.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + toLocaleString.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + toLocaleString.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + toLocaleString.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + toLocaleString.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + toLocaleString.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + toLocaleString.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..f98c9b5c0 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toLocaleString/BigInt/this-is-not-typedarray-instance.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.tolocalestring +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var toLocaleString = TypedArray.prototype.toLocaleString; + +assert.throws(TypeError, function() { + toLocaleString.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + toLocaleString.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + toLocaleString.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + toLocaleString.call(dv); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/toString/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/toString/BigInt/detached-buffer.js new file mode 100644 index 000000000..5b9e0cedc --- /dev/null +++ b/test/built-ins/TypedArray/prototype/toString/BigInt/detached-buffer.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.tostring +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.29 %TypedArray%.prototype.toString () + + ... + + 22.2.3.15 %TypedArray%.prototype.join ( separator ) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toString(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/values/BigInt/detached-buffer.js new file mode 100644 index 000000000..6c31b6bce --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/detached-buffer.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.values +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.30 %TypedArray%.prototype.values ( ) + + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.values(); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/values/BigInt/invoked-as-func.js new file mode 100644 index 000000000..f9e994aa3 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/invoked-as-func.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.29 +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.29 %TypedArray%.prototype.values ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var values = TypedArray.prototype.values; + +assert.sameValue(typeof values, 'function'); + +assert.throws(TypeError, function() { + values(); +}); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/values/BigInt/invoked-as-method.js new file mode 100644 index 000000000..5ec17b0f4 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/invoked-as-method.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.29 +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.29 %TypedArray%.prototype.values ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.values, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.values(); +}); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/iter-prototype.js b/test/built-ins/TypedArray/prototype/values/BigInt/iter-prototype.js new file mode 100644 index 000000000..72b1bd610 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/iter-prototype.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.30 +esid: sec-%typedarray%.prototype.values +description: > + The prototype of the returned iterator is ArrayIteratorPrototype +info: | + 22.2.3.30 %TypedArray%.prototype.values ( ) + + ... + 3. Return CreateArrayIterator(O, "value"). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var ArrayIteratorProto = Object.getPrototypeOf([][Symbol.iterator]()); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([0, 42, 64])); + var iter = sample.values(); + + assert.sameValue(Object.getPrototypeOf(iter), ArrayIteratorProto); +}); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/length.js b/test/built-ins/TypedArray/prototype/values/BigInt/length.js new file mode 100644 index 000000000..0e3da84d8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/length.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. + +/*--- +es6id: 22.2.3.29 +description: > + %TypedArray%.prototype.values.length is 0. +info: | + %TypedArray%.prototype.values ( ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.values.length, 0); + +verifyNotEnumerable(TypedArray.prototype.values, "length"); +verifyNotWritable(TypedArray.prototype.values, "length"); +verifyConfigurable(TypedArray.prototype.values, "length"); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/name.js b/test/built-ins/TypedArray/prototype/values/BigInt/name.js new file mode 100644 index 000000000..3f2139028 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.3.29 +description: > + %TypedArray%.prototype.values.name is "values". +info: | + %TypedArray%.prototype.values ( ) + + 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, testBigIntTypedArray.js] +---*/ + +assert.sameValue(TypedArray.prototype.values.name, "values"); + +verifyNotEnumerable(TypedArray.prototype.values, "name"); +verifyNotWritable(TypedArray.prototype.values, "name"); +verifyConfigurable(TypedArray.prototype.values, "name"); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/values/BigInt/prop-desc.js new file mode 100644 index 000000000..0a1c9796f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/prop-desc.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.3.29 +description: > + "values" 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, testBigIntTypedArray.js] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'values'); +verifyWritable(TypedArrayPrototype, 'values'); +verifyConfigurable(TypedArrayPrototype, 'values'); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/return-itor.js b/test/built-ins/TypedArray/prototype/values/BigInt/return-itor.js new file mode 100644 index 000000000..576a97a0e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/return-itor.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. +/*--- +es6id: 22.2.3.30 +esid: sec-%typedarray%.prototype.values +description: Return an iterator for the values. +info: | + 22.2.3.30 %TypedArray%.prototype.values ( ) + + ... + 3. Return CreateArrayIterator(O, "value"). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sample = [0, 42, 64]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(convertToBigInt(sample)); + var itor = typedArray.values(); + + var next = itor.next(); + assert.sameValue(next.value, convertToBigInt(0)); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, convertToBigInt(42)); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, convertToBigInt(64)); + assert.sameValue(next.done, false); + + next = itor.next(); + assert.sameValue(next.value, undefined); + assert.sameValue(next.done, true); +}); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/values/BigInt/this-is-not-object.js new file mode 100644 index 000000000..57b57a78b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/this-is-not-object.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.values +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.30 %TypedArray%.prototype.values ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var values = TypedArray.prototype.values; + +assert.throws(TypeError, function() { + values.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + values.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + values.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + values.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + values.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + values.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + values.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/values/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/values/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..68b78aedd --- /dev/null +++ b/test/built-ins/TypedArray/prototype/values/BigInt/this-is-not-typedarray-instance.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.values +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.30 %TypedArray%.prototype.values ( ) + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var values = TypedArray.prototype.values; + +assert.throws(TypeError, function() { + values.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + values.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + values.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + values.call(dv); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 000000000..2f86cd9c2 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength modulo elementSize ≠ 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(1); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js new file mode 100644 index 000000000..67f3f8871 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.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-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength modulo elementSize ≠ 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(1); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js new file mode 100644 index 000000000..9c590f859 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) is < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + 8. If offset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.js new file mode 100644 index 000000000..d0c70d669 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.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-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) is < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + 8. If offset < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js new file mode 100644 index 000000000..bfae5fa4c --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: pending +description: > + TypedArray's [[ByteOffset]] internal slot is always a positive number, test with negative zero. +info: | + %TypedArray% ( buffer [ , byteOffset [ , length ] ] ) + + ... + 6. Let offset be ? ToInteger(byteOffset). + 7. If offset < 0, throw a RangeError exception. + 8. If offset is -0, let offset be +0. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new SharedArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js new file mode 100644 index 000000000..14cca2584 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: pending +description: > + TypedArray's [[ByteOffset]] internal slot is always a positive number, test with negative zero. +info: | + %TypedArray% ( buffer [ , byteOffset [ , length ] ] ) + + ... + 6. Let offset be ? ToInteger(byteOffset). + 7. If offset < 0, throw a RangeError exception. + 8. If offset is -0, let offset be +0. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new ArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js new file mode 100644 index 000000000..cef10b698 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset as a symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, SharedArrayBuffer, TypedArray] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.js new file mode 100644 index 000000000..a3c12fd01 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.js @@ -0,0 +1,28 @@ +// 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-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset as a symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 000000000..b70167e3b --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 10. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.js new file mode 100644 index 000000000..2a3a79303 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.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-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 10. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js new file mode 100644 index 000000000..89430e6ab --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: If TypedArray() is passed a detached buffer, throw +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + var byteOffset = { valueOf() { $DETACHBUFFER(buffer); return offset; } }; + assert.throws(TypeError, () => new TA(buffer, byteOffset)); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js new file mode 100644 index 000000000..a80143c26 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); +var byteOffset = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-throws.js new file mode 100644 index 000000000..f30cc2584 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/byteoffset-to-number-throws.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-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var byteOffset = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js new file mode 100644 index 000000000..fbb038d25 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/custom-proto-access-throws.js new file mode 100644 index 000000000..88c98eebf --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/custom-proto-access-throws.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-buffer-byteoffset-length +description: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js new file mode 100644 index 000000000..2f153de63 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined length and offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(3 * offset); + + var ta1 = new TA(buffer, offset, 2); + assert.sameValue(ta1.length, 2, "ta1.length"); + assert.sameValue(ta1.buffer, buffer, "ta1.buffer"); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, offset, 0); + assert.sameValue(ta2.length, 0, "ta2.length"); + assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-and-offset.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-and-offset.js new file mode 100644 index 000000000..7e27248f8 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-and-offset.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-buffer-byteoffset-length +description: > + Return new typedArray from defined length and offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + + var ta1 = new TA(buffer, offset, 2); + assert.sameValue(ta1.length, 2, "ta1.length"); + assert.sameValue(ta1.buffer, buffer, "ta1.buffer"); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, offset, 0); + assert.sameValue(ta2.length, 0, "ta2.length"); + assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-sab.js new file mode 100644 index 000000000..916858939 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length-sab.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var length = 4; + var buffer = new SharedArrayBuffer(bpe * length * 4); + + var ta1 = new TA(buffer, 0, length); + assert.sameValue(ta1.length, length); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, 0); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-length.js new file mode 100644 index 000000000..711aeb53a --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-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-buffer-byteoffset-length +description: > + Return new typedArray from defined length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var length = 4; + var buffer = new ArrayBuffer(bpe * length * 4); + + var ta1 = new TA(buffer, 0, length); + assert.sameValue(ta1.length, length); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, 0); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-negative-length-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-negative-length-sab.js new file mode 100644 index 000000000..2138f4a81 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-negative-length-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws RangeError for negative ToInteger(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(16); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, -1); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, -Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-negative-length.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-negative-length.js new file mode 100644 index 000000000..f422a54d5 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-negative-length.js @@ -0,0 +1,28 @@ +// 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-buffer-byteoffset-length +description: > + Throws RangeError for negative ToInteger(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, -1); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, -Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-offset-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-offset-sab.js new file mode 100644 index 000000000..8cf9c14fe --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-offset-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe * 4); + + var ta1 = new TA(buffer, bpe * 2); + assert.sameValue(ta1.length, 2); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0); + assert.sameValue(ta2.length, 4); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-offset.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-offset.js new file mode 100644 index 000000000..a8005eb0b --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/defined-offset.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-buffer-byteoffset-length +description: > + Return new typedArray from defined offset +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe * 4); + + var ta1 = new TA(buffer, bpe * 2); + assert.sameValue(ta1.length, 2); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0); + assert.sameValue(ta2.length, 4); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/detachedbuffer.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/detachedbuffer.js new file mode 100644 index 000000000..26cf08ae9 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/detachedbuffer.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: If TypedArray() is passed a detached buffer, throw +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + $DETACHBUFFER(buffer); + assert.throws(TypeError, () => new TA(buffer)); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-length-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-length-throws-sab.js new file mode 100644 index 000000000..64d726466 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-length-throws-sab.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + If offset + newByteLength > bufferByteLength, throw a RangeError exception. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + b. Let newByteLength be newLength × elementSize. + c. If offset+newByteLength > bufferByteLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-length-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-length-throws.js new file mode 100644 index 000000000..1f2378625 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-length-throws.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-buffer-byteoffset-length +description: > + If offset + newByteLength > bufferByteLength, throw a RangeError exception. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + b. Let newByteLength be newLength × elementSize. + c. If offset+newByteLength > bufferByteLength, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js new file mode 100644 index 000000000..2b78d7926 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength - ToInteger(byteOffset) < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + b. Let newByteLength be bufferByteLength - offset. + c. If newByteLength < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2); + }); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-offset-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-offset-throws.js new file mode 100644 index 000000000..81454fba7 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/excessive-offset-throws.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-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength - ToInteger(byteOffset) < 0 +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + b. Let newByteLength be bufferByteLength - offset. + c. If newByteLength < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2); + }); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js new file mode 100644 index 000000000..7b3b9c9e2 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(4); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.js new file mode 100644 index 000000000..0301136c0 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.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-buffer-byteoffset-length +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(4); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/is-referenced-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/is-referenced-sab.js new file mode 100644 index 000000000..bdff85d02 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/is-referenced-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Reuse buffer argument instead of making a new clone +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 15. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer = new SharedArrayBuffer(bpe); + + var ta1 = new TA(buffer); + var ta2 = new TA(buffer); + + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta1.buffer, ta2.buffer); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/is-referenced.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/is-referenced.js new file mode 100644 index 000000000..1b609117f --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/is-referenced.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-buffer-byteoffset-length +description: > + Reuse buffer argument instead of making a new clone +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 15. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer = new ArrayBuffer(bpe); + + var ta1 = new TA(buffer); + var ta2 = new TA(buffer); + + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta1.buffer, ta2.buffer); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-access-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-access-throws-sab.js new file mode 100644 index 000000000..792101566 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-access-throws-sab.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Returns abrupt from ToLength(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); +var len = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, len); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-access-throws.js new file mode 100644 index 000000000..373311d0c --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-access-throws.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-buffer-byteoffset-length +description: > + Returns abrupt from ToLength(length) +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var len = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, len); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js new file mode 100644 index 000000000..d0619a3f8 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a TypeError if length is a Symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-is-symbol-throws.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-is-symbol-throws.js new file mode 100644 index 000000000..978e01e7d --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-is-symbol-throws.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a TypeError if length is a Symbol +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js new file mode 100644 index 000000000..9bf8105f0 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: If TypedArray() is passed a detached buffer, throw +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 9. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + var length = { valueOf() { $DETACHBUFFER(buffer); return 1; } }; + assert.throws(TypeError, () => new TA(buffer, 0, length)); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js new file mode 100644 index 000000000..5d5976424 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + The new typedArray instance from a buffer argument is extensible +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/new-instance-extensibility.js new file mode 100644 index 000000000..6f7c8b7f4 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/new-instance-extensibility.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-buffer-byteoffset-length +description: > + The new typedArray instance from a buffer argument is extensible +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js new file mode 100644 index 000000000..86374357e --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + [...] + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, SharedArrayBuffer, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new SharedArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/proto-from-ctor-realm.js new file mode 100644 index 000000000..8e5f4b12f --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/proto-from-ctor-realm.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-buffer-byteoffset-length +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + [...] + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new ArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/returns-new-instance-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/returns-new-instance-sab.js new file mode 100644 index 000000000..4067b836f --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/returns-new-instance-sab.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from undefined offset and length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer1 = new SharedArrayBuffer(bpe * 4); + var ta1 = new TA(buffer1); + assert.sameValue(ta1.length, 4); + assert.sameValue(ta1.buffer, buffer1); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var buffer2 = new SharedArrayBuffer(0); + var ta2 = new TA(buffer2); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer2); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/returns-new-instance.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/returns-new-instance.js new file mode 100644 index 000000000..d6fb802b9 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/returns-new-instance.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-buffer-byteoffset-length +description: > + Return new typedArray from undefined offset and length +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer1 = new ArrayBuffer(bpe * 4); + var ta1 = new TA(buffer1); + assert.sameValue(ta1.length, 4); + assert.sameValue(ta1.buffer, buffer1); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var buffer2 = new ArrayBuffer(0); + var ta2 = new TA(buffer2); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer2); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-bytelength-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-bytelength-sab.js new file mode 100644 index 000000000..3a9d2490e --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-bytelength-sab.js @@ -0,0 +1,73 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + ToIndex(length) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 11. If length is either not present or undefined, then + ... + 12. Else, + a. Let newLength be ? ToIndex(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 1; + } +}; + +var obj2 = { + toString: function() { + return 1; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 1, "object's valueOf"], + [obj2, 1, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["1", 1, "string '1'"], + [false, 0, "false"], + [true, 1, "true"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [1.1, 1, "1.1"], + [1.9, 1, "1.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var len = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, 0, len); + assert.sameValue(typedArray.length, expected, name + " length"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-bytelength.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-bytelength.js new file mode 100644 index 000000000..8155a4479 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-bytelength.js @@ -0,0 +1,72 @@ +// 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-buffer-byteoffset-length +description: > + ToIndex(length) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 11. If length is either not present or undefined, then + ... + 12. Else, + a. Let newLength be ? ToIndex(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 1; + } +}; + +var obj2 = { + toString: function() { + return 1; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 1, "object's valueOf"], + [obj2, 1, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["1", 1, "string '1'"], + [false, 0, "false"], + [true, 1, "true"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [1.1, 1, "1.1"], + [1.9, 1, "1.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var len = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, 0, len); + assert.sameValue(typedArray.length, expected, name + " length"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js new file mode 100644 index 000000000..e6085da48 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js @@ -0,0 +1,87 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + ToIndex(byteOffset) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToIndex(byteOffset). + 8. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 8; + } +}; + +var obj2 = { + toString: function() { + return 8; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 8, "object's valueOf"], + [obj2, 8, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["8", 8, "string '8'"], + [false, 0, "false"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [undefined, 0, "undefined"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [8.1, 8, "8.1"], + [8.9, 8, "8.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var offset = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, offset); + assert.sameValue(typedArray.byteOffset, expected, name + " byteOffset"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); + + // Testing `true`. See step 8 + if (TA.BYTES_PER_ELEMENT === 1) { + var typedArray = new TA(buffer, true); + assert.sameValue(typedArray.byteOffset, 1, "true => 1 byteOffset"); + assert.sameValue(typedArray.constructor, TA, "true => 1 constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + "true => 1 prototype" + ); + } else { + assert.throws(RangeError, function() { + new TA(buffer, true); + }, "1 modulo elementSize ≠ 0, throws a RangeError"); + } +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-byteoffset.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-byteoffset.js new file mode 100644 index 000000000..216f9cfdb --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/toindex-byteoffset.js @@ -0,0 +1,86 @@ +// 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-buffer-byteoffset-length +description: > + ToIndex(byteOffset) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToIndex(byteOffset). + 8. If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 8; + } +}; + +var obj2 = { + toString: function() { + return 8; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 8, "object's valueOf"], + [obj2, 8, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["8", 8, "string '8'"], + [false, 0, "false"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [undefined, 0, "undefined"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [8.1, 8, "8.1"], + [8.9, 8, "8.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var offset = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, offset); + assert.sameValue(typedArray.byteOffset, expected, name + " byteOffset"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); + + // Testing `true`. See step 8 + if (TA.BYTES_PER_ELEMENT === 1) { + var typedArray = new TA(buffer, true); + assert.sameValue(typedArray.byteOffset, 1, "true => 1 byteOffset"); + assert.sameValue(typedArray.constructor, TA, "true => 1 constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + "true => 1 prototype" + ); + } else { + assert.throws(RangeError, function() { + new TA(buffer, true); + }, "1 modulo elementSize ≠ 0, throws a RangeError"); + } +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js new file mode 100644 index 000000000..6a25a0aa9 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-typedarray +description: > + Passing a SharedArrayBuffer-backed TypedArray to a TypedArray constructor + produces an ArrayBuffer-backed TypedArray. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var sab = new SharedArrayBuffer(4); +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(View1) { + var ta1 = new View1(sab); + testWithTypedArrayConstructors(function(View2) { + var ta2 = new View2(ta1); + assert.sameValue(ta2.buffer.constructor, ArrayBuffer, + "TypedArray of SharedArrayBuffer-backed TypedArray is ArrayBuffer-backed"); + }, int_views); +}, int_views); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js new file mode 100644 index 000000000..b14fd3c4f --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Use prototype from new target if it's an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, Reflect, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-custom-proto-if-object.js new file mode 100644 index 000000000..0cbbb87f6 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-custom-proto-if-object.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-buffer-byteoffset-length +description: > + Use prototype from new target if it's an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js new file mode 100644 index 000000000..9e7a51901 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 000000000..7e8a5770a --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.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-buffer-byteoffset-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/custom-proto-access-throws.js new file mode 100644 index 000000000..3cc746cd1 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/custom-proto-access-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-length +description: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [1], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/init-zeros.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/init-zeros.js new file mode 100644 index 000000000..41bb0a8e2 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/init-zeros.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-length +description: All bytes are initialized to zero +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 5. If length was not passed, then + ... + 6. Else, + a. Perform ? AllocateTypedArrayBuffer(obj, length). + + 22.2.4.2.2 Runtime Semantics: AllocateTypedArrayBuffer + + 7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength). + + 24.1.1.1 AllocateArrayBuffer + + 3. Let block be ? CreateByteDataBlock(byteLength). + + 6.2.6.1 CreateByteDataBlock + + 1. Assert: size≥0. + 2. Let db be a new Data Block value consisting of size bytes. If it is + impossible to create such a Data Block, throw a RangeError exception. + 3. Set all of the bytes of db to 0. + 4. Return db. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var subject = new TA(9); + + assert.sameValue(subject[0], convertToBigInt(0), 'index 0'); + assert.sameValue(subject[1], convertToBigInt(0), 'index 1'); + assert.sameValue(subject[2], convertToBigInt(0), 'index 2'); + assert.sameValue(subject[3], convertToBigInt(0), 'index 3'); + assert.sameValue(subject[4], convertToBigInt(0), 'index 4'); + assert.sameValue(subject[5], convertToBigInt(0), 'index 5'); + assert.sameValue(subject[6], convertToBigInt(0), 'index 6'); + assert.sameValue(subject[7], convertToBigInt(0), 'index 7'); + assert.sameValue(subject[8], convertToBigInt(0), 'index 8'); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-infinity-throws-rangeerror.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-infinity-throws-rangeerror.js new file mode 100644 index 000000000..4e1b50f26 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-infinity-throws-rangeerror.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-length +description: > + Throws a RangeError if length is a Infinity value +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + 5. Let elementLength be ToLength(numberLength). + 6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError + exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.js new file mode 100644 index 000000000..8c634fd7b --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.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-length +description: > + Throws a RangeError if ToInteger(length) is a negative value +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 3. Let elementLength be ? ToIndex(length). + ... + + 7.1.17 ToIndex ( value ) + + 1. If value is undefined, then + ... + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(-1); + }); + + assert.throws(RangeError, function() { + new TA(-Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-symbol-throws.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-symbol-throws.js new file mode 100644 index 000000000..fd3767781 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/is-symbol-throws.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-length +description: > + If length is a Symbol, throw a TypeError exception. +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 4. Let numberLength be ? ToNumber(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol('1'); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(s); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/new-instance-extensibility.js new file mode 100644 index 000000000..740dff1f3 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/new-instance-extensibility.js @@ -0,0 +1,38 @@ +// 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-length +description: > + The new typedArray instance from a length argument is extensible +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/proto-from-ctor-realm.js new file mode 100644 index 000000000..7df294357 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/proto-from-ctor-realm.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-length +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%", elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [0], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/returns-object.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/returns-object.js new file mode 100644 index 000000000..09aa6d7d6 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/returns-object.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-length +description: > + Return a TypedArray object +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 7. Return obj +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(4); + var length = typedArray.length; + + assert.sameValue(length, 4, "length"); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/toindex-length.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/toindex-length.js new file mode 100644 index 000000000..22c1bba4d --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/toindex-length.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-length +description: > + ToIndex(length) operations +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 3. Let elementLength be ? ToIndex(length). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var items = [ + [-0, 0, "-0"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["1", 1, "string '1'"], + [true, 1, "true"], + [false, 0, "false"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [undefined, 0, "undefined"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [1.1, 1, "1.1"], + [1.9, 1, "1.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var len = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(len); + assert.sameValue(typedArray.length, expected, name + " length"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/undefined-newtarget-throws.js new file mode 100644 index 000000000..347b0deb8 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/undefined-newtarget-throws.js @@ -0,0 +1,28 @@ +// 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-length +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(0); + }); + + assert.throws(TypeError, function() { + TA(Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/use-custom-proto-if-object.js new file mode 100644 index 000000000..338672559 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/use-custom-proto-if-object.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-length +description: > + Use prototype from new target if it's an Object +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 000000000..b5651d31f --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.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-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: | + 22.2.4.2 TypedArray ( length ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is not Object. + + ... + 8. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, elementLength). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/no-args/custom-proto-access-throws.js new file mode 100644 index 000000000..20325c97c --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/no-args/custom-proto-access-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 +description: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors-bigint/no-args/new-instance-extensibility.js new file mode 100644 index 000000000..6fe9d4757 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/no-args/new-instance-extensibility.js @@ -0,0 +1,38 @@ +// 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 +description: > + The new typedArray instance is extensible +info: | + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors-bigint/no-args/proto-from-ctor-realm.js new file mode 100644 index 000000000..80460f1d4 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/no-args/proto-from-ctor-realm.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 +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%", 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/returns-object.js b/test/built-ins/TypedArrays/ctors-bigint/no-args/returns-object.js new file mode 100644 index 000000000..4751a27b1 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/no-args/returns-object.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 +description: > + Return a TypedArray object +info: | + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 7. Return obj +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(); + + assert.sameValue(typedArray.length, 0); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors-bigint/no-args/undefined-newtarget-throws.js new file mode 100644 index 000000000..c26e881c8 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/no-args/undefined-newtarget-throws.js @@ -0,0 +1,23 @@ +// 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 +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors-bigint/no-args/use-custom-proto-if-object.js new file mode 100644 index 000000000..9d44c6125 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/no-args/use-custom-proto-if-object.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 +description: > + Use prototype from new target if it's an Object +info: | + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors-bigint/no-args/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 000000000..339a4a757 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors-bigint/no-args/use-default-proto-if-custom-proto-is-not-object.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 +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: | + 22.2.4.1 TypedArray( ) + + This description applies only if the TypedArray function is called with no + arguments. + + ... + 3. Return ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%, 0). + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-array-returns.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-array-returns.js index 6e15b4ea4..84ada078a 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-array-returns.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-array-returns.js @@ -12,17 +12,17 @@ info: | object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] internal slot. -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ var obj = [7, 42]; -testWithTypedArrayConstructors(function(TA, N) { - var typedArray = new TA(N(obj)); +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(convertToBigInt(obj)); assert.sameValue(typedArray.length, 2); - assert.sameValue(typedArray[0], N(7)); - assert.sameValue(typedArray[1], N(42)); + assert.sameValue(typedArray[0], convertToBigInt(7)); + assert.sameValue(typedArray[1], convertToBigInt(42)); assert.sameValue(typedArray.constructor, TA); assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); }); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-generator-iterable-returns.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-generator-iterable-returns.js index 7e2876294..db9597546 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-generator-iterable-returns.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-as-generator-iterable-returns.js @@ -12,19 +12,19 @@ info: | object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] internal slot. -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var obj = (function *() { - yield N(7); yield N(42); + yield convertToBigInt(7); yield convertToBigInt(42); })(); var typedArray = new TA(obj); assert.sameValue(typedArray.length, 2); - assert.sameValue(typedArray[0], N(7)); - assert.sameValue(typedArray[1], N(42)); + assert.sameValue(typedArray[0], convertToBigInt(7)); + assert.sameValue(typedArray[1], convertToBigInt(42)); assert.sameValue(typedArray.constructor, TA); assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); }); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation-consistent-nan.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation-consistent-nan.js index a81d4c504..c3adc0642 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation-consistent-nan.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation-consistent-nan.js @@ -45,7 +45,7 @@ info: | encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value. ... -includes: [nans.js, testTypedArray.js, compareArray.js] +includes: [nans.js, testBigIntTypedArray.js, compareArray.js] ---*/ function body(FloatArray) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation.js index d14a14023..472cdccc0 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-conversion-operation.js @@ -42,7 +42,7 @@ info: | ... e. Else, ... -includes: [byteConversionValues.js, testTypedArray.js] +includes: [byteConversionValues.js, testBigIntTypedArray.js] ---*/ testTypedArrayConversions(byteConversionValues, function(TA, value, expected) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-custom-proto-access-throws.js index f5ced4ea4..750e65dab 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-custom-proto-access-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-custom-proto-access-throws.js @@ -28,8 +28,8 @@ info: | ... 3. Let proto be ? Get(constructor, "prototype"). ... -includes: [testTypedArray.js] -features: [Reflect, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] ---*/ var newTarget = function() {}.bind(null); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterating-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterating-throws.js index 41fc55509..0575a9901 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterating-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterating-throws.js @@ -15,8 +15,8 @@ info: | ... 4. Let arrayLike be ? IterableToArrayLike(object). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-not-callable-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-not-callable-throws.js index ad6db0877..f51d37e49 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-not-callable-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-not-callable-throws.js @@ -15,8 +15,8 @@ info: | ... 4. Let arrayLike be ? IterableToArrayLike(object). ... -includes: [testTypedArray.js] -features: [Symbol.iterator, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] ---*/ var obj = function () {}; diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-throws.js index 571ad77ad..03e08ee24 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-iterator-throws.js @@ -15,8 +15,8 @@ info: | ... 4. Let arrayLike be ? IterableToArrayLike(object). ... -includes: [testTypedArray.js] -features: [Symbol.iterator, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] ---*/ var obj = function () {}; diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-excessive-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-excessive-throws.js index f8279f50a..a0ff4e705 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-excessive-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-excessive-throws.js @@ -15,8 +15,8 @@ info: | ... 6. Perform ? AllocateTypedArrayBuffer(O, len). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ var obj = { diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-is-symbol-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-is-symbol-throws.js index b452dea03..53976243e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-is-symbol-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-is-symbol-throws.js @@ -15,8 +15,8 @@ info: | ... 5. Let len be ? ToLength(? Get(arrayLike, "length")). ... -includes: [testTypedArray.js] -features: [Symbol, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] ---*/ var obj = { diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-throws.js index 08f8cd130..d3147dc4c 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-length-throws.js @@ -15,8 +15,8 @@ info: | ... 5. Let len be ? ToLength(? Get(arrayLike, "length")). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ var obj = {}; diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-new-instance-extensibility.js index bd335774b..9536f2456 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-new-instance-extensibility.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-new-instance-extensibility.js @@ -25,15 +25,15 @@ info: | ... 11. Set the [[Extensible]] internal slot of A to true. ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var obj = { - "0": N(0), - "1": N(1), - "2": N(2), + "0": convertToBigInt(0), + "1": convertToBigInt(1), + "2": convertToBigInt(2), length: 3 }; diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-proto-from-ctor-realm.js index a92ceee00..3b3c5cb86 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-proto-from-ctor-realm.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-proto-from-ctor-realm.js @@ -22,8 +22,8 @@ info: | a. Let realm be ? GetFunctionRealm(constructor). b. Let proto be realm's intrinsic object named intrinsicDefaultProto. 5. Return proto. -includes: [testTypedArray.js] -features: [cross-realm, Reflect, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] ---*/ var other = $262.createRealm().global; diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-from-property.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-from-property.js index 4a0d60825..41e153911 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-from-property.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-from-property.js @@ -17,8 +17,8 @@ info: | ... b. Let kValue be ? Get(arrayLike, Pk). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ var obj = { @@ -31,9 +31,9 @@ Object.defineProperty(obj, "2", { } }); -testWithTypedArrayConstructors(function(TA, N) { - obj[0] = N(0); - obj[1] = N(0); +testWithTypedArrayConstructors(function(TA) { + obj[0] = convertToBigInt(0); + obj[1] = convertToBigInt(0); assert.throws(Test262Error, function() { new TA(obj); }); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive-typeerror.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive-typeerror.js index 3aee05e56..50dd3b1a3 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive-typeerror.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive-typeerror.js @@ -50,11 +50,11 @@ info: | b. If Type(result) is not Object, return result. c. Throw a TypeError exception. ... -includes: [testTypedArray.js] -features: [Symbol.toPrimitive, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toPrimitive, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new Int8Array(1); var toPrimitive = 0; var valueOf = 0; @@ -69,7 +69,7 @@ testWithTypedArrayConstructors(function(TA, N) { }; assert.throws(TypeError, function() { - new TA([N(8), sample]); + new TA([convertToBigInt(8), sample]); }, "abrupt completion from sample @@toPrimitive"); assert.sameValue(toPrimitive, 1, "toPrimitive was called once"); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive.js index 516586863..f468bdea7 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-to-primitive.js @@ -48,11 +48,11 @@ info: | 5. If exoticToPrim is not undefined, then a. Let result be ? Call(exoticToPrim, input, « hint »). ... -includes: [testTypedArray.js] -features: [Symbol.toPrimitive, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toPrimitive, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new Int8Array(1); var toPrimitive = 0; var valueOf = 0; @@ -67,7 +67,7 @@ testWithTypedArrayConstructors(function(TA, N) { }; assert.throws(Test262Error, function() { - new TA([N(8), sample]); + new TA([convertToBigInt(8), sample]); }, "abrupt completion from sample @@toPrimitive"); assert.sameValue(toPrimitive, 1, "toPrimitive was called once"); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-tostring.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-tostring.js index 3e2d84e75..1b507ccbf 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-tostring.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-tostring.js @@ -60,11 +60,11 @@ info: | b. If IsCallable(method) is true, then i. Let result be ? Call(method, O). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new Int8Array(1); var valueOf = 0; var toString = 0; @@ -80,7 +80,7 @@ testWithTypedArrayConstructors(function(TA, N) { }; assert.throws(Test262Error, function() { - new TA([N(8), sample]); + new TA([convertToBigInt(8), sample]); }, "abrupt completion from ToNumber(sample)"); assert.sameValue(valueOf, 1, "valueOf called once"); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof-typeerror.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof-typeerror.js index c58fe2425..aeb3eb632 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof-typeerror.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof-typeerror.js @@ -61,11 +61,11 @@ info: | i. Let result be ? Call(method, O). ii. If Type(result) is not Object, return result. 6. Throw a TypeError exception. -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new Int8Array(1); var valueOf = 0; var toString = 0; @@ -81,7 +81,7 @@ testWithTypedArrayConstructors(function(TA, N) { }; assert.throws(TypeError, function() { - new TA([N(8), sample]); + new TA([convertToBigInt(8), sample]); }, "abrupt completion from ToNumber(sample)"); assert.sameValue(valueOf, 1, "valueOf called once"); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof.js index ae4515f34..361426d2c 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-obj-valueof.js @@ -61,11 +61,11 @@ info: | i. Let result be ? Call(method, O). ii. If Type(result) is not Object, return result. 6. Throw a TypeError exception. -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new Int8Array(1); var valueOf = 0; @@ -75,7 +75,7 @@ testWithTypedArrayConstructors(function(TA, N) { }; assert.throws(Test262Error, function() { - new TA([N(8), sample]); + new TA([convertToBigInt(8), sample]); }, "abrupt completion from ToNumber(sample)"); assert.sameValue(valueOf, 1, "valueOf called once"); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-property.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-property.js index 489234c90..df7564b9d 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-property.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-property.js @@ -18,8 +18,8 @@ info: | b. Let kValue be ? Get(arrayLike, Pk). c. Perform ? Set(O, Pk, kValue, true). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ var obj = { @@ -31,9 +31,9 @@ var obj = { length: 4 }; -testWithTypedArrayConstructors(function(TA, N) { - obj[0] = N(0); - obj[1] = N(0); +testWithTypedArrayConstructors(function(TA) { + obj[0] = convertToBigInt(0); + obj[1] = convertToBigInt(0); assert.throws(Test262Error, function() { new TA(obj); }); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-symbol-property.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-symbol-property.js index 42b4a54b8..64de7b8c6 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-symbol-property.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-throws-setting-symbol-property.js @@ -18,8 +18,8 @@ info: | b. Let kValue be ? Get(arrayLike, Pk). c. Perform ? Set(O, Pk, kValue, true). ... -includes: [testTypedArray.js] -features: [Symbol, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] ---*/ var obj = { diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-undefined-newtarget-throws.js index 36f68493a..df5996746 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-undefined-newtarget-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-undefined-newtarget-throws.js @@ -15,8 +15,8 @@ info: | ... 2. If NewTarget is undefined, throw a TypeError exception. ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-custom-proto-if-object.js index bb5754a9c..1d688fac9 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-custom-proto-if-object.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-custom-proto-if-object.js @@ -31,8 +31,8 @@ info: | 10. Set the [[Prototype]] internal slot of A to prototype. ... 12. Return A. -includes: [testTypedArray.js] -features: [Reflect, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] ---*/ function newTarget() {} diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-default-proto-if-custom-proto-is-not-object.js index 6aba187c2..5f8355d12 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-default-proto-if-custom-proto-is-not-object.js +++ b/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-use-default-proto-if-custom-proto-is-not-object.js @@ -31,8 +31,8 @@ info: | 10. Set the [[Prototype]] internal slot of A to prototype. ... 12. Return A. -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ function newTarget() {} diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-custom-proto-access-throws.js index 281d09353..e77230e44 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-custom-proto-access-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-custom-proto-access-throws.js @@ -27,8 +27,8 @@ info: | ... 3. Let proto be ? Get(constructor, "prototype"). ... -includes: [testTypedArray.js] -features: [Reflect, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] ---*/ var newTarget = function() {}.bind(null); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js index 8ee2fba54..a3c275ef1 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js @@ -26,8 +26,8 @@ info: | 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] »). ... -includes: [testTypedArray.js, detachArrayBuffer.js] -features: [TypedArray, Symbol.species] +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray, Symbol.species] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js index 978f42af6..6a24fae75 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js @@ -30,8 +30,8 @@ info: | 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] »). ... -includes: [testTypedArray.js, detachArrayBuffer.js] -features: [TypedArray, Symbol.species] +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray, Symbol.species] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-new-instance-extensibility.js index d29848bf8..4483d6f3b 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-new-instance-extensibility.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-new-instance-extensibility.js @@ -25,8 +25,8 @@ info: | ... 11. Set the [[Extensible]] internal slot of A to true. ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ var typedArraySample1 = new Int8Array(); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js index b8976d696..776a56713 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js @@ -21,8 +21,8 @@ info: | ... 2. Let C be ? Get(O, "constructor"). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js index 03860d1a7..279dbf34b 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js @@ -33,8 +33,8 @@ info: | a. Let realm be ? GetFunctionRealm(constructor). b. Let proto be realm's intrinsic object named intrinsicDefaultProto. ... -includes: [testTypedArray.js] -features: [cross-realm, Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Symbol.species, TypedArray] ---*/ var sample1 = new Int8Array(); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js index a510d7806..f31427329 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js @@ -25,8 +25,8 @@ info: | 7. If IsConstructor(S) is true, return S. ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ var sample1 = new Int8Array(); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js index cfb79f1a9..d538503a3 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js @@ -23,8 +23,8 @@ info: | ... 4. If Type(C) is not Object, throw a TypeError exception. ... -includes: [testTypedArray.js] -features: [Symbol, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] ---*/ var sample1 = new Int8Array(); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js index 4b0b19aca..0cf6e2965 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js @@ -21,8 +21,8 @@ info: | ... 5. Let S be ? Get(C, @@species). ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ var sample1 = new Int8Array(); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js index c485cae13..4419406c6 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js @@ -23,8 +23,8 @@ info: | 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] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ var sample1 = new Int8Array(); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js index 96ba9009d..34b3a12df 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js @@ -22,8 +22,8 @@ info: | 5. Let S be ? Get(C, @@species). 6. If S is either undefined or null, return defaultConstructor. ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js index 135634646..16bfe8d87 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js @@ -31,8 +31,8 @@ info: | 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » ) ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ var sample1 = new Int8Array(); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js index 32e78a37d..a6cfd230f 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js @@ -22,8 +22,8 @@ info: | 5. Let S be ? Get(C, @@species). 6. If S is either undefined or null, return defaultConstructor. ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js index 34cb4dee6..abbabc666 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js @@ -10,8 +10,8 @@ info: | This description applies only if the TypedArray function is called with at least one argument and the Type of the first argument is Object and that object has a [[TypedArrayName]] internal slot. -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ var sample1 = new Int8Array(7); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js index 6e58746cd..45acca594 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js @@ -22,8 +22,8 @@ info: | a. Let realm be ? GetFunctionRealm(constructor). b. Let proto be realm's intrinsic object named intrinsicDefaultProto. 5. Return proto. -includes: [testTypedArray.js] -features: [cross-realm, Reflect, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] ---*/ var other = $262.createRealm().global; diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js index f8e75d209..c5d663909 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js @@ -28,8 +28,8 @@ info: | ... 2. Let C be ? Get(O, "constructor"). ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js index 43743b956..ae21a381b 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js @@ -45,8 +45,8 @@ info: | a. Let realm be ? GetFunctionRealm(constructor). b. Let proto be realm's intrinsic object named intrinsicDefaultProto. ... -includes: [testTypedArray.js] -features: [cross-realm, Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Symbol.species, TypedArray] ---*/ var other = $262.createRealm().global; diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js index 7ed3aca0d..cac5edc53 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js @@ -36,8 +36,8 @@ info: | ... 8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength). ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js index 2072aa96d..f8487280c 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js @@ -30,8 +30,8 @@ info: | 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] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js index e42780610..ff86f04d6 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js @@ -29,8 +29,8 @@ info: | 5. Let S be ? Get(C, @@species). 6. If S is either undefined or null, return defaultConstructor. ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js index b171826cf..9de4e9b3b 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js @@ -39,8 +39,8 @@ info: | 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » ) ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js index ec2aaf3c1..36fdbe8da 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js @@ -28,8 +28,8 @@ info: | ... 5. Let S be ? Get(C, @@species). ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js index 339d3041b..f040fe16e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js @@ -29,8 +29,8 @@ info: | 5. Let S be ? Get(C, @@species). 6. If S is either undefined or null, return defaultConstructor. ... -includes: [testTypedArray.js] -features: [Symbol.species, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js index ef9709749..758eef5c0 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js @@ -30,8 +30,8 @@ info: | ... 4. If Type(C) is not Object, throw a TypeError exception. ... -includes: [testTypedArray.js] -features: [Symbol, TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js index 4d9b442c9..3321aa5b4 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js @@ -16,8 +16,8 @@ info: | a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). ... 23. Return O. -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js index 12839b2d7..de0e9fdc2 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js +++ b/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js @@ -14,8 +14,8 @@ info: | ... 2. If NewTarget is undefined, throw a TypeError exception. ... -includes: [testTypedArray.js] -features: [TypedArray] +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] ---*/ testWithTypedArrayConstructors(function(TA) { diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js index 707aa00be..707aa00be 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.js index a886e5afd..a886e5afd 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-throws-sab.js index 89f58a1cd..89f58a1cd 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-throws.js index 058892465..058892465 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-zero-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-zero-sab.js index 1073b5af8..1073b5af8 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-zero-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-zero-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-zero.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-zero.js index 13d0a3e14..13d0a3e14 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-zero.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-negative-zero.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-symbol-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-symbol-throws-sab.js index b5fc270c9..b5fc270c9 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-symbol-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-symbol-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-symbol-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-symbol-throws.js index 60039a1f5..60039a1f5 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-symbol-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-is-symbol-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js index 79b398ccf..79b398ccf 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-throws-from-modulo-element-size.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-throws-from-modulo-element-size.js index 479f0d5dc..479f0d5dc 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-throws-from-modulo-element-size.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-throws-from-modulo-element-size.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-detachbuffer.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-to-number-detachbuffer.js index b8936e8cd..b8936e8cd 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-detachbuffer.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-to-number-detachbuffer.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-to-number-throws-sab.js index e7b336c5e..e7b336c5e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-to-number-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-to-number-throws.js index 20cd4b796..20cd4b796 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-byteoffset-to-number-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-custom-proto-access-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-custom-proto-access-throws-sab.js index b3ff8c56e..b3ff8c56e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-custom-proto-access-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-custom-proto-access-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-custom-proto-access-throws.js index a1b823317..a1b823317 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-custom-proto-access-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-custom-proto-access-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-and-offset-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length-and-offset-sab.js index 2107146b1..2107146b1 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-and-offset-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length-and-offset-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-and-offset.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length-and-offset.js index aefd48b55..aefd48b55 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-and-offset.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length-and-offset.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length-sab.js index a06e530d0..a06e530d0 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length.js index 11fb1c4a4..11fb1c4a4 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-length.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-negative-length-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-negative-length-sab.js index 4d1b1d29c..4d1b1d29c 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-negative-length-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-negative-length-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-negative-length.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-negative-length.js index d57d466d9..d57d466d9 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-negative-length.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-negative-length.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-offset-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-offset-sab.js index 515d822c1..515d822c1 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-offset-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-offset-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-offset.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-offset.js index 89e290b52..89e290b52 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-offset.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-defined-offset.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-detachedbuffer.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-detachedbuffer.js index b015d4c34..b015d4c34 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-detachedbuffer.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-detachedbuffer.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-length-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-length-throws-sab.js index 2549e93fd..2549e93fd 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-length-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-length-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-length-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-length-throws.js index 3ff3a6d61..3ff3a6d61 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-length-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-length-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-offset-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-offset-throws-sab.js index 62cf41145..62cf41145 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-offset-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-offset-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-offset-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-offset-throws.js index 5daf40ce7..5daf40ce7 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-offset-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-excessive-offset-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-invoked-with-undefined-newtarget-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-invoked-with-undefined-newtarget-sab.js index 24061049a..24061049a 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-invoked-with-undefined-newtarget-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-invoked-with-undefined-newtarget-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-invoked-with-undefined-newtarget.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-invoked-with-undefined-newtarget.js index 218b7c2c0..218b7c2c0 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-invoked-with-undefined-newtarget.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-invoked-with-undefined-newtarget.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-is-referenced-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-is-referenced-sab.js index 44c29229c..44c29229c 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-is-referenced-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-is-referenced-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-is-referenced.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-is-referenced.js index 0154deaf4..0154deaf4 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-is-referenced.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-is-referenced.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-access-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-access-throws-sab.js index 16872f860..16872f860 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-access-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-access-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-access-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-access-throws.js index ea99b8b40..ea99b8b40 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-access-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-access-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-is-symbol-throws-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-is-symbol-throws-sab.js index 8b77b806d..8b77b806d 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-is-symbol-throws-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-is-symbol-throws-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-is-symbol-throws.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-is-symbol-throws.js index db8ac8303..db8ac8303 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-is-symbol-throws.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-is-symbol-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-to-number-detachbuffer.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-to-number-detachbuffer.js index c8c3eb34b..c8c3eb34b 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-to-number-detachbuffer.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-length-to-number-detachbuffer.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-new-instance-extensibility-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-new-instance-extensibility-sab.js index 2b765a78f..2b765a78f 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-new-instance-extensibility-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-new-instance-extensibility-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-new-instance-extensibility.js index 74336215f..74336215f 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-new-instance-extensibility.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-new-instance-extensibility.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-proto-from-ctor-realm-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-proto-from-ctor-realm-sab.js index 9cab95b47..9cab95b47 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-proto-from-ctor-realm-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-proto-from-ctor-realm-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-proto-from-ctor-realm.js index d93538db4..d93538db4 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-proto-from-ctor-realm.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-proto-from-ctor-realm.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-returns-new-instance-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-returns-new-instance-sab.js index 52de96252..52de96252 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-returns-new-instance-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-returns-new-instance-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-returns-new-instance.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-returns-new-instance.js index 4723e75f9..4723e75f9 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-returns-new-instance.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-returns-new-instance.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-bytelength-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-bytelength-sab.js index 5fd87715f..5fd87715f 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-bytelength-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-bytelength-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-bytelength.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-bytelength.js index ae660b820..ae660b820 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-bytelength.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-bytelength.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-byteoffset-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-byteoffset-sab.js index 43ae9f601..43ae9f601 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-byteoffset-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-byteoffset-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-byteoffset.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-byteoffset.js index 35a087aaf..35a087aaf 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-byteoffset.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-toindex-byteoffset.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-typedarray-backed-by-sharedarraybuffer.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-typedarray-backed-by-sharedarraybuffer.js index 739d1cdd2..739d1cdd2 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-typedarray-backed-by-sharedarraybuffer.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-typedarray-backed-by-sharedarraybuffer.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-custom-proto-if-object-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-custom-proto-if-object-sab.js index c963b6bb1..c963b6bb1 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-custom-proto-if-object-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-custom-proto-if-object-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-custom-proto-if-object.js index 9eefdf56d..9eefdf56d 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-custom-proto-if-object.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-custom-proto-if-object.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js index 8c91aa84d..8c91aa84d 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object.js index df4909dab..df4909dab 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object.js +++ b/test/built-ins/TypedArrays/ctors/buffer-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-custom-proto-access-throws.js index 6ad49fdab..6ad49fdab 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-custom-proto-access-throws.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-custom-proto-access-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-init-zeros.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-init-zeros.js index 384e2399b..b36131709 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-init-zeros.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-init-zeros.js @@ -40,16 +40,16 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var subject = new TA(9); - assert.sameValue(subject[0], N(0), 'index 0'); - assert.sameValue(subject[1], N(0), 'index 1'); - assert.sameValue(subject[2], N(0), 'index 2'); - assert.sameValue(subject[3], N(0), 'index 3'); - assert.sameValue(subject[4], N(0), 'index 4'); - assert.sameValue(subject[5], N(0), 'index 5'); - assert.sameValue(subject[6], N(0), 'index 6'); - assert.sameValue(subject[7], N(0), 'index 7'); - assert.sameValue(subject[8], N(0), 'index 8'); + assert.sameValue(subject[0], 0, 'index 0'); + assert.sameValue(subject[1], 0, 'index 1'); + assert.sameValue(subject[2], 0, 'index 2'); + assert.sameValue(subject[3], 0, 'index 3'); + assert.sameValue(subject[4], 0, 'index 4'); + assert.sameValue(subject[5], 0, 'index 5'); + assert.sameValue(subject[6], 0, 'index 6'); + assert.sameValue(subject[7], 0, 'index 7'); + assert.sameValue(subject[8], 0, 'index 8'); }); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-infinity-throws-rangeerror.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-is-infinity-throws-rangeerror.js index 0084d5d6a..0084d5d6a 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-infinity-throws-rangeerror.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-is-infinity-throws-rangeerror.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-negative-integer-throws-rangeerror.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-is-negative-integer-throws-rangeerror.js index 0ff5d5a3f..0ff5d5a3f 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-negative-integer-throws-rangeerror.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-is-negative-integer-throws-rangeerror.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-symbol-throws.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-is-symbol-throws.js index 797dd4922..797dd4922 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-symbol-throws.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-is-symbol-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-new-instance-extensibility.js index d9b03deca..d9b03deca 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-new-instance-extensibility.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-new-instance-extensibility.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-proto-from-ctor-realm.js index f4effc208..77cef2616 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-proto-from-ctor-realm.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-proto-from-ctor-realm.js @@ -29,7 +29,7 @@ var other = $262.createRealm().global; var C = new other.Function(); C.prototype = null; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var ta = Reflect.construct(TA, [0], C); assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-returns-object.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-returns-object.js index 8a9121d88..8a9121d88 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-returns-object.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-returns-object.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-toindex-length.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-toindex-length.js index 4d16ff711..4d16ff711 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-toindex-length.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-toindex-length.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-undefined-newtarget-throws.js index 6a238255e..6a238255e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-undefined-newtarget-throws.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-undefined-newtarget-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-use-custom-proto-if-object.js index b36ff7014..b36ff7014 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-use-custom-proto-if-object.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-use-custom-proto-if-object.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-use-default-proto-if-custom-proto-is-not-object.js index e5fc367c0..e5fc367c0 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-use-default-proto-if-custom-proto-is-not-object.js +++ b/test/built-ins/TypedArrays/ctors/length-arg/length-arg-use-default-proto-if-custom-proto-is-not-object.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors/no-args/no-args-custom-proto-access-throws.js index 6b383e32e..6b383e32e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-custom-proto-access-throws.js +++ b/test/built-ins/TypedArrays/ctors/no-args/no-args-custom-proto-access-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors/no-args/no-args-new-instance-extensibility.js index cced58d2e..cced58d2e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-new-instance-extensibility.js +++ b/test/built-ins/TypedArrays/ctors/no-args/no-args-new-instance-extensibility.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/no-args/no-args-proto-from-ctor-realm.js index c69922185..c69922185 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-proto-from-ctor-realm.js +++ b/test/built-ins/TypedArrays/ctors/no-args/no-args-proto-from-ctor-realm.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-returns-object.js b/test/built-ins/TypedArrays/ctors/no-args/no-args-returns-object.js index c7274e5f9..c7274e5f9 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-returns-object.js +++ b/test/built-ins/TypedArrays/ctors/no-args/no-args-returns-object.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors/no-args/no-args-undefined-newtarget-throws.js index a06139865..a06139865 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-undefined-newtarget-throws.js +++ b/test/built-ins/TypedArrays/ctors/no-args/no-args-undefined-newtarget-throws.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors/no-args/no-args-use-custom-proto-if-object.js index 4266724f0..4266724f0 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-use-custom-proto-if-object.js +++ b/test/built-ins/TypedArrays/ctors/no-args/no-args-use-custom-proto-if-object.js diff --git a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors/no-args/no-args-use-default-proto-if-custom-proto-is-not-object.js index e76ef585e..e76ef585e 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-use-default-proto-if-custom-proto-is-not-object.js +++ b/test/built-ins/TypedArrays/ctors/no-args/no-args-use-default-proto-if-custom-proto-is-not-object.js diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-as-array-returns.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-as-array-returns.js new file mode 100644 index 000000000..a5e3c3bbc --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-as-array-returns.js @@ -0,0 +1,28 @@ +// 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-object +description: > + Return typedArray from array argument +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = [7, 42]; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 2); + assert.sameValue(typedArray[0], 7); + assert.sameValue(typedArray[1], 42); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-as-generator-iterable-returns.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-as-generator-iterable-returns.js new file mode 100644 index 000000000..f9af0defe --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-as-generator-iterable-returns.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return typedArray from iterable argument +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = (function *() { + yield 7; yield 42; + })(); + + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 2); + assert.sameValue(typedArray[0], 7); + assert.sameValue(typedArray[1], 42); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-conversion-operation-consistent-nan.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-conversion-operation-consistent-nan.js new file mode 100644 index 000000000..a81d4c504 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-conversion-operation-consistent-nan.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: Consistent canonicalization of NaN values +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 9. Repeat, while k < len + ... + c. Perform ? Set(O, Pk, kValue, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + a. Set rawBytes to a List containing the 4 bytes that are the result + of converting value to IEEE 754-2008 binary32 format using “Round to + nearest, ties to even” rounding mode. If isLittleEndian is false, the + bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + 9. Else, if type is "Float64", then + a. Set rawBytes to a List containing the 8 bytes that are the IEEE + 754-2008 binary64 format encoding of value. If isLittleEndian is false, + the bytes are arranged in big endian order. Otherwise, the bytes are + arranged in little endian order. If value is NaN, rawValue may be set + to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number + encoding. An implementation must always choose the same encoding for + each implementation distinguishable NaN value. + ... +includes: [nans.js, testTypedArray.js, compareArray.js] +---*/ + +function body(FloatArray) { + var first = new FloatArray(distinctNaNs); + var second = new FloatArray(distinctNaNs); + var firstBytes = new Uint8Array(first.buffer); + var secondBytes = new Uint8Array(second.buffer); + + assert(compareArray(firstBytes, secondBytes)); +} + +testWithTypedArrayConstructors(body, [Float32Array, Float64Array]); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-conversion-operation.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-conversion-operation.js new file mode 100644 index 000000000..d14a14023 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-conversion-operation.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-object +description: > + Verify conversion values on returned instance +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 9. Repeat, while k < len + ... + c. Perform ? Set(O, Pk, kValue, true). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testTypedArray.js] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected) { + var sample = new TA([value]); + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-custom-proto-access-throws.js new file mode 100644 index 000000000..f5ced4ea4 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-custom-proto-access-throws.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]], + NewTarget, "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +var o = {}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [o], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterating-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterating-throws.js new file mode 100644 index 000000000..41fc55509 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterating-throws.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-object +description: > + Return abrupt from iterating object argument +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 4. Let arrayLike be ? IterableToArrayLike(object). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = (function *() { + yield 0; + throw new Test262Error(); + })(); + + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterator-not-callable-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterator-not-callable-throws.js new file mode 100644 index 000000000..ad6db0877 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterator-not-callable-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt when object @@iterator is not callable +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 4. Let arrayLike be ? IterableToArrayLike(object). + ... +includes: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var obj = function () {}; + +testWithTypedArrayConstructors(function(TA) { + obj[Symbol.iterator] = {}; + assert.throws(TypeError, function() { + new TA(obj); + }); + + obj[Symbol.iterator] = true; + assert.throws(TypeError, function() { + new TA(obj); + }); + + obj[Symbol.iterator] = 42; + assert.throws(TypeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterator-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterator-throws.js new file mode 100644 index 000000000..571ad77ad --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-iterator-throws.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-object +description: > + Return abrupt from getting object @@iterator +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 4. Let arrayLike be ? IterableToArrayLike(object). + ... +includes: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var obj = function () {}; + +Object.defineProperty(obj, Symbol.iterator, { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-excessive-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-excessive-throws.js new file mode 100644 index 000000000..f8279f50a --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-excessive-throws.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt from allocating array buffer with excessive length +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 6. Perform ? AllocateTypedArrayBuffer(O, len). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + length: Math.pow(2, 53) +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-is-symbol-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-is-symbol-throws.js new file mode 100644 index 000000000..b452dea03 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-is-symbol-throws.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt from length property as a Symbol on the object argument +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 5. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var obj = { + length: Symbol("1") +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-throws.js new file mode 100644 index 000000000..08f8cd130 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-length-throws.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-object +description: > + Return abrupt from getting length property on the object argument +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 5. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = {}; + +Object.defineProperty(obj, "length", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-new-instance-extensibility.js new file mode 100644 index 000000000..86a2ac837 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-new-instance-extensibility.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-object +description: > + The new typedArray instance from an object argument is extensible +info: | + 22.2.4.4 TypedArray ( object ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + "0": 0, + "1": 1, + "2": 2, + length: 3 +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(obj); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-proto-from-ctor-realm.js new file mode 100644 index 000000000..a92ceee00 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-proto-from-ctor-realm.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-object +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + [...] + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testTypedArray.js] +features: [cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [{}], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-returns.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-returns.js index cb06ba220..57eec9720 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-returns.js +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-returns.js @@ -42,6 +42,4 @@ testWithTypedArrayConstructors(function(TA) { assert.sameValue(typedArray[1], 0); assert.sameValue(typedArray[4], 0); } -}, - // Cannot create Big*64Arrays from non-safe integers. - numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-from-property.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-from-property.js new file mode 100644 index 000000000..f9d384b5c --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-from-property.js @@ -0,0 +1,38 @@ +// 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-object +description: > + Return abrupt from getting object property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + length: 4 +}; + +Object.defineProperty(obj, "2", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-to-primitive-typeerror.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-to-primitive-typeerror.js new file mode 100644 index 000000000..215bf75fc --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-to-primitive-typeerror.js @@ -0,0 +1,77 @@ +// 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-object +description: > + Throw TypeError from @@toPrimitive returning an Object when setting a property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... + + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String and if SameValue(O, Receiver) is true, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 7.1.3 ToNumber ( argument ) + + Object, Apply the following steps: + + 1. Let primValue be ? ToPrimitive(argument, hint Number). + 2. Return ? ToNumber(primValue). + + 7.1.1 ToPrimitive ( input [ , PreferredType ] ) + + ... + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + b. If Type(result) is not Object, return result. + c. Throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol.toPrimitive, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new Int8Array(1); + var toPrimitive = 0; + var valueOf = 0; + + sample[Symbol.toPrimitive] = function() { + toPrimitive++; + return {}; + }; + + sample.valueOf = function() { + valueOf++; + }; + + assert.throws(TypeError, function() { + new TA([8, sample]); + }, "abrupt completion from sample @@toPrimitive"); + + assert.sameValue(toPrimitive, 1, "toPrimitive was called once"); + assert.sameValue(valueOf, 0, "sample.valueOf is not called"); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-to-primitive.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-to-primitive.js new file mode 100644 index 000000000..7a7170b6f --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-to-primitive.js @@ -0,0 +1,75 @@ +// 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-object +description: > + Return abrupt from @@toPrimitive when setting a property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... + + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String and if SameValue(O, Receiver) is true, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 7.1.3 ToNumber ( argument ) + + Object, Apply the following steps: + + 1. Let primValue be ? ToPrimitive(argument, hint Number). + 2. Return ? ToNumber(primValue). + + 7.1.1 ToPrimitive ( input [ , PreferredType ] ) + + ... + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + ... +includes: [testTypedArray.js] +features: [Symbol.toPrimitive, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new Int8Array(1); + var toPrimitive = 0; + var valueOf = 0; + + sample[Symbol.toPrimitive] = function() { + toPrimitive++; + throw new Test262Error(); + }; + + sample.valueOf = function() { + valueOf++; + }; + + assert.throws(Test262Error, function() { + new TA([8, sample]); + }, "abrupt completion from sample @@toPrimitive"); + + assert.sameValue(toPrimitive, 1, "toPrimitive was called once"); + assert.sameValue(valueOf, 0, "it does not call sample.valueOf"); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-tostring.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-tostring.js new file mode 100644 index 000000000..482e11595 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-tostring.js @@ -0,0 +1,88 @@ +// 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-object +description: > + Return abrupt from toString() when setting a property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... + + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String and if SameValue(O, Receiver) is true, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 7.1.3 ToNumber ( argument ) + + Object, Apply the following steps: + + 1. Let primValue be ? ToPrimitive(argument, hint Number). + 2. Return ? ToNumber(primValue). + + 7.1.1 ToPrimitive ( input [ , PreferredType ] ) + + ... + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + b. If Type(result) is not Object, return result. + c. Throw a TypeError exception. + ... + 7. Return ? OrdinaryToPrimitive(input, hint). + + OrdinaryToPrimitive + + ... + 5. For each name in methodNames in List order, do + a. Let method be ? Get(O, name). + b. If IsCallable(method) is true, then + i. Let result be ? Call(method, O). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new Int8Array(1); + var valueOf = 0; + var toString = 0; + + sample.valueOf = function() { + valueOf++; + return {}; + }; + + sample.toString = function() { + toString++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + new TA([8, sample]); + }, "abrupt completion from ToNumber(sample)"); + + assert.sameValue(valueOf, 1, "valueOf called once"); + assert.sameValue(toString, 1, "toString called once"); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-valueof-typeerror.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-valueof-typeerror.js new file mode 100644 index 000000000..767dd2182 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-valueof-typeerror.js @@ -0,0 +1,89 @@ +// 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-object +description: > + Throw TypeError from OrdinaryToPrimitive when setting a property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... + + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String and if SameValue(O, Receiver) is true, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 7.1.3 ToNumber ( argument ) + + Object, Apply the following steps: + + 1. Let primValue be ? ToPrimitive(argument, hint Number). + 2. Return ? ToNumber(primValue). + + 7.1.1 ToPrimitive ( input [ , PreferredType ] ) + + ... + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + b. If Type(result) is not Object, return result. + c. Throw a TypeError exception. + ... + 7. Return ? OrdinaryToPrimitive(input, hint). + + OrdinaryToPrimitive + + ... + 5. For each name in methodNames in List order, do + a. Let method be ? Get(O, name). + b. If IsCallable(method) is true, then + i. Let result be ? Call(method, O). + ii. If Type(result) is not Object, return result. + 6. Throw a TypeError exception. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new Int8Array(1); + var valueOf = 0; + var toString = 0; + + sample.valueOf = function() { + valueOf++; + return {}; + }; + + sample.toString = function() { + toString++; + return {}; + }; + + assert.throws(TypeError, function() { + new TA([8, sample]); + }, "abrupt completion from ToNumber(sample)"); + + assert.sameValue(valueOf, 1, "valueOf called once"); + assert.sameValue(toString, 1, "toString called once"); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-valueof.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-valueof.js new file mode 100644 index 000000000..f9baf7758 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-obj-valueof.js @@ -0,0 +1,82 @@ +// 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-object +description: > + Return abrupt from valueOf() when setting a property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... + + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String and if SameValue(O, Receiver) is true, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 7.1.3 ToNumber ( argument ) + + Object, Apply the following steps: + + 1. Let primValue be ? ToPrimitive(argument, hint Number). + 2. Return ? ToNumber(primValue). + + 7.1.1 ToPrimitive ( input [ , PreferredType ] ) + + ... + 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). + 5. If exoticToPrim is not undefined, then + a. Let result be ? Call(exoticToPrim, input, « hint »). + b. If Type(result) is not Object, return result. + c. Throw a TypeError exception. + ... + 7. Return ? OrdinaryToPrimitive(input, hint). + + OrdinaryToPrimitive + + ... + 5. For each name in methodNames in List order, do + a. Let method be ? Get(O, name). + b. If IsCallable(method) is true, then + i. Let result be ? Call(method, O). + ii. If Type(result) is not Object, return result. + 6. Throw a TypeError exception. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new Int8Array(1); + var valueOf = 0; + + sample.valueOf = function() { + valueOf++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + new TA([8, sample]); + }, "abrupt completion from ToNumber(sample)"); + + assert.sameValue(valueOf, 1, "valueOf called once"); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-property.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-property.js new file mode 100644 index 000000000..93f85dc98 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-property.js @@ -0,0 +1,38 @@ +// 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-object +description: > + Return abrupt from setting property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + "2": { + valueOf() { + throw new Test262Error(); + } + }, + length: 4 +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-symbol-property.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-symbol-property.js new file mode 100644 index 000000000..42b4a54b8 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-throws-setting-symbol-property.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-object +description: > + Return abrupt from setting property +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 8. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + c. Perform ? Set(O, Pk, kValue, true). + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var obj = { + "2": Symbol("1"), + length: 4 +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(obj); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-undefined-newtarget-throws.js new file mode 100644 index 000000000..36f68493a --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-undefined-newtarget-throws.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA({}); + }); + + assert.throws(TypeError, function() { + TA([]); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-use-custom-proto-if-object.js new file mode 100644 index 000000000..bb5754a9c --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-use-custom-proto-if-object.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-object +description: > + Use prototype from new target if it's an Object +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]], + NewTarget, "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/ctors/object-arg/object-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 000000000..6aba187c2 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/object-arg/object-arg-use-default-proto-if-custom-proto-is-not-object.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-object +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: | + 22.2.4.4 TypedArray ( object ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] + internal slot. + + ... + 3. Let O be ? AllocateTypedArray(TypedArray.[[TypedArrayConstructorName]], + NewTarget, "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +function newTarget() {} +newTarget.prototype = null; +var o = []; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [o], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-custom-proto-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-custom-proto-access-throws.js new file mode 100644 index 000000000..281d09353 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-custom-proto-access-throws.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-typedarray +description: > + Return abrupt completion getting newTarget's prototype +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +var sample = new Int8Array(); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [sample], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js new file mode 100644 index 000000000..8ee2fba54 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-different-type.js @@ -0,0 +1,61 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-typedarray +description: > + When a TypedArray is created from another TypedArray with a different element-type + and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still + executed. +info: | + 22.2.4.3 TypedArray ( typedArray ) + + ... + 16. If IsSharedArrayBuffer(srcData) is false, then + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + 18. If SameValue(elementType, srcType) is true, then + ... + 19. Else, + a. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). + b. If IsDetachedBuffer(srcData) is true, throw a TypeError exception. + ... + + 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength ) + + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", + « [[ArrayBufferData]], [[ArrayBufferByteLength]] »). + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray, Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var speciesCallCount = 0; + var bufferConstructor = Object.defineProperty({}, Symbol.species, { + get: function() { + speciesCallCount += 1; + $DETACHBUFFER(ta.buffer); + return speciesConstructor; + } + }); + + var prototypeCallCount = 0; + var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", { + get: function() { + prototypeCallCount += 1; + return null; + } + }); + + var ta = new TA(0); + ta.buffer.constructor = bufferConstructor; + + assert.throws(TypeError, function() { + var targetType = TA !== Int32Array ? Int32Array : Uint32Array; + new targetType(ta); + }, "TypeError thrown for detached source buffer"); + + assert.sameValue(speciesCallCount, 1, "@@species getter called once"); + assert.sameValue(prototypeCallCount, 1, "prototype getter called once"); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js new file mode 100644 index 000000000..978f42af6 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-detached-when-species-retrieved-same-type.js @@ -0,0 +1,64 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-typedarray +description: > + When a TypedArray is created from another TypedArray with the same element-type + and SpeciesConstructor detaches the source buffer, AllocateArrayBuffer is still + executed. +info: | + 22.2.4.3 TypedArray ( typedArray ) + + ... + 16. If IsSharedArrayBuffer(srcData) is false, then + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + 18. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset, byteLength, bufferConstructor). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset, srcLength, cloneConstructor ) + + ... + 3. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength). + 4. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception. + ... + + 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength ) + + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", + « [[ArrayBufferData]], [[ArrayBufferByteLength]] »). + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray, Symbol.species] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var speciesCallCount = 0; + var bufferConstructor = Object.defineProperty({}, Symbol.species, { + get: function() { + speciesCallCount += 1; + $DETACHBUFFER(ta.buffer); + return speciesConstructor; + } + }); + + var prototypeCallCount = 0; + var speciesConstructor = Object.defineProperty(function(){}.bind(), "prototype", { + get: function() { + prototypeCallCount += 1; + return null; + } + }); + + var ta = new TA(0); + ta.buffer.constructor = bufferConstructor; + + assert.throws(TypeError, function() { + new TA(ta); + }, "TypeError thrown for detached source buffer"); + + assert.sameValue(speciesCallCount, 1, "@@species getter called once"); + assert.sameValue(prototypeCallCount, 1, "prototype getter called once"); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-new-instance-extensibility.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-new-instance-extensibility.js new file mode 100644 index 000000000..d29848bf8 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-new-instance-extensibility.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-typedarray +description: > + The new typedArray instance from a typedArray argument is extensible +info: | + 22.2.4.3 TypedArray ( typedArray ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var typedArraySample1 = new Int8Array(); +var typedArraySample2 = new Int8Array(); +Object.preventExtensions(typedArraySample2); + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA(typedArraySample1); + + assert(Object.isExtensible(sample1), "new instance is extensible"); + + var sample2 = new TA(typedArraySample2); + assert( + Object.isExtensible(sample2), + "new instance does not inherit extensibility from typedarray argument" + ); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.js new file mode 100644 index 000000000..b8976d696 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-access-throws.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-typedarray +description: > + Return abrupt completion from getting typedArray argument's buffer.constructor +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var OtherCtor = TA === Int8Array ? Int16Array : Int8Array; + var sample = new OtherCtor(); + + Object.defineProperty(sample.buffer, "constructor", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js new file mode 100644 index 000000000..03860d1a7 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species-proto-from-ctor-realm.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-typedarray +description: > + Derive the ArrayBuffer prototype from the realm of the species constructor +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). + ... + + 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. + ... + + 9.1.14 GetPrototypeFromConstructor + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + ... +includes: [testTypedArray.js] +features: [cross-realm, Symbol.species, TypedArray] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = C; + + var typedArray = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype + ); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.js new file mode 100644 index 000000000..a510d7806 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-custom-species.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-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). + ... + + 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. + ... + +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + var called = 0; + var custom = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function() { + called++; + }; + + ctor[Symbol.species].prototype = custom; + + var typedArray = new TA(sample); + assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.js new file mode 100644 index 000000000..cfb79f1a9 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-not-object-throws.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-typedarray +description: > + Return abrupt completion from typedArray argument's buffer.constructor's value +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + + sample.buffer.constructor = 1; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = true; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = ""; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = null; + assert.throws(TypeError, function() { + new TA(sample); + }); + + var s = Symbol("1"); + sample.buffer.constructor = s; + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js new file mode 100644 index 000000000..4b0b19aca --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-access-throws.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-typedarray +description: > + Return abrupt from getting typedArray argument's buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + + sample.buffer.constructor = ctor; + Object.defineProperty(ctor, Symbol.species, { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.js new file mode 100644 index 000000000..c485cae13 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-not-ctor-throws.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-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 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] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +var ctor = function() { + throw new Test262Error(); +}; +var m = { m() {} }.m; +ctor[Symbol.species] = m; + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + + sample.buffer.constructor = ctor; + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.js new file mode 100644 index 000000000..96ba9009d --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-null.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-typedarray +description: > + Use default ArrayBuffer constructor on null buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 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 OtherCtor = TA === Int8Array ? Int16Array : Int8Array; + var sample = new OtherCtor(); + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = null; + var typedArray = new TA(sample); + + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is null" + ); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js new file mode 100644 index 000000000..135634646 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-prototype-throws.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + b. Let data be ? AllocateArrayBuffer(bufferConstructor, byteLength). + ... + + 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. + ... + + 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength ) + + ... + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, + "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » ) + ... +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +var sample1 = new Int8Array(); +var sample2 = new Int16Array(); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var ctor = {}; + var called = 0; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function() {called++;}.bind(null); + Object.defineProperty(ctor[Symbol.species], "prototype", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.js new file mode 100644 index 000000000..32e78a37d --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-buffer-ctor-species-undefined.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-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 18. Else, + a. Let bufferConstructor be ? SpeciesConstructor(srcData, %ArrayBuffer%). + ... + + 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 OtherCtor = TA === Int8Array ? Int16Array : Int8Array; + var sample = new OtherCtor(); + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = undefined; + var a = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(a.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is undefined" + ); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js new file mode 100644 index 000000000..411248ffd --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-other-ctor-returns-new-typedarray.js @@ -0,0 +1,28 @@ +// 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-typedarray +description: > + Return abrupt from getting typedArray argument's buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var sample1 = new Int8Array(7); +var sample2 = new Int16Array(7); + +testWithTypedArrayConstructors(function(TA) { + var sample = TA === Int8Array ? sample2 : sample1; + var typedArray = new TA(sample); + + assert.sameValue(typedArray.length, 7); + assert.notSameValue(typedArray, sample); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-proto-from-ctor-realm.js new file mode 100644 index 000000000..6e58746cd --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-proto-from-ctor-realm.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-typedarray +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + [...] + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testTypedArray.js] +features: [cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new TA()], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-returns-new-instance.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-returns-new-instance.js index 128ec4021..357730df5 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-returns-new-instance.js +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-returns-new-instance.js @@ -28,4 +28,4 @@ testWithTypedArrayConstructors(function(TA) { assert.sameValue(typedArray.length, len); assert.sameValue(typedArray.constructor, TA); assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); -}, numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.js new file mode 100644 index 000000000..f8e75d209 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-access-throws.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-typedarray +description: > + Return abrupt completion from getting typedArray argument's buffer.constructor +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + Object.defineProperty(sample.buffer, "constructor", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.js new file mode 100644 index 000000000..43743b956 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom-proto-from-ctor-realm.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-typedarray +description: > + Derive the ArrayBuffer prototype from the realm of the species constructor +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 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. + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength). + ... + + 9.1.14 GetPrototypeFromConstructor + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + ... +includes: [testTypedArray.js] +features: [cross-realm, Symbol.species, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = C; + + var typedArray = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), other.ArrayBuffer.prototype + ); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js new file mode 100644 index 000000000..7ed3aca0d --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-custom.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 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. + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength). + ... +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + var called = 0; + var custom = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function() { + called++; + }; + + ctor[Symbol.species].prototype = custom; + + var typedArray = new TA(sample); + assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom); + assert.sameValue(called, 0); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.js new file mode 100644 index 000000000..2072aa96d --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-not-ctor.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-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 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(); + var ctor = {}; + var m = { m() {} }; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = m; + + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.js new file mode 100644 index 000000000..e42780610 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-null.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-typedarray +description: > + Use default ArrayBuffer constructor on null buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 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(4); + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = null; + var typedArray = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is null" + ); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js new file mode 100644 index 000000000..b171826cf --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-prototype-throws.js @@ -0,0 +1,62 @@ +// 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-typedarray +description: > + Return abrupt from buffer.constructor.@@species.prototype +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + 8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, cloneLength). + ... + + 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. + ... + + 24.1.1.1 AllocateArrayBuffer ( constructor, byteLength ) + + ... + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, + "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] » ) + ... +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = function(){}.bind(null); + Object.defineProperty(ctor[Symbol.species], "prototype", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-throws.js new file mode 100644 index 000000000..ec2aaf3c1 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-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-typedarray +description: > + Return abrupt from getting typedArray argument's buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 5. Let S be ? Get(C, @@species). + ... +includes: [testTypedArray.js] +features: [Symbol.species, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + var ctor = {}; + + sample.buffer.constructor = ctor; + Object.defineProperty(ctor, Symbol.species, { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.js new file mode 100644 index 000000000..339d3041b --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-species-undefined.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-typedarray +description: > + Use default ArrayBuffer constructor on undefined buffer.constructor.@@species +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 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(4); + var ctor = {}; + + sample.buffer.constructor = ctor; + + ctor[Symbol.species] = undefined; + var typedArray = new TA(sample); + assert.sameValue( + Object.getPrototypeOf(typedArray.buffer), + ArrayBuffer.prototype, + "buffer ctor is not called when species is undefined" + ); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-throws.js new file mode 100644 index 000000000..ef9709749 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-buffer-ctor-value-not-obj-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-typedarray +description: > + Return abrupt completion from typedArray argument's buffer.constructor's value +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + + 24.1.1.4 CloneArrayBuffer ( srcBuffer, srcByteOffset [ , cloneConstructor ] ) + + ... + 2. If cloneConstructor is not present, then + a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + ... + 2. Let C be ? Get(O, "constructor"). + ... + 4. If Type(C) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + sample.buffer.constructor = 1; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = true; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = ''; + assert.throws(TypeError, function() { + new TA(sample); + }); + + sample.buffer.constructor = null; + assert.throws(TypeError, function() { + new TA(sample); + }); + + var s = Symbol('1'); + sample.buffer.constructor = s; + assert.throws(TypeError, function() { + new TA(sample); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.js new file mode 100644 index 000000000..4d9b442c9 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-same-ctor-returns-new-cloned-typedarray.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-typedarray +description: > + Same typedArray ctor argument returns a new cloned typedArray +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 17. If SameValue(elementType, srcType) is true, then + a. Let data be ? CloneArrayBuffer(srcData, srcByteOffset). + ... + 23. Return O. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(7); + var typedArray = new TA(sample); + + assert.sameValue(typedArray.length, 7); + assert.notSameValue(typedArray, sample); + assert.notSameValue(typedArray.buffer, sample.buffer); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-undefined-newtarget-throws.js new file mode 100644 index 000000000..12839b2d7 --- /dev/null +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-undefined-newtarget-throws.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-typedarray +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 22.2.4.3 TypedArray ( typedArray ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has a [[TypedArrayName]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(4); + + assert.throws(TypeError, function() { + TA(typedArray); + }); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js index 2745fc5e2..8af612edc 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js @@ -45,4 +45,4 @@ testWithTypedArrayConstructors(function(TA) { assert.sameValue(ta.constructor, Object); assert.sameValue(Object.getPrototypeOf(ta), proto); -}, numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js index ec1997e91..b31bd96e4 100644 --- a/test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js +++ b/test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js @@ -44,4 +44,4 @@ testWithTypedArrayConstructors(function(TA) { assert.sameValue(ta.constructor, TA); assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); -}, numericTypedArrayConstructors); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/arylk-get-length-error.js b/test/built-ins/TypedArrays/from/BigInt/arylk-get-length-error.js new file mode 100644 index 000000000..2a1028aee --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/arylk-get-length-error.js @@ -0,0 +1,28 @@ +// 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%.from +description: Returns error produced by accessing array-like's length +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var arrayLike = {}; + +Object.defineProperty(arrayLike, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/arylk-to-length-error.js b/test/built-ins/TypedArrays/from/BigInt/arylk-to-length-error.js new file mode 100644 index 000000000..d000bac39 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/arylk-to-length-error.js @@ -0,0 +1,28 @@ +// 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%.from +description: Returns error produced by interpreting length property as a length +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. Let len be ? ToLength(? Get(arrayLike, "length")). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var arrayLike = { length: {} }; + +arrayLike.length = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js b/test/built-ins/TypedArrays/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 000000000..0571b9ac5 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Custom constructor needs to instantiate a TypedArray +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 8. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.from.call(ctor, []); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/custom-ctor-returns-other-instance.js b/test/built-ins/TypedArrays/from/BigInt/custom-ctor-returns-other-instance.js new file mode 100644 index 000000000..14f59cfd4 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/custom-ctor-returns-other-instance.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. + +/*--- +es6id: 22.2.2.1 +esid: sec-%typedarray%.from +description: > + Custom constructor can return any TypedArray instance with higher or same + length +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. If usingIterator is not undefined, then + a. Let values be ? IterableToList(source, usingIterator). + b. Let len be the number of elements in values. + c. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + 10. Let len be ? ToLength(? Get(arrayLike, "length")). + 11. Let targetObj be ? TypedArrayCreate(C, « len »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sourceItor = convertToBigInt([1, 2]); + var sourceObj = { + 0: convertToBigInt(0), + 1: convertToBigInt(0), + length: 2 + }; + + var result; + var custom = new TA(2); + var ctor = function() { + return custom; + }; + + result = TypedArray.from.call(ctor, sourceItor); + assert.sameValue(result, custom, "using iterator, same length"); + + result = TypedArray.from.call(ctor, sourceObj); + assert.sameValue(result, custom, "not using iterator, same length"); + + custom = new TA(3); + + result = TypedArray.from.call(ctor, sourceItor); + assert.sameValue(result, custom, "using iterator, higher length"); + + result = TypedArray.from.call(ctor, sourceObj); + assert.sameValue(result, custom, "not using iterator, higher length"); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/custom-ctor-returns-smaller-instance-throws.js b/test/built-ins/TypedArrays/from/BigInt/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 000000000..8c2a128d0 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/custom-ctor-returns-smaller-instance-throws.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. + +/*--- +es6id: 22.2.2.1 +esid: sec-%typedarray%.from +description: > + Throws a TypeError if a custom `this` returns a smaller instance +info: | + %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 7. If usingIterator is not undefined, then + a. Let values be ? IterableToList(source, usingIterator). + b. Let len be the number of elements in values. + c. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + 10. Let len be ? ToLength(? Get(arrayLike, "length")). + 11. Let targetObj be ? TypedArrayCreate(C, « len »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var sourceItor = [1, 2]; +var sourceObj = { + length: 2 +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ctor = function() { + return new TA(1); + }; + assert.throws(TypeError, function() { + TA.from.call(ctor, sourceItor); + }, "source is using iterator"); + + assert.throws(TypeError, function() { + TA.from.call(ctor, sourceObj); + }, "source is not using iterator"); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/custom-ctor.js b/test/built-ins/TypedArrays/from/BigInt/custom-ctor.js new file mode 100644 index 000000000..1b98c27cf --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/custom-ctor.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%.from +description: > + Calls and return abrupt completion from custom constructor +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 8. Let targetObj be ? TypedArrayCreate(C, «len»). + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + var ctor = function() { + called++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + TA.from.call(ctor, []); + }); + + assert.sameValue(called, 1); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/inherited.js b/test/built-ins/TypedArrays/from/BigInt/inherited.js new file mode 100644 index 000000000..08c921147 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/inherited.js @@ -0,0 +1,25 @@ +// 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%.from +description: > + `from` is %TypedArray%.from +info: | + 22.2.1 The %TypedArray% Intrinsic Object + + The %TypedArray% intrinsic object is a constructor function object that all of + the TypedArray constructor object inherit from. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue( + TA.from, TypedArray.from, + "method is inherited %TypedArray%.from" + ); + assert.sameValue( + TA.hasOwnProperty("from"), false, + "constructor does not define an own property named 'from'" + ); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/invoked-as-func.js b/test/built-ins/TypedArrays/from/BigInt/invoked-as-func.js new file mode 100644 index 000000000..b602a99fa --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/invoked-as-func.js @@ -0,0 +1,23 @@ +// 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%.from +description: > + "from" cannot be invoked as a function +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 1. Let C be the this value. + 2. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var from = TA.from; + + assert.throws(TypeError, function() { + from([]); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/iter-access-error.js b/test/built-ins/TypedArrays/from/BigInt/iter-access-error.js new file mode 100644 index 000000000..21090c3db --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/iter-access-error.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%.from +description: Returns error produced by accessing @@iterator +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. Let arrayLike be ? IterableToArrayLike(source). + ... + + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 1. Let usingIterator be ? GetMethod(items, @@iterator). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/iter-invoke-error.js b/test/built-ins/TypedArrays/from/BigInt/iter-invoke-error.js new file mode 100644 index 000000000..552a6d728 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/iter-invoke-error.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%.from +description: Returns error produced by invoking @@iterator +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 6. Let arrayLike be ? IterableToArrayLike(source). + ... + + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 1. Let usingIterator be ? GetMethod(items, @@iterator). + 2. If usingIterator is not undefined, then + a. Let iterator be ? GetIterator(items, usingIterator). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/iter-next-error.js b/test/built-ins/TypedArrays/from/BigInt/iter-next-error.js new file mode 100644 index 000000000..836da920c --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/iter-next-error.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%.from +description: Returns error produced by advancing the iterator +info: | + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 2. If usingIterator is not undefined, then + ... + d. Repeat, while next is not false + i. Let next be ? IteratorStep(iterator). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/iter-next-value-error.js b/test/built-ins/TypedArrays/from/BigInt/iter-next-value-error.js new file mode 100644 index 000000000..08936b4e1 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/iter-next-value-error.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%.from +description: Returns error produced by accessing iterated value +info: | + 22.2.2.1.1 Runtime Semantics: IterableToArrayLike( items ) + + 2. If usingIterator is not undefined, then + ... + d. Repeat, while next is not false + ... + ii. If next is not false, then + 1. Let nextValue be ? IteratorValue(next). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + var result = {}; + Object.defineProperty(result, 'value', { + get: function() { + throw new Test262Error(); + } + }); + + return result; + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/mapfn-abrupt-completion.js b/test/built-ins/TypedArrays/from/BigInt/mapfn-abrupt-completion.js new file mode 100644 index 000000000..4efbf68fa --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/mapfn-abrupt-completion.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%.from +description: > + Return abrupt from mapfn +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = { + "0": 42, + length: 2 +}; +var mapfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/mapfn-arguments.js b/test/built-ins/TypedArrays/from/BigInt/mapfn-arguments.js new file mode 100644 index 000000000..a84021d47 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/mapfn-arguments.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%.from +description: > + Assert mapfn arguments +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43, 44]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(kValue, k) { + results.push({ + kValue: kValue, + k: k, + argsLength: arguments.length + }); + return convertToBigInt(0); + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 3); + + assert.sameValue(results[0].kValue, 42); + assert.sameValue(results[0].k, 0); + assert.sameValue(results[0].argsLength, 2); + + assert.sameValue(results[1].kValue, 43); + assert.sameValue(results[1].k, 1); + assert.sameValue(results[1].argsLength, 2); + + assert.sameValue(results[2].kValue, 44); + assert.sameValue(results[2].k, 2); + assert.sameValue(results[2].argsLength, 2); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/mapfn-is-not-callable.js b/test/built-ins/TypedArrays/from/BigInt/mapfn-is-not-callable.js new file mode 100644 index 000000000..36565b495 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/mapfn-is-not-callable.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: Throw a TypeError exception is mapfn is not callable +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 3. If mapfn was supplied and mapfn is not undefined, then + a. If IsCallable(mapfn) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, Symbol.iterator, TypedArray] +---*/ + +var getIterator = 0; +var arrayLike = {}; +Object.defineProperty(arrayLike, Symbol.iterator, { + get: function() { + getIterator++; + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from(arrayLike, null); + }, "mapfn is null"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, 42); + }, "mapfn is a number"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, ""); + }, "mapfn is a string"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, {}); + }, "mapfn is an ordinary object"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, []); + }, "mapfn is an array"); + + assert.throws(TypeError, function() { + TA.from(arrayLike, true); + }, "mapfn is a boolean"); + + var s = Symbol("1"); + assert.throws(TypeError, function() { + TA.from(arrayLike, s); + }, "mapfn is a symbol"); + + assert.sameValue( + getIterator, 0, + "IsCallable(mapfn) check occurs before getting source[@@iterator]" + ); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/mapfn-this-with-thisarg.js b/test/built-ins/TypedArrays/from/BigInt/mapfn-this-with-thisarg.js new file mode 100644 index 000000000..b748126af --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/mapfn-this-with-thisarg.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%.from +description: > + Assert mapfn `this` with thisArg +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43]; +var thisArg = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + return convertToBigInt(0); + }; + + TA.from(source, mapfn, thisArg); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], thisArg); + assert.sameValue(results[1], thisArg); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/mapfn-this-without-thisarg-non-strict.js b/test/built-ins/TypedArrays/from/BigInt/mapfn-this-without-thisarg-non-strict.js new file mode 100644 index 000000000..b16d6f9cc --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/mapfn-this-without-thisarg-non-strict.js @@ -0,0 +1,38 @@ +// 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%.from +description: > + Assert mapfn `this` without thisArg +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +flags: [noStrict] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43]; +var global = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(x) { + results.push(this); + return convertToBigInt(x); + }; + + TA.from(convertToBigInt(source), mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], global); + assert.sameValue(results[1], global); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/mapfn-this-without-thisarg-strict.js b/test/built-ins/TypedArrays/from/BigInt/mapfn-this-without-thisarg-strict.js new file mode 100644 index 000000000..9b575c2a9 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/mapfn-this-without-thisarg-strict.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%.from +description: > + Assert mapfn `this` without thisArg +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + ... +includes: [testBigIntTypedArray.js] +flags: [onlyStrict] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + return convertToBigInt(0); + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], undefined); + assert.sameValue(results[1], undefined); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/nan-conversion.js b/test/built-ins/TypedArrays/from/BigInt/nan-conversion.js new file mode 100644 index 000000000..a318c055a --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/nan-conversion.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%.from +description: > + Test NaN conversions +info: | + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([NaN, undefined]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], NaN); + assert.sameValue(result[1], NaN); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([NaN, undefined]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 0); + assert.sameValue(result[1], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int8Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]);
\ No newline at end of file diff --git a/test/built-ins/TypedArrays/from/BigInt/new-instance-empty.js b/test/built-ins/TypedArrays/from/BigInt/new-instance-empty.js new file mode 100644 index 000000000..e0cee67e2 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/new-instance-empty.js @@ -0,0 +1,17 @@ +// 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%.from +description: > + Return a new empty TypedArray +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([]); + assert.sameValue(result.length, 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/new-instance-from-ordinary-object.js b/test/built-ins/TypedArrays/from/BigInt/new-instance-from-ordinary-object.js new file mode 100644 index 000000000..22eff2856 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/new-instance-from-ordinary-object.js @@ -0,0 +1,53 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return a new TypedArray from an ordinary object +includes: [testBigIntTypedArray.js] +features: [BigInt, Array.prototype.values, TypedArray] +---*/ + +var source = { + "0": 42, + "2": 44, + length: 4 +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 4); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], NaN); + assert.sameValue(result[2], 44); + assert.sameValue(result[3], NaN); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 4); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 0); + assert.sameValue(result[2], 44); + assert.sameValue(result[3], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int8Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]); diff --git a/test/built-ins/TypedArrays/from/BigInt/new-instance-from-sparse-array.js b/test/built-ins/TypedArrays/from/BigInt/new-instance-from-sparse-array.js new file mode 100644 index 000000000..361edb9d6 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/new-instance-from-sparse-array.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%.from +description: > + Return a new TypedArray from a sparse array +includes: [testBigIntTypedArray.js] +features: [BigInt, Array.prototype.values, TypedArray] +---*/ + +var source = [,,42,,44,,]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 6); + assert.sameValue(result[0], NaN); + assert.sameValue(result[1], NaN); + assert.sameValue(result[2], 42); + assert.sameValue(result[3], NaN); + assert.sameValue(result[4], 44); + assert.sameValue(result[5], NaN); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 6); + assert.sameValue(result[0], 0); + assert.sameValue(result[1], 0); + assert.sameValue(result[2], 42); + assert.sameValue(result[3], 0); + assert.sameValue(result[4], 44); + assert.sameValue(result[5], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int8Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]); diff --git a/test/built-ins/TypedArrays/from/BigInt/new-instance-from-zero.js b/test/built-ins/TypedArrays/from/BigInt/new-instance-from-zero.js new file mode 100644 index 000000000..cbca4484d --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/new-instance-from-zero.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%.from +description: > + Return a new TypedArray using -0 and +0 +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([-0, +0]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], -0, "-0 => -0"); + assert.sameValue(result[1], 0, "+0 => 0"); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([-0, +0]); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 0, "-0 => 0"); + assert.sameValue(result[1], 0, "+0 => 0"); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int16Array, + Int32Array, + Int8Array, + Uint16Array, + Uint32Array, + Uint8Array, + Uint8ClampedArray +]);
\ No newline at end of file diff --git a/test/built-ins/TypedArrays/from/BigInt/new-instance-using-custom-ctor.js b/test/built-ins/TypedArrays/from/BigInt/new-instance-using-custom-ctor.js new file mode 100644 index 000000000..7e6bc6169 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/new-instance-using-custom-ctor.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return a new TypedArray using a custom Constructor +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + + var ctor = function(len) { + assert.sameValue(arguments.length, 1); + called++; + return new TA(len); + }; + + var result = TA.from.call(ctor, convertToBigInt(source)); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], convertToBigInt(42)); + assert.sameValue(result[1], convertToBigInt(43)); + assert.sameValue(result[2], convertToBigInt(42)); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); + assert.sameValue(called, 1); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/new-instance-with-mapfn.js b/test/built-ins/TypedArrays/from/BigInt/new-instance-with-mapfn.js new file mode 100644 index 000000000..48ee4d285 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/new-instance-with-mapfn.js @@ -0,0 +1,25 @@ +// 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%.from +description: > + Return a new TypedArray using mapfn +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var mapfn = function(kValue) { + return convertToBigInt(kValue * 2); + }; + + var result = TA.from(source, mapfn); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], convertToBigInt(84)); + assert.sameValue(result[1], convertToBigInt(86)); + assert.sameValue(result[2], convertToBigInt(84)); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/new-instance-without-mapfn.js b/test/built-ins/TypedArrays/from/BigInt/new-instance-without-mapfn.js new file mode 100644 index 000000000..af95e8015 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/new-instance-without-mapfn.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%.from +description: > + Return a new TypedArray +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from(convertToBigInt(source)); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], convertToBigInt(42)); + assert.sameValue(result[1], convertToBigInt(43)); + assert.sameValue(result[2], convertToBigInt(42)); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/property-abrupt-completion.js b/test/built-ins/TypedArrays/from/BigInt/property-abrupt-completion.js new file mode 100644 index 000000000..a3bd8b446 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/property-abrupt-completion.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%.from +description: > + Return abrupt from source property +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + b. Let kValue be ? Get(arrayLike, Pk). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = { + length: 2 +}; +Object.defineProperty(source, "0", { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/set-value-abrupt-completion.js b/test/built-ins/TypedArrays/from/BigInt/set-value-abrupt-completion.js new file mode 100644 index 000000000..34ee679a5 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/set-value-abrupt-completion.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.from +description: > + Return abrupt from setting a value on the new typedarray +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + ... + 10. Repeat, while k < len + ... + c. If mapping is true, then + i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + d. Else, let mappedValue be kValue. + e. Perform ? Set(targetObj, Pk, mappedValue, true). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var source = [convertToBigInt(42), obj, convertToBigInt(1)]; + var lastValue; + var mapfn = function(kValue) { + lastValue = kValue; + return kValue; + }; + + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); + + assert.sameValue(lastValue, obj, "interrupted source iteration"); + + assert.throws(Test262Error, function() { + TA.from(source); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/source-value-is-symbol-throws.js b/test/built-ins/TypedArrays/from/BigInt/source-value-is-symbol-throws.js new file mode 100644 index 000000000..cebc1b114 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/source-value-is-symbol-throws.js @@ -0,0 +1,23 @@ +// 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%.from +description: > + Throws a TypeError if argument is a Symbol +info: | + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from([s]); + }); +}); diff --git a/test/built-ins/TypedArrays/from/BigInt/this-is-not-constructor.js b/test/built-ins/TypedArrays/from/BigInt/this-is-not-constructor.js new file mode 100644 index 000000000..711f054a5 --- /dev/null +++ b/test/built-ins/TypedArrays/from/BigInt/this-is-not-constructor.js @@ -0,0 +1,23 @@ +// 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%.from +description: > + Throws a TypeError exception if this is not a constructor +info: | + 22.2.2.1 %TypedArray%.from ( source [ , mapfn [ , thisArg ] ] ) + + 1. Let C be the this value. + 2. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var m = { m() {} }.m; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from.call(m, []); + }); +}); diff --git a/test/built-ins/TypedArrays/from/custom-ctor-returns-other-instance.js b/test/built-ins/TypedArrays/from/custom-ctor-returns-other-instance.js index b59bf2297..8a0117682 100644 --- a/test/built-ins/TypedArrays/from/custom-ctor-returns-other-instance.js +++ b/test/built-ins/TypedArrays/from/custom-ctor-returns-other-instance.js @@ -23,14 +23,12 @@ includes: [testTypedArray.js] features: [Symbol.iterator, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sourceItor = N([1, 2]); - var sourceObj = { - 0: N(0), - 1: N(0), - length: 2 - }; +var sourceItor = [1, 2]; +var sourceObj = { + length: 2 +}; +testWithTypedArrayConstructors(function(TA) { var result; var custom = new TA(2); var ctor = function() { diff --git a/test/built-ins/TypedArrays/from/mapfn-arguments.js b/test/built-ins/TypedArrays/from/mapfn-arguments.js index 65150c85b..6d102d1b6 100644 --- a/test/built-ins/TypedArrays/from/mapfn-arguments.js +++ b/test/built-ins/TypedArrays/from/mapfn-arguments.js @@ -19,7 +19,7 @@ features: [TypedArray] var source = [42, 43, 44]; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var results = []; var mapfn = function(kValue, k) { results.push({ @@ -27,7 +27,6 @@ testWithTypedArrayConstructors(function(TA, N) { k: k, argsLength: arguments.length }); - return N(0); }; TA.from(source, mapfn); diff --git a/test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js b/test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js index 2df9a0efc..2fb965d08 100644 --- a/test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js +++ b/test/built-ins/TypedArrays/from/mapfn-this-with-thisarg.js @@ -22,11 +22,10 @@ features: [TypedArray] var source = [42, 43]; var thisArg = {}; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var results = []; var mapfn = function() { results.push(this); - return N(0); }; TA.from(source, mapfn, thisArg); diff --git a/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-non-strict.js b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-non-strict.js index e136207a3..02eeaba11 100644 --- a/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-non-strict.js +++ b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-non-strict.js @@ -23,14 +23,13 @@ features: [TypedArray] var source = [42, 43]; var global = this; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var results = []; - var mapfn = function(x) { + var mapfn = function() { results.push(this); - return N(x); }; - TA.from(N(source), mapfn); + TA.from(source, mapfn); assert.sameValue(results.length, 2); assert.sameValue(results[0], global); diff --git a/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-strict.js b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-strict.js index ca2968c7a..61612fa35 100644 --- a/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-strict.js +++ b/test/built-ins/TypedArrays/from/mapfn-this-without-thisarg-strict.js @@ -22,11 +22,10 @@ features: [TypedArray] var source = [42, 43]; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var results = []; var mapfn = function() { results.push(this); - return N(0); }; TA.from(source, mapfn); diff --git a/test/built-ins/TypedArrays/from/new-instance-using-custom-ctor.js b/test/built-ins/TypedArrays/from/new-instance-using-custom-ctor.js index bf8c34acf..2fe53a328 100644 --- a/test/built-ins/TypedArrays/from/new-instance-using-custom-ctor.js +++ b/test/built-ins/TypedArrays/from/new-instance-using-custom-ctor.js @@ -10,7 +10,7 @@ features: [TypedArray] var source = [42, 43, 42]; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var called = 0; var ctor = function(len) { @@ -19,11 +19,11 @@ testWithTypedArrayConstructors(function(TA, N) { return new TA(len); }; - var result = TA.from.call(ctor, N(source)); + var result = TA.from.call(ctor, source); assert.sameValue(result.length, 3); - assert.sameValue(result[0], N(42)); - assert.sameValue(result[1], N(43)); - assert.sameValue(result[2], N(42)); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 42); assert.sameValue(result.constructor, TA); assert.sameValue(Object.getPrototypeOf(result), TA.prototype); assert.sameValue(called, 1); diff --git a/test/built-ins/TypedArrays/from/new-instance-with-mapfn.js b/test/built-ins/TypedArrays/from/new-instance-with-mapfn.js index 66536c623..ab8da0b98 100644 --- a/test/built-ins/TypedArrays/from/new-instance-with-mapfn.js +++ b/test/built-ins/TypedArrays/from/new-instance-with-mapfn.js @@ -10,16 +10,16 @@ features: [TypedArray] var source = [42, 43, 42]; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var mapfn = function(kValue) { - return N(kValue * 2); + return kValue * 2; }; var result = TA.from(source, mapfn); assert.sameValue(result.length, 3); - assert.sameValue(result[0], N(84)); - assert.sameValue(result[1], N(86)); - assert.sameValue(result[2], N(84)); + assert.sameValue(result[0], 84); + assert.sameValue(result[1], 86); + assert.sameValue(result[2], 84); assert.sameValue(result.constructor, TA); assert.sameValue(Object.getPrototypeOf(result), TA.prototype); }); diff --git a/test/built-ins/TypedArrays/from/new-instance-without-mapfn.js b/test/built-ins/TypedArrays/from/new-instance-without-mapfn.js index ebedc93c8..d7ac6abc2 100644 --- a/test/built-ins/TypedArrays/from/new-instance-without-mapfn.js +++ b/test/built-ins/TypedArrays/from/new-instance-without-mapfn.js @@ -10,12 +10,12 @@ features: [TypedArray] var source = [42, 43, 42]; -testWithTypedArrayConstructors(function(TA, N) { - var result = TA.from(N(source)); +testWithTypedArrayConstructors(function(TA) { + var result = TA.from(source); assert.sameValue(result.length, 3); - assert.sameValue(result[0], N(42)); - assert.sameValue(result[1], N(43)); - assert.sameValue(result[2], N(42)); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 42); assert.sameValue(result.constructor, TA); assert.sameValue(Object.getPrototypeOf(result), TA.prototype); }); diff --git a/test/built-ins/TypedArrays/from/set-value-abrupt-completion.js b/test/built-ins/TypedArrays/from/set-value-abrupt-completion.js index efae38c90..ddde226a2 100644 --- a/test/built-ins/TypedArrays/from/set-value-abrupt-completion.js +++ b/test/built-ins/TypedArrays/from/set-value-abrupt-completion.js @@ -25,8 +25,9 @@ var obj = { } }; -testWithTypedArrayConstructors(function(TA, N) { - var source = [N(42), obj, N(1)]; +var source = [42, obj, 1]; + +testWithTypedArrayConstructors(function(TA) { var lastValue; var mapfn = function(kValue) { lastValue = kValue; diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/conversion-operation.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/conversion-operation.js new file mode 100644 index 000000000..9286ba6f5 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/conversion-operation.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Verify conversion after defining value +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + + ... + 3. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testBigIntTypedArray.js] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + Object.defineProperty(sample, "0", {value: value}); + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/desc-value-throws.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/desc-value-throws.js new file mode 100644 index 000000000..016d41b63 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/desc-value-throws.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Return abrupt from the evaluation of ToNumber(desc.value) +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + assert.throws(Test262Error, function() { + Object.defineProperty(sample, "0", {value: obj}); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..3fa462103 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer-realm.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws a TypeError if object has valid numeric index and a detached buffer + (honoring the Realm of the current execution context) +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var desc = { + value: 0, + configurable: false, + enumerable: true, + writable: true +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.defineProperty(sample, '0', desc); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 000000000..f20176156 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/detached-buffer.js @@ -0,0 +1,134 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Throws a TypeError if object has valid numeric index and a detached buffer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var desc = { + value: 0, + configurable: false, + enumerable: true, + writable: true +}; + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.defineProperty(sample, "0", desc); + }, "Throws TypeError on valid numeric index if instance has a detached buffer"); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", desc), + false, + "Return false before Detached Buffer check when value is a negative number" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", desc), + false, + "Return false before Detached Buffer check when value is not an integer" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", desc), + false, + "Return false before Detached Buffer check when value is -0" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + configurable: true, + enumerable: true, + writable: true, + value: obj + }), + false, + "Return false before Detached Buffer check when desc configurable is true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + configurable: false, + enumerable: false, + writable: true, + value: obj + }), + false, + "Return false before Detached Buffer check when desc enumerable is false" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "4", { + writable: false, + configurable: false, + enumerable: true, + value: obj + }), + false, + "Return false before Detached Buffer check when desc writable is false" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "42", desc), + false, + "Return false before Detached Buffer check when key == [[ArrayLength]]" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "43", desc), + false, + "Return false before Detached Buffer check when key > [[ArrayLength]]" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "5", { + get: function() {} + }), + false, + "Return false before Detached Buffer check with accessor descriptor" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "6", { + configurable: false, + enumerable: true, + writable: true + }), + true, + "Return true before Detached Buffer check when desc value is not present" + ); + + assert.throws(Test262Error, function() { + Reflect.defineProperty(sample, "7", {value: obj}); + }, "Return Abrupt before Detached Buffer check from ToNumber(desc.value)"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 000000000..d48eb4afb --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is >= [[ArrayLength]] +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + ... + v. Let length be the value of O's [[ArrayLength]] internal slot. + vi. If intIndex ≥ length, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex == length" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex > length" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 000000000..faaf037c3 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is < 0 +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ii. Let intIndex be numericIndex. + iv. If intIndex < 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-1" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..2c838c345 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-minus-zero.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is "-0" +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ii. Let intIndex be numericIndex. + iii. If intIndex = -0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "defineProperty returns false" + ); + assert.sameValue(sample[0], convertToBigInt(0), "does not change the value for [0]"); + assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..c87d89cf9 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,98 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Sets an ordinary property value if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +var fnset = function() {}; +var fnget = function() {}; + +var acDesc = { + get: fnget, + set: fnset, + enumerable: true, + configurable: false +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var dataDesc = { + value: convertToBigInt(42), + writable: true, + configurable: true + }; + + var sample1 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample1, key, dataDesc), + true, + "return true after defining data property [" + key + "]" + ); + + assert.sameValue(sample1[key], convertToBigInt(42), "value is set to [" + key + "]"); + verifyNotEnumerable(sample1, key); + verifyWritable(sample1, key); + verifyConfigurable(sample1, key); + + assert.sameValue(sample1[0], undefined, "no value is set on sample1[0]"); + assert.sameValue(sample1.length, 0, "length is still 0"); + + var sample2 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample2, key, acDesc), + true, + "return true after defining accessors property [" + key + "]" + ); + + var desc = Object.getOwnPropertyDescriptor(sample2, key); + verifyEnumerable(sample2, key); + assert.sameValue(desc.get, fnget, "accessor's get [" + key + "]"); + assert.sameValue(desc.set, fnset, "accessor's set [" + key + "]"); + verifyNotConfigurable(sample2, key); + + assert.sameValue(sample2[0], undefined,"no value is set on sample2[0]"); + assert.sameValue(sample2.length, 0, "length is still 0"); + + var sample3 = new TA(); + Object.preventExtensions(sample3); + + assert.sameValue( + Reflect.defineProperty(sample3, key, dataDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample3, key), undefined); + + var sample4 = new TA(); + Object.preventExtensions(sample4); + + assert.sameValue( + Reflect.defineProperty(sample4, key, acDesc), + false, + "return false defining property on a non-extensible sample" + ); + assert.sameValue(Object.getOwnPropertyDescriptor(sample4, key), undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..0d3d3cc79 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-integer.js @@ -0,0 +1,124 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if numericIndex is not an integer +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. If IsInteger(numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0.1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.1" + ); + assert.sameValue(sample[0], convertToBigInt(0), "'0.1' - does not change the value for [0]"); + assert.sameValue( + sample["0.1"], + undefined, + "'0.1' - does not define a value for ['0.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "0.000001", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.000001" + ); + assert.sameValue( + sample[0], convertToBigInt(0), + "'0.000001' - does not change the value for [0]" + ); + assert.sameValue( + sample["0.000001"], + undefined, + "'0.000001' - does not define a value for ['0.000001']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "1.1" + ); + assert.sameValue(sample[1], convertToBigInt(0), "'1.1' - does not change the value for [1]"); + assert.sameValue( + sample["1.1"], + undefined, + "'1.1' - does not define a value for ['1.1']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "Infinity", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "Infinity" + ); + assert.sameValue( + sample[0], convertToBigInt(0), + "'Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], convertToBigInt(0), + "'Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["Infinity"], + undefined, + "'Infinity' - does not define a value for ['Infinity']" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-Infinity", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-Infinity" + ); + assert.sameValue( + sample[0], convertToBigInt(0), + "'-Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], convertToBigInt(0), + "'-Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["-Infinity"], + undefined, + "'-Infinity' - does not define a value for ['-Infinity']" + ); + +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..8f262daeb --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "return true after defining property" + ); + + assert.sameValue(sample.foo, 42); + verifyNotWritable(sample, "foo"); + verifyNotConfigurable(sample, "foo"); + verifyNotEnumerable(sample, "foo"); + + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyConfigurable(sample, "bar"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js new file mode 100644 index 000000000..21ab9cfc3 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js @@ -0,0 +1,58 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Descriptor is an + AccessorDescriptor +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + vii. If IsAccessorDescriptor(Desc) is true, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get accessor" + ); + assert.sameValue(sample[0], convertToBigInt(0), "get accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + enumerable: true + }), + false, + "set accessor" + ); + assert.sameValue(sample[0], convertToBigInt(0), "set accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + get: function() { + return 42; + }, + enumerable: true + }), + false, + "get and set accessors" + ); + assert.sameValue(sample[0], convertToBigInt(0), "get and set accessors - side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js new file mode 100644 index 000000000..f928a3f93 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Configurable]] is true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + viii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is + true, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: true, + enumerable: true, + writable: true + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], convertToBigInt(0), "side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js new file mode 100644 index 000000000..79a56222a --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Enumerable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + ix. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is + false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: false, + enumerable: false, + writable: true + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], convertToBigInt(0), "side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js new file mode 100644 index 000000000..6f6483b90 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false if key is a numeric index and Desc.[[Writable]] is false +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, + return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: false, + enumerable: true, + writable: false + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], convertToBigInt(0), "side effect check"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex.js new file mode 100644 index 000000000..5f994cd86 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-numericindex.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns true after setting a valid numeric index key +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, + return false. + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 42])); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: convertToBigInt(8), + configurable: false, + enumerable: true, + writable: true + }), + true + ); + + assert.sameValue(sample[0], convertToBigInt(8), "property value was set"); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + + assert.sameValue(desc.value, convertToBigInt(8), "desc.value"); + assert.sameValue(desc.writable, true, "property is writable"); + + verifyEnumerable(sample, "0"); + verifyNotConfigurable(sample, "0"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 000000000..467e89a93 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/key-is-symbol.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Define an ordinary property value if key is a Symbol +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + var s1 = Symbol("foo"); + assert.sameValue( + Reflect.defineProperty(sample, s1, { + value: 42, + configurable: true + }), + true, + "return true after defining property" + ); + + assert.sameValue(sample[s1], 42); + verifyNotWritable(sample, s1); + verifyNotEnumerable(sample, s1); + verifyConfigurable(sample, s1); + + var s2 = Symbol("bar"); + var fnset = function() {}; + var fnget = function() {}; + assert.sameValue( + Reflect.defineProperty(sample, s2, { + get: fnget, + set: fnset, + enumerable: true + }), + true, + "return true after defining property" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, s2); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + assert.sameValue(desc.enumerable, true); + verifyNotConfigurable(sample, s2); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js new file mode 100644 index 000000000..5357f3bc0 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-new-key.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Can't define a new non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + false, + "return false on a non-extensible object - data descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "foo"), undefined); + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: function() {}, + set: function() {}, + enumerable: false, + configurable: true + }), + false, + "return false on a non-extensible object - accessor descriptor" + ); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "bar"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js new file mode 100644 index 000000000..eb6e41027 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js @@ -0,0 +1,57 @@ +// 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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Redefine a non-numerical key on a non-extensible instance +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + sample.foo = true; + sample.bar = true; + + Object.preventExtensions(sample); + + assert.sameValue( + Reflect.defineProperty(sample, "foo", {value:42}), + true, + "data descriptor" + ); + + assert.sameValue(sample.foo, 42); + verifyEnumerable(sample, "foo"); + verifyWritable(sample, "foo"); + verifyConfigurable(sample, "foo"); + + var fnget = function() {}; + var fnset = function() {}; + + assert.sameValue( + Reflect.defineProperty(sample, "bar", { + get: fnget, + set: fnset, + enumerable: false, + configurable: false + }), + true, + "accessor descriptor" + ); + + var desc = Object.getOwnPropertyDescriptor(sample, "bar"); + assert.sameValue(desc.get, fnget, "accessor's get"); + assert.sameValue(desc.set, fnset, "accessor's set"); + verifyNotEnumerable(sample, "bar"); + verifyNotConfigurable(sample, "bar"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/set-value.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/set-value.js new file mode 100644 index 000000000..f17b06837 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/set-value.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Set the value and return true +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + xi. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, intIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([0, 0])); + + assert.sameValue( + Reflect.defineProperty(sample, "0", {value: convertToBigInt(1)}), + true, + "set value for sample[0] returns true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1", {value: convertToBigInt(2)}), + true, + "set value for sample[1] returns true" + ); + + assert.sameValue(sample[0], convertToBigInt(1), "sample[0]"); + assert.sameValue(sample[1], convertToBigInt(2), "sample[1]"); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js new file mode 100644 index 000000000..04664a126 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/this-is-not-extensible.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-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Returns false for non-numeric index property value if `this` is not extensible +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryDefineOwnProperty(O, P, Desc). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + Object.preventExtensions(sample); + + assert.sameValue(Reflect.defineProperty(sample, "foo", {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, "foo"), undefined); + + var s = Symbol("1"); + assert.sameValue(Reflect.defineProperty(sample, s, {value:42}), false); + assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, s), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 000000000..26eb3526b --- /dev/null +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,55 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc +description: > + Defining a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, should + throw a TypeError and not modify the typed array. +info: | + 9.4.5.3 [[DefineOwnProperty]] ( P, Desc ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + x. If Desc has a [[Value]] field, then + 1. Let value be Desc.[[Value]]. + 2. Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA([17]); + + var desc = + { + value: { + valueOf: function() { + $262.detachArrayBuffer(ta.buffer); + return 42; + } + } + }; + + assert.throws(TypeError, function() { + Reflect.defineProperty(ta, 0, desc); + }, + "detaching a ArrayBuffer during defining an element of a typed array " + + "viewing it should throw"); + + assert.throws(TypeError, function() { + ta[0]; + }); +}); + diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/desc-value-throws.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/desc-value-throws.js index ba658f221..6572c1f94 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/desc-value-throws.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/desc-value-throws.js @@ -31,8 +31,8 @@ var obj = { } }; -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); assert.throws(Test262Error, function() { Object.defineProperty(sample, "0", {value: obj}); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-greater-than-last-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-greater-than-last-index.js index 4cc13c6f5..afb5672b9 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-greater-than-last-index.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-greater-than-last-index.js @@ -20,8 +20,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue( Reflect.defineProperty(sample, "2", { diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-lower-than-zero.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-lower-than-zero.js index 3c63a0ab7..ba21aec9c 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-lower-than-zero.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-lower-than-zero.js @@ -18,8 +18,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue( Reflect.defineProperty(sample, "-1", { diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-minus-zero.js index 207344f83..c891f5cc1 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-minus-zero.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-minus-zero.js @@ -18,7 +18,7 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new TA(2); assert.sameValue( @@ -31,6 +31,6 @@ testWithTypedArrayConstructors(function(TA, N) { false, "defineProperty returns false" ); - assert.sameValue(sample[0], N(0), "does not change the value for [0]"); + assert.sameValue(sample[0], 0, "does not change the value for [0]"); assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']"); }); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-canonical-index.js index 33511ca7b..193d91665 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-canonical-index.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-canonical-index.js @@ -24,6 +24,12 @@ var keys = [ "0.0000001" ]; +var dataDesc = { + value: 42, + writable: true, + configurable: true +}; + var fnset = function() {}; var fnget = function() {}; @@ -34,14 +40,8 @@ var acDesc = { configurable: false }; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { keys.forEach(function(key) { - var dataDesc = { - value: N(42), - writable: true, - configurable: true - }; - var sample1 = new TA(); assert.sameValue( @@ -50,7 +50,7 @@ testWithTypedArrayConstructors(function(TA, N) { "return true after defining data property [" + key + "]" ); - assert.sameValue(sample1[key], N(42), "value is set to [" + key + "]"); + assert.sameValue(sample1[key], 42, "value is set to [" + key + "]"); verifyNotEnumerable(sample1, key); verifyWritable(sample1, key); verifyConfigurable(sample1, key); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-integer.js index 4232ab638..b30fc17ec 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-integer.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-integer.js @@ -16,7 +16,7 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new TA(2); assert.sameValue( @@ -29,7 +29,7 @@ testWithTypedArrayConstructors(function(TA, N) { false, "0.1" ); - assert.sameValue(sample[0], N(0), "'0.1' - does not change the value for [0]"); + assert.sameValue(sample[0], 0, "'0.1' - does not change the value for [0]"); assert.sameValue( sample["0.1"], undefined, @@ -47,7 +47,7 @@ testWithTypedArrayConstructors(function(TA, N) { "0.000001" ); assert.sameValue( - sample[0], N(0), + sample[0], 0, "'0.000001' - does not change the value for [0]" ); assert.sameValue( @@ -66,7 +66,7 @@ testWithTypedArrayConstructors(function(TA, N) { false, "1.1" ); - assert.sameValue(sample[1], N(0), "'1.1' - does not change the value for [1]"); + assert.sameValue(sample[1], 0, "'1.1' - does not change the value for [1]"); assert.sameValue( sample["1.1"], undefined, @@ -84,11 +84,11 @@ testWithTypedArrayConstructors(function(TA, N) { "Infinity" ); assert.sameValue( - sample[0], N(0), + sample[0], 0, "'Infinity' - does not change the value for [0]" ); assert.sameValue( - sample[1], N(0), + sample[1], 0, "'Infinity' - does not change the value for [1]" ); assert.sameValue( @@ -108,11 +108,11 @@ testWithTypedArrayConstructors(function(TA, N) { "-Infinity" ); assert.sameValue( - sample[0], N(0), + sample[0], 0, "'-Infinity' - does not change the value for [0]" ); assert.sameValue( - sample[1], N(0), + sample[1], 0, "'-Infinity' - does not change the value for [1]" ); assert.sameValue( diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-numeric-index.js index b51e1f237..845a9afbe 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-numeric-index.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-not-numeric-index.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, propertyHelper.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue( Reflect.defineProperty(sample, "foo", {value:42}), diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js index 0c9e90797..5d8be8a2a 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js @@ -18,7 +18,7 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new TA(2); assert.sameValue( @@ -31,7 +31,7 @@ testWithTypedArrayConstructors(function(TA, N) { false, "get accessor" ); - assert.sameValue(sample[0], N(0), "get accessor - side effect check"); + assert.sameValue(sample[0], 0, "get accessor - side effect check"); assert.sameValue( Reflect.defineProperty(sample, "0", { @@ -41,7 +41,7 @@ testWithTypedArrayConstructors(function(TA, N) { false, "set accessor" ); - assert.sameValue(sample[0], N(0), "set accessor - side effect check"); + assert.sameValue(sample[0], 0, "set accessor - side effect check"); assert.sameValue( Reflect.defineProperty(sample, "0", { @@ -54,5 +54,5 @@ testWithTypedArrayConstructors(function(TA, N) { false, "get and set accessors" ); - assert.sameValue(sample[0], N(0), "get and set accessors - side effect check"); + assert.sameValue(sample[0], 0, "get and set accessors - side effect check"); }); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js index 5b03b57bf..133f3343d 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js @@ -18,7 +18,7 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new TA(2); assert.sameValue( @@ -31,5 +31,5 @@ testWithTypedArrayConstructors(function(TA, N) { false, "defineProperty's result" ); - assert.sameValue(sample[0], N(0), "side effect check"); + assert.sameValue(sample[0], 0, "side effect check"); }); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js index 7bf886140..09526d11f 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js @@ -18,7 +18,7 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new TA(2); assert.sameValue( @@ -31,5 +31,5 @@ testWithTypedArrayConstructors(function(TA, N) { false, "defineProperty's result" ); - assert.sameValue(sample[0], N(0), "side effect check"); + assert.sameValue(sample[0], 0, "side effect check"); }); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js index ab460e4e6..08c9a1b3a 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js @@ -18,7 +18,7 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sample = new TA(2); assert.sameValue( @@ -31,5 +31,5 @@ testWithTypedArrayConstructors(function(TA, N) { false, "defineProperty's result" ); - assert.sameValue(sample[0], N(0), "side effect check"); + assert.sameValue(sample[0], 0, "side effect check"); }); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex.js index c6ddb1070..d815738b6 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-numericindex.js @@ -18,12 +18,12 @@ includes: [testTypedArray.js, propertyHelper.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 42]); assert.sameValue( Reflect.defineProperty(sample, "0", { - value: N(8), + value: 8, configurable: false, enumerable: true, writable: true @@ -31,10 +31,10 @@ testWithTypedArrayConstructors(function(TA, N) { true ); - assert.sameValue(sample[0], N(8), "property value was set"); + assert.sameValue(sample[0], 8, "property value was set"); var desc = Object.getOwnPropertyDescriptor(sample, "0"); - assert.sameValue(desc.value, N(8), "desc.value"); + assert.sameValue(desc.value, 8, "desc.value"); assert.sameValue(desc.writable, true, "property is writable"); verifyEnumerable(sample, "0"); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-symbol.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-symbol.js index 856997801..c5cff6eee 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/key-is-symbol.js @@ -15,8 +15,8 @@ includes: [testTypedArray.js, propertyHelper.js] features: [Reflect, Symbol, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); var s1 = Symbol("foo"); assert.sameValue( diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-new-key.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-new-key.js index 681630928..e74c95f12 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-new-key.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-new-key.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); Object.preventExtensions(sample); assert.sameValue( diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-redefine-key.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-redefine-key.js index 5983e6dfb..a0baaf57e 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-redefine-key.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/non-extensible-redefine-key.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, propertyHelper.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); sample.foo = true; sample.bar = true; diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/set-value.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/set-value.js index 0571a46ea..ff71bee90 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/set-value.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/set-value.js @@ -25,21 +25,21 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([0, 0])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0, 0]); assert.sameValue( - Reflect.defineProperty(sample, "0", {value: N(1)}), + Reflect.defineProperty(sample, "0", {value: 1}), true, "set value for sample[0] returns true" ); assert.sameValue( - Reflect.defineProperty(sample, "1", {value: N(2)}), + Reflect.defineProperty(sample, "1", {value: 2}), true, "set value for sample[1] returns true" ); - assert.sameValue(sample[0], N(1), "sample[0]"); - assert.sameValue(sample[1], N(2), "sample[1]"); + assert.sameValue(sample[0], 1, "sample[0]"); + assert.sameValue(sample[1], 2, "sample[1]"); }); diff --git a/test/built-ins/TypedArrays/internals/DefineOwnProperty/this-is-not-extensible.js b/test/built-ins/TypedArrays/internals/DefineOwnProperty/this-is-not-extensible.js index e4f54b45e..5e586c775 100644 --- a/test/built-ins/TypedArrays/internals/DefineOwnProperty/this-is-not-extensible.js +++ b/test/built-ins/TypedArrays/internals/DefineOwnProperty/this-is-not-extensible.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js] features: [Reflect, Symbol, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); Object.preventExtensions(sample); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 000000000..b9caa2ddf --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,28 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + sample.foo = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.undef, undefined); + assert.sameValue(sample.foo, "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..9af111a76 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,28 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("1"); + + assert.sameValue(sample[s], undefined); + + sample[s] = "test262"; + assert.sameValue(sample[s], "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..af52e3392 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer-realm.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0]; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer.js new file mode 100644 index 000000000..74b9a69d8 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/detached-buffer.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached buffer +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0]; + }, "valid numeric index"); + + assert.throws(TypeError, function() { + sample["1.1"]; + }, "detach buffer runs before checking for 1.1"); + + assert.throws(TypeError, function() { + sample["-0"]; + }, "detach buffer runs before checking for -0"); + + assert.throws(TypeError, function() { + sample["-1"]; + }, "detach buffer runs before checking for -1"); + + assert.throws(TypeError, function() { + sample["1"]; + }, "detach buffer runs before checking for key == length"); + + assert.throws(TypeError, function() { + sample["2"]; + }, "detach buffer runs before checking for key > length"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value-sab.js b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value-sab.js new file mode 100644 index 000000000..b599b430c --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value-sab.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index, with SharedArrayBuffer +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray, SharedArrayBuffer] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + var sample = new TA(sab); + sample.set([convertToBigInt(42), convertToBigInt(1)]); + + assert.sameValue(sample["0"], convertToBigInt(42)); + assert.sameValue(sample["1"], convertToBigInt(1)); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value.js b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value.js new file mode 100644 index 000000000..d97004b83 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/indexed-value.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return value from valid numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 1])); + + assert.sameValue(sample["0"], convertToBigInt(42)); + assert.sameValue(sample["1"], convertToBigInt(1)); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/infinity-detached-buffer.js b/test/built-ins/TypedArrays/internals/Get/BigInt/infinity-detached-buffer.js new file mode 100644 index 000000000..1e04f9544 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/infinity-detached-buffer.js @@ -0,0 +1,40 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.4 [[Get]] ( P, Receiver ) + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + ... + 3. Let buffer be O.[[ViewedArrayBuffer]]. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample.Infinity; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..5a599409a --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-canonical-index.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrginaryGet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(); + + assert.sameValue( + sample[key], undefined, + "return undefined for inexistent properties [" + key + "]" + ); + + TypedArray.prototype[key] = "test262"; + + assert.sameValue( + sample[key], + "test262", + "return value from inherited key [" + key + "]" + ); + + sample[key] = "bar"; + assert.sameValue( + sample[key], "bar", + "return value from own key [" + key + "]" + ); + + Object.defineProperty(sample, key, { + get: function() { return "baz"; } + }); + + assert.sameValue( + sample[key], "baz", + "return value from get accessor [" + key + "]" + ); + + delete TypedArray.prototype[key]; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..8f844f550 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-integer.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is not an integer. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "1.1", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue(sample["1.1"], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-minus-zero.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-minus-zero.js new file mode 100644 index 000000000..30917db64 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-minus-zero.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index is -0. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "-0", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue(sample["-0"], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js new file mode 100644 index 000000000..a532b6cea --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js @@ -0,0 +1,38 @@ +// 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-integer-indexed-exotic-objects-get-p-receiver +description: > + Returns abrupt from OrginaryGet when key is not a numeric index +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). + + 9.1.8.1 OrdinaryGet (O, P, Receiver) + + ... + 8. Return ? Call(getter, Receiver). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..8eb2c0714 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrginaryGet if key is not a CanonicalNumericIndex +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +TypedArray.prototype.baz = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue( + sample.foo, undefined, + "return undefined for inexistent properties" + ); + + sample.foo = "bar"; + assert.sameValue(sample.foo, "bar", "return value"); + + Object.defineProperty(sample, "bar", { + get: function() { return "baz"; } + }); + assert.sameValue(sample.bar, "baz", "return value from get accessor"); + + assert.sameValue(sample.baz, "test262", "return value from inherited key"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-out-of-bounds.js new file mode 100644 index 000000000..b8f0b02a6 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-out-of-bounds.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Return undefined if key is numeric index < 0 or index ≥ [[ArrayLength]]. +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "-1", throwDesc); +Object.defineProperty(proto, "2", throwDesc); +Object.defineProperty(proto, "3", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue(sample["-1"], undefined); + assert.sameValue(sample["2"], undefined); + assert.sameValue(sample["3"], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-symbol.js new file mode 100644 index 000000000..52113ec86 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/BigInt/key-is-symbol.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-integer-indexed-exotic-objects-get-p-receiver +description: > + Use OrginaryGet if key is a Symbol +info: | + 9.4.5.4 [[Get]] (P, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinaryGet(O, P, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var parentKey = Symbol("2"); +TypedArray.prototype[parentKey] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + var s1 = Symbol("1"); + + assert.sameValue( + sample[s1], undefined, + "return undefined if not property is present" + ); + + sample[s1] = "foo"; + assert.sameValue(sample[s1], "foo", "return value"); + + Object.defineProperty(sample, s1, { + get: function() { return "bar"; } + }); + assert.sameValue(sample[s1], "bar", "return value from get accessor"); + + assert.sameValue(sample[parentKey], "test262", "value from parent key"); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-not-numeric-index.js index 4ebb82f7e..b0032bad7 100644 --- a/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-not-numeric-index.js +++ b/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-not-numeric-index.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); sample.foo = "test262"; $DETACHBUFFER(sample.buffer); diff --git a/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-symbol.js index 9910fe6eb..2b18a93ea 100644 --- a/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/Get/detached-buffer-key-is-symbol.js @@ -15,8 +15,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [Symbol, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); $DETACHBUFFER(sample.buffer); var s = Symbol("1"); diff --git a/test/built-ins/TypedArrays/internals/Get/detached-buffer.js b/test/built-ins/TypedArrays/internals/Get/detached-buffer.js index 467aff7cf..4e52b1cf0 100644 --- a/test/built-ins/TypedArrays/internals/Get/detached-buffer.js +++ b/test/built-ins/TypedArrays/internals/Get/detached-buffer.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); $DETACHBUFFER(sample.buffer); assert.throws(TypeError, function() { diff --git a/test/built-ins/TypedArrays/internals/Get/indexed-value-sab.js b/test/built-ins/TypedArrays/internals/Get/indexed-value-sab.js index c9e49d861..6145da9e2 100644 --- a/test/built-ins/TypedArrays/internals/Get/indexed-value-sab.js +++ b/test/built-ins/TypedArrays/internals/Get/indexed-value-sab.js @@ -18,11 +18,11 @@ var throwDesc = { Object.defineProperty(proto, "0", throwDesc); Object.defineProperty(proto, "1", throwDesc); -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); var sample = new TA(sab); - sample.set([N(42), N(1)]); + sample.set([42, 1]); - assert.sameValue(sample["0"], N(42)); - assert.sameValue(sample["1"], N(1)); + assert.sameValue(sample["0"], 42); + assert.sameValue(sample["1"], 1); }); diff --git a/test/built-ins/TypedArrays/internals/Get/indexed-value.js b/test/built-ins/TypedArrays/internals/Get/indexed-value.js index cb761c6db..f58c528b6 100644 --- a/test/built-ins/TypedArrays/internals/Get/indexed-value.js +++ b/test/built-ins/TypedArrays/internals/Get/indexed-value.js @@ -26,9 +26,9 @@ var throwDesc = { Object.defineProperty(proto, "0", throwDesc); Object.defineProperty(proto, "1", throwDesc); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 1])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 1]); - assert.sameValue(sample["0"], N(42)); - assert.sameValue(sample["1"], N(1)); + assert.sameValue(sample["0"], 42); + assert.sameValue(sample["1"], 1); }); diff --git a/test/built-ins/TypedArrays/internals/Get/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/Get/key-is-not-integer.js index 258f11193..5ad684b78 100644 --- a/test/built-ins/TypedArrays/internals/Get/key-is-not-integer.js +++ b/test/built-ins/TypedArrays/internals/Get/key-is-not-integer.js @@ -30,8 +30,8 @@ Object.defineProperty(proto, "1.1", { } }); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue(sample["1.1"], undefined); }); diff --git a/test/built-ins/TypedArrays/internals/Get/key-is-not-minus-zero.js b/test/built-ins/TypedArrays/internals/Get/key-is-not-minus-zero.js index 45e7af40f..851cf72b4 100644 --- a/test/built-ins/TypedArrays/internals/Get/key-is-not-minus-zero.js +++ b/test/built-ins/TypedArrays/internals/Get/key-is-not-minus-zero.js @@ -30,8 +30,8 @@ Object.defineProperty(proto, "-0", { } }); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue(sample["-0"], undefined); }); diff --git a/test/built-ins/TypedArrays/internals/Get/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Get/key-is-not-numeric-index.js index 116f04275..53824ad34 100644 --- a/test/built-ins/TypedArrays/internals/Get/key-is-not-numeric-index.js +++ b/test/built-ins/TypedArrays/internals/Get/key-is-not-numeric-index.js @@ -19,8 +19,8 @@ features: [TypedArray] TypedArray.prototype.baz = "test262"; -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue( sample.foo, undefined, diff --git a/test/built-ins/TypedArrays/internals/Get/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/Get/key-is-out-of-bounds.js index dfb3d0411..a6eaa05df 100644 --- a/test/built-ins/TypedArrays/internals/Get/key-is-out-of-bounds.js +++ b/test/built-ins/TypedArrays/internals/Get/key-is-out-of-bounds.js @@ -34,8 +34,8 @@ Object.defineProperty(proto, "-1", throwDesc); Object.defineProperty(proto, "2", throwDesc); Object.defineProperty(proto, "3", throwDesc); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue(sample["-1"], undefined); assert.sameValue(sample["2"], undefined); diff --git a/test/built-ins/TypedArrays/internals/Get/key-is-symbol.js b/test/built-ins/TypedArrays/internals/Get/key-is-symbol.js index 3454fd676..1d05d06bc 100644 --- a/test/built-ins/TypedArrays/internals/Get/key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/Get/key-is-symbol.js @@ -18,8 +18,8 @@ features: [Symbol, TypedArray] var parentKey = Symbol("2"); TypedArray.prototype[parentKey] = "test262"; -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); var s1 = Symbol("1"); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 000000000..6148dbea1 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js @@ -0,0 +1,38 @@ +// 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-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..ecd044e13 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..91c06732b --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer-realm.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: > + Throws a TypeError if this has a detached buffer (honoring the Realm of the + current execution context) +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(sample, 0); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 000000000..5f14f0317 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/detached-buffer.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-integer-indexed-exotic-objects-getownproperty-p +description: Throws a TypeError if this has a detached buffer +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.getOwnPropertyDescriptor(sample, 0); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js new file mode 100644 index 000000000..9523e3a5f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js @@ -0,0 +1,42 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-getownproperty-p +description: Test for-in enumeration with detached buffer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + ... + 3. Let buffer be O.[[ViewedArrayBuffer]]. + 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 13.7.5.15 EnumerateObjectProperties (O) + ... + EnumerateObjectProperties must obtain the own property keys of the + target object by calling its [[OwnPropertyKeys]] internal method. + Property attributes of the target object must be obtained by + calling its [[GetOwnProperty]] internal method. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + for (var key in sample) { + throw new Test262Error(); + } + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/index-prop-desc.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/index-prop-desc.js new file mode 100644 index 000000000..34c96bd49 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/index-prop-desc.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns a descriptor object from an index property +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. Return a PropertyDescriptor{[[Value]]: value, [[Writable]]: true, + [[Enumerable]]: true, [[Configurable]]: false}. + ... +includes: [testBigIntTypedArray.js, propertyHelper.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + var desc0 = Object.getOwnPropertyDescriptor(sample, 0); + assert.sameValue(desc0.value, convertToBigInt(42), "value", "desc0.value === 42"); + assert.sameValue(desc0.writable, true, "index descriptor is writable [0]"); + verifyEnumerable(sample, "0", "index descriptor is enumerable [0]"); + verifyNotConfigurable(sample, "0", "index descriptor is not configurable [0]"); + + var desc1 = Object.getOwnPropertyDescriptor(sample, 1); + assert.sameValue(desc1.value, convertToBigInt(43), "value", "desc1.value === 43"); + assert.sameValue(desc1.writable, true, "index descriptor is writable [1]"); + verifyEnumerable(sample, "1", "index descriptor is enumerable [1]"); + verifyNotConfigurable(sample, "1", "index descriptor is not configurable [1]"); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..1b4f76c0f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-minus-zero.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-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is -0. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + + ... + 2. If argument is "-0", return -0. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 6. If index = -0, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + // -0 as a number value is converted to "0" before calling [[GetOwnProperty]] + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-0"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..b9a163b79 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if numeric key is not a + CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key), + undefined, + "undefined property [" + key + "]" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, key, {value: "bar"}); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, key).value, + "bar", + "return value from a ordinary property key [" + key + "]" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..bc8674429 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-integer.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-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not an integer. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1.1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "0.1"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..d00d1a626 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,38 @@ +// 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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is not a CanonicalNumericIndex +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "undef"), + undefined, + "undefined property" + ); + + // Tests for the property descriptor are defined on the tests for + // [[DefineOwnProperty]] calls + Object.defineProperty(sample, "foo", { value: "bar" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, "foo").value, + "bar", + "return value from a String key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js new file mode 100644 index 000000000..8bb915de6 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.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-integer-indexed-exotic-objects-getownproperty-p +description: Returns undefined when P is not a valid index number. +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let value be ? IntegerIndexedElementGet(O, numericIndex). + ii. If value is undefined, return undefined. + ... + + 9.4.5.8 IntegerIndexedElementGet ( O, index ) + + ... + 7. Let length be the value of O's [[ArrayLength]] internal slot. + 8. If index < 0 or index ≥ length, return undefined. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-42"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "42"), undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 000000000..dd1cbdfb5 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/BigInt/key-is-symbol.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-integer-indexed-exotic-objects-getownproperty-p +description: > + Returns an ordinary property value if key is a Symbol +info: | + 9.4.5.1 [[GetOwnProperty]] ( P ) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return OrdinaryGetOwnProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-not-number.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-not-number.js index c0f54cd4a..81b274361 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-not-number.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-not-number.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); $DETACHBUFFER(sample.buffer); assert.sameValue( diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-symbol.js index b637e6fe3..308a2973f 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/detached-buffer-key-is-symbol.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [Symbol, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); $DETACHBUFFER(sample.buffer); var s = Symbol("foo"); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/index-prop-desc.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/index-prop-desc.js index 0771ae51e..fe7f1eca2 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/index-prop-desc.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/index-prop-desc.js @@ -19,17 +19,17 @@ includes: [testTypedArray.js, propertyHelper.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); var desc0 = Object.getOwnPropertyDescriptor(sample, 0); - assert.sameValue(desc0.value, N(42), "value", "desc0.value === 42"); + assert.sameValue(desc0.value, 42, "value", "desc0.value === 42"); assert.sameValue(desc0.writable, true, "index descriptor is writable [0]"); verifyEnumerable(sample, "0", "index descriptor is enumerable [0]"); verifyNotConfigurable(sample, "0", "index descriptor is not configurable [0]"); var desc1 = Object.getOwnPropertyDescriptor(sample, 1); - assert.sameValue(desc1.value, N(43), "value", "desc1.value === 43"); + assert.sameValue(desc1.value, 43, "value", "desc1.value === 43"); assert.sameValue(desc1.writable, true, "index descriptor is writable [1]"); verifyEnumerable(sample, "1", "index descriptor is enumerable [1]"); verifyNotConfigurable(sample, "1", "index descriptor is not configurable [1]"); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-minus-zero.js index 93fb63a55..1b1c828ab 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-minus-zero.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-minus-zero.js @@ -29,8 +29,8 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); // -0 as a number value is converted to "0" before calling [[GetOwnProperty]] assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-0"), undefined); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-canonical-index.js index e2f7352a0..35b6fa01c 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-canonical-index.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-canonical-index.js @@ -26,9 +26,9 @@ var keys = [ "0.0000001" ]; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { keys.forEach(function(key) { - var sample = new TA(N([42, 43])); + var sample = new TA([42, 43]); assert.sameValue( Object.getOwnPropertyDescriptor(sample, key), diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-integer.js index 78e7e5915..f77950d72 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-integer.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-integer.js @@ -23,8 +23,8 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1.1"), undefined); assert.sameValue(Object.getOwnPropertyDescriptor(sample, "0.1"), undefined); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-numeric-index.js index 32f68d2ce..57fd606ae 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-numeric-index.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-not-numeric-index.js @@ -18,8 +18,8 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue( Object.getOwnPropertyDescriptor(sample, "undef"), diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-out-of-bounds.js index a02b44bb4..891bc7184 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-out-of-bounds.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-out-of-bounds.js @@ -24,8 +24,8 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-1"), undefined); assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-42"), undefined); diff --git a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-symbol.js b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-symbol.js index 2d31cb822..6b440e119 100644 --- a/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/GetOwnProperty/key-is-symbol.js @@ -18,8 +18,8 @@ includes: [testTypedArray.js] features: [Symbol, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); var s = Symbol("foo"); Object.defineProperty(sample, s, { value: "baz" }); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js new file mode 100644 index 000000000..5c788c69a --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js @@ -0,0 +1,63 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return abrupt from OrdinaryHasProperty parent's [[HasProperty]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 9.1.7.1 OrdinaryHasProperty (O, P) + + ... + 2. Let hasOwn be ? O.[[GetOwnProperty]](P). + 3. If hasOwn is not undefined, return true. + 4. Let parent be ? O.[[GetPrototypeOf]](). + 5. If parent is not null, then + a. Return ? parent.[[HasProperty]](P). + 6. Return false. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, Proxy, TypedArray] +---*/ + +var handler = { + has: function() { + throw new Test262Error(); + } +}; + +var proxy = new Proxy(TypedArray.prototype, handler); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.setPrototypeOf(sample, proxy); + + assert.sameValue( + Reflect.has(sample, 0), true, + "OrdinaryHasProperty does not affect numericIndex properties [0]" + ); + assert.sameValue( + Reflect.has(sample, 1), false, + "OrdinaryHasProperty does not affect numericIndex properties [1]" + ); + + assert.throws(Test262Error, function() { + Reflect.has(sample, "foo"); + }, "Return abrupt from parent's [[HasProperty]] 'foo'"); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue( + Reflect.has(sample, "foo"), + true, + "trap is not triggered if [[GetOwnProperty]] returns a defined value" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 000000000..d4495d2e1 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-getproperty-p +description: > + Does not throw on an instance with a detached buffer if key is not a + CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + Object.defineProperty(sample, "bar", { value: 42 }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "foo"), false); + assert.sameValue(Reflect.has(sample, "bar"), true); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..50df7a49c --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("foo"); +var s2 = Symbol("bar"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + Object.defineProperty(sample, s1, { value: "baz" }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, s1), true); + assert.sameValue(Reflect.has(sample, s2), false); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..3870e5282 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer-realm.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Throws a TypeError if this has a detached buffer (honoring the Realm of the + current execution context) +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.has(sample, '0'); + }, '0'); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/detached-buffer.js new file mode 100644 index 000000000..d78265e35 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/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-integer-indexed-exotic-objects-hasproperty-p +description: Throws a TypeError if this has a detached buffer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Reflect.has(sample, "0"); + }, "0"); + + assert.throws(TypeError, function() { + Reflect.has(sample, "-0"); + }, "-0"); + + assert.throws(TypeError, function() { + Reflect.has(sample, "1.1"); + }, "1.1"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/indexed-value.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/indexed-value.js new file mode 100644 index 000000000..f01eb8689 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/indexed-value.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Return true for indexed properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + iii. If IsInteger(numericIndex) is false, return false. + iv. If numericIndex = -0, return false. + v. If numericIndex < 0, return false. + vi. If numericIndex ≥ the value of O's [[ArrayLength]] internal slot, + return false. + vii. Return true. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue(Reflect.has(sample, 0), true); + assert.sameValue(Reflect.has(sample, 1), true); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/infinity-with-detached-buffer.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/infinity-with-detached-buffer.js new file mode 100644 index 000000000..2e4cdb7ae --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/infinity-with-detached-buffer.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + "Infinity" is a canonical numeric string, test with access on detached buffer. +info: | + 9.4.5.2 [[HasProperty]]( P ) + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Let buffer be O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + + 7.1.16 CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + +flags: [noStrict] +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + with (sample) Infinity; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/inherited-property.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/inherited-property.js new file mode 100644 index 000000000..6407c2644 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/inherited-property.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Find inherited properties if property is not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +TypedArray.prototype.foo = 42; +TypedArray.prototype[42] = true; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + TA.prototype.bar = 42; + + assert.sameValue(Reflect.has(sample, "subarray"), true, "subarray"); + assert.sameValue(Reflect.has(sample, "foo"), true, "foo"); + assert.sameValue(Reflect.has(sample, "bar"), true, "bar"); + assert.sameValue(Reflect.has(sample, "baz"), false, "baz"); + + assert.sameValue(Reflect.has(sample, "42"), false, "42"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-greater-than-last-index.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 000000000..c1d721348 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-greater-than-last-index.js @@ -0,0 +1,28 @@ +// 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-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is >= this's [[ArrayLength]] +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + vi. If numericIndex ≥ the value of O's [[ArrayLength]] internal slot, + return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[1] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1"), false, "1"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-lower-than-zero.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 000000000..0048a4f97 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-lower-than-zero.js @@ -0,0 +1,28 @@ +// 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-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is < 0 +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + v. If numericIndex < 0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[-1] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-1"), false, "-1"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..0d6a1515f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-minus-zero.js @@ -0,0 +1,28 @@ +// 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-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is "-0" +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iv. If numericIndex = -0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["-0"] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-0"), false, "-0"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..ecd5dd725 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-canonical-index.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-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from numeric keys that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(1); + + assert.sameValue( + Reflect.has(sample, key), false, + "returns false without key [" + key + "]" + ); + + TypedArray.prototype[key] = 42; + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with inherited key [" + key + "]" + ); + + delete TypedArray.prototype[key]; + + Object.defineProperty(sample, key, {value: convertToBigInt(42)}); + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with own key [" + key + "]" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..303b60278 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-integer.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: Return false if P's value is not an integer +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + iii. If IsInteger(numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["1.1"] = "test262"; +TypedArray.prototype["0.000001"] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1.1"), false, "1.1"); + assert.sameValue(Reflect.has(sample, "0.000001"), false, "0.000001"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..d960abfdd --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-not-numeric-index.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from properties that are not a CanonicalNumericIndexString +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 4. Return ? OrdinaryHasProperty(O, P). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "foo"), false); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue(Reflect.has(sample, "foo"), true); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-symbol.js new file mode 100644 index 000000000..0f6d74487 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/BigInt/key-is-symbol.js @@ -0,0 +1,28 @@ +// 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-integer-indexed-exotic-objects-hasproperty-p +description: > + Return boolean from Symbol properties +info: | + 9.4.5.2 [[HasProperty]](P) + + ... + 3. If Type(P) is String, then + ... + 4. Return ? OrdinaryHasProperty(O, P). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("foo"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, s), false); + + Object.defineProperty(sample, s, { value: 42 }); + + assert.sameValue(Reflect.has(sample, s), true); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-not-number.js b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-not-number.js index 4a4b64540..011e80c0b 100644 --- a/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-not-number.js +++ b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-not-number.js @@ -18,8 +18,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); Object.defineProperty(sample, "bar", { value: 42 }); $DETACHBUFFER(sample.buffer); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-symbol.js index abc2bf4e3..2c34c3caa 100644 --- a/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-symbol.js @@ -20,8 +20,8 @@ features: [Reflect, Symbol, TypedArray] var s1 = Symbol("foo"); var s2 = Symbol("bar"); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); Object.defineProperty(sample, s1, { value: "baz" }); $DETACHBUFFER(sample.buffer); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/indexed-value.js b/test/built-ins/TypedArrays/internals/HasProperty/indexed-value.js index 88aea9dc6..5a3b0482a 100644 --- a/test/built-ins/TypedArrays/internals/HasProperty/indexed-value.js +++ b/test/built-ins/TypedArrays/internals/HasProperty/indexed-value.js @@ -24,8 +24,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); assert.sameValue(Reflect.has(sample, 0), true); assert.sameValue(Reflect.has(sample, 1), true); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-canonical-index.js index 14ffa9072..7e20c5b24 100644 --- a/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-canonical-index.js +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-canonical-index.js @@ -25,7 +25,7 @@ var keys = [ "0.0000001" ]; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { keys.forEach(function(key) { var sample = new TA(1); @@ -43,7 +43,7 @@ testWithTypedArrayConstructors(function(TA, N) { delete TypedArray.prototype[key]; - Object.defineProperty(sample, key, {value: N(42)}); + Object.defineProperty(sample, key, {value: 42}); assert.sameValue( Reflect.has(sample, key), true, diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js new file mode 100644 index 000000000..42adcfeba --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.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-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(convertToBigInt([42, 42, 42])); + sample1[s1] = 42; + sample1[s2] = 42; + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262", s1, s2]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2[s1] = 42; + sample2[s2] = 42; + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262", s1, s2]), + "result2" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js new file mode 100644 index 000000000..e3d78dac4 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.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-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return integer index + non numeric string keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(convertToBigInt([42, 42, 42])); + sample1.test262 = 42; + sample1.ecma262 = 42; + var result1 = Reflect.ownKeys(sample1); + assert( + compareArray(result1, ["0", "1", "2", "test262", "ecma262"]), + "result1" + ); + + var sample2 = new TA(4).subarray(2); + sample2.test262 = 42; + sample2.ecma262 = 42; + var result2 = Reflect.ownKeys(sample2); + assert( + compareArray(result2, ["0", "1", "test262", "ecma262"]), + "result2" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes.js new file mode 100644 index 000000000..9217b4627 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/integer-indexes.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-integer-indexed-exotic-objects-ownpropertykeys +description: > + Return keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample1 = new TA(convertToBigInt([42, 42, 42])); + var result1 = Reflect.ownKeys(sample1); + assert(compareArray(result1, ["0", "1", "2"]), "result1"); + + var sample2 = new TA(4); + var result2 = Reflect.ownKeys(sample2); + assert(compareArray(result2, ["0", "1", "2", "3"]), "result2"); + + var sample3 = new TA(4).subarray(2); + var result3 = Reflect.ownKeys(sample3); + assert(compareArray(result3, ["0", "1"]), "result3"); + + var sample4 = new TA(); + var result4 = Reflect.ownKeys(sample4); + assert(compareArray(result4, []), "result4"); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js new file mode 100644 index 000000000..d50d2d20f --- /dev/null +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.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-integer-indexed-exotic-objects-ownpropertykeys +description: > + List not-enumerable own keys +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let len be the value of O's [[ArrayLength]] internal slot. + 4. For each integer i starting with 0 such that i < len, in ascending order, + a. Add ! ToString(i) as the last element of keys. + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + Object.defineProperty(sample, s, { + value: 42, + enumerable: false + }); + Object.defineProperty(sample, "test262", { + value: 42, + enumerable: false + }); + var result = Reflect.ownKeys(sample); + assert(compareArray(result, ["test262", s])); +}); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js index d469c9ab1..9060bee4d 100644 --- a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js @@ -23,8 +23,8 @@ var s2 = Symbol("2"); TypedArray.prototype[3] = 42; TypedArray.prototype.bar = 42; -testWithTypedArrayConstructors(function(TA, N) { - var sample1 = new TA(N([42, 42, 42])); +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([42, 42, 42]); sample1[s1] = 42; sample1[s2] = 42; sample1.test262 = 42; diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js index 5f933e570..b227ef6f2 100644 --- a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js @@ -20,8 +20,8 @@ features: [Reflect, TypedArray] TypedArray.prototype[3] = 42; TypedArray.prototype.bar = 42; -testWithTypedArrayConstructors(function(TA, N) { - var sample1 = new TA(N([42, 42, 42])); +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([42, 42, 42]); sample1.test262 = 42; sample1.ecma262 = 42; var result1 = Reflect.ownKeys(sample1); diff --git a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes.js b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes.js index 17c78ca5a..00e57de34 100644 --- a/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes.js +++ b/test/built-ins/TypedArrays/internals/OwnPropertyKeys/integer-indexes.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, compareArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample1 = new TA(N([42, 42, 42])); +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([42, 42, 42]); var result1 = Reflect.ownKeys(sample1); assert(compareArray(result1, ["0", "1", "2"]), "result1"); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/conversion-operation.js b/test/built-ins/TypedArrays/internals/Set/BigInt/conversion-operation.js new file mode 100644 index 000000000..4c8bff504 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/conversion-operation.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Verify conversion after setting value +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + ... + 8. If type is "Float32", then + ... + 9. Else, if type is "Float64", then + ... + 10. Else, + ... + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 50 for Element Type type. + c. Let intValue be convOp(value). + d. If intValue ≥ 0, then + ... + e. Else, + ... +includes: [byteConversionValues.js, testBigIntTypedArray.js] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample[0] = value; + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 000000000..e7980f308 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is not a number +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.set(sample, "foo", "test262"), true); + assert.sameValue(sample.foo, "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..c7311063b --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-key-is-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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Does not throw on an instance with a detached buffer if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Symbol, Reflect, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.set(sample, s, "test262"), true); + assert.sameValue(sample[s], "test262"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-realm.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-realm.js new file mode 100644 index 000000000..f7e71ff0e --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer-realm.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0] = 0; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer.js b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer.js new file mode 100644 index 000000000..2a27fff80 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/detached-buffer.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Throws a TypeError if key has a numeric index and object has a detached buffer +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + 4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + sample[0] = convertToBigInt(1); + }, "valid numeric index"); + + assert.throws(TypeError, function() { + sample["1.1"] = convertToBigInt(1); + }, "detach buffer runs before checking for 1.1"); + + assert.throws(TypeError, function() { + sample["-0"] = convertToBigInt(1); + }, "detach buffer runs before checking for -0"); + + assert.throws(TypeError, function() { + sample["-1"] = convertToBigInt(1); + }, "detach buffer runs before checking for -1"); + + assert.throws(TypeError, function() { + sample["1"] = convertToBigInt(1); + }, "detach buffer runs before checking for key == length"); + + assert.throws(TypeError, function() { + sample["2"] = convertToBigInt(1); + }, "detach buffer runs before checking for key > length"); + + var obj = { + valueOf: function() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample["0"] = obj; + }, "ToNumber(value) is called before detached buffer check"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/indexed-value.js b/test/built-ins/TypedArrays/internals/Set/BigInt/indexed-value.js new file mode 100644 index 000000000..5203e21c9 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/indexed-value.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns true after setting value +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + set: function() { + throw new Test262Error("OrdinarySet was called! Ref: 9.1.9.1 3.b.i"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42, 43])); + + assert.sameValue(Reflect.set(sample, "0", convertToBigInt(1)), true, "sample[0]"); + assert.sameValue(sample[0], convertToBigInt(1), "sample[0] value is set"); + + assert.sameValue(Reflect.set(sample, "1", convertToBigInt(42)), true, "sample[1]"); + assert.sameValue(sample[1], convertToBigInt(42), "sample[1] value is set"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-minus-zero.js new file mode 100644 index 000000000..6fcd8dead --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-minus-zero.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if index is -0 +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 7. If index = -0, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + assert.sameValue(Reflect.set(sample, "-0", 1), false, "-0"); + assert.sameValue(sample.hasOwnProperty("-0"), false, "has no property [-0]"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-canonical-index.js new file mode 100644 index 000000000..f2760e7e1 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,58 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrginarySet if numeric key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA(convertToBigInt([42])); + + assert.sameValue( + Reflect.set(sample, key, "ecma262"), + true, + "Return true setting a new property [" + key + "]" + ); + assert.sameValue(sample[key], "ecma262"); + + assert.sameValue( + Reflect.set(sample, key, "es3000"), + true, + "Return true setting a value to a writable property [" + key + "]" + ); + assert.sameValue(sample[key], "es3000"); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, key, 42), + false, + "Return false setting a value to a non-writable property [" + key + "]" + ); + assert.sameValue( + sample[key], undefined, "non-writable [" + key + "] is preserved" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-integer.js new file mode 100644 index 000000000..758cc1072 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-integer.js @@ -0,0 +1,38 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if index is not integer +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 6. If IsInteger(index) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + assert.sameValue(Reflect.set(sample, "1.1", 1), false, "1.1"); + assert.sameValue(Reflect.set(sample, "0.0001", 1), false, "0.0001"); + + assert.sameValue(sample.hasOwnProperty("1.1"), false, "has no property [1.1]"); + assert.sameValue( + sample.hasOwnProperty("0.0001"), + false, + "has no property [0.0001]" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js new file mode 100644 index 000000000..1e55325f6 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index-set-throws.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from OrginarySet when key is not a numeric index +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). + + 9.1.9.1 OrdinarySet (O, P, V, Receiver) + + ... + 8. Perform ? Call(setter, Receiver, « V »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + set: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262 = 1; + }); + + assert.sameValue(sample.test262, undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index.js new file mode 100644 index 000000000..842de9dd0 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-not-numeric-index.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrginarySet if key is not a CanonicalNumericIndex +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + assert.sameValue( + Reflect.set(sample, "test262", "ecma262"), + true, + "Return true setting a new property" + ); + assert.sameValue(sample.test262, "ecma262"); + + assert.sameValue( + Reflect.set(sample, "test262", "es3000"), + true, + "Return true setting a value to a writable property" + ); + assert.sameValue(sample.test262, "es3000"); + + Object.defineProperty(sample, "foo", { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, "foo", 42), + false, + "Return false setting a value to a non-writable property" + ); + assert.sameValue(sample.foo, undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-out-of-bounds.js new file mode 100644 index 000000000..3031a6ed9 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-out-of-bounds.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false if index is out of bounds +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 8. Let length be the value of O's [[ArrayLength]] internal slot. + 9. If index < 0 or index ≥ length, return false. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + assert.sameValue(Reflect.set(sample, "-1", 1), false, "-1"); + assert.sameValue(Reflect.set(sample, "1", 1), false, "1"); + assert.sameValue(Reflect.set(sample, "2", 1), false, "2"); + + assert.sameValue(sample.hasOwnProperty("-1"), false, "has no property [-1]"); + assert.sameValue(sample.hasOwnProperty("1"), false, "has no property [1]"); + assert.sameValue(sample.hasOwnProperty("2"), false, "has no property [2]"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-symbol.js b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-symbol.js new file mode 100644 index 000000000..184ae7abc --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/key-is-symbol.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrginarySet if key is a Symbol +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + 3. Return ? OrdinarySet(O, P, V, Receiver). +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + assert.sameValue( + Reflect.set(sample, s1, "ecma262"), + true, + "Return true setting a new property" + ); + assert.sameValue(sample[s1], "ecma262"); + + assert.sameValue( + Reflect.set(sample, s1, "es3000"), + true, + "Return true setting a value to a writable property" + ); + assert.sameValue(sample[s1], "es3000"); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + "Return false setting a value to a non-writable property" + ); + assert.sameValue(sample[s2], undefined); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-detached-buffer.js b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 000000000..2111ef645 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,46 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Setting a typed array element to a value that, when converted to the typed + array element type, detaches the typed array's underlying buffer, should + throw a TypeError and not modify the typed array. +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + 16. Return true. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA([17]); + + assert.throws(TypeError, function() { + Reflect.set(ta, 0, { + valueOf: function() { + $262.detachArrayBuffer(ta.buffer); + return 42; + } + }); + }, + "detaching a ArrayBuffer during setting an element of a typed array " + + "viewing it should throw"); + + assert.throws(TypeError, function() { + ta[0]; + }); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-throws.js b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-throws.js new file mode 100644 index 000000000..a967ec01c --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Set/BigInt/tonumber-value-throws.js @@ -0,0 +1,58 @@ +// 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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from ToNumber(value) +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(convertToBigInt([42])); + + var obj = { + valueOf: function() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample["0"] = obj; + }, "ToNumber check with a valid index"); + + assert.throws(Test262Error, function() { + sample["1.1"] = obj; + }, "ToNumber runs before ToInteger(index)"); + + assert.throws(Test262Error, function() { + sample["-0"] = obj; + }, "ToNumber runs before -0 check"); + + assert.throws(Test262Error, function() { + sample["-1"] = obj; + }, "ToNumber runs before < 0 check"); + + assert.throws(Test262Error, function() { + sample["1"] = obj; + }, "ToNumber runs before index == length check"); + + assert.throws(Test262Error, function() { + sample["2"] = obj; + }, "ToNumber runs before index > length check"); +}); diff --git a/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-not-numeric-index.js index d802d2fd5..7382d626e 100644 --- a/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-not-numeric-index.js +++ b/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-not-numeric-index.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); $DETACHBUFFER(sample.buffer); assert.sameValue(Reflect.set(sample, "foo", "test262"), true); diff --git a/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-symbol.js index 18869f683..1fbe1b60c 100644 --- a/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/Set/detached-buffer-key-is-symbol.js @@ -17,8 +17,8 @@ features: [Symbol, Reflect, TypedArray] var s = Symbol("1"); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); $DETACHBUFFER(sample.buffer); assert.sameValue(Reflect.set(sample, s, "test262"), true); diff --git a/test/built-ins/TypedArrays/internals/Set/detached-buffer.js b/test/built-ins/TypedArrays/internals/Set/detached-buffer.js index 186259cee..a373f9fbe 100644 --- a/test/built-ins/TypedArrays/internals/Set/detached-buffer.js +++ b/test/built-ins/TypedArrays/internals/Set/detached-buffer.js @@ -25,32 +25,32 @@ includes: [testTypedArray.js, detachArrayBuffer.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); $DETACHBUFFER(sample.buffer); assert.throws(TypeError, function() { - sample[0] = N(1); + sample[0] = 1; }, "valid numeric index"); assert.throws(TypeError, function() { - sample["1.1"] = N(1); + sample["1.1"] = 1; }, "detach buffer runs before checking for 1.1"); assert.throws(TypeError, function() { - sample["-0"] = N(1); + sample["-0"] = 1; }, "detach buffer runs before checking for -0"); assert.throws(TypeError, function() { - sample["-1"] = N(1); + sample["-1"] = 1; }, "detach buffer runs before checking for -1"); assert.throws(TypeError, function() { - sample["1"] = N(1); + sample["1"] = 1; }, "detach buffer runs before checking for key == length"); assert.throws(TypeError, function() { - sample["2"] = N(1); + sample["2"] = 1; }, "detach buffer runs before checking for key > length"); var obj = { diff --git a/test/built-ins/TypedArrays/internals/Set/indexed-value.js b/test/built-ins/TypedArrays/internals/Set/indexed-value.js index bb325d11c..2333d4c44 100644 --- a/test/built-ins/TypedArrays/internals/Set/indexed-value.js +++ b/test/built-ins/TypedArrays/internals/Set/indexed-value.js @@ -32,12 +32,12 @@ var throwDesc = { Object.defineProperty(proto, "0", throwDesc); Object.defineProperty(proto, "1", throwDesc); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42, 43])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); - assert.sameValue(Reflect.set(sample, "0", N(1)), true, "sample[0]"); - assert.sameValue(sample[0], N(1), "sample[0] value is set"); + assert.sameValue(Reflect.set(sample, "0", 1), true, "sample[0]"); + assert.sameValue(sample[0], 1, "sample[0] value is set"); - assert.sameValue(Reflect.set(sample, "1", N(42)), true, "sample[1]"); - assert.sameValue(sample[1], N(42), "sample[1] value is set"); + assert.sameValue(Reflect.set(sample, "1", 42), true, "sample[1]"); + assert.sameValue(sample[1], 42, "sample[1] value is set"); }); diff --git a/test/built-ins/TypedArrays/internals/Set/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/Set/key-is-minus-zero.js index 5946ebc7c..a735e8baa 100644 --- a/test/built-ins/TypedArrays/internals/Set/key-is-minus-zero.js +++ b/test/built-ins/TypedArrays/internals/Set/key-is-minus-zero.js @@ -23,8 +23,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); assert.sameValue(Reflect.set(sample, "-0", 1), false, "-0"); assert.sameValue(sample.hasOwnProperty("-0"), false, "has no property [-0]"); diff --git a/test/built-ins/TypedArrays/internals/Set/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/Set/key-is-not-canonical-index.js index d89a0f1fb..1fb7a9ec6 100644 --- a/test/built-ins/TypedArrays/internals/Set/key-is-not-canonical-index.js +++ b/test/built-ins/TypedArrays/internals/Set/key-is-not-canonical-index.js @@ -24,9 +24,9 @@ var keys = [ "0.0000001" ]; -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { keys.forEach(function(key) { - var sample = new TA(N([42])); + var sample = new TA([42]); assert.sameValue( Reflect.set(sample, key, "ecma262"), diff --git a/test/built-ins/TypedArrays/internals/Set/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/Set/key-is-not-integer.js index c513faefe..252220f61 100644 --- a/test/built-ins/TypedArrays/internals/Set/key-is-not-integer.js +++ b/test/built-ins/TypedArrays/internals/Set/key-is-not-integer.js @@ -23,8 +23,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); assert.sameValue(Reflect.set(sample, "1.1", 1), false, "1.1"); assert.sameValue(Reflect.set(sample, "0.0001", 1), false, "0.0001"); diff --git a/test/built-ins/TypedArrays/internals/Set/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/Set/key-is-not-numeric-index.js index 03a181965..462eb752d 100644 --- a/test/built-ins/TypedArrays/internals/Set/key-is-not-numeric-index.js +++ b/test/built-ins/TypedArrays/internals/Set/key-is-not-numeric-index.js @@ -17,8 +17,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); assert.sameValue( Reflect.set(sample, "test262", "ecma262"), diff --git a/test/built-ins/TypedArrays/internals/Set/key-is-out-of-bounds.js b/test/built-ins/TypedArrays/internals/Set/key-is-out-of-bounds.js index 859bdee4f..e5a5d6da8 100644 --- a/test/built-ins/TypedArrays/internals/Set/key-is-out-of-bounds.js +++ b/test/built-ins/TypedArrays/internals/Set/key-is-out-of-bounds.js @@ -24,8 +24,8 @@ includes: [testTypedArray.js] features: [Reflect, TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); assert.sameValue(Reflect.set(sample, "-1", 1), false, "-1"); assert.sameValue(Reflect.set(sample, "1", 1), false, "1"); diff --git a/test/built-ins/TypedArrays/internals/Set/key-is-symbol.js b/test/built-ins/TypedArrays/internals/Set/key-is-symbol.js index e27d501c0..838ab74e0 100644 --- a/test/built-ins/TypedArrays/internals/Set/key-is-symbol.js +++ b/test/built-ins/TypedArrays/internals/Set/key-is-symbol.js @@ -18,8 +18,8 @@ features: [Reflect, Symbol, TypedArray] var s1 = Symbol("1"); var s2 = Symbol("2"); -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); assert.sameValue( Reflect.set(sample, s1, "ecma262"), diff --git a/test/built-ins/TypedArrays/internals/Set/tonumber-value-throws.js b/test/built-ins/TypedArrays/internals/Set/tonumber-value-throws.js index e90eb4798..08131f4bf 100644 --- a/test/built-ins/TypedArrays/internals/Set/tonumber-value-throws.js +++ b/test/built-ins/TypedArrays/internals/Set/tonumber-value-throws.js @@ -23,8 +23,8 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var sample = new TA(N([42])); +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); var obj = { valueOf: function() { diff --git a/test/built-ins/TypedArrays/of/BigInt/argument-is-symbol-throws.js b/test/built-ins/TypedArrays/of/BigInt/argument-is-symbol-throws.js new file mode 100644 index 000000000..b59311849 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/argument-is-symbol-throws.js @@ -0,0 +1,23 @@ +// 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%.of +description: > + Throws a TypeError if argument is a Symbol +info: | + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.of(s); + }); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/argument-number-value-throws.js b/test/built-ins/TypedArrays/of/BigInt/argument-number-value-throws.js new file mode 100644 index 000000000..fd22b08b1 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/argument-number-value-throws.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%.of +description: > + Return abrupt from object value +info: | + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 7. Repeat, while k < len + ... + c. Perform ? Set(newObj, Pk, kValue, true). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var lastValue = false; + + var obj1 = { + valueOf() { + lastValue = "obj1"; + return convertToBigInt(42); + } + }; + var obj2 = { + valueOf() { + lastValue = "obj2"; + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + TA.of(obj1, obj2, obj1); + }); + + assert.sameValue(lastValue, "obj2"); +}); + diff --git a/test/built-ins/TypedArrays/of/BigInt/custom-ctor-does-not-instantiate-ta-throws.js b/test/built-ins/TypedArrays/of/BigInt/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 000000000..ca17d437e --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/custom-ctor-does-not-instantiate-ta-throws.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.of +description: > + Custom constructor needs to instantiate a TypedArray +info: | + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 5. Let newObj be ? TypedArrayCreate(C, «len»). + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.of.call(ctor, 42); + }); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/custom-ctor-returns-other-instance.js b/test/built-ins/TypedArrays/of/BigInt/custom-ctor-returns-other-instance.js new file mode 100644 index 000000000..3c289e0a8 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/custom-ctor-returns-other-instance.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. + +/*--- +es6id: 22.2.2.2 +esid: sec-%typedarray%.of +description: > + Custom constructor can return any TypedArray instance with higher or same + length +info: | + %TypedArray%.of ( ...items ) + + 1. Let len be the actual number of arguments passed to this function. + ... + 5. Let newObj be ? TypedArrayCreate(C, « len »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result; + var custom = new TA(3); + var ctor = function() { + return custom; + }; + + result = TypedArray.of.call(ctor, convertToBigInt(1), convertToBigInt(2), convertToBigInt(3)); + assert.sameValue(result, custom, "using iterator, same length"); + + result = TypedArray.of.call(ctor, convertToBigInt(1), convertToBigInt(2)); + assert.sameValue(result, custom, "using iterator, higher length"); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/custom-ctor-returns-smaller-instance-throws.js b/test/built-ins/TypedArrays/of/BigInt/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 000000000..cddf2c4cf --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/custom-ctor-returns-smaller-instance-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 22.2.2.2 +esid: sec-%typedarray%.of +description: > + Throws a TypeError if a custom `this` returns a smaller instance +info: | + %TypedArray%.of ( ...items ) + + 1. Let len be the actual number of arguments passed to this function. + ... + 5. Let newObj be ? TypedArrayCreate(C, « len »). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ctor = function() { + return new TA(1); + }; + + assert.throws(TypeError, function() { + TypedArray.of.call(ctor, 1, 2); + }); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/custom-ctor.js b/test/built-ins/TypedArrays/of/BigInt/custom-ctor.js new file mode 100644 index 000000000..e087cada3 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/custom-ctor.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%.of +description: > + Calls and return abrupt from custom constructor +info: | + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 5. Let newObj be ? TypedArrayCreate(C, «len»). + ... + + 22.2.4.6 TypedArrayCreate ( constructor, argumentList ) + + 1. Let newTypedArray be ? Construct(constructor, argumentList). + 2. Perform ? ValidateTypedArray(newTypedArray). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + var ctor = function() { + called++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + TA.of.call(ctor, 42); + }); + + assert.sameValue(called, 1); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/inherited.js b/test/built-ins/TypedArrays/of/BigInt/inherited.js new file mode 100644 index 000000000..677cb59fb --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/inherited.js @@ -0,0 +1,25 @@ +// 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%.of +description: > + `of` is %TypedArray%.of +info: | + 22.2.1 The %TypedArray% Intrinsic Object + + The %TypedArray% intrinsic object is a constructor function object that all of + the TypedArray constructor object inherit from. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue( + TA.of, TypedArray.of, + "method is inherited %TypedArray%.of" + ); + assert.sameValue( + TA.hasOwnProperty("of"), false, + "constructor does not define an own property named 'of'" + ); +});
\ No newline at end of file diff --git a/test/built-ins/TypedArrays/of/BigInt/invoked-as-func.js b/test/built-ins/TypedArrays/of/BigInt/invoked-as-func.js new file mode 100644 index 000000000..7becb0d7d --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/invoked-as-func.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.2.2 +esid: sec-%typedarray%.of +description: > + "of" cannot be invoked as a function +info: | + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 3. Let C be the this value. + 4. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var of = TA.of; + + assert.throws(TypeError, function() { + of(); + }); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/nan-conversion.js b/test/built-ins/TypedArrays/of/BigInt/nan-conversion.js new file mode 100644 index 000000000..4158c3709 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/nan-conversion.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%.of +description: > + Test NaN conversions +info: | + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(NaN, undefined); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], NaN); + assert.sameValue(result[1], NaN); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(NaN, undefined); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 0); + assert.sameValue(result[1], 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int8Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]); diff --git a/test/built-ins/TypedArrays/of/BigInt/new-instance-empty.js b/test/built-ins/TypedArrays/of/BigInt/new-instance-empty.js new file mode 100644 index 000000000..1891ae199 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/new-instance-empty.js @@ -0,0 +1,16 @@ +// 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%.of +description: > + Return a new empty TypedArray +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(); + assert.sameValue(result.length, 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/new-instance-from-zero.js b/test/built-ins/TypedArrays/of/BigInt/new-instance-from-zero.js new file mode 100644 index 000000000..973753857 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/new-instance-from-zero.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%.of +description: > + Return a new TypedArray using -0 and +0 values +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(-0, +0); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], -0, "-0 => 0"); + assert.sameValue(result[1], 0, "+0 => 0"); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Float32Array, + Float64Array +]); + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(-0, +0); + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 0, "-0 => 0"); + assert.sameValue(result[1], 0, "+0 => 0"); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}, +[ + Int16Array, + Int32Array, + Int8Array, + Uint16Array, + Uint32Array, + Uint8Array, + Uint8ClampedArray +]); diff --git a/test/built-ins/TypedArrays/of/BigInt/new-instance-using-custom-ctor.js b/test/built-ins/TypedArrays/of/BigInt/new-instance-using-custom-ctor.js new file mode 100644 index 000000000..58641f945 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/new-instance-using-custom-ctor.js @@ -0,0 +1,28 @@ +// 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%.of +description: > + Return a new TypedArray using a custom Constructor +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + + var ctor = function(len) { + assert.sameValue(arguments.length, 1); + called++; + return new TA(len); + }; + + + var result = TA.of.call(ctor, convertToBigInt(42), convertToBigInt(43), convertToBigInt(42)); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], convertToBigInt(42)); + assert.sameValue(result[1], convertToBigInt(43)); + assert.sameValue(result[2], convertToBigInt(42)); + assert.sameValue(result.constructor, TA); + assert.sameValue(called, 1); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/new-instance.js b/test/built-ins/TypedArrays/of/BigInt/new-instance.js new file mode 100644 index 000000000..7e9cc745c --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/new-instance.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%.of +description: > + Return a new TypedArray +info: | + 9.4.5.5 [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String and if SameValue(O, Receiver) is true, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + i. Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + 9.4.5.9 IntegerIndexedElementSet ( O, index, value ) + + ... + 3. Let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(convertToBigInt(42), convertToBigInt(43), convertToBigInt(false)); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], convertToBigInt(42)); + assert.sameValue(result[1], convertToBigInt(43)); + assert.sameValue(result[2], convertToBigInt(0)); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/of/BigInt/this-is-not-constructor.js b/test/built-ins/TypedArrays/of/BigInt/this-is-not-constructor.js new file mode 100644 index 000000000..006b67404 --- /dev/null +++ b/test/built-ins/TypedArrays/of/BigInt/this-is-not-constructor.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%.of +description: > + Throws a TypeError exception if this is not a constructor +info: | + 22.2.2.2 %TypedArray%.of ( ...items ) + + ... + 3. Let C be the this value. + 4. If IsConstructor(C) is false, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var m = { m() {} }.m; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.of.call(m, []); + }); +}); diff --git a/test/built-ins/TypedArrays/of/argument-number-value-throws.js b/test/built-ins/TypedArrays/of/argument-number-value-throws.js index 3d8a49ded..bda57f8cd 100644 --- a/test/built-ins/TypedArrays/of/argument-number-value-throws.js +++ b/test/built-ins/TypedArrays/of/argument-number-value-throws.js @@ -16,21 +16,23 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var lastValue = false; +var lastValue; - var obj1 = { - valueOf() { - lastValue = "obj1"; - return N(42); - } - }; - var obj2 = { - valueOf() { - lastValue = "obj2"; - throw new Test262Error(); - } - }; +var obj1 = { + valueOf() { + lastValue = "obj1"; + return 42; + } +}; +var obj2 = { + valueOf() { + lastValue = "obj2"; + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + lastValue = false; assert.throws(Test262Error, function() { TA.of(obj1, obj2, obj1); diff --git a/test/built-ins/TypedArrays/of/custom-ctor-returns-other-instance.js b/test/built-ins/TypedArrays/of/custom-ctor-returns-other-instance.js index 6417c73d5..e116b1db7 100644 --- a/test/built-ins/TypedArrays/of/custom-ctor-returns-other-instance.js +++ b/test/built-ins/TypedArrays/of/custom-ctor-returns-other-instance.js @@ -18,16 +18,16 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var result; var custom = new TA(3); var ctor = function() { return custom; }; - result = TypedArray.of.call(ctor, N(1), N(2), N(3)); + result = TypedArray.of.call(ctor, 1, 2, 3); assert.sameValue(result, custom, "using iterator, same length"); - result = TypedArray.of.call(ctor, N(1), N(2)); + result = TypedArray.of.call(ctor, 1, 2); assert.sameValue(result, custom, "using iterator, higher length"); }); diff --git a/test/built-ins/TypedArrays/of/new-instance-using-custom-ctor.js b/test/built-ins/TypedArrays/of/new-instance-using-custom-ctor.js index fbcc55b27..7cc95230e 100644 --- a/test/built-ins/TypedArrays/of/new-instance-using-custom-ctor.js +++ b/test/built-ins/TypedArrays/of/new-instance-using-custom-ctor.js @@ -8,7 +8,7 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { +testWithTypedArrayConstructors(function(TA) { var called = 0; var ctor = function(len) { @@ -18,11 +18,11 @@ testWithTypedArrayConstructors(function(TA, N) { }; - var result = TA.of.call(ctor, N(42), N(43), N(42)); + var result = TA.of.call(ctor, 42, 43, 42); assert.sameValue(result.length, 3); - assert.sameValue(result[0], N(42)); - assert.sameValue(result[1], N(43)); - assert.sameValue(result[2], N(42)); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 42); assert.sameValue(result.constructor, TA); assert.sameValue(called, 1); }); diff --git a/test/built-ins/TypedArrays/of/new-instance.js b/test/built-ins/TypedArrays/of/new-instance.js index a0fbe0150..e83ad648d 100644 --- a/test/built-ins/TypedArrays/of/new-instance.js +++ b/test/built-ins/TypedArrays/of/new-instance.js @@ -23,12 +23,12 @@ includes: [testTypedArray.js] features: [TypedArray] ---*/ -testWithTypedArrayConstructors(function(TA, N) { - var result = TA.of(N(42), N(43), N(false)); +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(42, 43, null); assert.sameValue(result.length, 3); - assert.sameValue(result[0], N(42)); - assert.sameValue(result[1], N(43)); - assert.sameValue(result[2], N(0)); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 0); assert.sameValue(result.constructor, TA); assert.sameValue(Object.getPrototypeOf(result), TA.prototype); }); diff --git a/test/built-ins/TypedArrays/prototype/Symbol.toStringTag/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/Symbol.toStringTag/bigint-inherited.js new file mode 100644 index 000000000..e0372adb7 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/Symbol.toStringTag/bigint-inherited.js @@ -0,0 +1,14 @@ +// 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-get-%typedarray%.prototype-@@tostringtag +description: > + _TypedArray_.prototype[@@toStringTag] is inherited from %TypedArray% + _TypedArray_.prototype has no own property @@toStringTag +includes: [testTypedArray.js] +features: [Symbol.toStringTag, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty(Symbol.toStringTag), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/bigint-Symbol.iterator.js b/test/built-ins/TypedArrays/prototype/bigint-Symbol.iterator.js new file mode 100644 index 000000000..46590fe4d --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/bigint-Symbol.iterator.js @@ -0,0 +1,13 @@ +// 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-@@iterator +description: > + _TypedArray_.prototype has no own property @@iterator +includes: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty(Symbol.iterator), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/buffer/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/buffer/bigint-inherited.js new file mode 100644 index 000000000..323b7476f --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/buffer/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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-get-%typedarray%.prototype.buffer +description: > + _TypedArray_.prototype has no own property "buffer" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("buffer"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/byteLength/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/byteLength/bigint-inherited.js new file mode 100644 index 000000000..52b343265 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/byteLength/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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-get-%typedarray%.prototype.bytelength +description: > + _TypedArray_.prototype has no own property "byteLength" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("byteLength"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/byteOffset/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/byteOffset/bigint-inherited.js new file mode 100644 index 000000000..1d60311e0 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/byteOffset/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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-get-%typedarray%.prototype.byteoffset +description: > + _TypedArray_.prototype has no own property "byteOffset" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("byteOffset"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/copyWithin/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/copyWithin/bigint-inherited.js new file mode 100644 index 000000000..db5105ac6 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/copyWithin/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.copywithin +description: > + _TypedArray_.prototype has no own property "copyWithin" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("copyWithin"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/entries/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/entries/bigint-inherited.js new file mode 100644 index 000000000..8601bc268 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/entries/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.entries +description: > + _TypedArray_.prototype has no own property "entries" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("entries"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/every/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/every/bigint-inherited.js new file mode 100644 index 000000000..9b3da52bf --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/every/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.every +description: > + _TypedArray_.prototype has no own property "every" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("every"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/fill/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/fill/bigint-inherited.js new file mode 100644 index 000000000..b6862164e --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/fill/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.fill +description: > + _TypedArray_.prototype has no own property "fill" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("fill"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/filter/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/filter/bigint-inherited.js new file mode 100644 index 000000000..36d9019de --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/filter/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.filter +description: > + _TypedArray_.prototype has no own property "filter" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("filter"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/find/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/find/bigint-inherited.js new file mode 100644 index 000000000..828c4f4c4 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/find/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.find +description: > + _TypedArray_.prototype has no own property "find" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("find"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/findIndex/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/findIndex/bigint-inherited.js new file mode 100644 index 000000000..63f6f2279 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/findIndex/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.findindex +description: > + _TypedArray_.prototype has no own property "findIndex" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("findIndex"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/forEach/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/forEach/bigint-inherited.js new file mode 100644 index 000000000..de6e9371d --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/forEach/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.foreach +description: > + _TypedArray_.prototype has no own property "forEach" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("forEach"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/indexOf/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/indexOf/bigint-inherited.js new file mode 100644 index 000000000..362ef22a9 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/indexOf/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.indexof +description: > + _TypedArray_.prototype has no own property "indexOf" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("indexOf"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/join/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/join/bigint-inherited.js new file mode 100644 index 000000000..cc649c89f --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/join/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.join +description: > + _TypedArray_.prototype has no own property "join" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("join"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/keys/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/keys/bigint-inherited.js new file mode 100644 index 000000000..f4c800c5e --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/keys/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.keys +description: > + _TypedArray_.prototype has no own property "keys" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("keys"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/lastIndexOf/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/lastIndexOf/bigint-inherited.js new file mode 100644 index 000000000..5a68f3fa3 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/lastIndexOf/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.lastindexof +description: > + _TypedArray_.prototype has no own property "lastIndexOf" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("lastIndexOf"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/length/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/length/bigint-inherited.js new file mode 100644 index 000000000..b75ccb831 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/length/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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-get-%typedarray%.prototype.length +description: > + _TypedArray_.prototype has no own property "length" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("length"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/map/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/map/bigint-inherited.js new file mode 100644 index 000000000..2d5d48aae --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/map/bigint-inherited.js @@ -0,0 +1,13 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.map +description: > + _TypedArray_.prototype has no own property "map" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("map"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/reduce/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/reduce/bigint-inherited.js new file mode 100644 index 000000000..d01bda709 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/reduce/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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-get-%typedarray%.prototype.reduce +description: > + _TypedArray_.prototype has no own property "reduce" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("reduce"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/reduceRight/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/reduceRight/bigint-inherited.js new file mode 100644 index 000000000..784e4c2b7 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/reduceRight/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.reduceright +description: > + _TypedArray_.prototype has no own property "reduceRight" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("reduceRight"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/reverse/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/reverse/bigint-inherited.js new file mode 100644 index 000000000..7d8a7d6e2 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/reverse/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.reverse +description: > + _TypedArray_.prototype has no own property "reverse" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("reverse"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/set/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/set/bigint-inherited.js new file mode 100644 index 000000000..411b66fda --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/set/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.set +description: > + _TypedArray_.prototype has no own property "set" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("set"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/slice/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/slice/bigint-inherited.js new file mode 100644 index 000000000..a1ae44026 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/slice/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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: > + _TypedArray_.prototype has no own property "slice" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("slice"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/some/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/some/bigint-inherited.js new file mode 100644 index 000000000..4b75f87f2 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/some/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.some +description: > + _TypedArray_.prototype has no own property "some" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("some"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/sort/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/sort/bigint-inherited.js new file mode 100644 index 000000000..37aab5255 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/sort/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.sort +description: > + _TypedArray_.prototype has no own property "sort" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("sort"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/subarray/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/subarray/bigint-inherited.js new file mode 100644 index 000000000..2416208a3 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/subarray/bigint-inherited.js @@ -0,0 +1,13 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.subarray +description: > + _TypedArray_.prototype has no own property "subarray" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("subarray"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/toLocaleString/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/toLocaleString/bigint-inherited.js new file mode 100644 index 000000000..d4a48e25d --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/toLocaleString/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.tolocalestring +description: > + _TypedArray_.prototype has no own property "toLocaleString" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("toLocaleString"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/toString/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/toString/bigint-inherited.js new file mode 100644 index 000000000..9f1b0e217 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/toString/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.tostring +description: > + _TypedArray_.prototype has no own property "toString" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("toString"), false); +}); diff --git a/test/built-ins/TypedArrays/prototype/values/bigint-inherited.js b/test/built-ins/TypedArrays/prototype/values/bigint-inherited.js new file mode 100644 index 000000000..bd4aaec70 --- /dev/null +++ b/test/built-ins/TypedArrays/prototype/values/bigint-inherited.js @@ -0,0 +1,13 @@ +// 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.values +description: > + _TypedArray_.prototype has no own property "values" +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("values"), false); +}); |