diff --git a/harness/testBigIntTypedArray.js b/harness/testBigIntTypedArray.js new file mode 100644 index 0000000000000000000000000000000000000000..90bb3aee45e91c125387de74de788f8b535df17d --- /dev/null +++ b/harness/testBigIntTypedArray.js @@ -0,0 +1,77 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +---*/ + +/** + * Array containing every typed array constructor. + */ +var BigIntTypedArrayConstructors = [ + BigInt64Array, + BigUint64Array +]; + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +function convertToBigInt(x) { + return (Array.isArray(x)) ? x.map(convertToBigInt) : BigInt(x); +} + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + var constructors = selected || BigIntTypedArrayConstructors; + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testBigIntTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithBigIntTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + \ No newline at end of file diff --git a/harness/testTypedArray.js b/harness/testTypedArray.js index 7f777b56cac291eae0e703aaed2e6f1009ad3e2a..bf6c4875eae353caee1b4cf9c95a0f881a6c76e8 100644 --- a/harness/testTypedArray.js +++ b/harness/testTypedArray.js @@ -20,22 +20,11 @@ var typedArrayConstructors = [ Uint8ClampedArray ]; -var numericTypedArrayConstructors = typedArrayConstructors.slice(); - -if (typeof BigInt !== "undefined") { - typedArrayConstructors.push(BigInt64Array); - typedArrayConstructors.push(BigUint64Array); -} - /** * The %TypedArray% intrinsic constructor function. */ var TypedArray = Object.getPrototypeOf(Int8Array); -function convertToBigInt(x) { - return (Array.isArray(x)) ? x.map(convertToBigInt) : BigInt(x); -} - /** * Callback for testing a typed array constructor. * @@ -52,12 +41,9 @@ function convertToBigInt(x) { function testWithTypedArrayConstructors(f, selected) { var constructors = selected || typedArrayConstructors; for (var i = 0; i < constructors.length; ++i) { + // TODO: Remove this var N = function(x) { return x; }; var constructor = constructors[i]; - if (constructor.name == "BigInt64Array" || - constructor.name == "BigUint64Array") { - N = convertToBigInt; - } try { f(constructor, N); } catch (e) { 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 0000000000000000000000000000000000000000..3bfba344096969843f4c609cdb7da61e1eb57846 --- /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 0000000000000000000000000000000000000000..a7f84333760f7679ff24b21bd90c5debd59e841a --- /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 0000000000000000000000000000000000000000..fee58c92fe7fe4e3fd986d1d73f691575acf95b7 --- /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 0000000000000000000000000000000000000000..6b8e035cd714ca475a81b909fb3eb6214cf64b80 --- /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 0000000000000000000000000000000000000000..9b9342a72ea7ea17e193275ae5aafd4226848c0f --- /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 0000000000000000000000000000000000000000..bae8ca763596f2e1ef16c746689be9b27efe2dc0 --- /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 0000000000000000000000000000000000000000..80a3116b87c13565ccb0b69b9d136579faa86154 --- /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 0000000000000000000000000000000000000000..9414c2d00c0089c686a2152d1004a5ff3d1ba240 --- /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 0000000000000000000000000000000000000000..1ae3cf292369273e13cd2df0b15179b97021c308 --- /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 0000000000000000000000000000000000000000..3332f1a6c0cfd37e931bd321d47325226a9f39b5 --- /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 0000000000000000000000000000000000000000..c49a8df0a4677858453c038f0ae7bef4a97f68a5 --- /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 0000000000000000000000000000000000000000..16cfcd4343c885ec30955cecc27fef9e2e1fab4e --- /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 0000000000000000000000000000000000000000..c60a408011d7a8e19c10bb1968f7649945492a09 --- /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 0000000000000000000000000000000000000000..74710e488c606674fbe215b522a90b3210af7738 --- /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 0000000000000000000000000000000000000000..692d5ee569213b6b73c43f77e93823c74087252a --- /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 0000000000000000000000000000000000000000..709166c7e967a463e3dbee7bdf0f7752e0519396 --- /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 0000000000000000000000000000000000000000..c91d0c8835600be79cdbd57397940f8db0129ae1 --- /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 0000000000000000000000000000000000000000..7b7baf7d365320390d9fd5d5368d498deba58b5b --- /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 0000000000000000000000000000000000000000..0014ea674fe468d666065c2c1c23cd21a7aa7384 --- /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 0000000000000000000000000000000000000000..0b02e6462c1d3175bf40b76f2a5ce6774c7fa040 --- /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 0000000000000000000000000000000000000000..9b2836c2d903eed42aedd10c5572a8688ab0d504 --- /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 0000000000000000000000000000000000000000..fdc3f22eb3e458e3e3c04763811f11b58c57b197 --- /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 0000000000000000000000000000000000000000..56ed9e3122a31ffc9ccfc2c430c8e4038c21e273 --- /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 0000000000000000000000000000000000000000..f1eaecc38a8d1b2205e20f7323694c928f32786c --- /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 0000000000000000000000000000000000000000..45fd8f36d71eb5637c23028352eadb2a91fbba86 --- /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 0000000000000000000000000000000000000000..17c08eea3cc612732461b6efc76478882747e18e --- /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 0000000000000000000000000000000000000000..84ee0dcca2f994c3d35ef7759aaa9770a039123f --- /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 0000000000000000000000000000000000000000..613f4f50c681fb52a6b6ba433505a07dd5afecc7 --- /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 0000000000000000000000000000000000000000..928d349d37352027e829e39e6e97d968d87148ad --- /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 0000000000000000000000000000000000000000..e7e08504bb579bd7822ce2fedca8dbd32eb259ec --- /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 0000000000000000000000000000000000000000..a921443c437c59c2a7869ae555f5f6ecf1f157b9 --- /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 0000000000000000000000000000000000000000..8782ea76a5d45b168fc7e30d38c256fca49320df --- /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 0000000000000000000000000000000000000000..f958bc6e0f788d33b2b8590925565cc7db6ecd65 --- /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 0000000000000000000000000000000000000000..cda7b0e030148c3e82adfbe9889fd63b09d2932c --- /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 0000000000000000000000000000000000000000..c3e90369a36e871e1aed69a967c47e01ac66163d --- /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 0000000000000000000000000000000000000000..adcbf5318514ab58a86df1ee89ff8f8294021462 --- /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 0000000000000000000000000000000000000000..bd4fd5bc1c9ab0e578364d5a374cd6b55d561e15 --- /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 0000000000000000000000000000000000000000..196600a8ae25bbbbc429fcb97a447c6721d15157 --- /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 0000000000000000000000000000000000000000..788473453a3352844e1d2c3aaa06f1b49ae4b1e1 --- /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 0000000000000000000000000000000000000000..20e8bf58a5bc723ff5610c47ecc0a4c78ee9c576 --- /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 0000000000000000000000000000000000000000..9c8b00b4cfd7cc758323ba0bc96c88b55fa95838 --- /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 0000000000000000000000000000000000000000..62a3f69a1052c582852ced04c68a609e72f32d75 --- /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 0000000000000000000000000000000000000000..3c1b7c435887a38362f6218da200881af8d56dc6 --- /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 0000000000000000000000000000000000000000..95d9bfd12074d5f5d8228c06f343f54840f4182a --- /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 0000000000000000000000000000000000000000..3a0d5df7df9e1a193c29326a41faa2284815bc68 --- /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 0000000000000000000000000000000000000000..ead1ec4bf863bb97b79dcbf8bfe3a76eb7d11dde --- /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 0000000000000000000000000000000000000000..ae795bb04b58130ad68e01551cac7e677cc7b19c --- /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 0000000000000000000000000000000000000000..2c2b47cd46ab510586e3cd489c213b2ba1f3ad13 --- /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 0000000000000000000000000000000000000000..e6a878b01f2f0eef2d3855ed67f82cf96b34db13 --- /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 0000000000000000000000000000000000000000..1f2dce11109648b400d002a879c7c51f17b42c99 --- /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 0000000000000000000000000000000000000000..13660264f40908db2ebb57e02d5d665e1ec8a83c --- /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 0000000000000000000000000000000000000000..678605aefef09576b476268c7f1375ca47bce5ee --- /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 0000000000000000000000000000000000000000..49827a5ca6e1a425c46823b1d471b93df391a202 --- /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 0000000000000000000000000000000000000000..07c599fd71d369459d3686c270dd6a84345b2e7d --- /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 0000000000000000000000000000000000000000..b46f77ad0d874c2149c8865ede5994772e093a3d --- /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 0000000000000000000000000000000000000000..d165d7be7e75175953fb08fb53c342e4d22dea1c --- /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 0000000000000000000000000000000000000000..8949bb2f1f183ed2c7c7d12adc918e86eab8ee51 --- /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 0000000000000000000000000000000000000000..589cfec3045a30200ab4076edac1021915c376aa --- /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 0000000000000000000000000000000000000000..5c622dc6adae3500f0fe1e539e2a12214a65da43 --- /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 0000000000000000000000000000000000000000..af887bf1e89b45d7246c76ad3f074949e8fe2695 --- /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 0000000000000000000000000000000000000000..1ae892380ad10ebc65083bde6b29e6f5cba091f0 --- /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 0000000000000000000000000000000000000000..24d9fd6fd7bfc731179bbcc8289fd10ca10d1c7f --- /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 0000000000000000000000000000000000000000..ee523a26081d85fe6123d13fdd898048cabed723 --- /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 0000000000000000000000000000000000000000..0bd6cc2552d9240ca9cd91545e0c59d6fc5685b9 --- /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 0000000000000000000000000000000000000000..cd6a80a3adbfa957f065fa5165fe7b9f95a3ad53 --- /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 0000000000000000000000000000000000000000..8271e51097cacf54d2a5550fd28eb49741bda648 --- /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 0000000000000000000000000000000000000000..761b8784b21b8825ae6db6613d1c72b3a346fce5 --- /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 0000000000000000000000000000000000000000..af9557ea02a86c828beba64cbfcc5d80c893b36a --- /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 0000000000000000000000000000000000000000..21ff576b5a8852090106ce82c29dc02294864360 --- /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 0000000000000000000000000000000000000000..5be553d1db64edee96f5eb2fd1e7fda43303e139 --- /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 0000000000000000000000000000000000000000..9a53f55a4ba639a05c0eb101f1facee2cfb5dcd8 --- /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 0000000000000000000000000000000000000000..96e7980aca682f353a32f5e189d6ef69cab28692 --- /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 0000000000000000000000000000000000000000..f26998f7661f0dff61398890f6881f7a141292ce --- /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 0000000000000000000000000000000000000000..827dc9344378651487d26d069dcb628229dd24fa --- /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 0000000000000000000000000000000000000000..40e9e3fe9b6a465e2d20e6fdea62bd1f5f8c2980 --- /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 0000000000000000000000000000000000000000..48602ea1185963b74c5c8728c1cfbec4e278210e --- /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 0000000000000000000000000000000000000000..c4a97bfc9e99ee123d688528439b277d99ad7a6d --- /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 0000000000000000000000000000000000000000..b5bbe59dab5dfbfd689dae7e0fd0a735ede42283 --- /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 0000000000000000000000000000000000000000..674cf14901ee510774cbd7d95f6538dbe3818e64 --- /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 0000000000000000000000000000000000000000..687db856d90bb04b4b61509f6b3f1b04bfe987fc --- /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 0000000000000000000000000000000000000000..83a2bbd7a62c47dd10147aaa37d1e59b65d66c36 --- /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 0000000000000000000000000000000000000000..36ca60566e7468ae7cad94ecb782f0c529e39517 --- /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 0000000000000000000000000000000000000000..363ba5180a8f9e367dbc24c310f13f40bc073617 --- /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 0000000000000000000000000000000000000000..20dc89a179e6a401d103c45e34a670a918b671d8 --- /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 0000000000000000000000000000000000000000..17bf261595ed32417dd1618e210e3ff80d8d29e9 --- /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 0000000000000000000000000000000000000000..99c9ec2b4f2adeb261c754319655c1791cb69c65 --- /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 0000000000000000000000000000000000000000..b3f0392057246b277ae854e402189e420cfa3254 --- /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 0000000000000000000000000000000000000000..1ad1b898c49cd4373b2b0d90ac5565767fc3e42e --- /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 0000000000000000000000000000000000000000..3a2aa9285895c3da1aeb6498d235fc2552b4d11a --- /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 0000000000000000000000000000000000000000..5133dac2498f0c3dbac7acafc90f09fabcf98e18 --- /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 0000000000000000000000000000000000000000..69749d03c1276b9b2063bb7a83c5729e5c1755e6 --- /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 0000000000000000000000000000000000000000..37bed7f7ac79525db4a3e5884615f9cb420a4f0b --- /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 0000000000000000000000000000000000000000..b9b93eed44ff75e5ca979c6954f77642ac9da836 --- /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 0000000000000000000000000000000000000000..5846bbcae4ecafc69c4a3c52adb5d04d9397b0bb --- /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 0000000000000000000000000000000000000000..8cb01210801c6b55fb8781177945cfb2e88bf27a --- /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 0b935fd4413e6b8465c60ff54bbac194a4e4afe5..52b4e53c4c707c33582060f5ce18972dc6213f04 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 0000000000000000000000000000000000000000..ecd36aa8adb54417444e2b5e0063f5971ee9089d --- /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 0000000000000000000000000000000000000000..d0d796be5a4fe77b6fcb19f032771972d6b06004 --- /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 0000000000000000000000000000000000000000..ca3e078d294d6bd7ccb779acd7ae5bf95f57c833 --- /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 0000000000000000000000000000000000000000..56c07c040e280da7e6cd205c28ea57f6b70d3246 --- /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 0000000000000000000000000000000000000000..e99e1b71540291243e868b94390b756ccc8c66bd --- /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 0000000000000000000000000000000000000000..ff563cd3adb1a752dea1d00962a498045611c610 --- /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 0000000000000000000000000000000000000000..b980efe7213011cb7f00644b004c76794f20ff79 --- /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 0000000000000000000000000000000000000000..6d2c4a71a872adb59e4252f22e022ac736fed905 --- /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 0000000000000000000000000000000000000000..47cc032e07959b4788e82cbc227c3903b6a1233a --- /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 0000000000000000000000000000000000000000..4bac7788664233c7004f487b9ab40fa2de21fe78 --- /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 0000000000000000000000000000000000000000..411b5ef8c5124514af8a603fb83fd6b2d2ab5617 --- /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 0000000000000000000000000000000000000000..a4e86b427b2ad98cfcb2a2aadad2162db92e4f3e --- /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 0000000000000000000000000000000000000000..fc7e0bccb520e95e147132fab6a5dfed6d3c15be --- /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 0000000000000000000000000000000000000000..19539b599d4929d5b8768a718864cfec6674e03c --- /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 0000000000000000000000000000000000000000..86c878c8874a1007ca570719a4011f7d9477d80b --- /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 0000000000000000000000000000000000000000..0c70719e1d72f488cc4220c918e6053bf7c81e0e --- /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 0000000000000000000000000000000000000000..2b5d020a31479ebc3f6c5bc9e41c7f9a53f59af6 --- /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 0000000000000000000000000000000000000000..f582e69dd498d38cb46fc07eeb0693ddfa22c817 --- /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 0000000000000000000000000000000000000000..898755704fb0ef6c57659fe2983972b0cb7f301d --- /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 0000000000000000000000000000000000000000..1a84196dc2409135c90b81386b3843a3beab710d --- /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 0000000000000000000000000000000000000000..34058a260b0493ff4865249981bc815588a13ae6 --- /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 0000000000000000000000000000000000000000..d63ba8691c8f42ecbc8eb48683eebbafc4cb6516 --- /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 0000000000000000000000000000000000000000..9b7bc9dfcab7849403dd77047664c6eab5bc0fb3 --- /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 0000000000000000000000000000000000000000..35fe965b0bc3f08650ac7f3147c7b71ff91dc69b --- /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 0000000000000000000000000000000000000000..79e40b47c43e2ca02963e47ba1fdd17c3073ad8e --- /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 0000000000000000000000000000000000000000..0b64ac3ca939be2f5c5064fdadb34c357eaa5125 --- /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 0000000000000000000000000000000000000000..eb585beb703d8dd3e51caa3e5bb392a43f6c7cfe --- /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 0000000000000000000000000000000000000000..1efefe1bebc5373bf9bed1b2042bd13dde66f6f4 --- /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 0000000000000000000000000000000000000000..80b0ea9f9784e2620f96c1315ef027182c2af8e4 --- /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 0000000000000000000000000000000000000000..38af74b53b1322f15a9a0db4cf545c549d88dbb3 --- /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 0000000000000000000000000000000000000000..31f2887b33519c04811c08e0ee64a9577212e646 --- /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 0000000000000000000000000000000000000000..ae5d33183be493b3790b195ba1471ceb0dd654e7 --- /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 0000000000000000000000000000000000000000..f881f792d5e31dc95c049409d6f6c52c35173e8d --- /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 0000000000000000000000000000000000000000..12a76cdda386fbe808e534fa62567037c6a60292 --- /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 0000000000000000000000000000000000000000..9ecb72b056e8565a167634a20d478a9763941bee --- /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 0000000000000000000000000000000000000000..04e413a381b3dfc63e68fd78c9ae5454019f814b --- /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 0000000000000000000000000000000000000000..0a8a31a276164ecc963539b0aaa182cdb9caa92c --- /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 0000000000000000000000000000000000000000..4bb60e605e18df132f48ca72743d376de4682d54 --- /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 0000000000000000000000000000000000000000..25b7eb24aa228ddd142ed232dfac72aba20a15db --- /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 0000000000000000000000000000000000000000..b7f2775f2c0d8d0e71ff825cb04a7ddfefa06568 --- /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 0000000000000000000000000000000000000000..f3cfaeb3e211ac3c0012e51b02f8f6805d3c1a75 --- /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 0000000000000000000000000000000000000000..790de25db6b8b3fa59dddc19209a76c65735d1e3 --- /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 0000000000000000000000000000000000000000..eea7537b28dd484faa6464bd1cf2a5d9ec5b8f17 --- /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 0000000000000000000000000000000000000000..ed0d1a9a2de8a50d805fd435e44caf9d61e513a8 --- /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 0000000000000000000000000000000000000000..e61e1c21e4ea7211eec253d7cc6ecbb4cdcde1c8 --- /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 0000000000000000000000000000000000000000..ab18751c2219301278f30a3125332e41e5782816 --- /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 0000000000000000000000000000000000000000..6ed966f70b3ecc6f3fd3429a12ae5c12cb1e8ce5 --- /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 0000000000000000000000000000000000000000..fd69894e669c40f872d9d3ff16d4a7a0b36c75b4 --- /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 0000000000000000000000000000000000000000..538bd26acb7bda61ea2aa753b9c99d98317b5181 --- /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 0000000000000000000000000000000000000000..414440969652d176d32a37dc9fe5d1e9a4ef18ee --- /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 0000000000000000000000000000000000000000..c9b0f5ace777cbeac61a7b7c525d3491ed576f86 --- /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 0000000000000000000000000000000000000000..fafed535edd2e8fdcb3dc484e143f0d7d122131c --- /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 0000000000000000000000000000000000000000..029c16522f3c7f019d5ae9a4e109e17c5f5cf549 --- /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 0000000000000000000000000000000000000000..13af89a56e5b185926af1fa2393f3fc5e1eb05ac --- /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 0000000000000000000000000000000000000000..0942d004dd267a1467caafd0e3e75bcc92d77fd3 --- /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 0000000000000000000000000000000000000000..63fda941346e0370f1f04274712838479869ee9f --- /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 0000000000000000000000000000000000000000..86f3f6cd36c19b4fe63b01109230afbe14a68be2 --- /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 0000000000000000000000000000000000000000..14930635201167b4ec6c62894f86c431c77dc4f0 --- /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 0000000000000000000000000000000000000000..957be1152416d3e919b0d6353a78df8233d12194 --- /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 0000000000000000000000000000000000000000..f8e8ed4496adf2b89e6bf365dfd21627b808b2d5 --- /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 0000000000000000000000000000000000000000..64ba1216f1fe58eeb27d3adca1d8bf7b10b251e6 --- /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 0000000000000000000000000000000000000000..eec6d63418475bd9959dd3e818b7ac16c21e1558 --- /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 0000000000000000000000000000000000000000..73197eb1df8391904ca3c3b7901de5bdb51daf2a --- /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 0000000000000000000000000000000000000000..aeab6fc8e9ac631aefd3ffc0c3a4ba87491384ab --- /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 0000000000000000000000000000000000000000..a0cc1c7723dc55bb77ccb6f97f8b13167626b8b2 --- /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 0000000000000000000000000000000000000000..0dc15c76e4b9f5d945dc4943da3d468c53fb1e04 --- /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 0000000000000000000000000000000000000000..e63adf53ff30fe9b9ab1b14a951e8fe5ccb566f5 --- /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 0000000000000000000000000000000000000000..a4a8ab7eb43dac01e3a46271be44a7b6d7641413 --- /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 0000000000000000000000000000000000000000..554a55aa0e60cbcbf75feb3638fa0f5643c3ac07 --- /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 0000000000000000000000000000000000000000..3a21431013c4504c3daab4fcab6625d978b43a4e --- /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 0000000000000000000000000000000000000000..3bf9014ffa719afcaa4ee99835f7581c9676440d --- /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 0000000000000000000000000000000000000000..a58100f03df1586e6357fc0756eb3f3ef92b9fb7 --- /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 0000000000000000000000000000000000000000..a4bf542d72a762f9512e02ad096aaa228c66123a --- /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 0000000000000000000000000000000000000000..6994a79544322e53a94d1dd9a53276569edf5013 --- /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 0000000000000000000000000000000000000000..0c979bd4f6f2568d0404b5d6998a782461855056 --- /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 0000000000000000000000000000000000000000..28001d77c52e3ca94801c5613599635a680b9cf4 --- /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 0000000000000000000000000000000000000000..fedede8b0847a4f5df46ae1487b2f80f66182813 --- /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 0000000000000000000000000000000000000000..0c1bbab00dd25f349b71b316212c15d722371acb --- /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 0000000000000000000000000000000000000000..c5d14f29ef6e083da5cb5162a38ccfec102892e0 --- /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 0000000000000000000000000000000000000000..ada379de22ab1c11ea87bf10156417c676c2e767 --- /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 0000000000000000000000000000000000000000..81011139ed6efbd27b0a974455c05c35f94a12db --- /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 0000000000000000000000000000000000000000..0f7725e4fe4119fb85123e0d232d61d450d38f41 --- /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 0000000000000000000000000000000000000000..2198725107e3517d3688cf170170a9f831befef1 --- /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 0000000000000000000000000000000000000000..95c7e4b3747142805f146a549d543c2e0c974686 --- /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 0000000000000000000000000000000000000000..f81f5ac40c897b6c8db3fd48c32d3b791c935630 --- /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 0000000000000000000000000000000000000000..82da435a19769602d4ae645dc3c7d98d32430391 --- /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 0000000000000000000000000000000000000000..fb9c58a2012c880cc6bf910fa8901abdd9974a6d --- /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 0000000000000000000000000000000000000000..2b2865b4c287f218890f946358252d369e9cea08 --- /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 0000000000000000000000000000000000000000..df900d1250ed38949f36a4d279ced09752d61a8f --- /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 0000000000000000000000000000000000000000..fe196e0cb9e0122ac4e4671073abbc2343009aca --- /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 0000000000000000000000000000000000000000..6ea0a324c9f4de9f2961492bf61f420131b2274e --- /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 0000000000000000000000000000000000000000..7062e8b1da03edc6e148250187f8f30fd92063fa --- /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 0000000000000000000000000000000000000000..bb291f6775af315d79243bc9d92ecc96f1dac742 --- /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 0000000000000000000000000000000000000000..6adfd3c6b645e568ace41f4dfe0c6d2432621030 --- /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 0000000000000000000000000000000000000000..56bafc356bfd721b721e99e39d3b42cb3dfda4b7 --- /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 0000000000000000000000000000000000000000..467825d2779b9499f9cbb1c77563737923bbb07f --- /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 0000000000000000000000000000000000000000..6317c05d5ddaef78724d85e3698a1cfa7967993f --- /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 0000000000000000000000000000000000000000..33db208c960fb3a85ef83fa6764146c3ec064b05 --- /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 0000000000000000000000000000000000000000..d937cf44f6eecda50b5c197812e81c9274486c2e --- /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 0000000000000000000000000000000000000000..990e4b01a8a3bc76df961c8cc5498a10b0ce5a4b --- /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 0000000000000000000000000000000000000000..a59b7084a562c7b25b2177900e33a378661b4abe --- /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 0000000000000000000000000000000000000000..0d44d7a65c53037243c103f3068b619ff2ae68c3 --- /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 0000000000000000000000000000000000000000..285a7c31688b00ffdefcc79ec3812669a137f681 --- /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 0000000000000000000000000000000000000000..85ab71b09c17dc9e00baae92f69a08f8c9effb21 --- /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 0000000000000000000000000000000000000000..cb8069bc371cdc7127ae922c2cdadea0eeb8e479 --- /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 0000000000000000000000000000000000000000..78f7428a106073117173ac59038fcf37d6ff290a --- /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 0000000000000000000000000000000000000000..9c06fa6c1dda52f689025c2332fcf10e02b585de --- /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 0000000000000000000000000000000000000000..9f7938791c16f5e98bc6eee055383d85139cc94d --- /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 0000000000000000000000000000000000000000..fdc316989664034a96a027c51eb27d913ea554af --- /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 0000000000000000000000000000000000000000..fcdef18da14283816d504e1439d8edb53f727860 --- /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 0000000000000000000000000000000000000000..33c8861abbd247b1d68118fb1e4eff14c4200745 --- /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 0000000000000000000000000000000000000000..6ddcb1f70f5c99a04d2b2dd6a6f144c7cb559d90 --- /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 0000000000000000000000000000000000000000..f11212ce43a8277d5c004fc036de12eb5a490ccc --- /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 0000000000000000000000000000000000000000..5bf3b9086e19283f31d928a086bf4f5fcbdd931b --- /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 0000000000000000000000000000000000000000..2bee1f2f367df8f624abbb3a3b8bf877db7783c2 --- /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 0000000000000000000000000000000000000000..713fe26dd395e3dc1444df6a38e69866805065af --- /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 0000000000000000000000000000000000000000..67fbd38da7b122aae3bcbaa4749c334e4de1d82b --- /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 c06e20b1a5b96138259a61335853a861cca3c859..c6ad3785becb8a2fb7a9d8e54a428b38cbfc1a8f 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 0000000000000000000000000000000000000000..1d44ab16d85d59d6f283982235fe596abe0b41fc --- /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 0000000000000000000000000000000000000000..022f4a15679ba6dd1c3a554526a1cfa47ffd81ee --- /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 0000000000000000000000000000000000000000..38a6515cf8ad7ac633e5902257d0c81fb6390c5f --- /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 0000000000000000000000000000000000000000..bd141027d21a89cab69e04ffad4ab9a799acbae9 --- /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 0000000000000000000000000000000000000000..61a961bd43615fe7ac969ae0b477a288cc3398ef --- /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 0000000000000000000000000000000000000000..8134bac148540022c3e9a0a227283f245f8aba9b --- /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 0000000000000000000000000000000000000000..6a87487b78a118e48566876ca66905da7a8e8143 --- /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 0000000000000000000000000000000000000000..510a58f7bbf1575a180e0d5c6427c9ac5c49a345 --- /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 0000000000000000000000000000000000000000..fc4a0303d79773914fe7ffc7d6253570067c1e07 --- /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 0000000000000000000000000000000000000000..5945953442793e6ca13866df23667dc9ec955078 --- /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 0000000000000000000000000000000000000000..a9454f493e921964c76f45e7f1cd51bd0407ece8 --- /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 0000000000000000000000000000000000000000..843a22a29cdee6e4991469e19d9d382393be6429 --- /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 0000000000000000000000000000000000000000..751b482b93aa6fd1c40055841588896871b3369d --- /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 0000000000000000000000000000000000000000..e932c2689cd0ae6c3b053794af06b4d80249f632 --- /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 0000000000000000000000000000000000000000..94dc9285eeceb6712a5066fde959f188189dbebb --- /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 0000000000000000000000000000000000000000..c572d7dd35224d121a25e1bf438430eb394275c9 --- /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 0000000000000000000000000000000000000000..753fc3f7915f461a012c795043151a9e0940174b --- /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 0000000000000000000000000000000000000000..e338bf1a474742da9de9502525d4d511f8920575 --- /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 ddd3540f8fdc1979718e4361ec50333393c58d06..5a7883f9703ffee4735621fb22ce34b66c9db3aa 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 0000000000000000000000000000000000000000..2f611e46fbd67ddb086f8b0b6313928f3b786179 --- /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 0000000000000000000000000000000000000000..1af7ae94c5ce171e515a78de9e2611ad24386c4c --- /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 0000000000000000000000000000000000000000..a7103a83e83abd29ec101346496151bc876b28f1 --- /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 0000000000000000000000000000000000000000..24ca6f0e32c1783f70ea2a3479e8b8f016d86224 --- /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 0000000000000000000000000000000000000000..f2bab1f7fb3f581d25ff5b68c409f913616f58a0 --- /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 0000000000000000000000000000000000000000..11bf0bedaec98482af51924c715285a6af01a39b --- /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 0000000000000000000000000000000000000000..540d1aba3fbcec88fff6b7cdcda91fe20f3b8139 --- /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 0000000000000000000000000000000000000000..dea31a3c7849c9feccb989445718e3511426c31b --- /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 0000000000000000000000000000000000000000..2102a0b24da70e0a0b5ec712026b190a43d0ca4b --- /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 0000000000000000000000000000000000000000..186585603abd6aae3f7c45f8df41a9f9a92d4117 --- /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 0000000000000000000000000000000000000000..fe27585b253622ba82e8288bc19e85ee77545eec --- /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 0000000000000000000000000000000000000000..beb8d16b0d81807f726d69c82be698d29006ee2a --- /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 0000000000000000000000000000000000000000..6f04ef810f498e12205c47fba5fc9af44904b9d0 --- /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 0000000000000000000000000000000000000000..582c99f3d174056a1fe1a2ab9c5db858714944c2 --- /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 d135c173fe6ee1035e49e584552edd301852da0d..94caedf65a437ce780138be251f0becdfd75a29f 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 df27d079cfe5d80e49851aecc62cffa57c2fbd77..d3d699ffa08899b67f6c7971977551827c99644b 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 0000000000000000000000000000000000000000..90189e441df231554e2b38f427b99c20c6e7106a --- /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 0000000000000000000000000000000000000000..f96271997521ac8f74be5d3dadb31cbe53640496 --- /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 0000000000000000000000000000000000000000..ca9b0d663b01d6c6a01ccb00616a7d0e330277bc --- /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 0000000000000000000000000000000000000000..fd5e0a5ecaa297d75efb5fc432ec34fac6586196 --- /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 0000000000000000000000000000000000000000..39d20e5e2da632a535d807f80f2753ac4710a533 --- /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 0000000000000000000000000000000000000000..2cd9e67d4204224bac02d92646052cca84c6ba87 --- /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 0000000000000000000000000000000000000000..669d272573ae1b28676b1ff83d1cc851ea028b91 --- /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 0000000000000000000000000000000000000000..e4bc1b0bad2b934af222113f0db97b11966fd8d5 --- /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 0000000000000000000000000000000000000000..7fd0c8f051dd3150f92b4838a143af011662917d --- /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 0000000000000000000000000000000000000000..6978bfb3d6463046e2c090d8b55723d49e9ce6d3 --- /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 0000000000000000000000000000000000000000..616f96ce5a95214eb4f84f32fedfa3b85017950e --- /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 0000000000000000000000000000000000000000..d7c28b1301c5d13f96d111fd8b07005d56ab7f3a --- /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 0000000000000000000000000000000000000000..284d49930fa8be841be8ad1b3091799600f6b2d2 --- /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 0000000000000000000000000000000000000000..2b4daf2dd2a6488d1324f0bf41171e8d87bb9359 --- /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 0000000000000000000000000000000000000000..d36811f9031e7b8931e8fb31aa21d9478bd7950d --- /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 0000000000000000000000000000000000000000..ec03407bbf027da705d0d54d9cd5aef024814e73 --- /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 0000000000000000000000000000000000000000..07fc5da7266fb0d5cddc434f4d5e1e1b5b5a888e --- /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 0000000000000000000000000000000000000000..809454a16355237e7de8b5f9d3792d62f2e988c7 --- /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 0000000000000000000000000000000000000000..4e500aaf42da25311bfd685afbb3aae4eaf825b6 --- /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 0000000000000000000000000000000000000000..0b5ab2e592ccfbaebd52368173ac80296a50a334 --- /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 0000000000000000000000000000000000000000..67c1ea4c62a78866b419b0a9f6da813e695ce0d7 --- /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 0000000000000000000000000000000000000000..2f3465b343a1614ad24cb3cffd21c9ff8c07a9a5 --- /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 0000000000000000000000000000000000000000..255672fa46544bf664c57e5bab7fd6b044eb0811 --- /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 0000000000000000000000000000000000000000..d53260ab864b962c43fca2e0dcbaea377ca4efcf --- /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 0000000000000000000000000000000000000000..02a4312c088fac3a5e2728e0bfa65071008844de --- /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 0000000000000000000000000000000000000000..e59dc5c5365e5b14c267c6d69e4dc068d766a909 --- /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 0000000000000000000000000000000000000000..8c591c1a791c29ceed7122a076653f034270da92 --- /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 1adeec42fbd2b9d2ef51ebec3fa3f2d9efe5de44..374cebfa5c71d234ec2a2b23c154b265b79f3232 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 0000000000000000000000000000000000000000..31ee554843382bde95a27c3ed96162b979219656 --- /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 0000000000000000000000000000000000000000..e8f07cb684931c9ee3e8c583e1fe8814337f7406 --- /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 0000000000000000000000000000000000000000..0e3283914348da612981ecdd86a55f22eaa6decb --- /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 0000000000000000000000000000000000000000..873bf7d570e60c205eb7930005f66d73efca3ea8 --- /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 0000000000000000000000000000000000000000..168a579c7ad0902c64f56240f703c41b0bcd33bd --- /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 0000000000000000000000000000000000000000..be321d354d034541032b3a0b2435ee3d6a55feaf --- /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 0000000000000000000000000000000000000000..419acd0f62d6a8d2615ce5b20d39989b4d7217d8 --- /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 0000000000000000000000000000000000000000..1dd1d7696833e10e828aea533b7d1f9ca6436390 --- /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 0000000000000000000000000000000000000000..663a6402b030e37befa3f163a993ef88e48103e7 --- /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 0000000000000000000000000000000000000000..c7450131500f1e01b5a3c30fb5cf5ffcd84a0800 --- /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 0000000000000000000000000000000000000000..85ff13e4ee474f7bd39e509983519d2aeb1db1d2 --- /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 0000000000000000000000000000000000000000..1e12f5551f2e2fbe0d3b64b2b82020599a80c402 --- /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 0000000000000000000000000000000000000000..59971da1e0f73a92186e9c704272718c74ee481e --- /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 0000000000000000000000000000000000000000..4f30cdf5092fce1d8043894f03e60ed241075481 --- /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 0000000000000000000000000000000000000000..a1b5639f13ec9a3b1513454db77624632d4d4a61 --- /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 0000000000000000000000000000000000000000..3e7a82aeb6db503b6360a68dc8a4bc55544feab6 --- /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 0000000000000000000000000000000000000000..cfd180d1f6d431cc44b1e65f03398978977ac1cc --- /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 0000000000000000000000000000000000000000..bc0f6f32bdc4143fb8e81eb17b494030fd01eeb9 --- /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 0000000000000000000000000000000000000000..a672b35bd5683b8e07d97c14584e85a54ba7566a --- /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 0000000000000000000000000000000000000000..c8080729d3a13ac0853d48ce2deefd42d4f3b6e3 --- /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 0000000000000000000000000000000000000000..2e0f7eed1bc27251d01453d736e4c0203ccddadc --- /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 0000000000000000000000000000000000000000..e5ee5393c6da025acb7f6f5a9c3efa13fca3f268 --- /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 0000000000000000000000000000000000000000..c7039bd1dab522cec345fe15e7f227eb1b494467 --- /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 0000000000000000000000000000000000000000..1c07da18e00c6151b003b6e92323d7da181b12c9 --- /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 0000000000000000000000000000000000000000..3d5bb1f8f5905ec3fe8fce9fb67bc1e3ed69da84 --- /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 0000000000000000000000000000000000000000..75c9a5aced92b2f93e004c0b7e75a2ada113c25a --- /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 0000000000000000000000000000000000000000..bd5237b2dad131f68c431c0dc90db3662a9d2a49 --- /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 0000000000000000000000000000000000000000..c68afe4810146d5840139764297137667e654915 --- /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 0000000000000000000000000000000000000000..a8c3cb62e44913e562d7ef2a7bc1d7d088b621f3 --- /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 0000000000000000000000000000000000000000..fdc16e2ab9e297622b6b25a2dcc8a82641a5d353 --- /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 0000000000000000000000000000000000000000..957bb7cddf412ad1873475bb7e689e73b7615a51 --- /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 0000000000000000000000000000000000000000..e7ba977099a36613e93604a4d93821b088007827 --- /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 0000000000000000000000000000000000000000..50fa543a6d0290955b30f0289cfa3d8c16f21f39 --- /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 0000000000000000000000000000000000000000..97266d74950106e9021a685cc6d5b375f2168678 --- /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 0000000000000000000000000000000000000000..a8665d931348fb3d8aecbebb3e663f6f45b5c79e --- /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 0000000000000000000000000000000000000000..8527302fd2aa54ac01b48ebd4fcede6f3c0bb55f --- /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 0000000000000000000000000000000000000000..b4514895a85fbb1d4cd255558681368062d2d524 --- /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 0000000000000000000000000000000000000000..60ce57fe78370a78bf15e60810e51050989629ee --- /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 0000000000000000000000000000000000000000..36b147501903f5c15085509af9c9266cf43bd313 --- /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 0000000000000000000000000000000000000000..b230de9005d12f6244a03c841bc601e4bcd30c7c --- /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 0000000000000000000000000000000000000000..8bcbcfd43a287b9d480aa6eee4685560ca94fefc --- /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 0000000000000000000000000000000000000000..05a8adddf2a2c73b82231e121309d499d9aab6f4 --- /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 0000000000000000000000000000000000000000..25470aff7bb3fa21449b1b5e446c5bb39a8e8f9a --- /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 0000000000000000000000000000000000000000..395a5aea78a07d2e555cee5c2c66bea1eeaa20f9 --- /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 0000000000000000000000000000000000000000..fe364eeac87d77d69331c129b83300200e4cb4d4 --- /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 0000000000000000000000000000000000000000..91763bcfbe5c44e8c2e9335aa6e49917be6efa3d --- /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 0000000000000000000000000000000000000000..34ed97d79edb070b988015c3da83cb0bf6ff8c41 --- /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 0000000000000000000000000000000000000000..f903b32a0d6d476100879f75390e7a701b6bdde7 --- /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 0000000000000000000000000000000000000000..a4f6c763ede69ec038968636e2284e39b321943e --- /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 0000000000000000000000000000000000000000..32441ea61b33d1eff7f60729489f63dd0bb17564 --- /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 0000000000000000000000000000000000000000..fcc586259c618df746cd813ee6073a0e50123c08 --- /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 0000000000000000000000000000000000000000..03b80a145e5b7f91d4107ae793ee7c35d4c20661 --- /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 0000000000000000000000000000000000000000..86ad9f3d416a4b0fcba31087a18c14736fc33b47 --- /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 0000000000000000000000000000000000000000..6b53a2630a4293c7e868d3968780d50e3734414d --- /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 0000000000000000000000000000000000000000..83e9a723ff40f002afb31c6a302f06d67d7030b8 --- /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 0000000000000000000000000000000000000000..370a5b0528edaa8a9cd8a4ad9f76ec4421bc4ae4 --- /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 0000000000000000000000000000000000000000..7fbd76fa0630123f26bb585e0c7af419bfe0b99e --- /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 0000000000000000000000000000000000000000..14680f3d4473225e0d202dc0b6ead819c0e573fe --- /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 0000000000000000000000000000000000000000..6dedc8cd2b6fb20be242f887c365f90c064970c9 --- /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 0000000000000000000000000000000000000000..7b602dd9d690292e9a3762e16d30ac5c055c689d --- /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 0000000000000000000000000000000000000000..8ecb1ff4fc5d1815fac1ee47249941eff81fd4c3 --- /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 0000000000000000000000000000000000000000..d80202ebce58995e1db7264eea5d5b929ee228f8 --- /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 0000000000000000000000000000000000000000..c484769f4fb348cb35cd7df4e99bc82487ea5f2c --- /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 0000000000000000000000000000000000000000..880e1a1a965382ca4334ed3079ab4dc02be376a7 --- /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 0000000000000000000000000000000000000000..a0f2fb513d9cb3bcc429d8c69876898219f09f73 --- /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 0000000000000000000000000000000000000000..ce9dc4b0554bd8df9ff536a2abebd18fa7678b7b --- /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 0000000000000000000000000000000000000000..2bf7460bf895f1e6ad35e3b80cfc17feb48538c8 --- /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 0000000000000000000000000000000000000000..ce1cc6d0e670861bf179324aba1a68cb2b22c6cc --- /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 0000000000000000000000000000000000000000..d0fd3510f67978494e11dc4f152507d4acde5e1d --- /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 0000000000000000000000000000000000000000..6210eea5047e7661f1b331abcbe76447223c2d34 --- /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 0000000000000000000000000000000000000000..08e635433268a1bf04094e006bd2aa41180eda96 --- /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 0000000000000000000000000000000000000000..2818b78b111447f799057800b8ae573c8e2004e8 --- /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 0000000000000000000000000000000000000000..65b07a1ce15acdef49978670a2eb25e7cfebdc18 --- /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 0000000000000000000000000000000000000000..e2cb704a06350212d928651d52b0bde431cf7b7c --- /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 0000000000000000000000000000000000000000..7bc30e60c55cb727d6aea22e867a0680878402b9 --- /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 0000000000000000000000000000000000000000..468ad5e36f63d9993fdb98c50469423e5c94beaa --- /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 0000000000000000000000000000000000000000..cb857c2f50ec5ddf611aa8d5836feea9af382c95 --- /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 0000000000000000000000000000000000000000..fa94ac1191458dc31870f6871f98812470e0a02f --- /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 0000000000000000000000000000000000000000..71eeecbbf75fe444d7e7f75e5b63e782102b21e9 --- /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 0000000000000000000000000000000000000000..feeb92f0f5eabd056c566f9304e5397e5ca842a0 --- /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 0000000000000000000000000000000000000000..d3731ab589a0dadc65f775d6df3e3967e4e4aa77 --- /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 0000000000000000000000000000000000000000..3219fb68272f075a403b28629217232149b0af03 --- /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 0000000000000000000000000000000000000000..fccf9de2bf19501d7ca7dd49a01e7e08121200a8 --- /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 0000000000000000000000000000000000000000..8092e93e937c6b90f3de86a9e22a83114088a1cf --- /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 0000000000000000000000000000000000000000..a7f5cda055bdc9d2f5e9844e7e92cc77d31d752c --- /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 0000000000000000000000000000000000000000..5067380d565bc715e1da9062a0b03625923e0f40 --- /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 0000000000000000000000000000000000000000..7acdfdfff2343e74bc1dcff7940d057bb4c59e30 --- /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 0000000000000000000000000000000000000000..f8b4b6fde87bc09875a23f0e881cb11737b41565 --- /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 0000000000000000000000000000000000000000..ec8dd59458a5ae5835222e89b036da14c133a481 --- /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 0000000000000000000000000000000000000000..afb56f9e165f31e22c4228d5382c5112cd49e990 --- /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 0000000000000000000000000000000000000000..9652d5a60818bef1bce41c1565008d93e6c6bfa9 --- /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 0000000000000000000000000000000000000000..a06d52f98046e94e1c0991767c3bb12ed01f5bfb --- /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 0000000000000000000000000000000000000000..56c828f36acc68c1347842f9d821806e032ed3df --- /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 0000000000000000000000000000000000000000..c9f8fdafd7da5122e749ddb8b2dac85392ee968e --- /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 0000000000000000000000000000000000000000..660088f029b0e4fafacb10fa6b5afb547a7ec592 --- /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 0000000000000000000000000000000000000000..82255a345418db552215a0c8b9681b3e3d11c7c9 --- /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 0000000000000000000000000000000000000000..07b5138d992e8fe492721f09cf6ed8bb08057ae6 --- /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 0000000000000000000000000000000000000000..a5896d24b4da3baa3e7150568475b65830f1f6a4 --- /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 0000000000000000000000000000000000000000..b47dc9de6037f91698c74c503f8f50dc706c588e --- /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 0000000000000000000000000000000000000000..2dd5b23ea0a04dffb2875dff5888ac6e6c410535 --- /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 0000000000000000000000000000000000000000..451e7bad15ce86b4218565e5a1a0d4f44d279583 --- /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 0000000000000000000000000000000000000000..f1a65b06e6a447234ac20d620595acd46e11cc3a --- /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 0000000000000000000000000000000000000000..401a486dbc802ef8ef717f53cf45d60ddd0e9d77 --- /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 0000000000000000000000000000000000000000..fd9121934187ceddee14900da2036d3238421626 --- /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 0000000000000000000000000000000000000000..af1f983492afc92a4725d5c5b6047c10a57064d3 --- /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 0000000000000000000000000000000000000000..f9d8699ab54a90239eab907f660518666ac5ad37 --- /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 0000000000000000000000000000000000000000..ca31811e516a37957e079141d7a05ea262805f62 --- /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 0000000000000000000000000000000000000000..8ee19ce7ca4a483f48c0b3561d1f9bb21b6ca193 --- /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 0000000000000000000000000000000000000000..7a5ed98509129ed316fca61e3fc86072d863b88e --- /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 0000000000000000000000000000000000000000..3a58887263303db5877d720b63c7c69e92d1d939 --- /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 0000000000000000000000000000000000000000..04d51868923c814c8d1b4f0b017da0edfc6ed08b --- /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 0000000000000000000000000000000000000000..a07ffab4f7e415247e17a845e490d90321b8104a --- /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 0000000000000000000000000000000000000000..3ad61f0b6f1e006df6c460b51914178b8168057b --- /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 0000000000000000000000000000000000000000..95c1a9776a1fb19777ce85638a33e53e4e7e28b9 --- /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 0000000000000000000000000000000000000000..7e53f42215ad7c98da04dbe8b0aaf6b2d1a8ad68 --- /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 0000000000000000000000000000000000000000..a25113b5a2f2bd6ece9a3fd79f6d46b57a018a20 --- /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 0000000000000000000000000000000000000000..9a2bd25315a1a4a8ece0e65f71f5f0287504d981 --- /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 0000000000000000000000000000000000000000..07ec822420d607504068eca4fdcd1109aca13ef2 --- /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 0000000000000000000000000000000000000000..1826706ff766e4c7e6ad1ffcebab48121103e1c4 --- /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 0000000000000000000000000000000000000000..4f52624e73bf5d551cd417cf1c1ca54f38283682 --- /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 0000000000000000000000000000000000000000..a206e85a94d958954f687ba55d8bd4890dcf1bee --- /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 0000000000000000000000000000000000000000..2bb904d8fee56a862e68ad3993fc22146a333530 --- /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 0000000000000000000000000000000000000000..6dabe5c1b0759f6a6d88db82db7483e2495ee6de --- /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 0000000000000000000000000000000000000000..d1b6242e9d5c43e86ea77f57c0a25096f99b2093 --- /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 0000000000000000000000000000000000000000..77220ea6a7450972a458d6f55f33462154393368 --- /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 0000000000000000000000000000000000000000..d5848d91ae75b4cd29f2ee3762ede0dba4f2ae65 --- /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 0000000000000000000000000000000000000000..9d5b2478fee1e0c87fc9748f3ce1ec78af2024ab --- /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 0000000000000000000000000000000000000000..1dd14da8cd762b5b5d1d0a3ad7035fb234dcf132 --- /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 0000000000000000000000000000000000000000..7f3c93ff351f5e5aa2857e82d0633928e9ae9705 --- /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 0000000000000000000000000000000000000000..7cf6f1111189f1ff43569eee83d2a6414f31604c --- /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 0000000000000000000000000000000000000000..5e819db9ce9e965685ec85dba37343e06970ccc9 --- /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 0000000000000000000000000000000000000000..408633ced394c9b7eb25ea3a876a008ad2f634c7 --- /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 0000000000000000000000000000000000000000..1b18693456cc6bc4a10c9745a5f19907550e831b --- /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 0000000000000000000000000000000000000000..6e1279ea4c26d4ca1ee5b23646bb70bc3cdd51e0 --- /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 0000000000000000000000000000000000000000..be938ca511949e09a9728131fef2d8154f7111b1 --- /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 0000000000000000000000000000000000000000..86c686e3b2d55b9d074f42d633782205ed7cc8c7 --- /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 0000000000000000000000000000000000000000..8daad3956454c467632df741424a441b4bd51123 --- /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 0000000000000000000000000000000000000000..9da7cbdcf4f3d038e600498e2c1d5171ecbeae73 --- /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 0000000000000000000000000000000000000000..b75cbbd8eae866a2d4571fb6489fd60e3b6d2182 --- /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 0000000000000000000000000000000000000000..2a24d0990a80000138c5e0130b0dc3f657fac8d7 --- /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 0000000000000000000000000000000000000000..98ae8b2fa920684226a4130a9ba9c389caa7b062 --- /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 0000000000000000000000000000000000000000..7eed1fff1692363f5509a472c87c2c56c0216439 --- /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 0000000000000000000000000000000000000000..ba1909dd5ef4ff054934ad4de7c69c62e3a30dd1 --- /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 0000000000000000000000000000000000000000..b57c24551c96bcaf8d13f5f7e6a77fa11bd96b27 --- /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 9ea3f3ef08d0cdf06c094dd66e4ebf7e68a8b494..45d648c1a20dc9e0bd47eea2d241c739f25d870a 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 0000000000000000000000000000000000000000..9f97ab033bc0764dbcc3ac2d806917994af5bc07 --- /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 0000000000000000000000000000000000000000..4c581eb60115c40dca69cf3e713d71b6a1f2f703 --- /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 0000000000000000000000000000000000000000..5dee0faf73c2d05e1daa8a42c2faf77457077e84 --- /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 0000000000000000000000000000000000000000..a5e64a7d186585bd5db4edd9b9d986dbca0401b7 --- /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 0000000000000000000000000000000000000000..5ce258d5c37d7efb4b35d484e3e549df7353fa5e --- /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 0000000000000000000000000000000000000000..29258266b6ca193e1613feac17d3a5254ad8e371 --- /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 0000000000000000000000000000000000000000..adcd18b71e1c442edcbb25f17f5a1af96179d1e7 --- /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 0000000000000000000000000000000000000000..67372bd73712b6e17b142a41e9488bf4eac9065a --- /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 0000000000000000000000000000000000000000..846386175a815a9fdb15c9cc24f1250e55797f63 --- /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 0000000000000000000000000000000000000000..07f62263ad232ec6aa921ca350801069c9e1a1ed --- /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 0000000000000000000000000000000000000000..d12fa6245da9e411645033970f38c226710214f3 --- /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 0000000000000000000000000000000000000000..c352bbaf649470d6b2a447b3e7ee891deded2ec6 --- /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 0000000000000000000000000000000000000000..615fac7a27041246955b9ae91bf037fbdabeefaf --- /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 0000000000000000000000000000000000000000..19657957a341b5a27265057ee5508eb6d11c479f --- /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 0000000000000000000000000000000000000000..e26ef197ab9abca1e841fb3d5a032426de949e13 --- /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 0000000000000000000000000000000000000000..a750f37500f4a39ef3d0c25afef9f4dd5aff971e --- /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 0000000000000000000000000000000000000000..00b6132acebe5a94f3537fe0541551895c8ea07e --- /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 0000000000000000000000000000000000000000..22c8a0abead2d209561e9fcffb5076c5d9064831 --- /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 0000000000000000000000000000000000000000..386149b457c6fe2262984d95bb31501d455bc144 --- /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 0000000000000000000000000000000000000000..a8cee48aaa23e534918d31cfabc5b2bded1c4f1b --- /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 0000000000000000000000000000000000000000..c0ec87e5a76cf35c1b03755fa7fa01a5564cafc9 --- /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 0000000000000000000000000000000000000000..9fa2117984d2a0545bbf0aca131ee35cd68d8700 --- /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 0000000000000000000000000000000000000000..6e003f8df9bcb104d515d4ec3759c20c933c5cb8 --- /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 0000000000000000000000000000000000000000..3b79f13759cfd20ee8d8c2938818b9cfbb23fb80 --- /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 0000000000000000000000000000000000000000..93b074f1f28e4dce83c8f246dbf6b6a95ee526b5 --- /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 0000000000000000000000000000000000000000..6294fa6b1ce69b27727d823a41e2550b1bb8c1fc --- /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 0000000000000000000000000000000000000000..15f1e5765e55c2529cfdd52a40b3a10dad2bc7d0 --- /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 0000000000000000000000000000000000000000..7a742b9b87ccd54f0c352b9ba36faa044195538a --- /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 0000000000000000000000000000000000000000..9675790716f487cfa725b131f5d88a0efed5e22d --- /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 0000000000000000000000000000000000000000..74de9aceb8f762f9864862628d017684547376bd --- /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 0000000000000000000000000000000000000000..5187a421f580cbf59a7424d11be45117d1ab870c --- /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 0000000000000000000000000000000000000000..6f699c2d3299033ae77810d5dbac5dd29d88f843 --- /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 0000000000000000000000000000000000000000..5159487aee7c17d6039a94a86031bca3fce0a637 --- /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 0000000000000000000000000000000000000000..b323cc7ecd93268d02c52ece8c794fe3e6625ddf --- /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 0000000000000000000000000000000000000000..e35f1af62cd4a0223816d496347d45b05e4acf33 --- /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 0000000000000000000000000000000000000000..00a426e10c2c76e10b3b948282661a68cc24537e --- /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 0000000000000000000000000000000000000000..a24ba5a52d9ac8ad03752c3ace2c1a96f0c3a6a2 --- /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 0000000000000000000000000000000000000000..4429f6336d6b03c3f0fd39af87feed9ba64a86c4 --- /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 0000000000000000000000000000000000000000..a2cf9e131174e3816080c9867fc68ef3cbc07961 --- /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 0000000000000000000000000000000000000000..a16cf1c8cb99a320b7bf1bda7c892a1fac5204f5 --- /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 0000000000000000000000000000000000000000..ad429c8a15e622a7e7245b742e5add157350d7e1 --- /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 0000000000000000000000000000000000000000..979b2df9f73b7efc9aaadcc861df4300f26689fc --- /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 0000000000000000000000000000000000000000..8ce0fde83efd01f245cf4a4264e29b1c74c0afa5 --- /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 0000000000000000000000000000000000000000..df0c06fc3b6068c63f040a32aace73faa0b607ff --- /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 0000000000000000000000000000000000000000..4f52490ef6ba3f300d6298dea4d322dd01531f61 --- /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 0000000000000000000000000000000000000000..9c92aed2326ed7fbfbb8d93ea6984004dd3e793c --- /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 0000000000000000000000000000000000000000..b01b5e621e975f2a309f1acb8b235eb2821a9afa --- /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 0000000000000000000000000000000000000000..ce453a2c6b265f1fe766a3f8c6649502066a7ded --- /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 0000000000000000000000000000000000000000..4480beb4df332054c86daac3607f66a8a1797319 --- /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 0000000000000000000000000000000000000000..19a6337d030619c52c172d2bea2db9872f6eb99e --- /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 0000000000000000000000000000000000000000..eef277bfb7da8c11bb67c62ba54053624bfab695 --- /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 0000000000000000000000000000000000000000..4a2331d42771aadfad13eaf0a65fd5ded86708e7 --- /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 0000000000000000000000000000000000000000..dc08ba4aa0173d982f971d1fc908ce28cccdc951 --- /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 0000000000000000000000000000000000000000..ec32a7df4468355c95d29a16f302473a9a66a1e0 --- /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 0000000000000000000000000000000000000000..2135d10ca07b962b5b633f4fa095a63645045976 --- /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 0000000000000000000000000000000000000000..f093afd9bbcfb06f47126b6d9a714cd036277fdd --- /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 0000000000000000000000000000000000000000..7fc5373186d836e4bf669c17ee0dbd53afa385c3 --- /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 0000000000000000000000000000000000000000..c1574968f84d70f4dc899e3b4d88dd68178c4205 --- /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 0000000000000000000000000000000000000000..e216ae7805e7088844da7863300bfe4f074bd4c6 --- /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 0000000000000000000000000000000000000000..00de662ca3daf9a24e21b5430ab0384936a52151 --- /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 0000000000000000000000000000000000000000..ef733a11edb43bbfc7c15d4b998606f86b020fda --- /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 0000000000000000000000000000000000000000..da956be06531e8542946c2ac51ace0851769aa15 --- /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 0000000000000000000000000000000000000000..cc7aba63fb83f12c7de22e8b13e6f07a5015cbbd --- /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 0000000000000000000000000000000000000000..3cc3bb41f011015af8d56e2b9f99942dd937aa44 --- /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 0000000000000000000000000000000000000000..bd1d209f8aff4ba54d55c68e17bfad94a93bb0ce --- /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 0000000000000000000000000000000000000000..b8436a5f31097757cd86b5529b170faf5b29bd4c --- /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 0000000000000000000000000000000000000000..d319341a7fe9df4e53868abfc4e7b6d60fbcd57e --- /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 0000000000000000000000000000000000000000..c058cddac2af80235925b94a32b6443aaab3bfef --- /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 0000000000000000000000000000000000000000..80f23f61836e3d9ee358e297a7e3e70ca76f7d09 --- /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 0000000000000000000000000000000000000000..caa7f80a28a81620adfd8eebdb3a7ef5ffd5edd0 --- /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 0000000000000000000000000000000000000000..e49bb08837dc3cf1c4b0de86ed2c7e7fb2b634f5 --- /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 0000000000000000000000000000000000000000..89e84fc27048b7d26d03d747705f5086a0829f41 --- /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 0000000000000000000000000000000000000000..fea2db35b1f537ba042034c4cc310c006674694c --- /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 0000000000000000000000000000000000000000..028e2639b66f0f5bc61147847f65fa233ec84fec --- /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 0000000000000000000000000000000000000000..2214531a3d0a92a60f72bbc1626135e53a48f6d6 --- /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 0000000000000000000000000000000000000000..21f05def7194a9f0220f74d3a456ef853bbdc4f5 --- /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 0000000000000000000000000000000000000000..d3ad6056f6c7771126639bef615946abdc327d30 --- /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 0000000000000000000000000000000000000000..b7f73c650a7ce7bf6a8763decb21980f61f5d112 --- /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 0000000000000000000000000000000000000000..7a553b13ee32a8140696cacbcc72e80935a6b16b --- /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 0000000000000000000000000000000000000000..588f1b49f28d20bfb085118f516b5947c11ba90a --- /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 0000000000000000000000000000000000000000..9c8a4c7fbb3f1e81b724e86fd8061b6952bf6725 --- /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 0000000000000000000000000000000000000000..74e47bae58fd078253796e8011e743358a6ca5ad --- /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 0000000000000000000000000000000000000000..b8e4087e58377e68265d442c87e01b6b8dcc6ac9 --- /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 0000000000000000000000000000000000000000..0ac7cb592d09075dd7427d0ad8ee935209849b2c --- /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 0000000000000000000000000000000000000000..ca95986442f4327dceac75f83d85ce52c8959b8a --- /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 0000000000000000000000000000000000000000..abfefd8fc0d0a0840286f09f38959102ffefd683 --- /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 0000000000000000000000000000000000000000..7d6bb6297dc753c0e043be4cdafa248a6e1a4b4d --- /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 0000000000000000000000000000000000000000..a0349c37576f5cd61a0b45e71743a3c3b5b444d7 --- /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 0000000000000000000000000000000000000000..d5d11e1b554ee44288787b1cbb807db7aba90411 --- /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 0000000000000000000000000000000000000000..23353fadb757df6d37bae302a77bb3378a61e8c9 --- /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 0000000000000000000000000000000000000000..17f2b3a4c2672e76f0c1cabd1543dea20c51b422 --- /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 0000000000000000000000000000000000000000..d4b9a09a7d3f9f23343e28333dbb8812dfb4c3bb --- /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 0000000000000000000000000000000000000000..87801c85ea497920d386aa52162eae1250285b3b --- /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 0000000000000000000000000000000000000000..3be58ad564e312d954504d37e230d2ed6922f351 --- /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 0000000000000000000000000000000000000000..f31ec844829606eda8fcc17cd1802fe119326b9c --- /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 0000000000000000000000000000000000000000..8e51f899f7167f0458e395219bb5a2c1a4849c44 --- /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 0000000000000000000000000000000000000000..a05ad6261e504d4378fa0ec6a9160910a8598138 --- /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 0000000000000000000000000000000000000000..edff4831feea2c6c2fa976b04ddcd81cb961d8c5 --- /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 0000000000000000000000000000000000000000..29f517746d26111b3d0c14289c2be3f9b8adb627 --- /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 0000000000000000000000000000000000000000..d9f1bf3b5d71ef8749894609becd13ad5f386d5c --- /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 0000000000000000000000000000000000000000..5f66e654f0cf872d817fa1712a2349d2e06b40ff --- /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 0000000000000000000000000000000000000000..0e70b705112ae1ce94740ccd481dd7b14330e12a --- /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 0000000000000000000000000000000000000000..fc8c9cad0e99f3e4e9df595037a8942708704921 --- /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 0000000000000000000000000000000000000000..e552af771225d06c4bc415c4edda19d21ae2e9ac --- /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 0000000000000000000000000000000000000000..c1b64586d8639830399bcb6e841e8283a9830e79 --- /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 0000000000000000000000000000000000000000..1747a44ea7f6d9f2b10b51c3cd982de20a334001 --- /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 0000000000000000000000000000000000000000..1993db3f6bf54d0acbf0c8044622180686e3c9d4 --- /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 0000000000000000000000000000000000000000..958378556a6c2a12b6c6b07f45048a66c657cb87 --- /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 0000000000000000000000000000000000000000..7b11bb59691068980ed03fc38e29095ded9cae37 --- /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 0000000000000000000000000000000000000000..1a01c046056fd95cd1470c7c9c67b443dde9a433 --- /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 0000000000000000000000000000000000000000..1b1a4e46f0cdc409dc5e78a5eea4ab7f2f1dba2d --- /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 0000000000000000000000000000000000000000..01f3427bfee32bbf1af4a0a00beeb28a61385943 --- /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 0000000000000000000000000000000000000000..976731c66bdc377e1a4b751c1a5329df99b44c21 --- /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 0000000000000000000000000000000000000000..275f5e2bde4451f85efa17659bdcc415f562c00a --- /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 0000000000000000000000000000000000000000..6a7885155c600c30c263951db2a3f9991c291a0c --- /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 0000000000000000000000000000000000000000..f847b6d27d756bfe1434126c135b40bb2a216b06 --- /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 0000000000000000000000000000000000000000..c40f36561f53a6b16ed37717b448204c047e8a1e --- /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 0000000000000000000000000000000000000000..9a9fe93d0b31699205df0069b0318f5f911f97e7 --- /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 0000000000000000000000000000000000000000..b01c60feb7ff23c5d7e3a50a1f006657747c6d2d --- /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 0000000000000000000000000000000000000000..debd112e63e2756b7e0c17fed8ccbacf2dfbf0fc --- /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 0000000000000000000000000000000000000000..e933bce82b7c4b24a2b1984a3bc08dd869abf48b --- /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 0000000000000000000000000000000000000000..f1662225cc88111dddad589ff91039d68bed30f1 --- /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 0000000000000000000000000000000000000000..b124aaf261c7c04cab3f2f44342531b69065d251 --- /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 0000000000000000000000000000000000000000..27ad4e2bc21c4284d777ef5cd7825b7db20be7cf --- /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 0000000000000000000000000000000000000000..20f6962efbaab32dd9ae21f89d5a5b5c4e6239dc --- /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 0000000000000000000000000000000000000000..2899e7f6c5ee15546b089688ee5208badb800aa5 --- /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 0000000000000000000000000000000000000000..7842681701f764864ee9a4126467077d9305a392 --- /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 0000000000000000000000000000000000000000..378b4e5b806b5249c02eba21274e6b622a74fc4b --- /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 0000000000000000000000000000000000000000..3398b29ef61eb1ce948bc30601da778bc25c2835 --- /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 0000000000000000000000000000000000000000..fceea34efa5451e727373d8e458d3b1217ddba8f --- /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 0000000000000000000000000000000000000000..1bac9b691dc1f812900cf953283dba812efbb747 --- /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 0000000000000000000000000000000000000000..3c45b81c12e824303f5f609330bb9fd5c88858c6 --- /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 0000000000000000000000000000000000000000..f683ad285ad0be99d0fa058fc91d65c30b540271 --- /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 0000000000000000000000000000000000000000..c3588c70fb5b0944ab93e9d5dbcf6f1b11849f9e --- /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 0000000000000000000000000000000000000000..b67bf77c4e484d56b520e5a3b38658eabf1f0cf1 --- /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 0000000000000000000000000000000000000000..f98c9b5c0fb23fb17b9228c8b38775ceba4f86b2 --- /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 0000000000000000000000000000000000000000..5b9e0cedc656ddddfb1a4e5080b64a965a8030df --- /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 0000000000000000000000000000000000000000..6c31b6bce65b077f5882c1aa88e659bdfeb85dbe --- /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 0000000000000000000000000000000000000000..f9e994aa3b5559e42ccd30108933ebefc018e13f --- /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 0000000000000000000000000000000000000000..5ec17b0f4c49fd6aaad04226708b81e7c49fee5a --- /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 0000000000000000000000000000000000000000..72b1bd61019141432bff89c8fce3a3c6db24fa5d --- /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 0000000000000000000000000000000000000000..0e3da84d85f14947f3c32508fa72094cb0064bd7 --- /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 0000000000000000000000000000000000000000..3f21390283fdf776c89218fe798a98c9c087acb5 --- /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 0000000000000000000000000000000000000000..0a1c9796fa5564535919ac0446558b9d4f6a540d --- /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 0000000000000000000000000000000000000000..576a97a0e2a4f2f2e4c812dbd64df39cb1f837ad --- /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 0000000000000000000000000000000000000000..57b57a78b7faef28cea148217679ffb89232dbdf --- /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 0000000000000000000000000000000000000000..68b78aeddd50392ea92d249c8ad9f171043645e1 --- /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 0000000000000000000000000000000000000000..2f86cd9c28ea101352542f1b9fc467374d7bafee --- /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 0000000000000000000000000000000000000000..67f3f887170dc93adc55e9531fd47fa5cca79fa3 --- /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 0000000000000000000000000000000000000000..9c590f8595aa376309969577c8eae3c0bf63dd70 --- /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 0000000000000000000000000000000000000000..d0c70d6690e9c58a6b9853962efa56abaa71a895 --- /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 0000000000000000000000000000000000000000..bfae5fa4c12b544cc946778ad3552f03f4cacbca --- /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 0000000000000000000000000000000000000000..14cca25849328226488eed83a36e5aa446e1b967 --- /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 0000000000000000000000000000000000000000..cef10b698485e0effb82c002e9d968ff45aed9dd --- /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 0000000000000000000000000000000000000000..a3c12fd016e7e6e564bc72f4836296aece344a8b --- /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 0000000000000000000000000000000000000000..b70167e3b78eeacf296aac38472065676ddc0280 --- /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 0000000000000000000000000000000000000000..2a3a79303c55e87fa2b5625b5791b5e48047a391 --- /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 0000000000000000000000000000000000000000..89430e6ab071136005f7a21909c02c557b3cfb58 --- /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 0000000000000000000000000000000000000000..a80143c266eb1ee027c6b120f714571250c7b071 --- /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 0000000000000000000000000000000000000000..f30cc25843964529cb95e7e7b39f6e8ed2134b41 --- /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 0000000000000000000000000000000000000000..fbb038d25797159f8279e9057ffedd55ea7288fa --- /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 0000000000000000000000000000000000000000..88c98eebf2d17c815048e40a25555b4b8c377192 --- /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 0000000000000000000000000000000000000000..2f153de63d1dd02318052d2da26798db75061ea9 --- /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 0000000000000000000000000000000000000000..7e27248f8121af4d816dd5e3f8a141c2174f43a6 --- /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 0000000000000000000000000000000000000000..9168589393ff5ffc781d7b82925ae42416af964b --- /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 0000000000000000000000000000000000000000..711aeb53a3f292ce113a3463dab637dc2983c03b --- /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 0000000000000000000000000000000000000000..2138f4a81939c23d8e576cf669633b4bc2817f90 --- /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 0000000000000000000000000000000000000000..f422a54d55e3d028c2c572ff41324648a83bea1c --- /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 0000000000000000000000000000000000000000..8cf9c14fe33e39904fd80379595e1e843a9e592b --- /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 0000000000000000000000000000000000000000..a8005eb0bb20b8b31b9a1bc378161a2aa25803ce --- /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 0000000000000000000000000000000000000000..26cf08ae9c0389b6ccb077f9435564705a54ef40 --- /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 0000000000000000000000000000000000000000..64d72646694981eb03997b01f1c30f0c1ee27270 --- /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 0000000000000000000000000000000000000000..1f2378625c4e53e5d1e59e3f48cffdd89d758f6c --- /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 0000000000000000000000000000000000000000..2b78d7926569d08815fe504af35563be04746c12 --- /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 0000000000000000000000000000000000000000..81454fba77fc557e025e505c53a8d194f5906751 --- /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 0000000000000000000000000000000000000000..7b3b9c9e21938a1524832b99233d7c8c420cc0d3 --- /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 0000000000000000000000000000000000000000..0301136c0b59feff9e87be116924d1a4c6167969 --- /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 0000000000000000000000000000000000000000..bdff85d0264255e5587e124fe0b33f370f4b5666 --- /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 0000000000000000000000000000000000000000..1b609117f238d30bd377fd96bfa1308c87db8fd9 --- /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 0000000000000000000000000000000000000000..7921015663a7a40be17e2ae80e4741fad35cfeaa --- /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 0000000000000000000000000000000000000000..373311d0c942f71e796575852bff08904e9ea7ec --- /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 0000000000000000000000000000000000000000..d0619a3f892cbf484216015a34adca4764e20a7f --- /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 0000000000000000000000000000000000000000..978e01e7d8c4109ac8fff8d3edc2ac0947c18a04 --- /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 0000000000000000000000000000000000000000..9bf8105f0e7388de18023933bdd3531cf06576e3 --- /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 0000000000000000000000000000000000000000..5d5976424346edbb60af568f5e06fdad96bee068 --- /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 0000000000000000000000000000000000000000..6f7c8b7f48a7e76f47b235ecb33a2482b80d723a --- /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 0000000000000000000000000000000000000000..86374357e33a18d7e935937590cfe4248d264be8 --- /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 0000000000000000000000000000000000000000..8e5f4b12f23db788601f6b4a49c7461dc0df67e7 --- /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 0000000000000000000000000000000000000000..4067b836f3d6df2d5ab305d3dabb7e74f4188228 --- /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 0000000000000000000000000000000000000000..d6fb802b93b5af4051f29c3049b2e9643fa49d38 --- /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 0000000000000000000000000000000000000000..3a9d2490ef82854ab825558983ab14b6d02be3b8 --- /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 0000000000000000000000000000000000000000..8155a44795fa2d59b1d39deed9b740e6ddd8967f --- /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 0000000000000000000000000000000000000000..e6085da48007d9f86b55ca93f2112fd6b6fa1c23 --- /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 0000000000000000000000000000000000000000..216f9cfdbaade6b47246efaffaf5634b99067dec --- /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 0000000000000000000000000000000000000000..6a25a0aa97dacc68789238c8573999106b52a292 --- /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 0000000000000000000000000000000000000000..b14fd3c4fb159099a44a0d4593bf55ef2660e9f1 --- /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 0000000000000000000000000000000000000000..0cbbb87f6b4b12be4ad998972656904e4d56fa34 --- /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 0000000000000000000000000000000000000000..9e7a519015b333cffe8419542e758944794af4ac --- /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 0000000000000000000000000000000000000000..7e8a5770abb5cf94e7253d8f94512de2b1cc4c15 --- /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 0000000000000000000000000000000000000000..3cc746cd1aa98b1f2c2ecc8c4674a50cbe43bf90 --- /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 0000000000000000000000000000000000000000..41bb0a8e29213452f66fa5c31b574714b612f5cc --- /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 0000000000000000000000000000000000000000..4e1b50f26cf885115a906698fdd53a6ef83ca474 --- /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 0000000000000000000000000000000000000000..8c634fd7bab7af053c075756c478b07c6485840b --- /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 0000000000000000000000000000000000000000..fd3767781483f37217f4f9be7ada77bbdacea066 --- /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 0000000000000000000000000000000000000000..740dff1f3a6ce79db3528279ff2176cf87f75742 --- /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 0000000000000000000000000000000000000000..7df2943579ddfd39a868d3fa84296bc2b9fbbe9e --- /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 0000000000000000000000000000000000000000..09aa6d7d620febde08e1d74df8630bd24305e739 --- /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 0000000000000000000000000000000000000000..22c1bba4d428c61877706e8a0d0599a5fcfd6c1d --- /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 0000000000000000000000000000000000000000..347b0deb8269e98e538367a4f842896aef1bd6ba --- /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 0000000000000000000000000000000000000000..3386725594a9471b93fa087f03caec3aa65605f4 --- /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 0000000000000000000000000000000000000000..b5651d31f7eca679f98d50f36ff303e25b06b3bb --- /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 0000000000000000000000000000000000000000..20325c97c239340afd640596961ff91f44db9fcf --- /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 0000000000000000000000000000000000000000..6fe9d475720e23dd8e5284dd1078b3d18ae86af2 --- /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 0000000000000000000000000000000000000000..80460f1d418b772ad7335365554c9fc4b2b65000 --- /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 0000000000000000000000000000000000000000..4751a27b178e78f4ce84c0c9f95e4aba646a16db --- /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 0000000000000000000000000000000000000000..c26e881c8a1fd547ccd6814680a742586ee3223b --- /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 0000000000000000000000000000000000000000..9d44c612552b685aba3569b2ad8b72cdefdbe212 --- /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 0000000000000000000000000000000000000000..339a4a757fb882c8bdefba7320a930b597b8a156 --- /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 6e15b4ea4c304dbfa0b04978ffe4cf06ffaab16a..84ada078a2e31206127dc1d55e6d048fddb9e494 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 7e2876294245f5ea1c8e7674efa7a87fe4d05164..db9597546a6cfd6035238619cd8ddee6e31cf74c 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 a81d4c504951398507d5c24994bdd03fb4be213e..c3adc0642a0135113b7340f6179c762dde29ed89 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 d14a14023d1f93accf859fe68d03721895f284d4..472cdccc06e6a190cc8905db8cb6758d366ba697 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 f5ced4ea44349961766401d8f55505b3659035f0..750e65dabbc7bbf089db1cd306eb7f79227cd257 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 41fc555098bf52ffd4b67ce642f01501a413587e..0575a9901b70cf4d0d135a3c68140cfa81e001df 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 ad6db0877ac63069e1e69e61347e103c1a275453..f51d37e49acbafa3c025f9a8aff9c8a6c69dfb45 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 571ad77ad84c99361986d7e794055f2e28b9ab16..03e08ee2466c51cbdb2ca731d16e6cd435e0cc1b 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 f8279f50a7e0e6a0eb7cc46f3c57ed71a38ed3c2..a0ff4e705cc07111ab1059163ccccfd92f1aae1b 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 b452dea0357689d02333b0a357e881faae7a9654..53976243e431eb76fb27d8d8eb779c6d4f5975f0 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 08f8cd13021e037d2965ba141cca3bf838c908ea..d3147dc4c0c7dcd91f96033e2fe863c654e69bc8 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 bd335774b4c5a49faf4effe22a42f6be660cac31..9536f2456ad854a86d977837a0e6b80fcf2c411a 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 a92ceee00143ddef3d030ab1033b2ae82f640a98..3b3c5cb868e2dada4271d540710ef55b6e825ba5 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 4a0d60825f6b7156d88322f2e3e648175485126d..41e153911ccb4ec1f68643fd529423ac7f8dd677 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 3aee05e56603359b2952f8d6b97fddf5121462fb..50dd3b1a3a96e702daca21fe5cbc354f60aa8f06 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 516586863e5094f8ec5472290a3995a253db4f34..f468bdea7ed25bf95074b85a3e6007760c544e4f 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 3e2d84e75b371c5628f8e8803ecbc54a49947869..1b507ccbf2f08c0dab55fcc026bff3a6196a1ed0 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 c58fe24252cfa3e5ec8954e907d4fb13253edf4d..aeb3eb6323230643c5dd1ac63b041c8ea047d335 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 ae4515f3497b9746081e138560e6f402f1411dc6..361426d2c9a6274feb448129d28c793e654af539 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 489234c901fe2740d163138e2c92dfbe213ac617..df7564b9d186e0a8410e8f5698bc43bbf4ca3352 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 42b4a54b8ab0cfffd1b78fc03bd2b49f27483f3d..64de7b8c6dee69c5a7a4e7448a3ab29787828027 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 36f68493ad93b3d3c812b579f065509aaf212c7a..df5996746dc27c6360668d0abd8b088724add0c4 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 bb5754a9c0e89499b23b067620bc15da4e707bf7..1d688fac980138040d037c67fabc3dcf75260a9a 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 6aba187c2bcd0c185951247a50b65d9aa29442e1..5f8355d12aafa99511e01aff93acc534d2e47119 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 281d09353970f4ad2423b149f77883f49ed47642..e77230e44ba652d4b1c55320572ef347922766bf 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 8ee2fba54bc195dcafe393b24bc22652e86493ce..a3c275ef16ac76e87d6452e1f7749dab730f2180 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 978f42af64be0e5e280840bfa0670894f2af8ac3..6a24fae75f917ee06e49916057999e5dbfdeead3 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 d29848bf81e856359c11e77e09bd03b08595cf9e..4483d6f3b7b82df92da6f3452695a7f00efa20b7 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 b8976d696deb2a81e7088ab95f18df9051e0ddbd..776a5671387973d4bf4baa58f1b1d5587978b268 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 03860d1a7beddceefabebbfcf81fe9a63724c5d8..279dbf34b61b2f24daec8b696ddd87dcf90af9da 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 a510d7806da4ec10db4e586606b5f19d185fa126..f31427329ef24d1136d13def91ebe02a58ffb16d 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 cfb79f1a948549ca4a4b8e3c16f0a48089e113a7..d538503a39fe0cbcdcfa8bd9f77325c4e49a512e 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 4b0b19aca73f95e929866d0c514659d388574426..0cf6e2965d8177f8d80baa78cf4fd4a78f3e0b0f 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 c485cae138f684c86bd68ad1b41c6ba92b7b794c..4419406c6de5a99dd528f2ad33631b6bfca5e75d 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 96ba9009d66d0bdfc172bcb9d0d6b316a0161fb1..34b3a12dfbc67a1b6aa3409507a26f8097797e74 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 135634646b491497da941db744062d5879665e88..16bfe8d874f8b56c4932ff6f8de1dabb2868e2c8 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 32e78a37dcd0da8c07eac359d386106ceb76ad27..a6cfd230fb807c4b3e574ddfe6f47b3bcf9bb055 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 34cb4dee6841c644e005905e628ef467d427bdda..abbabc666e0c94d6df8936f51624c5b9df832ebb 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 6e58746cd697c99868701e78bf726b3e57fc5951..45acca5948db09004828b741673dba55cd3d474d 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 f8e75d20916914ded361d5451c7dcfc11d4bc6df..c5d66390975df508a59ff0dc8e000838c8e828be 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 43743b956e742c63289ac819b000f7b596a7e54d..ae21a381b447f419452c6fd652683ec5c736d1d9 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 7ed3aca0da1148beb44d30f6810c30d1863e53a1..cac5edc53b9106e3f0fadcdefe92d8433e3ad98a 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 2072aa96dd1a48530c622f0ebf8e5ab5cb8337fd..f8487280ccffe1d3285cf1639b3020540841e5fa 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 e427806102b71e551d2c67cdc26a64f0164a680b..ff86f04d64aeb84b0473a6f858ba82de07152c5f 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 b171826cfb1747d0c959669c36edc17026a72aa8..9de4e9b3bbd18dae2f6be8a6f72193f871dc953a 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 ec2aaf3c1f5250a5461b0bc5f773d365b8a17b53..36fdbe8daf2da4be51bb8739ea6b990427c88e8d 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 339d3041b682a2bcfaaba6d154707a4f57edd86b..f040fe16eec729a339603d62968ecfdd5a9fbac0 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 ef97097495cf3dd666749f28a05791138ecfa8d4..758eef5c0bc3e96fda45329ee201d33b36fc10e8 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 4d9b442c90ee778ebacd53c060fb16f35fc48060..3321aa5b44e3baf1a93c3b7df1f4c8e9000b36c4 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 12839b2d711b14ae7a12585acd2c0d3d0434eee3..de0e9fdc2c21a0153e37b26283beeb72120328c1 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-zero-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-negative-zero.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-symbol-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-is-symbol-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-throws-from-modulo-element-size.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-detachbuffer.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-byteoffset-to-number-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-custom-proto-access-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-custom-proto-access-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-and-offset-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-and-offset.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-length.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-negative-length-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-negative-length.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-offset-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-defined-offset.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-detachedbuffer.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-length-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-length-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-offset-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-excessive-offset-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-invoked-with-undefined-newtarget-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-invoked-with-undefined-newtarget.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-is-referenced-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-is-referenced.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-access-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-access-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-is-symbol-throws-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-is-symbol-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-length-to-number-detachbuffer.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-new-instance-extensibility-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-new-instance-extensibility.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-proto-from-ctor-realm-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-proto-from-ctor-realm.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-returns-new-instance-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-returns-new-instance.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-bytelength-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-bytelength.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-byteoffset-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-toindex-byteoffset.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-typedarray-backed-by-sharedarraybuffer.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-custom-proto-if-object-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-custom-proto-if-object.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/butter-arg/buffer-arg-use-default-proto-if-custom-proto-is-not-object.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-custom-proto-access-throws.js rename to 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 similarity index 72% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-init-zeros.js rename to test/built-ins/TypedArrays/ctors/length-arg/length-arg-init-zeros.js index 384e2399b4306e24a1d4e3aeaa713e52cedf1cec..b361317094d3e4d14f43804a88daaefbc0537e54 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-infinity-throws-rangeerror.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-negative-integer-throws-rangeerror.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-is-symbol-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-new-instance-extensibility.js rename to 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 similarity index 95% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-proto-from-ctor-realm.js rename to test/built-ins/TypedArrays/ctors/length-arg/length-arg-proto-from-ctor-realm.js index f4effc20816086cec9bd64aee9c5a58a6dd9e8f4..77cef261627bc415d84998af7aeef55d608ec6eb 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-returns-object.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-toindex-length.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-undefined-newtarget-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-use-custom-proto-if-object.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/length-arg/length-arg-use-default-proto-if-custom-proto-is-not-object.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-custom-proto-access-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-new-instance-extensibility.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-proto-from-ctor-realm.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-returns-object.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-undefined-newtarget-throws.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-use-custom-proto-if-object.js rename to 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 similarity index 100% rename from test/built-ins/TypedArrays/ctors-bigint/no-args/no-args-use-default-proto-if-custom-proto-is-not-object.js rename to 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 0000000000000000000000000000000000000000..a5e3c3bbc845194f0b07890d3d96be2663189f6f --- /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 0000000000000000000000000000000000000000..f9af0defe76e01525dd59de0c4338564411af782 --- /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 0000000000000000000000000000000000000000..a81d4c504951398507d5c24994bdd03fb4be213e --- /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 0000000000000000000000000000000000000000..d14a14023d1f93accf859fe68d03721895f284d4 --- /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 0000000000000000000000000000000000000000..f5ced4ea44349961766401d8f55505b3659035f0 --- /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 0000000000000000000000000000000000000000..41fc555098bf52ffd4b67ce642f01501a413587e --- /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 0000000000000000000000000000000000000000..ad6db0877ac63069e1e69e61347e103c1a275453 --- /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 0000000000000000000000000000000000000000..571ad77ad84c99361986d7e794055f2e28b9ab16 --- /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 0000000000000000000000000000000000000000..f8279f50a7e0e6a0eb7cc46f3c57ed71a38ed3c2 --- /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 0000000000000000000000000000000000000000..b452dea0357689d02333b0a357e881faae7a9654 --- /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 0000000000000000000000000000000000000000..08f8cd13021e037d2965ba141cca3bf838c908ea --- /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 0000000000000000000000000000000000000000..86a2ac837bec2766329afad8d8726fe22e450de0 --- /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 0000000000000000000000000000000000000000..a92ceee00143ddef3d030ab1033b2ae82f640a98 --- /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 similarity index 93% rename from test/built-ins/TypedArrays/ctors-bigint/object-arg/object-arg-returns.js rename to test/built-ins/TypedArrays/ctors/object-arg/object-arg-returns.js index cb06ba2207c3b60778f43d6e081b23350324c032..57eec9720cd0ec4b63fadd0f71f060d0cc8a8965 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 0000000000000000000000000000000000000000..f9d384b5cf242ec6e2df0470b795e1aa7d11ee41 --- /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 0000000000000000000000000000000000000000..215bf75fc01570233d3fe7e6e06bbde1648e6c70 --- /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 0000000000000000000000000000000000000000..7a7170b6f1de92fcff6181b7185c002a08ecb08d --- /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 0000000000000000000000000000000000000000..482e1159571e1a06c59bb849ddd06a735b56cc34 --- /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 0000000000000000000000000000000000000000..767dd21825299ee6cc5795a9e5616f415531c594 --- /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 0000000000000000000000000000000000000000..f9baf7758facc39c96b53c8a02ebd48912d4597f --- /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 0000000000000000000000000000000000000000..93f85dc9820749e571199ac23f03868fd71a7252 --- /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 0000000000000000000000000000000000000000..42b4a54b8ab0cfffd1b78fc03bd2b49f27483f3d --- /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 0000000000000000000000000000000000000000..36f68493ad93b3d3c812b579f065509aaf212c7a --- /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 0000000000000000000000000000000000000000..bb5754a9c0e89499b23b067620bc15da4e707bf7 --- /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 0000000000000000000000000000000000000000..6aba187c2bcd0c185951247a50b65d9aa29442e1 --- /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 0000000000000000000000000000000000000000..281d09353970f4ad2423b149f77883f49ed47642 --- /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 0000000000000000000000000000000000000000..8ee2fba54bc195dcafe393b24bc22652e86493ce --- /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 0000000000000000000000000000000000000000..978f42af64be0e5e280840bfa0670894f2af8ac3 --- /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 0000000000000000000000000000000000000000..d29848bf81e856359c11e77e09bd03b08595cf9e --- /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 0000000000000000000000000000000000000000..b8976d696deb2a81e7088ab95f18df9051e0ddbd --- /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 0000000000000000000000000000000000000000..03860d1a7beddceefabebbfcf81fe9a63724c5d8 --- /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 0000000000000000000000000000000000000000..a510d7806da4ec10db4e586606b5f19d185fa126 --- /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 0000000000000000000000000000000000000000..cfb79f1a948549ca4a4b8e3c16f0a48089e113a7 --- /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 0000000000000000000000000000000000000000..4b0b19aca73f95e929866d0c514659d388574426 --- /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 0000000000000000000000000000000000000000..c485cae138f684c86bd68ad1b41c6ba92b7b794c --- /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 0000000000000000000000000000000000000000..96ba9009d66d0bdfc172bcb9d0d6b316a0161fb1 --- /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 0000000000000000000000000000000000000000..135634646b491497da941db744062d5879665e88 --- /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 0000000000000000000000000000000000000000..32e78a37dcd0da8c07eac359d386106ceb76ad27 --- /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 0000000000000000000000000000000000000000..411248ffd413d2365792dfbf8c6de2ca20ed991f --- /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 0000000000000000000000000000000000000000..6e58746cd697c99868701e78bf726b3e57fc5951 --- /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 similarity index 96% rename from test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-returns-new-instance.js rename to test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-returns-new-instance.js index 128ec40217e3ffafc98f605b64122e7fbd9b4553..357730df55210ce2136ce0c3d7bc7a5d348eb087 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 0000000000000000000000000000000000000000..f8e75d20916914ded361d5451c7dcfc11d4bc6df --- /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 0000000000000000000000000000000000000000..43743b956e742c63289ac819b000f7b596a7e54d --- /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 0000000000000000000000000000000000000000..7ed3aca0da1148beb44d30f6810c30d1863e53a1 --- /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 0000000000000000000000000000000000000000..2072aa96dd1a48530c622f0ebf8e5ab5cb8337fd --- /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 0000000000000000000000000000000000000000..e427806102b71e551d2c67cdc26a64f0164a680b --- /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 0000000000000000000000000000000000000000..b171826cfb1747d0c959669c36edc17026a72aa8 --- /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 0000000000000000000000000000000000000000..ec2aaf3c1f5250a5461b0bc5f773d365b8a17b53 --- /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 0000000000000000000000000000000000000000..339d3041b682a2bcfaaba6d154707a4f57edd86b --- /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 0000000000000000000000000000000000000000..ef97097495cf3dd666749f28a05791138ecfa8d4 --- /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 0000000000000000000000000000000000000000..4d9b442c90ee778ebacd53c060fb16f35fc48060 --- /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 0000000000000000000000000000000000000000..12839b2d711b14ae7a12585acd2c0d3d0434eee3 --- /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 similarity index 97% rename from test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js rename to test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-custom-proto-if-object.js index 2745fc5e2512b91f3d11c59f998e727cfc831e4b..8af612edcbd527c6a08ad5f20be8cb05ed149990 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 similarity index 97% rename from test/built-ins/TypedArrays/ctors-bigint/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js rename to test/built-ins/TypedArrays/ctors/typedarray-arg/typedarray-arg-use-default-proto-if-custom-proto-is-not-object.js index ec1997e91aba2de918ae9665e7b1bba87be6a457..b31bd96e4de54ba328c206b61f84ca0dd36c4a03 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 0000000000000000000000000000000000000000..2a1028aee8c2787cb1471c23c599a45bade3aa6e --- /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 0000000000000000000000000000000000000000..d000bac394036d402404d6120a964d140c131908 --- /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 0000000000000000000000000000000000000000..0571b9ac53940561963aae328fa62e94b759fbca --- /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 0000000000000000000000000000000000000000..14f59cfd40a86c1abb10e166fa033bdf4cd6b469 --- /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 0000000000000000000000000000000000000000..8c2a128d0c6d438abc972715246b4d6d0e7a6235 --- /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 0000000000000000000000000000000000000000..1b98c27cfe15aa26cb4103b6f5951a24c0570ad1 --- /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 0000000000000000000000000000000000000000..08c921147f338c427d2ea376d16864b0e144427a --- /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 0000000000000000000000000000000000000000..b602a99fa9ed2392fb21c32b033a3c0e010fa72b --- /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 0000000000000000000000000000000000000000..21090c3db5541b8a1f81f0709b17c6d66529c756 --- /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 0000000000000000000000000000000000000000..552a6d7283e787b223f397de1f451fae1795d60e --- /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 0000000000000000000000000000000000000000..836da920c86b4b3c9a6d6c8feffd6ef237b64938 --- /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 0000000000000000000000000000000000000000..08936b4e1d694840a159f9544204a8e86986bee9 --- /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 0000000000000000000000000000000000000000..4efbf68faa2ad85a9f9b8fa34e7641053f3315f5 --- /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 0000000000000000000000000000000000000000..a84021d474439e15df255c5cb088b7a0eded9198 --- /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 0000000000000000000000000000000000000000..36565b495dcaec7665be6905869501ef02a9d405 --- /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 0000000000000000000000000000000000000000..b748126af89ce4a5af51bf9d18fdd2799a9aada0 --- /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 0000000000000000000000000000000000000000..b16d6f9cc07f888bf917fc77cd09ad4ffc05a151 --- /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 0000000000000000000000000000000000000000..9b575c2a9eb19b77b08687c0a2bdb598b21f2cd5 --- /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 0000000000000000000000000000000000000000..a318c055a3141ddbeb7c980748814bf1d60a9c04 --- /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 0000000000000000000000000000000000000000..e0cee67e21d0a8260bdc0d8de16beb0b2efbf571 --- /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 0000000000000000000000000000000000000000..22eff2856c879f7a960602d6a4685af6c6cdd006 --- /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 0000000000000000000000000000000000000000..361edb9d623f8bbd469fd394a379f68a655a9146 --- /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 0000000000000000000000000000000000000000..cbca4484d98a2e71cd9fed8c68e177755b1ea39b --- /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 0000000000000000000000000000000000000000..7e6bc616946f99d36300f9dc22ae8dc63c68ef4b --- /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 0000000000000000000000000000000000000000..48ee4d2851c0df2542737929d390753ae828829d --- /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 0000000000000000000000000000000000000000..af95e8015dad9e31a3028fbcb31a3225c12da747 --- /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 0000000000000000000000000000000000000000..a3bd8b446173f9c59bc40f660fece7dc59e30a6b --- /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 0000000000000000000000000000000000000000..34ee679a552e0bb892be189c042de3d4f329a4f3 --- /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 0000000000000000000000000000000000000000..cebc1b1141fdbcead94cfb0dafb041139344119b --- /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 0000000000000000000000000000000000000000..711f054a5cfadd0f6f65e8f466262b83312eb7ab --- /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 b59bf2297155904884c680c192f24a45a0e15393..8a01176822c640f53d023ebe8adbd2ce4a690224 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 65150c85b9c22844f012c4283159684e94576186..6d102d1b6c8d2ed8c2e4f4e25ba874061b94e6f2 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 2df9a0efc55232dc8b1e5cada3996ff65437f743..2fb965d08c314a84108e45631a0c13e873fa2c6c 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 e136207a354f80991507a56700a311e9797a0fc6..02eeaba113e8876bb68d2ef98767c8d380c0882a 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 ca2968c7ac0f408511d6a761ba04c06a3a7f9196..61612fa35aa17d1b4c7e07c59ab04f10a1c9e66f 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 bf8c34acf3eb286862974ef8e63ae993658f9794..2fe53a328fce7b1fe2d1a5d02ac66f51c94e6c8a 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 66536c623d8d779c4a74f8bc5c46876d9502b717..ab8da0b98c0ad120ce95b9f8c78c038c399c541c 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 ebedc93c8057f0f4007d21645b012662884640fb..d7ac6abc2c573953f72d0afe6e6afc421bd90032 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 efae38c9021c1a8373f85029bac3a995843ea74c..ddde226a2b626ae51144e4084a9a5a6ae1922225 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 0000000000000000000000000000000000000000..9286ba6f54949072f899df775218d18534abb138 --- /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 0000000000000000000000000000000000000000..016d41b63aa22e270161e80a9dd45739db6642b5 --- /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 0000000000000000000000000000000000000000..3fa462103a1b867ac12b168464dc5cc79006c23f --- /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 0000000000000000000000000000000000000000..f20176156637cd6f60eaf231d14570e3e831675b --- /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 0000000000000000000000000000000000000000..d48eb4afbb89ea5ea8de18c2e617c0f4d886953a --- /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 0000000000000000000000000000000000000000..faaf037c3ca889a30d53ef986415b8649a491814 --- /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 0000000000000000000000000000000000000000..2c838c345a6050d4edb87d9ab57e5df0b3eb53d8 --- /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 0000000000000000000000000000000000000000..c87d89cf971068990756444a09257adb6d3c9ac8 --- /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 0000000000000000000000000000000000000000..0d3d3cc7945dec01d44704d288d6518983a9db9d --- /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 0000000000000000000000000000000000000000..8f262daebb5044d3aeaf9090de17640449590a32 --- /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 0000000000000000000000000000000000000000..21ab9cfc39fba644939013488b23df52dc3d4959 --- /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 0000000000000000000000000000000000000000..f928a3f93a39b3e9e1b4deda4756e3f1706011ad --- /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 0000000000000000000000000000000000000000..79a56222aa45c0a7e183d2d9a873c6560f3086ea --- /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 0000000000000000000000000000000000000000..6f6483b9011c31f0295f15e208687e5a9a99dd65 --- /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 0000000000000000000000000000000000000000..5f994cd868d05a2129067c21dd82ba42f21a7204 --- /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 0000000000000000000000000000000000000000..467e89a93cac717c7f729dd47c58e8eb5a46e62f --- /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 0000000000000000000000000000000000000000..5357f3bc0f9e16a04bc82a564d23dd775f59e1c6 --- /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 0000000000000000000000000000000000000000..eb6e41027598d172d933956a05fc36c236fcd2c9 --- /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 0000000000000000000000000000000000000000..f17b06837b6a5a327613db2b1f96b387cc9b491f --- /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 0000000000000000000000000000000000000000..04664a12611b40afd7c8bb98c59aa9ab21cd1267 --- /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 0000000000000000000000000000000000000000..26eb3526b2f1d7653770a30a5112794a90061089 --- /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 ba658f22149d1d9571dd947f1fd6f7cc0b5542cc..6572c1f94620325a2bedf9bf703b7e0ef46759ae 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 4cc13c6f53c5d22c457707e9bd7caae3645bbdfc..afb5672b9943099d3c4e5d4750d5e2a20bb04a83 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 3c63a0ab7fa96f2fb8c85315f84fe2872ab825c9..ba21aec9c5ee94bebbcb3d76c42c2263fb84cf8f 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 207344f831fbc4352a9d05e3e991ab7d51ae9d2a..c891f5cc1a618455424ee5cf094c6db98976788b 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 33511ca7b48f99ae1597ccd1927da46390646122..193d9166566f7b52d0793dcc48f1bde2ecfb56bb 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 4232ab63821b942d16ca7ed6f79b111e1d84deac..b30fc17ece94f3c93103d48c691a289b316e0e8b 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 b51e1f23760b46b780a5b1d3b23c16e13805d47a..845a9afbe29718a1b4cf17900fd6fcdd909da0e4 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 0c9e907975d26e10d7fb799ded41184226d186cc..5d8be8a2a658c2001a41e4419c5be0fa76f57b57 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 5b03b57bfc19c03f28d87b1b5a7055cb08886e18..133f3343d5d8d605b7cdc8deeb735ac8d220e60e 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 7bf8861403340668f1904436534db3b604ae7ad6..09526d11f77dbf1a2a7df8ee6eb02e2a96ca8e2d 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 ab460e4e670640c423f681ab4f36e7f23aae3ccf..08c9a1b3a725b21eab832cd0a46b5fe9c4982f27 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 c6ddb107074fe3c09511f8d5afc62c98e7c0411b..d815738b6e4c61d2be884714fc61a44f3819842a 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 856997801c57fbf7361c59f8e0e9ff77d77e2419..c5cff6eee32fee99473287c527dd33a3cc2e771c 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 681630928da4a6adf68f5d74c519dbf21f58aaf1..e74c95f12f51da36443de158147cea75f3a83269 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 5983e6dfbd1b0efcf6044ad674346419946e8681..a0baaf57e54eedf837ded056148c087e00478051 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 0571a46eadcdb9258bf8509c512720163a50f0ee..ff71bee907fabbd6fc26ff418bce54a59c187607 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 e4f54b45e61c784d697e658ded844f60922bbf10..5e586c7759dadd01955720b7eebb50d36ce648a1 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 0000000000000000000000000000000000000000..b9caa2ddf4d8b29be6e5556de98f9b534906a9a9 --- /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 0000000000000000000000000000000000000000..9af111a7650f4279bb41a94b535409355152d1ea --- /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 0000000000000000000000000000000000000000..af52e3392018a5fe46a6de210376411dd43f02ea --- /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 0000000000000000000000000000000000000000..74b9a69d804f12e3843b997a37aab922bb9b32d0 --- /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 0000000000000000000000000000000000000000..b599b430cb6ee8fd756b97a29d51cfcfa6f1d4f0 --- /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 0000000000000000000000000000000000000000..d97004b83a70bd6aadc40108a071bd840ea5dec1 --- /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 0000000000000000000000000000000000000000..1e04f95443a5aa4cd481c3857246e3b177068b02 --- /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 0000000000000000000000000000000000000000..5a599409a60f4dd5cd87ccc7a0a54d831d94e1a4 --- /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 0000000000000000000000000000000000000000..8f844f550f0f705f429763a4196fc869221857af --- /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 0000000000000000000000000000000000000000..30917db64b894dabf71b3ae09889a5b0cb24ced0 --- /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 0000000000000000000000000000000000000000..a532b6cea14dfa3e2b3b27b433cf9887df6cafac --- /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 0000000000000000000000000000000000000000..8eb2c071482a49261a179fcfc644a1f845cc9458 --- /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 0000000000000000000000000000000000000000..b8f0b02a6152051f383b2391186a1843f817852b --- /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 0000000000000000000000000000000000000000..52113ec8637802ff6df501b44a9dc15d563eed66 --- /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 4ebb82f7e0266c681dcdbd825fbaa2b952ea4913..b0032bad71f2dc01aa9701ad06417af40e89f94c 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 9910fe6ebe06b6d5f4bc6260a2a133f36cf8c854..2b18a93ea5fcee71f17492b504b6ec820f6e6e4e 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 467aff7cf51b05033d138d40554d82d9e5b84c78..4e52b1cf0a240fcc3aff416c4f280862faffede3 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 c9e49d861df4174443d652c0747bee83d767f8fe..6145da9e24e8f2cfca84b353a274354e15f9a11f 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 cb761c6db4f4904c120fd955d3470acabdcc0c65..f58c528b6a7e9fa32e829a090aa049f0cecc3ae1 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 258f11193ee892d7724d6a82b465a348df6df21f..5ad684b787180488819f560618709ce68b994594 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 45e7af40fa7d4cd757571e2a39b8f8a5d5750b47..851cf72b44ee0d020d25a56d4e13a1f0df5ba469 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 116f042753c7d4d15dd080cee0c9b61ac6d1594c..53824ad34abdfb4a4f4edcd1e09b33a15748985d 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 dfb3d0411db79e77a354a01c7f97cee20f910713..a6eaa05dfc2d4729caaae8c57d6d999b38205b06 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 3454fd676d4aa3435596359bf39b10bdc2be0ae0..1d05d06bc0bc87b4ef7a9ef8927e2c26997eb414 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 0000000000000000000000000000000000000000..6148dbea1d900110534b359af7710372aa5c3a62 --- /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 0000000000000000000000000000000000000000..ecd044e13d7b82676ac8a36f25cc10bc3c0e8c47 --- /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 0000000000000000000000000000000000000000..91c06732bcebcefcfc5c04a0c06a34025dae3c44 --- /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 0000000000000000000000000000000000000000..5f14f03170f0424f1224e5ed2ee18405a243e83b --- /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 0000000000000000000000000000000000000000..9523e3a5fd5a62619eb56dbc7cef32dd7f23c2fe --- /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 0000000000000000000000000000000000000000..34c96bd49b480a6805ec78f784ee1f089d37c02c --- /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 0000000000000000000000000000000000000000..1b4f76c0f594a19507f8c77017c90054a8b5c598 --- /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 0000000000000000000000000000000000000000..b9a163b79b08f59dc559b57f08fe4faa209937a6 --- /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 0000000000000000000000000000000000000000..bc8674429d50835747ed4ab4b8b4d8ebabd559eb --- /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 0000000000000000000000000000000000000000..d00d1a626a6edfdf76e3bfc41d93a8b6014a46bb --- /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 0000000000000000000000000000000000000000..8bb915de61bf961ff3ab162b53bad7f2f692c996 --- /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 0000000000000000000000000000000000000000..dd1cbdfb5ae6c8131657399debc528b2137bfae7 --- /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 c0f54cd4a449bc7bdf6f8d5b950ed50ae15b623b..81b274361f49e72e7ff1f8399c778dc489646c75 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 b637e6fe3453a7ee50979cc254c8aa918bc6f21d..308a2973f1431c58c5084e3fa4013203dcf93a3e 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 0771ae51ec4a68ab1eff00f2856c6a13b0d0bcd1..fe7f1eca260af7b3c48c57b8c83609a52e7ee09e 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 93fb63a55bfc06ee08cf73dc5db3f030dd2cd75b..1b1c828abc21848314ac83b302e1d4876890962b 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 e2f7352a0370a1b825abba297ec7af4a316a8aa4..35b6fa01c5ec92d9c14e711932ae0f5e17ece0ac 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 78e7e59150161b7e407f0dfdc9c79397dd95decb..f77950d728a88a4abdd529dddcea6fb75f9eeb6b 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 32f68d2ceb776c10058f2700b82b93637bc4d4d0..57fd606ae598febd780e57871bf3d8c5465895e4 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 a02b44bb4dee8a2b57383404ac5b482cdcaba452..891bc7184de16327d00caa57bf4db28b24d492d5 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 2d31cb822e49c02458fab51512edb68ce8fd33af..6b440e1194c063e76301e28d4088f1ffc5a6b012 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 0000000000000000000000000000000000000000..5c788c69a657fc8876a52da0d9ea801ef90ed3eb --- /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 0000000000000000000000000000000000000000..d4495d2e1bef9fa53eca2f70ad1bf5f4dbdf5992 --- /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 0000000000000000000000000000000000000000..50df7a49c7fce6e40f0ca3c9a4249e01e5770b05 --- /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 0000000000000000000000000000000000000000..3870e5282ab61b051bd54ee86828a74fbc835331 --- /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 0000000000000000000000000000000000000000..d78265e35098fb99ff62744a40e227d3cd1f3fe5 --- /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 0000000000000000000000000000000000000000..f01eb86896c5bf5c10887ef85f9e1bac95f449b4 --- /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 0000000000000000000000000000000000000000..2e4cdb7aeb8be3b1bdedadf9ec83cb73903866a4 --- /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 0000000000000000000000000000000000000000..6407c2644c4468ddd5d86012c8daa8c8ed927018 --- /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 0000000000000000000000000000000000000000..c1d721348e86fb812b4c6712fa8769ce8017ffc2 --- /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 0000000000000000000000000000000000000000..0048a4f975192b781ea15cf5ac5b2790e4957a61 --- /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 0000000000000000000000000000000000000000..0d6a1515f3a1ec79cfec3a2c593cd2278b8f73f5 --- /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 0000000000000000000000000000000000000000..ecd5dd72527e88a3a8d25db3fbceb11f1a7898c5 --- /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 0000000000000000000000000000000000000000..303b602781083725e0e8fe1374851918a8727996 --- /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 0000000000000000000000000000000000000000..d960abfdd5b36cbb1b3de232c4d242a96e9954e5 --- /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 0000000000000000000000000000000000000000..0f6d744877920c8032af1159d278dbcbba31dc2d --- /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 4a4b645403288ce06182da3d4895541f7abdc4e2..011e80c0b61429e0a6d643bc20c27c920c999345 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 abc2bf4e3ca9cafac54c09657590a6925d9c125d..2c34c3caa0fd1f0e0c6e61955b413a417a1466c2 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 88aea9dc65f787db0006ad46ef731885b4758ec9..5a3b0482ac3e9eebda363c3c1b0145b1e7984d59 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 14ffa907287c53733d1aa3fe84f0b9a5722b94a3..7e20c5b24fb951ffca70565f64ce4eb7e6279db1 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 0000000000000000000000000000000000000000..42adcfeba7bffa631e5899d5a661a6d1ca56dcda --- /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 0000000000000000000000000000000000000000..e3d78dac42165b2439038f04ba91e7cbcc655390 --- /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 0000000000000000000000000000000000000000..9217b46279ddab73c76c6ed20452956c73ff1e61 --- /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 0000000000000000000000000000000000000000..d50d2d20f9c72e18c27eb00e6cead1aa97400787 --- /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 d469c9ab1c9c82d8778ae52f0302a447e48aa791..9060bee4d74f04baa3a1a3d2047d29d39c71aa89 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 5f933e570b3611b0b5636a28d8e1356b51d168db..b227ef6f22645a60c0ce329c7bfa2ba772f9bad2 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 17c78ca5a3de40120f9b950528e2e54de3bec532..00e57de342dabb7d7060b49d02583f4a9994da64 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 0000000000000000000000000000000000000000..4c8bff504579067e820a7873be68dde7e364fc97 --- /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 0000000000000000000000000000000000000000..e7980f30865ce46f506e5b1b417592b75721bd80 --- /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 0000000000000000000000000000000000000000..c7311063b52ec0f82dc9660d2393742f3aadaa7d --- /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 0000000000000000000000000000000000000000..f7e71ff0ebdf9e158fbd713cb2bfff9c29e091b0 --- /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 0000000000000000000000000000000000000000..2a27fff807300e366b3d8c281b982db7212edec4 --- /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 0000000000000000000000000000000000000000..5203e21c980f4ae3ae36ecd79f707eec58a803f7 --- /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 0000000000000000000000000000000000000000..6fcd8dead1286ce75138cd4987225e63ccf41165 --- /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 0000000000000000000000000000000000000000..f2760e7e131f97f4d9cee2e1e356d1a466630327 --- /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 0000000000000000000000000000000000000000..758cc107268a2adf42719c1e3b209de6128a3835 --- /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 0000000000000000000000000000000000000000..1e55325f6c59a8f2cac39ab18b7803b4e6908e1a --- /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 0000000000000000000000000000000000000000..842de9dd0a45f0657cada8e6f9148e090e51def0 --- /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 0000000000000000000000000000000000000000..3031a6ed9644837a6a9bf6120e6a830826cb8074 --- /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 0000000000000000000000000000000000000000..184ae7abcf31454f9bca634d60c925eb0b31d857 --- /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 0000000000000000000000000000000000000000..2111ef6458f0b2c07bc10261610472ba1b115103 --- /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 0000000000000000000000000000000000000000..a967ec01c772ff6b0e34395c8794566e5c7ed05b --- /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 d802d2fd5c7932a5279492c7ffac4ac675c6d5e4..7382d626e72ffeda832f5f67af742b5b7291dfbd 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 18869f683d8f459eb5e46781fb23ea302781a279..1fbe1b60ca206fe19970237fc56611e2420919f8 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 186259cee4d4b682f40f6af43f6d3fc563ddbffd..a373f9fbe3d54becdab8c78655ad782c5893e2af 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 bb325d11c4e45fb1283f10885ae0cf1dda72a03b..2333d4c44bf56a20e85b2510d3ef5be135ec809a 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 5946ebc7c37d7e30d44db86762513a09c8a95312..a735e8baad35b92f82820cec8ec4a76867f11165 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 d89a0f1fb25a7db1611d23ad7f461aa23918fd31..1fb7a9ec6bc1508d729705eb8216390e932198d4 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 c513faefeef14defcaedc3b4bd993c0ed81c0982..252220f61d999cf6921e23b68a2c71bc53ad637b 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 03a181965e3ae23748ae457bd7018d5e61237164..462eb752d3436238a1ec39afa9ba437bd8bd135a 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 859bdee4f96608cbe82ee44892cd1470fc56dc6f..e5a5d6da854a2ff4396eaf640b97e5c1039db53b 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 e27d501c056167c080586a3531b7400189e5caf1..838ab74e0bbcddf44cf46e5420a675c393fd508d 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 e90eb47988984d6a2a297db43f1f31e918518614..08131f4bf39215edb205dbef0ee83c0def860f03 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 0000000000000000000000000000000000000000..b5931184957d39db0485d06aeeb0875069cf3581 --- /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 0000000000000000000000000000000000000000..fd22b08b1996ec368587ca9dccbc56e3a02a7678 --- /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 0000000000000000000000000000000000000000..ca17d437ed177eddafc86a20b6392854886452a9 --- /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 0000000000000000000000000000000000000000..3c289e0a813f38027580f8c5dc6b270bd5369333 --- /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 0000000000000000000000000000000000000000..cddf2c4cf6c9b39338c9991662883df8a7053d19 --- /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 0000000000000000000000000000000000000000..e087cada3b7a73d564b123fa7b3d88a00467183a --- /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 0000000000000000000000000000000000000000..677cb59fb42e53dbc41cc9e0563a3e9c3d2be0fa --- /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 0000000000000000000000000000000000000000..7becb0d7dc13e3a5fc25a77d7a550e16c18363a2 --- /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 0000000000000000000000000000000000000000..4158c3709095f0f780e6a40437fae633a80eaab5 --- /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 0000000000000000000000000000000000000000..1891ae19993fbb08418301cbabf2006b1464ac9b --- /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 0000000000000000000000000000000000000000..973753857f27e5e2d85df21d51c4acf215947ddf --- /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 0000000000000000000000000000000000000000..58641f945e104960e815eb055f8d83b7fee275db --- /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 0000000000000000000000000000000000000000..7e9cc745c40be382b3e53a4908262a6627d86499 --- /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 0000000000000000000000000000000000000000..006b674047a68ab4aba573be40faf6199f4fda9f --- /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 3d8a49deddfdfc7da6dacff1bf00922f1f7bb3f1..bda57f8cd45f5724fb90b913dc56ec5ec8682e88 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 6417c73d5eab1603a4b13cf39e5e0a13973e4fc3..e116b1db7e174a5538e02e244df76f2d10338047 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 fbcc55b27e6ddd15f29e1c974f8327b4c58eaba9..7cc95230eb31a6439572f8a44d481fd55175ecc3 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 a0fbe0150eaea8e5b5b44f3a6a6336b381c7a71c..e83ad648d95dae047ca52502d463cb5ee90b8504 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 0000000000000000000000000000000000000000..e0372adb729de535ae25ecfbe482f96f39411313 --- /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 0000000000000000000000000000000000000000..46590fe4d59567d9bbf70d0c9cb97a6302d66b90 --- /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 0000000000000000000000000000000000000000..323b7476fc87d12ac7ac7d49fe6ba6cb3ef87cd0 --- /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 0000000000000000000000000000000000000000..52b3432653516519de9c150a2b447f3102d1e65b --- /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 0000000000000000000000000000000000000000..1d60311e03f72af81d04ccf01bc4097b98a53368 --- /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 0000000000000000000000000000000000000000..db5105ac69d84d255941aa7c248e31377f23aaf5 --- /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 0000000000000000000000000000000000000000..8601bc2683467edd233967f5322319a5470b9d89 --- /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 0000000000000000000000000000000000000000..9b3da52bf21de0d44cbeb3c95e0b56ba7bf67935 --- /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 0000000000000000000000000000000000000000..b6862164edf89936a2918757647e664bd597425d --- /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 0000000000000000000000000000000000000000..36d9019de38bc7a201b4572e424fc22f3d60de9c --- /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 0000000000000000000000000000000000000000..828c4f4c4765bb680884c1de67d661d36eb4376f --- /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 0000000000000000000000000000000000000000..63f6f2279a2e704b57b9234ec63295ba1e31b43a --- /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 0000000000000000000000000000000000000000..de6e9371d76371a6fcf3fccc38ee711469f386e9 --- /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 0000000000000000000000000000000000000000..362ef22a98db53c25aef5e929d158ee1d7f1d794 --- /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 0000000000000000000000000000000000000000..cc649c89fd8a48d54358a8a3621117d43d18a1c6 --- /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 0000000000000000000000000000000000000000..f4c800c5e3158c1e7775da5e6105cfa88ec1d816 --- /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 0000000000000000000000000000000000000000..5a68f3fa3e4d245f66834950537ae8adfc602a21 --- /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 0000000000000000000000000000000000000000..b75ccb8317d0e75e887e5b63527136b6166d703a --- /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 0000000000000000000000000000000000000000..2d5d48aaeefb5e2e96e09b9c6e56adf4b6de3609 --- /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 0000000000000000000000000000000000000000..d01bda7097141139d79c21771b528947db235336 --- /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 0000000000000000000000000000000000000000..784e4c2b7058182533fafca68eec46af2189309c --- /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 0000000000000000000000000000000000000000..7d8a7d6e2296177c5bb2d0eb2b3bf21005882b11 --- /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 0000000000000000000000000000000000000000..411b66fdaf158fef89a0c0e1b04c880638826532 --- /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 0000000000000000000000000000000000000000..a1ae44026d256e23fc35b84b93de61a96bb9d22d --- /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 0000000000000000000000000000000000000000..4b75f87f2e53170efa5be4e595e0cb65204e3aeb --- /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 0000000000000000000000000000000000000000..37aab5255d1f793adcb3878ee1a2aead3ec579f8 --- /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 0000000000000000000000000000000000000000..2416208a3f780730baa4b07d6f9489dd1df2cf14 --- /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 0000000000000000000000000000000000000000..d4a48e25d652a1ad46f8631d94e5f4eb2ffd1415 --- /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 0000000000000000000000000000000000000000..9f1b0e2177828358a5b697d8a06976572dc70391 --- /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 0000000000000000000000000000000000000000..bd4aaec70aaafc5f64d28f55020de55e5b7cb812 --- /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); +});