diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/TypedArrayConstructors | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
886 files changed, 32972 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..cc0ec24ce5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/BYTES_PER_ELEMENT.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.bytes_per_element +description: BigInt64Array.BYTES_PER_ELEMENT property descriptor +info: | + 22.2.5.1 TypedArray.BYTES_PER_ELEMENT + + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 52 for TypedArray. + + This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt64Array, "BYTES_PER_ELEMENT", { + value: 8, + writable: false, + enumerable: false, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/constructor.js new file mode 100644 index 0000000000..940076e123 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/constructor.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: BigInt64Array is a constructor function +info: | + 22.2.4 The TypedArray Constructors + + [...] + + The TypedArray intrinsic constructor functions are single functions + whose behaviour is overloaded based upon the number and types of its + arguments. The actual behaviour of a call of TypedArray depends upon + the number and kind of arguments that are passed to it. +features: [BigInt] +---*/ + +assert.sameValue(typeof BigInt64Array, "function"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/is-a-constructor.js new file mode 100644 index 0000000000..a61e34ba33 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The BigInt64Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, BigInt, TypedArray] +---*/ + +assert.sameValue(isConstructor(BigInt64Array), true, 'isConstructor(BigInt64Array) must return true'); +new BigInt64Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/length.js new file mode 100644 index 0000000000..f8ee7d0f73 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: BigInt64Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [BigInt, TypedArray] +---*/ + +verifyProperty(BigInt64Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/name.js new file mode 100644 index 0000000000..683f829815 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/name.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: BigInt64Array.name property descriptor +info: | + 22.2.5 Properties of the TypedArray Constructors + + [...] + + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 52. + + 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, this value is the name that + is given to the function in this specification. For functions that + are specified as properties of objects, the name value is the + property name string used to access the function. [...] + + 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] +features: [BigInt] +---*/ + +verifyProperty(BigInt64Array, "name", { + value: "BigInt64Array", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prop-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prop-desc.js new file mode 100644 index 0000000000..6ddc794bd8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prop-desc.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-objects +description: BigInt64Array property descriptor +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(this, "BigInt64Array", { + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/proto.js new file mode 100644 index 0000000000..23e5d1da1d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/proto.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: BigInt64Array prototype internal slot +info: | + 22.2.5 Properties of the TypedArray Constructors + + The value of the [[Prototype]] internal slot of each TypedArray + constructor is the %TypedArray% intrinsic object. +includes: [testTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(BigInt64Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype.js new file mode 100644 index 0000000000..41a7afcb84 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: BigInt64Array.prototype property descriptor +info: | + 22.2.5.2 TypedArray.prototype + + The initial value of TypedArray.prototype is the corresponding + TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt64Array, "prototype", { + value: Object.getPrototypeOf(new BigInt64Array()), + writable: false, + enumerable: false, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..135681804d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/BYTES_PER_ELEMENT.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype.bytes_per_element +description: BigInt64Array.prototype.BYTES_PER_ELEMENT property descriptor +info: | + 22.2.5.1 TypedArray.prototype.BYTES_PER_ELEMENT + + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number + value of the Element Size value specified in Table 52 for TypedArray. + + This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt64Array.prototype, "BYTES_PER_ELEMENT", { + value: 8, + writable: false, + enumerable: false, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/constructor.js new file mode 100644 index 0000000000..5b10a19b66 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/constructor.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype.constructor +description: BigInt64Array.prototype.constructor property descriptor +info: | + 22.2.6.2 TypedArray.prototype.constructor + + The initial value of a TypedArray.prototype.constructor is the + corresponding %TypedArray% intrinsic object. + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigInt64Array.prototype, "constructor", { + value: BigInt64Array, + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..716b051ec3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/not-typedarray-object.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: BigInt64Array.prototype is not a TypedArray instance +info: | + 22.2.6 Properties of TypedArray Prototype Objects + + [...] A TypedArray prototype object is an ordinary object. It does not + have a [[ViewedArrayBuffer]] or any other of the internal slots that + are specific to TypedArray instance objects. +features: [BigInt] +---*/ +assert.sameValue(typeof BigInt64Array, 'function'); +assert.throws(TypeError, function () { + BigInt64Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/proto.js new file mode 100644 index 0000000000..460aaca932 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/proto.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: BigInt64Array.prototype prototype internal slot +info: | + 22.2.6 Properties of TypedArray Prototype Objects + + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype%. [...] +includes: [testTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(BigInt64Array.prototype), + TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigInt64Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..0949547998 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/BYTES_PER_ELEMENT.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.bytes_per_element +description: BigUint64Array.BYTES_PER_ELEMENT property descriptor +info: | + 22.2.5.1 TypedArray.BYTES_PER_ELEMENT + + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 52 for TypedArray. + + This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigUint64Array, "BYTES_PER_ELEMENT", { + value: 8, + writable: false, + enumerable: false, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/constructor.js new file mode 100644 index 0000000000..3dd32413a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/constructor.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: BigUint64Array is a constructor function +info: | + 22.2.4 The TypedArray Constructors + + [...] + + The TypedArray intrinsic constructor functions are single functions + whose behaviour is overloaded based upon the number and types of its + arguments. The actual behaviour of a call of TypedArray depends upon + the number and kind of arguments that are passed to it. +features: [BigInt] +---*/ + +assert.sameValue(typeof BigUint64Array, "function"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/is-a-constructor.js new file mode 100644 index 0000000000..4bf662a43c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The BigUint64Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(BigUint64Array), true, 'isConstructor(BigUint64Array) must return true'); +new BigUint64Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/length.js new file mode 100644 index 0000000000..9d2c001391 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: BigUint64Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [BigInt, TypedArray] +---*/ + +verifyProperty(BigUint64Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/name.js new file mode 100644 index 0000000000..c06e8f68d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/name.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: BigUint64Array.name property descriptor +info: | + 22.2.5 Properties of the TypedArray Constructors + + [...] + + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 52. + + 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, this value is the name that + is given to the function in this specification. For functions that + are specified as properties of objects, the name value is the + property name string used to access the function. [...] + + 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] +features: [BigInt] +---*/ + +verifyProperty(BigUint64Array, "name", { + value: "BigUint64Array", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prop-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prop-desc.js new file mode 100644 index 0000000000..e9fb09f32f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prop-desc.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-objects +description: BigUint64Array property descriptor +info: | + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(this, "BigUint64Array", { + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/proto.js new file mode 100644 index 0000000000..6af1546744 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/proto.js @@ -0,0 +1,18 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: BigUint64Array prototype internal slot +info: | + 22.2.5 Properties of the TypedArray Constructors + + The value of the [[Prototype]] internal slot of each TypedArray + constructor is the %TypedArray% intrinsic object. +includes: [testTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(BigUint64Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype.js new file mode 100644 index 0000000000..4a90e63f70 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: BigUint64Array.prototype property descriptor +info: | + 22.2.5.2 TypedArray.prototype + + The initial value of TypedArray.prototype is the corresponding + TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigUint64Array, "prototype", { + value: Object.getPrototypeOf(new BigUint64Array()), + writable: false, + enumerable: false, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..9fe2a661da --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/BYTES_PER_ELEMENT.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype.bytes_per_element +description: BigUint64Array.prototype.BYTES_PER_ELEMENT property descriptor +info: | + 22.2.5.1 TypedArray.prototype.BYTES_PER_ELEMENT + + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number + value of the Element Size value specified in Table 52 for TypedArray. + + This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigUint64Array.prototype, "BYTES_PER_ELEMENT", { + value: 8, + writable: false, + enumerable: false, + configurable: false +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/constructor.js new file mode 100644 index 0000000000..415a8f2fc3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/constructor.js @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype.constructor +description: BigUint64Array.prototype.constructor property descriptor +info: | + 22.2.6.2 TypedArray.prototype.constructor + + The initial value of a TypedArray.prototype.constructor is the + corresponding %TypedArray% intrinsic object. + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [BigInt] +---*/ + +verifyProperty(BigUint64Array.prototype, "constructor", { + value: BigUint64Array, + writable: true, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..d1d4230489 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/not-typedarray-object.js @@ -0,0 +1,20 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: BigUint64Array.prototype is not a TypedArray instance +info: | + 22.2.6 Properties of TypedArray Prototype Objects + + [...] A TypedArray prototype object is an ordinary object. It does not + have a [[ViewedArrayBuffer]] or any other of the internal slots that + are specific to TypedArray instance objects. +features: [BigInt] +---*/ +assert.sameValue(typeof BigUint64Array, 'function'); +assert.throws(TypeError, function () { + BigUint64Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/proto.js new file mode 100644 index 0000000000..b114d3ae20 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/proto.js @@ -0,0 +1,19 @@ +// Copyright (C) 2017 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: BigUint64Array.prototype prototype internal slot +info: | + 22.2.6 Properties of TypedArray Prototype Objects + + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype%. [...] +includes: [testTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(BigUint64Array.prototype), + TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/BigUint64Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..6cb49dc140 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Float32Array.BYTES_PER_ELEMENT is 4. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Float32Array.BYTES_PER_ELEMENT, 4); + +verifyNotEnumerable(Float32Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Float32Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Float32Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/constructor.js new file mode 100644 index 0000000000..d378eefe9c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Float32Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Float32Array, 'function', 'typeof Float32Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/is-a-constructor.js new file mode 100644 index 0000000000..0160b66aa6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Float32Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Float32Array), true, 'isConstructor(Float32Array) must return true'); +new Float32Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/length.js new file mode 100644 index 0000000000..68f3d42a09 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Float32Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Float32Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/name.js new file mode 100644 index 0000000000..e7e141d975 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Float32Array.name is "Float32Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Float32Array.name, "Float32Array"); + +verifyNotEnumerable(Float32Array, "name"); +verifyNotWritable(Float32Array, "name"); +verifyConfigurable(Float32Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/proto.js new file mode 100644 index 0000000000..82f214ed30 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Float32Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Float32Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype.js new file mode 100644 index 0000000000..e350f7215f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Float32Array.prototype is the Float32Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Float32Array.prototype, Object.getPrototypeOf(new Float32Array(0))); + +verifyNotEnumerable(Float32Array, "prototype"); +verifyNotWritable(Float32Array, "prototype"); +verifyNotConfigurable(Float32Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..716cb5b7b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/BYTES_PER_ELEMENT.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: sec-typedarray.prototype.bytes_per_element +description: > + The initial value of Float32Array.prototype.BYTES_PER_ELEMENT is 4. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Float32Array.prototype.BYTES_PER_ELEMENT, 4); + +verifyNotEnumerable(Float32Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Float32Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Float32Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/constructor.js new file mode 100644 index 0000000000..0e8900d4fa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Float32Array.prototype.constructor is the Float32Array object. +info: | + The initial value of Float32Array.prototype.constructor is the intrinsic + object %Float32Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Float32Array.prototype.constructor, Float32Array); + +verifyNotEnumerable(Float32Array.prototype, "constructor"); +verifyWritable(Float32Array.prototype, "constructor"); +verifyConfigurable(Float32Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..2c13bccf65 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Float64Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Float64Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/proto.js new file mode 100644 index 0000000000..1db64d3074 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Float32Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Float32Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float32Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..52455ee3e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Float64Array.BYTES_PER_ELEMENT is 8. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Float64Array.BYTES_PER_ELEMENT, 8); + +verifyNotEnumerable(Float64Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Float64Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Float64Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/constructor.js new file mode 100644 index 0000000000..27fbc9e25d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Float64Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Float64Array, 'function', 'typeof Float64Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/is-a-constructor.js new file mode 100644 index 0000000000..4b09abfee8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Float64Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Float64Array), true, 'isConstructor(Float64Array) must return true'); +new Float64Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/length.js new file mode 100644 index 0000000000..2f95790929 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Float64Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Float64Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/name.js new file mode 100644 index 0000000000..e9e559c9ee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Float64Array.name is "Float64Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Float64Array.name, "Float64Array"); + +verifyNotEnumerable(Float64Array, "name"); +verifyNotWritable(Float64Array, "name"); +verifyConfigurable(Float64Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/proto.js new file mode 100644 index 0000000000..1f9a6dbdb0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Float64Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Float64Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype.js new file mode 100644 index 0000000000..fd538ec346 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Float64Array.prototype is the Float64Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Float64Array.prototype, Object.getPrototypeOf(new Float64Array(0))); + +verifyNotEnumerable(Float64Array, "prototype"); +verifyNotWritable(Float64Array, "prototype"); +verifyNotConfigurable(Float64Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..84d7449fd6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/BYTES_PER_ELEMENT.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: sec-typedarray.prototype.bytes_per_element +description: > + The initial value of Float64Array.prototype.BYTES_PER_ELEMENT is 8. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Float64Array.prototype.BYTES_PER_ELEMENT, 8); + +verifyNotEnumerable(Float64Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Float64Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Float64Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/constructor.js new file mode 100644 index 0000000000..aac70d907f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Float64Array.prototype.constructor is the Float64Array object. +info: | + The initial value of Float64Array.prototype.constructor is the intrinsic + object %Float64Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Float64Array.prototype.constructor, Float64Array); + +verifyNotEnumerable(Float64Array.prototype, "constructor"); +verifyWritable(Float64Array.prototype, "constructor"); +verifyConfigurable(Float64Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..2c13bccf65 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Float64Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Float64Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/proto.js new file mode 100644 index 0000000000..ec35277dbd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Float64Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Float64Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Float64Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..c7d3f66fd7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Int16Array.BYTES_PER_ELEMENT is 2. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int16Array.BYTES_PER_ELEMENT, 2); + +verifyNotEnumerable(Int16Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Int16Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Int16Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/constructor.js new file mode 100644 index 0000000000..70c4f20e95 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Int16Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Int16Array, 'function', 'typeof Int16Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/is-a-constructor.js new file mode 100644 index 0000000000..3765dff0c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Int16Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Int16Array), true, 'isConstructor(Int16Array) must return true'); +new Int16Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/length.js new file mode 100644 index 0000000000..b5d92a72d7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Int16Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Int16Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/name.js new file mode 100644 index 0000000000..188718a488 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Int16Array.name is "Int16Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Int16Array.name, "Int16Array"); + +verifyNotEnumerable(Int16Array, "name"); +verifyNotWritable(Int16Array, "name"); +verifyConfigurable(Int16Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/proto.js new file mode 100644 index 0000000000..cd1a83901c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Int16Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Int16Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype.js new file mode 100644 index 0000000000..099514e6a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Int16Array.prototype is the Int16Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int16Array.prototype, Object.getPrototypeOf(new Int16Array(0))); + +verifyNotEnumerable(Int16Array, "prototype"); +verifyNotWritable(Int16Array, "prototype"); +verifyNotConfigurable(Int16Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..710a982f36 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/BYTES_PER_ELEMENT.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: sec-typedarray.prototype.bytes_per_element +description: > + The initial value of Int16Array.prototype.BYTES_PER_ELEMENT is 2. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int16Array.prototype.BYTES_PER_ELEMENT, 2); + +verifyNotEnumerable(Int16Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Int16Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Int16Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/constructor.js new file mode 100644 index 0000000000..7a6d4d4d83 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Int16Array.prototype.constructor is the Int16Array object. +info: | + The initial value of Int16Array.prototype.constructor is the intrinsic + object %Int16Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Int16Array.prototype.constructor, Int16Array); + +verifyNotEnumerable(Int16Array.prototype, "constructor"); +verifyWritable(Int16Array.prototype, "constructor"); +verifyConfigurable(Int16Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..c9d010ee3e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Int16Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Int16Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/proto.js new file mode 100644 index 0000000000..99a478232b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Int16Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Int16Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int16Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..42a6d373e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Int32Array.BYTES_PER_ELEMENT is 4. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int32Array.BYTES_PER_ELEMENT, 4); + +verifyNotEnumerable(Int32Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Int32Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Int32Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/constructor.js new file mode 100644 index 0000000000..c6ab6e689e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Int32Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Int32Array, 'function', 'typeof Int32Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/is-a-constructor.js new file mode 100644 index 0000000000..f8e0bdb7e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Int32Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Int32Array), true, 'isConstructor(Int32Array) must return true'); +new Int32Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/length.js new file mode 100644 index 0000000000..9465f489ea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Int32Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Int32Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/name.js new file mode 100644 index 0000000000..d7e639093b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Int32Array.name is "Int32Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Int32Array.name, "Int32Array"); + +verifyNotEnumerable(Int32Array, "name"); +verifyNotWritable(Int32Array, "name"); +verifyConfigurable(Int32Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/proto.js new file mode 100644 index 0000000000..24f99cf935 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Int32Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Int32Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype.js new file mode 100644 index 0000000000..8005d5f814 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Int32Array.prototype is the Int32Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int32Array.prototype, Object.getPrototypeOf(new Int32Array(0))); + +verifyNotEnumerable(Int32Array, "prototype"); +verifyNotWritable(Int32Array, "prototype"); +verifyNotConfigurable(Int32Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..a2fbafe0f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/BYTES_PER_ELEMENT.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: sec-typedarray.prototype.bytes_per_element +description: > + The initial value of Int32Array.prototype.BYTES_PER_ELEMENT is 4. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int32Array.prototype.BYTES_PER_ELEMENT, 4); + +verifyNotEnumerable(Int32Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Int32Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Int32Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/constructor.js new file mode 100644 index 0000000000..2489221760 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Int32Array.prototype.constructor is the Int32Array object. +info: | + The initial value of Int32Array.prototype.constructor is the intrinsic + object %Int32Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Int32Array.prototype.constructor, Int32Array); + +verifyNotEnumerable(Int32Array.prototype, "constructor"); +verifyWritable(Int32Array.prototype, "constructor"); +verifyConfigurable(Int32Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..ba3e48ea62 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Int32Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Int32Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/proto.js new file mode 100644 index 0000000000..cdec27c587 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Int32Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Int32Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int32Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..ecc264228b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Int8Array.BYTES_PER_ELEMENT is 1. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int8Array.BYTES_PER_ELEMENT, 1); + +verifyNotEnumerable(Int8Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Int8Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Int8Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/constructor.js new file mode 100644 index 0000000000..8996f30ef5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Int8Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Int8Array, 'function', 'typeof Int8Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/is-a-constructor.js new file mode 100644 index 0000000000..02896a1294 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Int8Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Int8Array), true, 'isConstructor(Int8Array) must return true'); +new Int8Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/length.js new file mode 100644 index 0000000000..b4d8d412be --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Int8Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Int8Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/name.js new file mode 100644 index 0000000000..e4a12de7e7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Int8Array.name is "Int8Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Int8Array.name, "Int8Array"); + +verifyNotEnumerable(Int8Array, "name"); +verifyNotWritable(Int8Array, "name"); +verifyConfigurable(Int8Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/proto.js new file mode 100644 index 0000000000..615d4f90ad --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Int8Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Int8Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype.js new file mode 100644 index 0000000000..3466c23461 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Int8Array.prototype is the Int8Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int8Array.prototype, Object.getPrototypeOf(new Int8Array(0))); + +verifyNotEnumerable(Int8Array, "prototype"); +verifyNotWritable(Int8Array, "prototype"); +verifyNotConfigurable(Int8Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..09c269c109 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/BYTES_PER_ELEMENT.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: sec-typedarray.prototype.bytes_per_element +description: > + The initial value of Int8Array.prototype.BYTES_PER_ELEMENT is 1. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Int8Array.prototype.BYTES_PER_ELEMENT, 1); + +verifyNotEnumerable(Int8Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Int8Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Int8Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/constructor.js new file mode 100644 index 0000000000..f51fec8974 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Int8Array.prototype.constructor is the Int8Array object. +info: | + The initial value of Int8Array.prototype.constructor is the intrinsic + object %Int8Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Int8Array.prototype.constructor, Int8Array); + +verifyNotEnumerable(Int8Array.prototype, "constructor"); +verifyWritable(Int8Array.prototype, "constructor"); +verifyConfigurable(Int8Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..be64360d06 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Int8Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Int8Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/proto.js new file mode 100644 index 0000000000..6886e56cff --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Int8Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Int8Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Int8Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..db3c16b120 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Uint16Array.BYTES_PER_ELEMENT is 2. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint16Array.BYTES_PER_ELEMENT, 2); + +verifyNotEnumerable(Uint16Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint16Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint16Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/constructor.js new file mode 100644 index 0000000000..fa1bd2dbde --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Uint16Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Uint16Array, 'function', 'typeof Uint16Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/is-a-constructor.js new file mode 100644 index 0000000000..7f78905d2a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Uint16Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Uint16Array), true, 'isConstructor(Uint16Array) must return true'); +new Uint16Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/length.js new file mode 100644 index 0000000000..ae7d22ccd5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Uint16Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Uint16Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/name.js new file mode 100644 index 0000000000..35e59e9927 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Uint16Array.name is "Uint16Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint16Array.name, "Uint16Array"); + +verifyNotEnumerable(Uint16Array, "name"); +verifyNotWritable(Uint16Array, "name"); +verifyConfigurable(Uint16Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/proto.js new file mode 100644 index 0000000000..1926d6eefe --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Uint16Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint16Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype.js new file mode 100644 index 0000000000..2aef9dea51 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Uint16Array.prototype is the Uint16Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint16Array.prototype, Object.getPrototypeOf(new Uint16Array(0))); + +verifyNotEnumerable(Uint16Array, "prototype"); +verifyNotWritable(Uint16Array, "prototype"); +verifyNotConfigurable(Uint16Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..ebb9c9555b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/BYTES_PER_ELEMENT.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: sec-typedarray.prototype.bytes_per_element +description: > + The initial value of Uint16Array.prototype.BYTES_PER_ELEMENT is 2. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint16Array.prototype.BYTES_PER_ELEMENT, 2); + +verifyNotEnumerable(Uint16Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint16Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint16Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/constructor.js new file mode 100644 index 0000000000..3be3a992dc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Uint16Array.prototype.constructor is the Uint16Array object. +info: | + The initial value of Uint16Array.prototype.constructor is the intrinsic + object %Uint16Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint16Array.prototype.constructor, Uint16Array); + +verifyNotEnumerable(Uint16Array.prototype, "constructor"); +verifyWritable(Uint16Array.prototype, "constructor"); +verifyConfigurable(Uint16Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..10e2c7123a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Uint16Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Uint16Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/proto.js new file mode 100644 index 0000000000..b28264d2f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Uint16Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint16Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint16Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..d6bfc95a61 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Uint32Array.BYTES_PER_ELEMENT is 4. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint32Array.BYTES_PER_ELEMENT, 4); + +verifyNotEnumerable(Uint32Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint32Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint32Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/constructor.js new file mode 100644 index 0000000000..d68134350b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Uint32Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Uint32Array, 'function', 'typeof Uint32Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/is-a-constructor.js new file mode 100644 index 0000000000..9c082743aa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Uint32Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Uint32Array), true, 'isConstructor(Uint32Array) must return true'); +new Uint32Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/length.js new file mode 100644 index 0000000000..2f43b323eb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Uint32Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Uint32Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/name.js new file mode 100644 index 0000000000..231782fbf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Uint32Array.name is "Uint32Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint32Array.name, "Uint32Array"); + +verifyNotEnumerable(Uint32Array, "name"); +verifyNotWritable(Uint32Array, "name"); +verifyConfigurable(Uint32Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/proto.js new file mode 100644 index 0000000000..23afd396b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Uint32Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint32Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype.js new file mode 100644 index 0000000000..47a31f0c1f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Uint32Array.prototype is the Uint32Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint32Array.prototype, Object.getPrototypeOf(new Uint32Array(0))); + +verifyNotEnumerable(Uint32Array, "prototype"); +verifyNotWritable(Uint32Array, "prototype"); +verifyNotConfigurable(Uint32Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..f75d146066 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/BYTES_PER_ELEMENT.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: sec-typedarray.prototype.bytes_per_element +description: > + The initial value of Uint32Array.prototype.BYTES_PER_ELEMENT is 4. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint32Array.prototype.BYTES_PER_ELEMENT, 4); + +verifyNotEnumerable(Uint32Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint32Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint32Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/constructor.js new file mode 100644 index 0000000000..04a94a3139 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Uint32Array.prototype.constructor is the Uint32Array object. +info: | + The initial value of Uint32Array.prototype.constructor is the intrinsic + object %Uint32Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint32Array.prototype.constructor, Uint32Array); + +verifyNotEnumerable(Uint32Array.prototype, "constructor"); +verifyWritable(Uint32Array.prototype, "constructor"); +verifyConfigurable(Uint32Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..31c49abe88 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Uint32Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Uint32Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/proto.js new file mode 100644 index 0000000000..db175cdf0f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Uint32Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint32Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint32Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..4a6a489f8c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Uint8Array.BYTES_PER_ELEMENT is 1. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8Array.BYTES_PER_ELEMENT, 1); + +verifyNotEnumerable(Uint8Array, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint8Array, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint8Array, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/constructor.js new file mode 100644 index 0000000000..ccb01277c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Uint8Array is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Uint8Array, 'function', 'typeof Uint8Array is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/is-a-constructor.js new file mode 100644 index 0000000000..335a183a10 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Uint8Array constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct, TypedArray] +---*/ + +assert.sameValue(isConstructor(Uint8Array), true, 'isConstructor(Uint8Array) must return true'); +new Uint8Array(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/length.js new file mode 100644 index 0000000000..09e57e6804 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Uint8Array.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Uint8Array, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/name.js new file mode 100644 index 0000000000..c3b17bdc55 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Uint8Array.name is "Uint8Array". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8Array.name, "Uint8Array"); + +verifyNotEnumerable(Uint8Array, "name"); +verifyNotWritable(Uint8Array, "name"); +verifyConfigurable(Uint8Array, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/proto.js new file mode 100644 index 0000000000..4549c9c5c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Uint8Array is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint8Array), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype.js new file mode 100644 index 0000000000..6268bee61e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Uint8Array.prototype is the Uint8Array prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8Array.prototype, Object.getPrototypeOf(new Uint8Array(0))); + +verifyNotEnumerable(Uint8Array, "prototype"); +verifyNotWritable(Uint8Array, "prototype"); +verifyNotConfigurable(Uint8Array, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..d2ebd79e05 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/BYTES_PER_ELEMENT.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: sec-properties-of-typedarray-prototype-objects +description: > + The initial value of Uint8Array.prototype.BYTES_PER_ELEMENT is 1. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8Array.prototype.BYTES_PER_ELEMENT, 1); + +verifyNotEnumerable(Uint8Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint8Array.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint8Array.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/constructor.js new file mode 100644 index 0000000000..6703145f92 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Uint8Array.prototype.constructor is the Uint8Array object. +info: | + The initial value of Uint8Array.prototype.constructor is the intrinsic + object %Uint8Array%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8Array.prototype.constructor, Uint8Array); + +verifyNotEnumerable(Uint8Array.prototype, "constructor"); +verifyWritable(Uint8Array.prototype, "constructor"); +verifyConfigurable(Uint8Array.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..5d4f4bcfa9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Uint8Array.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Uint8Array.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/proto.js new file mode 100644 index 0000000000..780a41c80d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Uint8Array.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint8Array.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8Array/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..2db04077c8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/BYTES_PER_ELEMENT.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: sec-typedarray.bytes_per_element +description: > + The initial value of Uint8ClampedArray.BYTES_PER_ELEMENT is 1. +info: | + The value of TypedArray.BYTES_PER_ELEMENT is the Number value of the + Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8ClampedArray.BYTES_PER_ELEMENT, 1); + +verifyNotEnumerable(Uint8ClampedArray, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint8ClampedArray, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint8ClampedArray, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/constructor.js new file mode 100644 index 0000000000..48dd23b711 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/constructor.js @@ -0,0 +1,13 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: > + Uint8ClampedArray is a constructor function. +features: [TypedArray] +---*/ + +assert.sameValue(typeof Uint8ClampedArray, 'function', 'typeof Uint8ClampedArray is "function"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/is-a-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/is-a-constructor.js new file mode 100644 index 0000000000..1d5d915332 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/is-a-constructor.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + The Uint8ClampedArray constructor implements [[Construct]] +info: | + IsConstructor ( argument ) + + The abstract operation IsConstructor takes argument argument (an ECMAScript language value). + It determines if argument is a function object with a [[Construct]] internal method. + It performs the following steps when called: + + If Type(argument) is not Object, return false. + If argument has a [[Construct]] internal method, return true. + Return false. +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +assert.sameValue(isConstructor(Uint8ClampedArray), true, 'isConstructor(Uint8ClampedArray) must return true'); +new Uint8ClampedArray(); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/length.js new file mode 100644 index 0000000000..7d65eaeb2e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-constructors +description: Uint8ClampedArray.length property descriptor +info: | + The TypedArray Constructors + + The length property of the TypedArray constructor function is 3. + + 17 ECMAScript Standard Built-in Objects + + ... + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +verifyProperty(Uint8ClampedArray, "length", { + value: 3, + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/name.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/name.js new file mode 100644 index 0000000000..263014c653 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + Uint8ClampedArray.name is "Uint8ClampedArray". +info: | + Each TypedArray constructor has a name property whose value is the + String value of the constructor name specified for it in Table 49. + + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8ClampedArray.name, "Uint8ClampedArray"); + +verifyNotEnumerable(Uint8ClampedArray, "name"); +verifyNotWritable(Uint8ClampedArray, "name"); +verifyConfigurable(Uint8ClampedArray, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/proto.js new file mode 100644 index 0000000000..42cf2b2121 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/proto.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-the-typedarray-constructors +description: > + The prototype of Uint8ClampedArray is %TypedArray%. +info: | + The value of the [[Prototype]] internal slot of each TypedArray constructor is the %TypedArray% intrinsic object (22.2.1). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint8ClampedArray), TypedArray); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype.js new file mode 100644 index 0000000000..28ade76879 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray.prototype +description: > + The initial value of Uint8ClampedArray.prototype is the Uint8ClampedArray prototype object. +info: | + The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (22.2.6). + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8ClampedArray.prototype, Object.getPrototypeOf(new Uint8ClampedArray(0))); + +verifyNotEnumerable(Uint8ClampedArray, "prototype"); +verifyNotWritable(Uint8ClampedArray, "prototype"); +verifyNotConfigurable(Uint8ClampedArray, "prototype"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/BYTES_PER_ELEMENT.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/BYTES_PER_ELEMENT.js new file mode 100644 index 0000000000..251f12144c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/BYTES_PER_ELEMENT.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: sec-properties-of-typedarray-prototype-objects +description: > + The initial value of Uint8ClampedArray.prototype.BYTES_PER_ELEMENT is 1. +info: | + The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Number value + of the Element Size value specified in Table 49 for TypedArray. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8ClampedArray.prototype.BYTES_PER_ELEMENT, 1); + +verifyNotEnumerable(Uint8ClampedArray.prototype, "BYTES_PER_ELEMENT"); +verifyNotWritable(Uint8ClampedArray.prototype, "BYTES_PER_ELEMENT"); +verifyNotConfigurable(Uint8ClampedArray.prototype, "BYTES_PER_ELEMENT"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/constructor.js new file mode 100644 index 0000000000..bb572e729f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/constructor.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. + +/*--- +esid: sec-typedarray.prototype.constructor +description: > + The initial value of Uint8ClampedArray.prototype.constructor is the Uint8ClampedArray object. +info: | + The initial value of Uint8ClampedArray.prototype.constructor is the intrinsic + object %Uint8ClampedArray%. + + 17 ECMAScript Standard Built-in Objects: + 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] +features: [TypedArray] +---*/ + +assert.sameValue(Uint8ClampedArray.prototype.constructor, Uint8ClampedArray); + +verifyNotEnumerable(Uint8ClampedArray.prototype, "constructor"); +verifyWritable(Uint8ClampedArray.prototype, "constructor"); +verifyConfigurable(Uint8ClampedArray.prototype, "constructor"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/not-typedarray-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/not-typedarray-object.js new file mode 100644 index 0000000000..c145223f14 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/not-typedarray-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + Uint8ClampedArray.prototype is not a TypedArray instance object. +info: | + A TypedArray prototype object is an ordinary object. It does not have + a [[ViewedArrayBuffer]] or any other of the internal slots that are + specific to TypedArray instance objects. +features: [TypedArray] +---*/ + +assert.throws(TypeError, function() { + Uint8ClampedArray.prototype.buffer; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/proto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/proto.js new file mode 100644 index 0000000000..59620ea596 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/proto.js @@ -0,0 +1,17 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-properties-of-typedarray-prototype-objects +description: > + The prototype of Uint8ClampedArray.prototype is %TypedArrayPrototype%. +info: | + The value of the [[Prototype]] internal slot of a TypedArray prototype + object is the intrinsic object %TypedArrayPrototype% (22.2.3). +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(Object.getPrototypeOf(Uint8ClampedArray.prototype), TypedArray.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/shell.js new file mode 100644 index 0000000000..7b3c8c67d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/Uint8ClampedArray/shell.js @@ -0,0 +1,148 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000..17a67c109c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..4fd2fe7557 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.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: > + 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js new file mode 100644 index 0000000000..8de2a88295 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws-sab.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-throws.js new file mode 100644 index 0000000000..17c490f7d5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-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: > + 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js new file mode 100644 index 0000000000..067562add9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero-sab.js @@ -0,0 +1,26 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new SharedArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js new file mode 100644 index 0000000000..e67b124ab2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-negative-zero.js @@ -0,0 +1,25 @@ +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new ArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js new file mode 100644 index 0000000000..ad2a67f321 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws-sab.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-is-symbol-throws.js new file mode 100644 index 0000000000..020fe02256 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-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-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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000..af8fee1332 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,31 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..7a06d2d90e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-throws-from-modulo-element-size.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 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js new file mode 100644 index 0000000000..f7ed2b83f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-detachbuffer.js @@ -0,0 +1,23 @@ +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js new file mode 100644 index 0000000000..cb1f36aa18 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-throws.js new file mode 100644 index 0000000000..4506ef7091 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/byteoffset-to-number-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-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(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js new file mode 100644 index 0000000000..6e5409b30a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws-sab.js @@ -0,0 +1,51 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..108824e778 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/custom-proto-access-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-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(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js new file mode 100644 index 0000000000..48548d742f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset.js new file mode 100644 index 0000000000..2805a58bae --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-and-offset.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 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-sab.js new file mode 100644 index 0000000000..b96e70672d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length-sab.js @@ -0,0 +1,38 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length.js new file mode 100644 index 0000000000..67ea4cacef --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-length.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-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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length-sab.js new file mode 100644 index 0000000000..8af91702b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length-sab.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, -1); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.js new file mode 100644 index 0000000000..9132a9611f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-negative-length.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-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); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, -1); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, -Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset-sab.js new file mode 100644 index 0000000000..08b4ee8c7b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset.js new file mode 100644 index 0000000000..883f17b91f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/defined-offset.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 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/detachedbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/detachedbuffer.js new file mode 100644 index 0000000000..c9137f8f25 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/detachedbuffer.js @@ -0,0 +1,23 @@ +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + $DETACHBUFFER(buffer); + assert.throws(TypeError, () => new TA(buffer)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws-sab.js new file mode 100644 index 0000000000..d79be12adf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws-sab.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-throws.js new file mode 100644 index 0000000000..c617926519 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-length-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: > + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js new file mode 100644 index 0000000000..7eeb93fcea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws-sab.js @@ -0,0 +1,39 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws.js new file mode 100644 index 0000000000..134c621afc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/excessive-offset-throws.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 - 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js new file mode 100644 index 0000000000..c531b120af --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget-sab.js @@ -0,0 +1,30 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.js new file mode 100644 index 0000000000..3f4ead077e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/invoked-with-undefined-newtarget.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 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(TA.BYTES_PER_ELEMENT); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced-sab.js new file mode 100644 index 0000000000..9d4c5fc17f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced.js new file mode 100644 index 0000000000..45428dfbe4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/is-referenced.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: > + 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws-sab.js new file mode 100644 index 0000000000..c427ae805b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws-sab.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, len); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-throws.js new file mode 100644 index 0000000000..ce616b31b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-access-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: > + 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(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, len); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js new file mode 100644 index 0000000000..c28a05dada --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws-sab.js @@ -0,0 +1,33 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-throws.js new file mode 100644 index 0000000000..adcbfc36e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-is-symbol-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 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"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js new file mode 100644 index 0000000000..83ca72fc7c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/length-to-number-detachbuffer.js @@ -0,0 +1,23 @@ +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js new file mode 100644 index 0000000000..8c464be41b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility-sab.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..c85d2e32f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/new-instance-extensibility.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-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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js new file mode 100644 index 0000000000..e91da4c63c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new SharedArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..3aefc42967 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-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-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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new ArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js new file mode 100644 index 0000000000..bbf1124b01 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance.js new file mode 100644 index 0000000000..f307a9dd17 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance.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: > + 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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/shell.js new file mode 100644 index 0000000000..1c02f57631 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/shell.js @@ -0,0 +1,60 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength-sab.js new file mode 100644 index 0000000000..ee266307a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength-sab.js @@ -0,0 +1,76 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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"] +]; + +testWithBigIntTypedArrayConstructors(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" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength.js new file mode 100644 index 0000000000..3822a656f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-bytelength.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-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"] +]; + +testWithBigIntTypedArrayConstructors(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" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js new file mode 100644 index 0000000000..b0ef7909c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset-sab.js @@ -0,0 +1,90 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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"] +]; + +testWithBigIntTypedArrayConstructors(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"); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.js new file mode 100644 index 0000000000..5d11140a7c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/toindex-byteoffset.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-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"] +]; + +testWithBigIntTypedArrayConstructors(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"); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js new file mode 100644 index 0000000000..d72633b53c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/typedarray-backed-by-sharedarraybuffer.js @@ -0,0 +1,28 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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(8); + +testWithBigIntTypedArrayConstructors(function(View1) { + var ta1 = new View1(sab); + testWithBigIntTypedArrayConstructors(function(View2) { + var ta2 = new View2(ta1); + assert.sameValue( + ta2.buffer.constructor, + ArrayBuffer, + "TypedArray of SharedArrayBuffer-backed TypedArray is ArrayBuffer-backed" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js new file mode 100644 index 0000000000..d03bc4726b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object-sab.js @@ -0,0 +1,52 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..6baa8c836c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-custom-proto-if-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-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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js new file mode 100644 index 0000000000..0a442701f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js @@ -0,0 +1,51 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..520a8d1f61 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..51cf40ab6f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/custom-proto-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-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(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [1], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/init-zeros.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/init-zeros.js new file mode 100644 index 0000000000..b857489ae1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/init-zeros.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-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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var subject = new TA(9); + + assert.sameValue(subject[0], 0n, 'index 0'); + assert.sameValue(subject[1], 0n, 'index 1'); + assert.sameValue(subject[2], 0n, 'index 2'); + assert.sameValue(subject[3], 0n, 'index 3'); + assert.sameValue(subject[4], 0n, 'index 4'); + assert.sameValue(subject[5], 0n, 'index 5'); + assert.sameValue(subject[6], 0n, 'index 6'); + assert.sameValue(subject[7], 0n, 'index 7'); + assert.sameValue(subject[8], 0n, 'index 8'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-infinity-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-infinity-throws-rangeerror.js new file mode 100644 index 0000000000..e1a9d812ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-infinity-throws-rangeerror.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-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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.js new file mode 100644 index 0000000000..57f8f11914 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-negative-integer-throws-rangeerror.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-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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(-1); + }); + + assert.throws(RangeError, function() { + new TA(-Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/is-symbol-throws.js new file mode 100644 index 0000000000..130470811b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/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-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'); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..6378d55d33 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/new-instance-extensibility.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-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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..6351fd73f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.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: 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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [0], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/returns-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/returns-object.js new file mode 100644 index 0000000000..b8b24235fd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/returns-object.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-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] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/toindex-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/toindex-length.js new file mode 100644 index 0000000000..64ef8ac3c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/toindex-length.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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"] +]; + +testWithBigIntTypedArrayConstructors(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" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/undefined-newtarget-throws.js new file mode 100644 index 0000000000..65bc5efd6f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-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-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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(0); + }); + + assert.throws(TypeError, function() { + TA(Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..87cef3c04c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-custom-proto-if-object.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-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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..b1fd97885e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/length-arg/use-default-proto-if-custom-proto-is-not-object.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-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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [1], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/custom-proto-access-throws.js new file mode 100644 index 0000000000..460a899803 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/custom-proto-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 +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(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/new-instance-extensibility.js new file mode 100644 index 0000000000..8c6adc6e50 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/new-instance-extensibility.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 +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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/proto-from-ctor-realm.js new file mode 100644 index 0000000000..9a68a4185a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/proto-from-ctor-realm.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: 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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/returns-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/returns-object.js new file mode 100644 index 0000000000..13b94816ac --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/returns-object.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 +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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(); + + assert.sameValue(typedArray.length, 0); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/undefined-newtarget-throws.js new file mode 100644 index 0000000000..7706a65bcf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/undefined-newtarget-throws.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 +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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/use-custom-proto-if-object.js new file mode 100644 index 0000000000..2e836d96c7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/use-custom-proto-if-object.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 +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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..bbaf57989a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/no-args/use-default-proto-if-custom-proto-is-not-object.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 +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; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/as-array-returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/as-array-returns.js new file mode 100644 index 0000000000..0387477cfc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA([7n, 42n]); + assert.sameValue(typedArray.length, 2); + assert.sameValue(typedArray[0], 7n); + assert.sameValue(typedArray[1], 42n); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/as-generator-iterable-returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/as-generator-iterable-returns.js new file mode 100644 index 0000000000..22f9358687 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/as-generator-iterable-returns.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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = (function *() { + yield 7n; yield 42n; + })(); + + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 2); + assert.sameValue(typedArray[0], 7n); + assert.sameValue(typedArray[1], 42n); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/bigint-tobigint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/bigint-tobigint64.js new file mode 100644 index 0000000000..b69f3f7759 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/bigint-tobigint64.js @@ -0,0 +1,106 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Behavior for input array of BigInts +info: | + 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). + ... + + [[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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigInt64 + Conversion Operation: ToBigInt64 + + ToBigInt64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. If int64bit ≥ 2^63, return int64bit - 2^64; otherwise return int64bit. + +features: [BigInt, TypedArray] +---*/ + +var vals = [ + 18446744073709551618n, // 2n ** 64n + 2n + 9223372036854775810n, // 2n ** 63n + 2n + 2n, + 0n, + -2n, + -9223372036854775810n, // -(2n ** 63n) - 2n + -18446744073709551618n, // -(2n ** 64n) - 2n +]; + +var typedArray = new BigInt64Array(vals); + +assert.sameValue(typedArray[0], 2n, + "ToBigInt64(2n ** 64n + 2n) => 2n"); + +assert.sameValue(typedArray[1], -9223372036854775806n, // 2n - 2n ** 63n + "ToBigInt64(2n ** 63n + 2n) => -9223372036854775806n"); + +assert.sameValue(typedArray[2], 2n, + "ToBigInt64(2n) => 2n"); + +assert.sameValue(typedArray[3], 0n, + "ToBigInt64(0n) => 0n"); + +assert.sameValue(typedArray[4], -2n, + "ToBigInt64( -2n) => -2n"); + +assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2 + "ToBigInt64( -(2n ** 64n) - 2n) => 9223372036854775806n"); + +assert.sameValue(typedArray[6], -2n, + "ToBigInt64( -(2n ** 64n) - 2n) => -2n"); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/bigint-tobiguint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/bigint-tobiguint64.js new file mode 100644 index 0000000000..4d7dca6050 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/bigint-tobiguint64.js @@ -0,0 +1,106 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Behavior for input array of BigInts +info: | + 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). + ... + + [[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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigUint64 + Conversion Operation: ToBigUint64 + + ToBigUint64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. Return int64bit. + +features: [BigInt, TypedArray] +---*/ + +var vals = [ + 18446744073709551618n, // 2n ** 64n + 2n + 9223372036854775810n, // 2n ** 63n + 2n + 2n, + 0n, + -2n, + -9223372036854775810n, // -(2n ** 63n) - 2n + -18446744073709551618n, // -(2n ** 64n) - 2n +]; + +var typedArray = new BigUint64Array(vals); + + +assert.sameValue(typedArray[0], 2n, + "ToBigUint64(2n ** 64n + 2n) => 2n"); + +assert.sameValue(typedArray[1], 9223372036854775810n, // 2n ** 63n + 2n + "ToBigUint64(2n ** 63n + 2n) => 9223372036854775810"); + +assert.sameValue(typedArray[2], 2n, + "ToBigUint64(2n) => 2n"); + +assert.sameValue(typedArray[3], 0n, + "ToBigUint64(0n) => 0n"); + +assert.sameValue(typedArray[4], 18446744073709551614n, // 2n ** 64n - 2n + "ToBigUint64( -2n) => 18446744073709551614n"); + +assert.sameValue(typedArray[5], 9223372036854775806n, // 2n ** 63n - 2n + "ToBigUint64( -(2n ** 63n) - 2n) => 9223372036854775806n"); + +assert.sameValue(typedArray[6], 18446744073709551614n, // 2n ** 64n - 2n + "ToBigUint64( -(2n ** 64n) - 2n) => 18446744073709551614n"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/boolean-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/boolean-tobigint.js new file mode 100644 index 0000000000..a3ed66ff5c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/boolean-tobigint.js @@ -0,0 +1,64 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Behavior for input array of Booleans +info: | + 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). + ... + + [[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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Boolean + Result: Return 1n if prim is true and 0n if prim is false. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA([false, true]); + + assert.sameValue(typedArray[0], 0n); + assert.sameValue(typedArray[1], 1n); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..78ec0dcf6b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/custom-proto-access-throws.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-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: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +var o = {}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [o], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterating-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterating-throws.js new file mode 100644 index 0000000000..c043d54876 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterating-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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = (function *() { + yield 0; + throw new Test262Error(); + })(); + + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterator-not-callable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterator-not-callable-throws.js new file mode 100644 index 0000000000..fd884b5656 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterator-not-callable-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-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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var obj = function () {}; + +testWithBigIntTypedArrayConstructors(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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterator-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterator-throws.js new file mode 100644 index 0000000000..613de71ced --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/iterator-throws.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-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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +var obj = function () {}; + +Object.defineProperty(obj, Symbol.iterator, { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-excessive-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-excessive-throws.js new file mode 100644 index 0000000000..3492481689 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-excessive-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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + length: Math.pow(2, 53) +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-is-symbol-throws.js new file mode 100644 index 0000000000..b12e29585f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-is-symbol-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-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: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var obj = { + length: Symbol("1") +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-throws.js new file mode 100644 index 0000000000..2c670d66d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/length-throws.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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = {}; + +Object.defineProperty(obj, "length", { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..8bec71adf4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/new-instance-extensibility.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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var obj = { + "0": 0n, + "1": 1n, + "2": 2n, + length: 3 + }; + + var sample = new TA(obj); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/null-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/null-tobigint.js new file mode 100644 index 0000000000..78a81a68fd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/null-tobigint.js @@ -0,0 +1,65 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt on null +info: | + 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). + ... + + [[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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Null + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + + assert.throws(TypeError, function() { + new TA([null]); + }, "abrupt completion from Null"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/number-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/number-tobigint.js new file mode 100644 index 0000000000..caedd3ca5d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/number-tobigint.js @@ -0,0 +1,93 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt on Number +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Number + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + + assert.throws(TypeError, function() { + new TA([1]); + }, "abrupt completion from Number: 1"); + + assert.throws(TypeError, function() { + new TA([Math.pow(2, 63)]); + }, "abrupt completion from Number: 2**63"); + + assert.throws(TypeError, function() { + new TA([+0]); + }, "abrupt completion from Number: +0"); + + assert.throws(TypeError, function() { + new TA([-0]); + }, "abrupt completion from Number: -0"); + + assert.throws(TypeError, function() { + new TA([Infinity]); + }, "abrupt completion from Number: Infinity"); + + assert.throws(TypeError, function() { + new TA([-Infinity]); + }, "abrupt completion from Number: -Infinity"); + + assert.throws(TypeError, function() { + new TA([NaN]); + }, "abrupt completion from Number: NaN"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..36c1419438 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/proto-from-ctor-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-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: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [{}], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/string-nan-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/string-nan-tobigint.js new file mode 100644 index 0000000000..f117b1c110 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/string-nan-tobigint.js @@ -0,0 +1,72 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt String, when StringToBigInt returns NaN +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + + assert.throws(SyntaxError, function() { + new TA(["definately not a number"]); + }, "StringToBigInt(prim) == NaN"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/string-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/string-tobigint.js new file mode 100644 index 0000000000..631f126299 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/string-tobigint.js @@ -0,0 +1,88 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Behavior for input array of Strings, successful conversion +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(['', '1']); + + assert.sameValue(typedArray[0], 0n); + assert.sameValue(typedArray[1], 1n); + + assert.throws(SyntaxError, function() { + new TA(["1n"]); + }, "A StringNumericLiteral may not include a BigIntLiteralSuffix."); + + assert.throws(SyntaxError, function() { + new TA(["Infinity"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity.."); + + assert.throws(SyntaxError, function() { + new TA(["1.1"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... decimal points..."); + + assert.throws(SyntaxError, function() { + new TA(["1e7"]); + }, "Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow... exponents..."); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/symbol-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/symbol-tobigint.js new file mode 100644 index 0000000000..4315e69e0d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/symbol-tobigint.js @@ -0,0 +1,71 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt on Symbol +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Symbol + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray, Symbol] +---*/ + +var s = Symbol() + +testWithBigIntTypedArrayConstructors(function(TA) { + + assert.throws(TypeError, function() { + new TA([s]); + }, "abrupt completion from Symbol"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-from-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-from-property.js new file mode 100644 index 0000000000..3b6564b2f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-from-property.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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + length: 4 +}; + +Object.defineProperty(obj, "2", { + get() { + throw new Test262Error(); + } +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + obj[0] = 0n; + obj[1] = 0n; + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-to-primitive-typeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-to-primitive-typeerror.js new file mode 100644 index 0000000000..a2b1f6c1f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-to-primitive-typeerror.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: > + 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table 10. + + 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toPrimitive, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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([8n, sample]); + }, "abrupt completion from sample @@toPrimitive"); + + assert.sameValue(toPrimitive, 1, "toPrimitive was called once"); + assert.sameValue(valueOf, 0, "sample.valueOf is not called"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-to-primitive.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-to-primitive.js new file mode 100644 index 0000000000..1a6627e153 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-to-primitive.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table 10. + + 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toPrimitive, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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([8n, sample]); + }, "abrupt completion from sample @@toPrimitive"); + + assert.sameValue(toPrimitive, 1, "toPrimitive was called once"); + assert.sameValue(valueOf, 0, "it does not call sample.valueOf"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-tostring.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-tostring.js new file mode 100644 index 0000000000..dee658572f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-tostring.js @@ -0,0 +1,99 @@ +// Copyright (C) 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table 10. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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([8n, sample]); + }, "abrupt completion from ToBigInt(sample)"); + + assert.sameValue(valueOf, 1, "valueOf called once"); + assert.sameValue(toString, 1, "toString called once"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-valueof-typeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-valueof-typeerror.js new file mode 100644 index 0000000000..b0bae2c1bb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-valueof-typeerror.js @@ -0,0 +1,100 @@ +// Copyright (C) 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table 10. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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([8n, sample]); + }, "abrupt completion from ToBigInt(sample)"); + + assert.sameValue(valueOf, 1, "valueOf called once"); + assert.sameValue(toString, 1, "toString called once"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-valueof.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-valueof.js new file mode 100644 index 0000000000..b2eaa9904d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-obj-valueof.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table 10. + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new Int8Array(1); + var valueOf = 0; + + sample.valueOf = function() { + valueOf++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + new TA([8n, sample]); + }, "abrupt completion from ToBigInt(sample)"); + + assert.sameValue(valueOf, 1, "valueOf called once"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-property.js new file mode 100644 index 0000000000..e56a95c7f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-property.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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + "2": { + valueOf() { + throw new Test262Error(); + } + }, + length: 4 +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + obj[0] = 0n; + obj[1] = 0n; + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-symbol-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-symbol-property.js new file mode 100644 index 0000000000..7094f1b416 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/throws-setting-symbol-property.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-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: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var obj = { + "2": Symbol("1"), + length: 4 +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/undefined-newtarget-throws.js new file mode 100644 index 0000000000..9e8d92fb0f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/undefined-newtarget-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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA({}); + }); + + assert.throws(TypeError, function() { + TA([]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/undefined-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/undefined-tobigint.js new file mode 100644 index 0000000000..5ae317141e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/undefined-tobigint.js @@ -0,0 +1,65 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-object +description: > + Return abrupt on undefined +info: | + 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). + ... + + [[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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Undefined + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + + assert.throws(TypeError, function() { + new TA([undefined]); + }, "abrupt completion from undefined"); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..ee60d97474 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/use-custom-proto-if-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..4855ab6159 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/object-arg/use-default-proto-if-custom-proto-is-not-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +function newTarget() {} +newTarget.prototype = null; +var o = []; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [o], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..e5c9eb3679 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/custom-proto-access-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 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: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +var sample = new BigInt64Array(); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [sample], newTarget); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..485ef634d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/new-instance-extensibility.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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var typedArraySample1 = new BigInt64Array(); +var typedArraySample2 = new BigInt64Array(); +Object.preventExtensions(typedArraySample2); + +testWithBigIntTypedArrayConstructors(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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-buffer-ctor-species-null.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-buffer-ctor-species-null.js new file mode 100644 index 0000000000..7708637ae9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-buffer-ctor-species-null.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: > + 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherCtor = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + 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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-buffer-ctor-species-undefined.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-buffer-ctor-species-undefined.js new file mode 100644 index 0000000000..a14374aa2d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-buffer-ctor-species-undefined.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: > + 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherCtor = TA === BigInt64Array ? BigUint64Array : BigInt64Array; + 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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-returns-new-typedarray.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-returns-new-typedarray.js new file mode 100644 index 0000000000..f81decd8e1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/other-ctor-returns-new-typedarray.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-typedarray +description: Instantiate a new TypedArray with an existing 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. + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sample1 = new BigInt64Array(7); +var sample2 = new BigUint64Array(7); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = TA === BigInt64Array ? 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..1346caf1fd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/proto-from-ctor-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-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: [testBigIntTypedArray.js] +features: [BigInt, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new TA()], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-buffer-ctor-species-null.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-buffer-ctor-species-null.js new file mode 100644 index 0000000000..afc55e0dba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-buffer-ctor-species-null.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-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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-buffer-ctor-species-undefined.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-buffer-ctor-species-undefined.js new file mode 100644 index 0000000000..a0bd03691e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-buffer-ctor-species-undefined.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-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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.species, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-returns-new-cloned-typedarray.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-returns-new-cloned-typedarray.js new file mode 100644 index 0000000000..9b44fd800d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/same-ctor-returns-new-cloned-typedarray.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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/shell.js new file mode 100644 index 0000000000..1157ee5318 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/shell.js @@ -0,0 +1,166 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/src-typedarray-not-big-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/src-typedarray-not-big-throws.js new file mode 100644 index 0000000000..385307c130 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/src-typedarray-not-big-throws.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-typedarray +description: > + If typedArray constructor argument is not a Big(U)Int, throw +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. + + ... + 19. Else, + ... + c. If one of srcType and elementType contains the substring "Big" and the other + does not, throw a TypeError exception. + +includes: [testBigIntTypedArray.js, testTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var notBigTypedArray; + +testWithTypedArrayConstructors(function(TA) { + + notBigTypedArray = new TA(16); + + testWithBigIntTypedArrayConstructors(function(BTA) { + assert.throws(TypeError, function() { + new BTA(notBigTypedArray); + }); + }); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/undefined-newtarget-throws.js new file mode 100644 index 0000000000..d664255beb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/undefined-newtarget-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-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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(4); + + assert.throws(TypeError, function() { + TA(typedArray); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000..a8477dae4f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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. + + + Let elementSize be the Number value of the Element Size value in Table 56 for constructorName.* + ... + If length is either not present or undefined, then + a. If bufferByteLength modulo elementSize ≠ 0, throw a RangeError exception. + ... + + * Int8Array, Uint8Array, Uint8ClampedArray all have element size 1, so will never fail. + +includes: [testTypedArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(1); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}, [ Float64Array, Float32Array, Int32Array, Int16Array, Uint32Array, Uint16Array ]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..6e65e0b77b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/bufferbyteoffset-throws-from-modulo-element-size.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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var buffer = new ArrayBuffer(1); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}, [ Float64Array, Float32Array, Int32Array, Int16Array, Uint32Array, Uint16Array ]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-throws-sab.js new file mode 100644 index 0000000000..70d62315c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-throws-sab.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-throws.js new file mode 100644 index 0000000000..996976385e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-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: > + 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero-sab.js new file mode 100644 index 0000000000..ecb8b39000 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero-sab.js @@ -0,0 +1,26 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new SharedArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero.js new file mode 100644 index 0000000000..cd8b786ccc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-negative-zero.js @@ -0,0 +1,25 @@ +// 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new ArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-symbol-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-symbol-throws-sab.js new file mode 100644 index 0000000000..b7a509cb98 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-symbol-throws-sab.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [Symbol, SharedArrayBuffer, TypedArray] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-is-symbol-throws.js new file mode 100644 index 0000000000..9423fc4d6c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-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-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: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000..838b1d2ab3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,38 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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. + + + Let elementSize be the Number value of the Element Size value in Table 56 for constructorName.* + + ... + If offset modulo elementSize ≠ 0, throw a RangeError exception. + ... + + * Int8Array, Uint8Array, Uint8ClampedArray all have element size 1, so will never fail. + +includes: [testTypedArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}, [ Float64Array, Float32Array, Int32Array, Int16Array, Uint32Array, Uint16Array ]); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-throws-from-modulo-element-size.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-throws-from-modulo-element-size.js new file mode 100644 index 0000000000..e6ff6965fe --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-throws-from-modulo-element-size.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 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}, [ Float64Array, Float32Array, Int32Array, Int16Array, Uint32Array, Uint16Array ]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-detachbuffer.js new file mode 100644 index 0000000000..627c8778ad --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-detachbuffer.js @@ -0,0 +1,23 @@ +// 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: [testTypedArray.js, detachArrayBuffer.js] +features: [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)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-throws-sab.js new file mode 100644 index 0000000000..5b3ec7591d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-throws-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-throws.js new file mode 100644 index 0000000000..47ff7ea095 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/byteoffset-to-number-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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var byteOffset = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/custom-proto-access-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/custom-proto-access-throws-sab.js new file mode 100644 index 0000000000..bccf102235 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/custom-proto-access-throws-sab.js @@ -0,0 +1,51 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..3f43b72932 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/custom-proto-access-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-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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-and-offset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-and-offset-sab.js new file mode 100644 index 0000000000..56ecd2f44a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-and-offset-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-and-offset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-and-offset.js new file mode 100644 index 0000000000..80e815cf61 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-and-offset.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 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-sab.js new file mode 100644 index 0000000000..a729a9a231 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length-sab.js @@ -0,0 +1,38 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length.js new file mode 100644 index 0000000000..52abb61850 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-length.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-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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-negative-length-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-negative-length-sab.js new file mode 100644 index 0000000000..3e7a33df8a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-negative-length-sab.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-negative-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-negative-length.js new file mode 100644 index 0000000000..f795adabeb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-negative-length.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-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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-offset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-offset-sab.js new file mode 100644 index 0000000000..3ad0730ddb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-offset-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-offset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-offset.js new file mode 100644 index 0000000000..1c416c4a45 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/defined-offset.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 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/detachedbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/detachedbuffer.js new file mode 100644 index 0000000000..15f2abe5e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/detachedbuffer.js @@ -0,0 +1,23 @@ +// 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: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(3 * offset); + $DETACHBUFFER(buffer); + assert.throws(TypeError, () => new TA(buffer)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-length-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-length-throws-sab.js new file mode 100644 index 0000000000..ee0b54e943 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-length-throws-sab.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-length-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-length-throws.js new file mode 100644 index 0000000000..ab5836e944 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-length-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: > + 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws-resizable-ab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws-resizable-ab.js new file mode 100644 index 0000000000..5973728ff1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws-resizable-ab.js @@ -0,0 +1,25 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError for resizable ArrayBuffers when offset > byteLength +includes: [testTypedArray.js] +features: [TypedArray, resizable-arraybuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var buffer = new ArrayBuffer(BPE, {maxByteLength: BPE}); + + assert.throws(RangeError, function() { + new TA(buffer, BPE * 2); + }); + + assert.throws(RangeError, function() { + new TA(buffer, BPE * 2, undefined); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws-sab.js new file mode 100644 index 0000000000..bba14855bf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws-sab.js @@ -0,0 +1,39 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws.js new file mode 100644 index 0000000000..17d39e4ea5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/excessive-offset-throws.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 - 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/invoked-with-undefined-newtarget-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/invoked-with-undefined-newtarget-sab.js new file mode 100644 index 0000000000..d08a6e8f7f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/invoked-with-undefined-newtarget-sab.js @@ -0,0 +1,30 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(4); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/invoked-with-undefined-newtarget.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/invoked-with-undefined-newtarget.js new file mode 100644 index 0000000000..7b8abeb3aa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/invoked-with-undefined-newtarget.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 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(4); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/is-referenced-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/is-referenced-sab.js new file mode 100644 index 0000000000..a7c268a073 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/is-referenced-sab.js @@ -0,0 +1,36 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/is-referenced.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/is-referenced.js new file mode 100644 index 0000000000..9a7ad5ac4e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/is-referenced.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: > + 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-access-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-access-throws-sab.js new file mode 100644 index 0000000000..e22085c72a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-access-throws-sab.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-access-throws.js new file mode 100644 index 0000000000..c05d709abc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-access-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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var len = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, len); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-is-symbol-throws-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-is-symbol-throws-sab.js new file mode 100644 index 0000000000..61cc16a0cb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-is-symbol-throws-sab.js @@ -0,0 +1,33 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [Symbol, SharedArrayBuffer, TypedArray] +---*/ + +var buffer = new SharedArrayBuffer(8); +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-is-symbol-throws.js new file mode 100644 index 0000000000..f04940f4ee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-is-symbol-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 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: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var buffer = new ArrayBuffer(8); +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-to-number-detachbuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-to-number-detachbuffer.js new file mode 100644 index 0000000000..47ff17be0e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/length-to-number-detachbuffer.js @@ -0,0 +1,23 @@ +// 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: [testTypedArray.js, detachArrayBuffer.js] +features: [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)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/new-instance-extensibility-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/new-instance-extensibility-sab.js new file mode 100644 index 0000000000..be15fb3873 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/new-instance-extensibility-sab.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [SharedArrayBuffer, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..14be0cdec5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/new-instance-extensibility.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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new ArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm-sab.js new file mode 100644 index 0000000000..1da9bed6a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm-sab.js @@ -0,0 +1,41 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..300629cadc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-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-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: [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 ArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance-sab.js new file mode 100644 index 0000000000..17ea189089 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance-sab.js @@ -0,0 +1,37 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance.js new file mode 100644 index 0000000000..46bb08e0ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance.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: > + 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/shell.js new file mode 100644 index 0000000000..f9aa35231b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/shell.js @@ -0,0 +1,142 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-bytelength-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-bytelength-sab.js new file mode 100644 index 0000000000..f95a6366a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-bytelength-sab.js @@ -0,0 +1,76 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-bytelength.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-bytelength.js new file mode 100644 index 0000000000..062330df84 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-bytelength.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-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: [testTypedArray.js] +features: [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" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-byteoffset-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-byteoffset-sab.js new file mode 100644 index 0000000000..8ba2f41b9c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-byteoffset-sab.js @@ -0,0 +1,90 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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"); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-byteoffset.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-byteoffset.js new file mode 100644 index 0000000000..66a3629446 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/toindex-byteoffset.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-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: [testTypedArray.js] +features: [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"); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/typedarray-backed-by-sharedarraybuffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/typedarray-backed-by-sharedarraybuffer.js new file mode 100644 index 0000000000..2ba3df217a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/typedarray-backed-by-sharedarraybuffer.js @@ -0,0 +1,26 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-custom-proto-if-object-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-custom-proto-if-object-sab.js new file mode 100644 index 0000000000..1b67197f02 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-custom-proto-if-object-sab.js @@ -0,0 +1,52 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..aad34833ca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-custom-proto-if-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-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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js new file mode 100644 index 0000000000..21086e7a26 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-default-proto-if-custom-proto-is-not-object-sab.js @@ -0,0 +1,51 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..dfef9bdf32 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/buffer-arg/use-default-proto-if-custom-proto-is-not-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..d8808efd52 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/custom-proto-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-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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/init-zeros.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/init-zeros.js new file mode 100644 index 0000000000..60f2e09349 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/init-zeros.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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var subject = new TA(9); + + 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'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-infinity-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-infinity-throws-rangeerror.js new file mode 100644 index 0000000000..e2eee55c64 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-infinity-throws-rangeerror.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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-negative-integer-throws-rangeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-negative-integer-throws-rangeerror.js new file mode 100644 index 0000000000..b633202456 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-negative-integer-throws-rangeerror.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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(-1); + }); + + assert.throws(RangeError, function() { + new TA(-Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/is-symbol-throws.js new file mode 100644 index 0000000000..a383eb453c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/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-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: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol('1'); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..28a76944ff --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/new-instance-extensibility.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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(4); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..02f39b12e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/proto-from-ctor-realm.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: 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: [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, [0], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/returns-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/returns-object.js new file mode 100644 index 0000000000..25f90a4a1d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/returns-object.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-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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/shell.js new file mode 100644 index 0000000000..e9580b3113 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/shell.js @@ -0,0 +1,124 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/toindex-length.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/toindex-length.js new file mode 100644 index 0000000000..d84897dfa8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/toindex-length.js @@ -0,0 +1,55 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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: [testTypedArray.js] +features: [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" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/undefined-newtarget-throws.js new file mode 100644 index 0000000000..8c43e87b2d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(0); + }); + + assert.throws(TypeError, function() { + TA(Infinity); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..59f7b7f0f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/use-custom-proto-if-object.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-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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..6617e5c899 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/length-arg/use-default-proto-if-custom-proto-is-not-object.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-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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/custom-proto-access-throws.js new file mode 100644 index 0000000000..5c3a24bd54 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/custom-proto-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 +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: [testTypedArray.js] +features: [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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/new-instance-extensibility.js new file mode 100644 index 0000000000..e72a6b7e38 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/new-instance-extensibility.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 +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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + + assert(Object.isExtensible(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/proto-from-ctor-realm.js new file mode 100644 index 0000000000..533d41736f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/proto-from-ctor-realm.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: 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: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/returns-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/returns-object.js new file mode 100644 index 0000000000..2538dbc5f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/returns-object.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 +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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/shell.js new file mode 100644 index 0000000000..e9580b3113 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/shell.js @@ -0,0 +1,124 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/undefined-newtarget-throws.js new file mode 100644 index 0000000000..f238450d16 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/undefined-newtarget-throws.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 +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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/use-custom-proto-if-object.js new file mode 100644 index 0000000000..420e56e088 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/use-custom-proto-if-object.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 +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: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..ca9f018f0d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-args/use-default-proto-if-custom-proto-is-not-object.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 +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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-species.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-species.js new file mode 100644 index 0000000000..af48263ff6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/no-species.js @@ -0,0 +1,32 @@ +// Copyright (C) 2022 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Creating TypedArray from other TypedArrays doesn't look up Symbol.species. +features: [TypedArray, ArrayBuffer, Symbol.species] +---*/ + +let throwOnGrossBufferConstruction = false; + +class GrossBuffer extends ArrayBuffer { + constructor() { + super(...arguments); + if (throwOnGrossBufferConstruction) { + throw new Test262Error("unreachable"); + } + } + static get [Symbol.species]() { + throw new Test262Error("unreachable"); + } +} + +let grossBuf = new GrossBuffer(1024); +throwOnGrossBufferConstruction = true; +let grossTA = new Uint8Array(grossBuf); +let mysteryTA = new Int8Array(grossTA); + +assert.sameValue(mysteryTA.buffer.__proto__, ArrayBuffer.prototype); +assert.sameValue(mysteryTA.buffer.constructor, ArrayBuffer); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-array-returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-array-returns.js new file mode 100644 index 0000000000..abbc8b5979 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-array-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 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-generator-iterable-returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-generator-iterable-returns.js new file mode 100644 index 0000000000..a86d9ef1a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/as-generator-iterable-returns.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-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.js new file mode 100644 index 0000000000..f766adaa22 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation-consistent-nan.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-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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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] +features: [TypedArray] +---*/ + +function body(FloatArray) { + var first = new FloatArray(NaNs); + var second = new FloatArray(NaNs); + var firstBytes = new Uint8Array(first.buffer); + var secondBytes = new Uint8Array(second.buffer); + + assert(compareArray(firstBytes, secondBytes)); +} + +testWithTypedArrayConstructors(body, [Float32Array, Float64Array]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.js new file mode 100644 index 0000000000..b8c41f1de1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/conversion-operation.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-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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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] +features: [TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected) { + var sample = new TA([value]); + + assert.sameValue(sample[0], expected, value + " converts to " + expected); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..c34af4e31b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/custom-proto-access-throws.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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterating-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterating-throws.js new file mode 100644 index 0000000000..7867b4a3a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterating-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-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: [generators, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var obj = (function *() { + yield 0; + throw new Test262Error(); + })(); + + assert.throws(Test262Error, function() { + new TA(obj); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-is-null-as-array-like.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-is-null-as-array-like.js new file mode 100644 index 0000000000..de906f06b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-is-null-as-array-like.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-object +description: > + If object's @@iterator is `null`, it is considered an array-like object. +info: | + 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 usingIterator be ? GetMethod(object, @@iterator). + 6. If usingIterator is not undefined, then + [...] + 7. NOTE: object is not an Iterable so assume it is already an array-like object. + [...] + + GetMethod ( V, P ) + + [...] + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. +includes: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var obj = {length: 2, 0: 1, 1: 2}; +obj[Symbol.iterator] = null; + +testWithTypedArrayConstructors(function(TypedArray) { + var typedArray = new TypedArray(obj); + + assert(typedArray instanceof TypedArray); + assert.sameValue(typedArray.length, 2); + assert.sameValue(typedArray[0], 1); + assert.sameValue(typedArray[1], 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-not-callable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-not-callable-throws.js new file mode 100644 index 0000000000..500437a3ed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-not-callable-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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-throws.js new file mode 100644 index 0000000000..9b9c57a11b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/iterator-throws.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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-excessive-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-excessive-throws.js new file mode 100644 index 0000000000..1d681cfe61 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-excessive-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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-is-symbol-throws.js new file mode 100644 index 0000000000..1e2f7e23c9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-is-symbol-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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-throws.js new file mode 100644 index 0000000000..8dccea8901 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/length-throws.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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..25345c0979 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/new-instance-extensibility.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-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)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..213fbfbdd8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/proto-from-ctor-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-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/returns.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/returns.js new file mode 100644 index 0000000000..d807ea95a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/returns.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: > + Return typedArray from 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. + +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var obj = { + "0": null, + "2": 42, + "3": "7", + "4": NaN, + "5": Symbol("1"), + length: 5 +}; + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(obj); + assert.sameValue(typedArray.length, 5); + assert.sameValue(typedArray[0], 0); + assert.sameValue(typedArray[2], 42); + assert.sameValue(typedArray[3], 7); + assert.sameValue(typedArray[5], undefined); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); + + if (TA === Float32Array || TA === Float64Array) { + assert.sameValue(typedArray[1], NaN); + assert.sameValue(typedArray[4], NaN); + } else { + assert.sameValue(typedArray[1], 0); + assert.sameValue(typedArray[4], 0); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/shell.js new file mode 100644 index 0000000000..d29e7ddcc3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/shell.js @@ -0,0 +1,596 @@ +// GENERATED, DO NOT EDIT +// file: byteConversionValues.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Provide a list for original and expected values for different byte + conversions. + This helper is mostly used on tests for TypedArray and DataView, and each + array from the expected values must match the original values array on every + index containing its original value. +defines: [byteConversionValues] +---*/ +var byteConversionValues = { + values: [ + 127, // 2 ** 7 - 1 + 128, // 2 ** 7 + 32767, // 2 ** 15 - 1 + 32768, // 2 ** 15 + 2147483647, // 2 ** 31 - 1 + 2147483648, // 2 ** 31 + 255, // 2 ** 8 - 1 + 256, // 2 ** 8 + 65535, // 2 ** 16 - 1 + 65536, // 2 ** 16 + 4294967295, // 2 ** 32 - 1 + 4294967296, // 2 ** 32 + 9007199254740991, // 2 ** 53 - 1 + 9007199254740992, // 2 ** 53 + 1.1, + 0.1, + 0.5, + 0.50000001, + 0.6, + 0.7, + undefined, + -1, + -0, + -0.1, + -1.1, + NaN, + -127, // - ( 2 ** 7 - 1 ) + -128, // - ( 2 ** 7 ) + -32767, // - ( 2 ** 15 - 1 ) + -32768, // - ( 2 ** 15 ) + -2147483647, // - ( 2 ** 31 - 1 ) + -2147483648, // - ( 2 ** 31 ) + -255, // - ( 2 ** 8 - 1 ) + -256, // - ( 2 ** 8 ) + -65535, // - ( 2 ** 16 - 1 ) + -65536, // - ( 2 ** 16 ) + -4294967295, // - ( 2 ** 32 - 1 ) + -4294967296, // - ( 2 ** 32 ) + Infinity, + -Infinity, + 0 + ], + + expected: { + Int8: [ + 127, // 127 + -128, // 128 + -1, // 32767 + 0, // 32768 + -1, // 2147483647 + 0, // 2147483648 + -1, // 255 + 0, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 0, // 32768 + 255, // 2147483647 + 0, // 2147483648 + 255, // 255 + 0, // 256 + 255, // 65535 + 0, // 65536 + 255, // 4294967295 + 0, // 4294967296 + 255, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 255, // -1 + 0, // -0 + 0, // -0.1 + 255, // -1.1 + 0, // NaN + 129, // -127 + 128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8Clamped: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 255, // 32768 + 255, // 2147483647 + 255, // 2147483648 + 255, // 255 + 255, // 256 + 255, // 65535 + 255, // 65536 + 255, // 4294967295 + 255, // 4294967296 + 255, // 9007199254740991 + 255, // 9007199254740992 + 1, // 1.1, + 0, // 0.1 + 0, // 0.5 + 1, // 0.50000001, + 1, // 0.6 + 1, // 0.7 + 0, // undefined + 0, // -1 + 0, // -0 + 0, // -0.1 + 0, // -1.1 + 0, // NaN + 0, // -127 + 0, // -128 + 0, // -32767 + 0, // -32768 + 0, // -2147483647 + 0, // -2147483648 + 0, // -255 + 0, // -256 + 0, // -65535 + 0, // -65536 + 0, // -4294967295 + 0, // -4294967296 + 255, // Infinity + 0, // -Infinity + 0 + ], + Int16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + -32768, // 32768 + -1, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + -255, // -255 + -256, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 65535, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 0, // 65536 + 65535, // 4294967295 + 0, // 4294967296 + 65535, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 65535, // -1 + 0, // -0 + 0, // -0.1 + 65535, // -1.1 + 0, // NaN + 65409, // -127 + 65408, // -128 + 32769, // -32767 + 32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 65281, // -255 + 65280, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Int32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + -2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 0, // 4294967296 + 4294967295, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 4294967295, // -1 + 0, // -0 + 0, // -0.1 + 4294967295, // -1.1 + 0, // NaN + 4294967169, // -127 + 4294967168, // -128 + 4294934529, // -32767 + 4294934528, // -32768 + 2147483649, // -2147483647 + 2147483648, // -2147483648 + 4294967041, // -255 + 4294967040, // -256 + 4294901761, // -65535 + 4294901760, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Float32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483648, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967296, // 4294967295 + 4294967296, // 4294967296 + 9007199254740992, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.100000023841858, // 1.1 + 0.10000000149011612, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.6000000238418579, // 0.6 + 0.699999988079071, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.10000000149011612, // -0.1 + -1.100000023841858, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483648, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967296, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float64: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 4294967296, // 4294967296 + 9007199254740991, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.1, // 1.1 + 0.1, // 0.1 + 0.5, // 0.5 + 0.50000001, // 0.50000001, + 0.6, // 0.6 + 0.7, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.1, // -0.1 + -1.1, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967295, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ] + } +}; + +// file: nans.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-from-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-from-property.js new file mode 100644 index 0000000000..574b628f9e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-from-property.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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive-typeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive-typeerror.js new file mode 100644 index 0000000000..1e0cba0b5a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive-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 @@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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive.js new file mode 100644 index 0000000000..b70a039911 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-to-primitive.js @@ -0,0 +1,87 @@ +// Copyright (C) 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-tostring.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-tostring.js new file mode 100644 index 0000000000..9940e1e608 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-tostring.js @@ -0,0 +1,100 @@ +// Copyright (C) 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof-typeerror.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof-typeerror.js new file mode 100644 index 0000000000..746e244537 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof-typeerror.js @@ -0,0 +1,101 @@ +// Copyright (C) 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof.js new file mode 100644 index 0000000000..7bb03318c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-obj-valueof.js @@ -0,0 +1,94 @@ +// Copyright (C) 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-property.js new file mode 100644 index 0000000000..0e5f93d30a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-property.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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-symbol-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-symbol-property.js new file mode 100644 index 0000000000..f30ef12f5c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/throws-setting-symbol-property.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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/undefined-newtarget-throws.js new file mode 100644 index 0000000000..b5b6b00fa1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/undefined-newtarget-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-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([]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..996f9d659a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-custom-proto-if-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..7ae957d8a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/object-arg/use-default-proto-if-custom-proto-is-not-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/custom-proto-access-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/custom-proto-access-throws.js new file mode 100644 index 0000000000..9668bd269b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/custom-proto-access-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 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/new-instance-extensibility.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/new-instance-extensibility.js new file mode 100644 index 0000000000..59d5efba90 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/new-instance-extensibility.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-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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/other-ctor-returns-new-typedarray.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/other-ctor-returns-new-typedarray.js new file mode 100644 index 0000000000..8f6d0f51fe --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/other-ctor-returns-new-typedarray.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-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/proto-from-ctor-realm.js new file mode 100644 index 0000000000..d7aae2b83f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/proto-from-ctor-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-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/returns-new-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/returns-new-instance.js new file mode 100644 index 0000000000..b59e86f5a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-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-typedarray +description: > + Return a TypedArray object +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. + + ... + 20. Return O. + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var len = 10; +var typedArraySample = new Int8Array(len); + +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(typedArraySample); + + assert.notSameValue(typedArray, typedArraySample); + assert.sameValue(typedArray.length, len); + assert.sameValue(typedArray.constructor, TA); + assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-null.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-null.js new file mode 100644 index 0000000000..2dc3b4bd0a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-null.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-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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-undefined.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-undefined.js new file mode 100644 index 0000000000..53904f8aa1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-buffer-ctor-species-undefined.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-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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-returns-new-cloned-typedarray.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-returns-new-cloned-typedarray.js new file mode 100644 index 0000000000..95d273cff2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/same-ctor-returns-new-cloned-typedarray.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-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/shell.js new file mode 100644 index 0000000000..1157ee5318 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/shell.js @@ -0,0 +1,166 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/src-typedarray-big-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/src-typedarray-big-throws.js new file mode 100644 index 0000000000..d7aaead773 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/src-typedarray-big-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-typedarray +description: > + If typedArray constructor argument is a Big(U)Int, throw +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. + + ... + 19. Else, + ... + c. If one of srcType and elementType contains the substring "Big" and the other + does not, throw a TypeError exception. + +includes: [testBigIntTypedArray.js, testTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var bigTypedArray; + +testWithBigIntTypedArrayConstructors(function(BTA) { + + bigTypedArray = new BTA(16); + + testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(bigTypedArray); + }); + }); + +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/undefined-newtarget-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/undefined-newtarget-throws.js new file mode 100644 index 0000000000..4ea662775e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/undefined-newtarget-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-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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/use-custom-proto-if-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/use-custom-proto-if-object.js new file mode 100644 index 0000000000..c52ac6df1a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/use-custom-proto-if-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-typedarray +description: > + Use prototype from new target if it's an Object +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). + 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; + +var sample = new Int8Array(8); + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [sample], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/use-default-proto-if-custom-proto-is-not-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/use-default-proto-if-custom-proto-is-not-object.js new file mode 100644 index 0000000000..e82396a021 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/ctors/typedarray-arg/use-default-proto-if-custom-proto-is-not-object.js @@ -0,0 +1,49 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-typedarray +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +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). + 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 sample = new Int8Array(8); + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [sample], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-get-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-get-length-error.js new file mode 100644 index 0000000000..3dc905d154 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-get-length-error.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: 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-to-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-to-length-error.js new file mode 100644 index 0000000000..a021fb9377 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/arylk-to-length-error.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: 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000..7381016558 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-does-not-instantiate-ta-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%.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, []); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-other-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-other-instance.js new file mode 100644 index 0000000000..616faeccbe --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-other-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%.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 = [1n, 2n]; + var sourceObj = { + 0: 0n, + 1: 0n, + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-smaller-instance-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 0000000000..2982a4cd38 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor-returns-smaller-instance-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%.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 = [1n, 2n]; +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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor.js new file mode 100644 index 0000000000..538cce831f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/custom-ctor.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/inherited.js new file mode 100644 index 0000000000..8d4cf94da0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/inherited.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%.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'" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/invoked-as-func.js new file mode 100644 index 0000000000..53ab9a7a3e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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. +/*--- +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([]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-access-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-access-error.js new file mode 100644 index 0000000000..b9831aaf5a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-access-error.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: 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-invoke-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-invoke-error.js new file mode 100644 index 0000000000..4399a1956a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-invoke-error.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: 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-error.js new file mode 100644 index 0000000000..7b2007b15d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-error.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%.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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-value-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-value-error.js new file mode 100644 index 0000000000..cf3ba3e849 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/iter-next-value-error.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%.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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-abrupt-completion.js new file mode 100644 index 0000000000..f2464ac64c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-abrupt-completion.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: > + 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": 42n, + length: 2 +}; +var mapfn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-arguments.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-arguments.js new file mode 100644 index 0000000000..9f4de52fb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-arguments.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: > + 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 0n; + }; + + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-is-not-callable.js new file mode 100644 index 0000000000..77921c51a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-is-not-callable.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%.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]" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-with-thisarg.js new file mode 100644 index 0000000000..3c273cb9b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-with-thisarg.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%.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 0n; + }; + + TA.from(source, mapfn, thisArg); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], thisArg); + assert.sameValue(results[1], thisArg); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-non-strict.js new file mode 100644 index 0000000000..4cb1c28bf3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-non-strict.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%.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 global = this; + +testWithBigIntTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(x) { + results.push(this); + return x; + }; + + TA.from([42n, 43n], mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], global); + assert.sameValue(results[1], global); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-strict-strict.js new file mode 100644 index 0000000000..aa79478973 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/mapfn-this-without-thisarg-strict-strict.js @@ -0,0 +1,40 @@ +'use strict'; +// Copyright (C) 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 0n; + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], undefined); + assert.sameValue(results[1], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-empty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-empty.js new file mode 100644 index 0000000000..cd2af5b6bd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-empty.js @@ -0,0 +1,19 @@ +// Copyright (C) 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-ordinary-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-ordinary-object.js new file mode 100644 index 0000000000..a346a427ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-ordinary-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-%typedarray%.from +description: > + Return a new TypedArray from an ordinary object +includes: [testBigIntTypedArray.js] +features: [BigInt, Array.prototype.values, TypedArray] +---*/ + +var source = { + "0": 42n, + "1": 44n, + length: 2 +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from(source); + + assert.sameValue(result.length, 2); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 44n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-sparse-array.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-sparse-array.js new file mode 100644 index 0000000000..336afe286c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-from-sparse-array.js @@ -0,0 +1,19 @@ +// Copyright (C) 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 casting undefined value from sparse array to BigInt +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var source = [,42n]; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from(source); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-using-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000..5441898a3c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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] +---*/ + +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, [42n, 43n, 42n]); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result[2], 42n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); + assert.sameValue(called, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-with-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-with-mapfn.js new file mode 100644 index 0000000000..474f7ef675 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var mapfn = function(kValue) { + return kValue * 2n; + }; + + var result = TA.from([42n, 43n, 42n], mapfn); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 84n); + assert.sameValue(result[1], 86n); + assert.sameValue(result[2], 84n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-without-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/new-instance-without-mapfn.js new file mode 100644 index 0000000000..e7b1585343 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.from([42n, 43n, 42n]); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result[2], 42n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/property-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/property-abrupt-completion.js new file mode 100644 index 0000000000..1587324cf1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/property-abrupt-completion.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: > + 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/set-value-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/set-value-abrupt-completion.js new file mode 100644 index 0000000000..b61d83c13d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/set-value-abrupt-completion.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%.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 = [42n, obj, 1n]; + 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/source-value-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/source-value-is-symbol-throws.js new file mode 100644 index 0000000000..50db94969c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/source-value-is-symbol-throws.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: > + Throws a TypeError if argument is a Symbol +info: | + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from([s]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/this-is-not-constructor.js new file mode 100644 index 0000000000..9ad1a48462 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/BigInt/this-is-not-constructor.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: > + 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, []); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-get-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-get-length-error.js new file mode 100644 index 0000000000..a81e83852d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-get-length-error.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: 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var arrayLike = {}; + +Object.defineProperty(arrayLike, "length", { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-to-length-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-to-length-error.js new file mode 100644 index 0000000000..55eb5749ca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/arylk-to-length-error.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: 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var arrayLike = { length: {} }; + +arrayLike.length = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(arrayLike); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-does-not-instantiate-ta-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000..c7e4907e32 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-does-not-instantiate-ta-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%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.from.call(ctor, []); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-other-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-other-instance.js new file mode 100644 index 0000000000..9083ca3c08 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-other-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%.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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var sourceItor = [1, 2]; +var sourceObj = { + length: 2 +}; + +testWithTypedArrayConstructors(function(TA) { + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-smaller-instance-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 0000000000..044910acbf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor-returns-smaller-instance-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%.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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var sourceItor = [1, 2]; +var sourceObj = { + length: 2 +}; + +testWithTypedArrayConstructors(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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor.js new file mode 100644 index 0000000000..292093d14d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/custom-ctor.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var called = 0; + var ctor = function() { + called++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + TA.from.call(ctor, []); + }); + + assert.sameValue(called, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/inherited.js new file mode 100644 index 0000000000..9577e35aab --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/inherited.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%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(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'" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/invoked-as-func.js new file mode 100644 index 0000000000..b5dd5512cb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/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. +/*--- +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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var from = TA.from; + + assert.throws(TypeError, function() { + from([]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-access-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-access-error.js new file mode 100644 index 0000000000..e5c3737c29 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-access-error.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: 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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-invoke-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-invoke-error.js new file mode 100644 index 0000000000..5ff5bcc32e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-invoke-error.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: 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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-error.js new file mode 100644 index 0000000000..709c8026f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-error.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%.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: [testTypedArray.js] +features: [Symbol.iterator, TypedArray] +---*/ + +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-value-error.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-value-error.js new file mode 100644 index 0000000000..221433130d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/iter-next-value-error.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%.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: [testTypedArray.js] +features: [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; + } + }; +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(iter); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-abrupt-completion.js new file mode 100644 index 0000000000..9d32ab9524 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-abrupt-completion.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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = { + "0": 42, + length: 2 +}; +var mapfn = function() { + throw new Test262Error(); +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source, mapfn); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-arguments.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-arguments.js new file mode 100644 index 0000000000..28b04f06da --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-arguments.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%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 44]; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function(kValue, k) { + results.push({ + kValue: kValue, + k: k, + argsLength: arguments.length + }); + }; + + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-is-not-callable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-is-not-callable.js new file mode 100644 index 0000000000..f5b9b7865b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-is-not-callable.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%.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: [testTypedArray.js] +features: [Symbol, Symbol.iterator, TypedArray] +---*/ + +var getIterator = 0; +var arrayLike = {}; +Object.defineProperty(arrayLike, Symbol.iterator, { + get: function() { + getIterator++; + } +}); + +testWithTypedArrayConstructors(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]" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-with-thisarg.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-with-thisarg.js new file mode 100644 index 0000000000..4be11060b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-with-thisarg.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` 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43]; +var thisArg = {}; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + }; + + TA.from(source, mapfn, thisArg); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], thisArg); + assert.sameValue(results[1], thisArg); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-non-strict.js new file mode 100644 index 0000000000..b6ff0005da --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-non-strict.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%.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: [testTypedArray.js] +flags: [noStrict] +features: [TypedArray] +---*/ + +var source = [42, 43]; +var global = this; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], global); + assert.sameValue(results[1], global); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-strict-strict.js new file mode 100644 index 0000000000..8a136b75bc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/mapfn-this-without-thisarg-strict-strict.js @@ -0,0 +1,39 @@ +'use strict'; +// Copyright (C) 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: [testTypedArray.js] +flags: [onlyStrict] +features: [TypedArray] +---*/ + +var source = [42, 43]; + +testWithTypedArrayConstructors(function(TA) { + var results = []; + var mapfn = function() { + results.push(this); + }; + + TA.from(source, mapfn); + + assert.sameValue(results.length, 2); + assert.sameValue(results[0], undefined); + assert.sameValue(results[1], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/nan-conversion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/nan-conversion.js new file mode 100644 index 0000000000..5eed829650 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/nan-conversion.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%.from +description: > + Test NaN conversions +info: | + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(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 +]); + +testWithTypedArrayConstructors(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 +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-empty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-empty.js new file mode 100644 index 0000000000..0a276b5b58 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-empty.js @@ -0,0 +1,19 @@ +// Copyright (C) 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: [testTypedArray.js] +features: [TypedArray] +---*/ + + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from([]); + assert.sameValue(result.length, 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-ordinary-object.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-ordinary-object.js new file mode 100644 index 0000000000..b49dc011ef --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-ordinary-object.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%.from +description: > + Return a new TypedArray from an ordinary object +includes: [testTypedArray.js] +features: [Array.prototype.values, TypedArray] +---*/ + +var source = { + "0": 42, + "2": 44, + length: 4 +}; + +testWithTypedArrayConstructors(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 +]); + +testWithTypedArrayConstructors(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 +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-sparse-array.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-sparse-array.js new file mode 100644 index 0000000000..c246dde70a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-sparse-array.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%.from +description: > + Return a new TypedArray from a sparse array +includes: [testTypedArray.js] +features: [Array.prototype.values, TypedArray] +---*/ + +var source = [,,42,,44,,]; + +testWithTypedArrayConstructors(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 +]); + +testWithTypedArrayConstructors(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 +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-zero.js new file mode 100644 index 0000000000..b37287c67e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-from-zero.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%.from +description: > + Return a new TypedArray using -0 and +0 +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(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 +]); + +testWithTypedArrayConstructors(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 +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000..375458c109 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-using-custom-ctor.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 a new TypedArray using a custom Constructor +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithTypedArrayConstructors(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, source); + assert.sameValue(result.length, 3); + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-with-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-with-mapfn.js new file mode 100644 index 0000000000..9a17d2db77 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-with-mapfn.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%.from +description: > + Return a new TypedArray using mapfn +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithTypedArrayConstructors(function(TA) { + var mapfn = function(kValue) { + return kValue * 2; + }; + + var result = TA.from(source, mapfn); + assert.sameValue(result.length, 3); + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-without-mapfn.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-without-mapfn.js new file mode 100644 index 0000000000..f5aa405987 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/new-instance-without-mapfn.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: > + Return a new TypedArray +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = [42, 43, 42]; + +testWithTypedArrayConstructors(function(TA) { + var result = TA.from(source); + assert.sameValue(result.length, 3); + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/property-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/property-abrupt-completion.js new file mode 100644 index 0000000000..20b1934e03 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/property-abrupt-completion.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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var source = { + length: 2 +}; +Object.defineProperty(source, "0", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + TA.from(source); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.js new file mode 100644 index 0000000000..e94d807876 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/set-value-abrupt-completion.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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf() { + throw new Test262Error(); + } +}; + +var source = [42, obj, 1]; + +testWithTypedArrayConstructors(function(TA) { + 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/shell.js new file mode 100644 index 0000000000..e9580b3113 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/shell.js @@ -0,0 +1,124 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/source-value-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/source-value-is-symbol-throws.js new file mode 100644 index 0000000000..e5a1ff264b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/source-value-is-symbol-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%.from +description: > + Throws a TypeError if argument is a Symbol +info: | + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from([s]); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/from/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/this-is-not-constructor.js new file mode 100644 index 0000000000..3369baef9b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/from/this-is-not-constructor.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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var m = { m() {} }.m; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.from.call(m, []); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/desc-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/desc-value-throws.js new file mode 100644 index 0000000000..687ae5e5ef --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/desc-value-throws.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: > + 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.throws(Test262Error, function() { + Object.defineProperty(sample, "0", {value: obj}); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws-realm.js new file mode 100644 index 0000000000..2a17145caf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws-realm.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: > + Throws TypeError for valid descriptor & canonical numeric string if buffer is detached. + (honoring the Realm of the current execution context) +info: | + [[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 ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA([0n]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws.js new file mode 100644 index 0000000000..747595e86b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer-throws.js @@ -0,0 +1,50 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid descriptor & canonical numeric string if buffer is detached. +info: | + [[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 ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 0000000000..b857d4c3a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/detached-buffer.js @@ -0,0 +1,122 @@ +// Copyright (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 this 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +var desc = { + value: 0n, + 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.sameValue( + Reflect.defineProperty(sample, '0', desc), + false, + 'Reflect.defineProperty(sample, "0", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '-1', desc), + false, + 'Reflect.defineProperty(sample, "-1", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '1.1', desc), + false, + 'Reflect.defineProperty(sample, "1.1", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '-0', desc), + false, + 'Reflect.defineProperty(sample, "-0", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue(Reflect.defineProperty(sample, '2', { + configurable: true, + enumerable: true, + writable: true, + value: obj + }), false, 'Reflect.defineProperty(sample, "2", {configurable: true, enumerable: true, writable: true, value: obj}) must return false'); + + assert.sameValue(Reflect.defineProperty(sample, '3', { + configurable: false, + enumerable: false, + writable: true, + value: obj + }), false, 'Reflect.defineProperty(sample, "3", {configurable: false, enumerable: false, writable: true, value: obj}) must return false'); + + assert.sameValue(Reflect.defineProperty(sample, '4', { + writable: false, + configurable: false, + enumerable: true, + value: obj + }), false, 'Reflect.defineProperty(sample, "4", {writable: false, configurable: false, enumerable: true, value: obj}) must return false'); + + assert.sameValue( + Reflect.defineProperty(sample, '42', desc), + false, + 'Reflect.defineProperty(sample, "42", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, '43', desc), + false, + 'Reflect.defineProperty(sample, "43", {value: 0n, configurable: false, enumerable: true, writable: true}) must return false' + ); + + assert.sameValue(Reflect.defineProperty(sample, '5', { + get: function() {} + }), false, 'Reflect.defineProperty(sample, "5", {get: function() {}}) must return false'); + + assert.sameValue(Reflect.defineProperty(sample, '6', { + configurable: false, + enumerable: true, + writable: true + }), false, 'Reflect.defineProperty(sample, "6", {configurable: false, enumerable: true, writable: true}) must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..08799367b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-greater-than-last-index.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-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([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex == length" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "numericIndex > length" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 0000000000..b7e490c51d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-lower-than-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 + ... + 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([42n, 43n]); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", { + value: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-1" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..5dadc628c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-minus-zero.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-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: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "defineProperty returns false" + ); + assert.sameValue(sample[0], 0n, "does not change the value for [0]"); + assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..7fdad5a989 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-canonical-index.js @@ -0,0 +1,100 @@ +// Copyright (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: 42n, + 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], 42n, "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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..c0c53679d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-integer.js @@ -0,0 +1,126 @@ +// Copyright (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: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.1" + ); + assert.sameValue(sample[0], 0n, "'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: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "0.000001" + ); + assert.sameValue( + sample[0], 0n, + "'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: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "1.1" + ); + assert.sameValue(sample[1], 0n, "'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: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "Infinity" + ); + assert.sameValue( + sample[0], 0n, + "'Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0n, + "'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: 42n, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-Infinity" + ); + assert.sameValue( + sample[0], 0n, + "'-Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0n, + "'-Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["-Infinity"], + undefined, + "'-Infinity' - does not define a value for ['-Infinity']" + ); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index-throws.js new file mode 100644 index 0000000000..272c7e74f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index-throws.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid descriptor & canonical numeric string that is invalid index. +info: | + [[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 ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 3. If ! IsIntegralNumber(index) is false, return false. + 4. If index is -0𝔽, return false. + 5. If ℝ(index) < 0 or ℝ(index) ≥ O.[[ArrayLength]], return false. +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..c2d3b19e17 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-not-numeric-index.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: > + 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([42n, 43n]); + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc-throws.js new file mode 100644 index 0000000000..6093419b97 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & accessor descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iv. If IsAccessorDescriptor(Desc) is true, return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42n; }, + }); + }, "get accessor"); + assert.sameValue(sample[0], 0n, "get accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + set: function(_v) {}, + }); + }, "set accessor"); + assert.sameValue(sample[0], 0n, "set accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42n; }, + set: function(_v) {}, + }); + }, "get and set accessors"); + assert.sameValue(sample[0], 0n, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.js new file mode 100644 index 0000000000..073c905f19 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-accessor-desc.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-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], 0n, "get accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + enumerable: true + }), + false, + "set accessor" + ); + assert.sameValue(sample[0], 0n, "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], 0n, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.js new file mode 100644 index 0000000000..02fbb4e786 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-configurable.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-defineownproperty-p-desc +description: > + Returns true 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 + ... + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42n, + configurable: true, + enumerable: true, + writable: true + }), + true, + "defineProperty's result" + ); + assert.sameValue(sample[0], 42n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-configurable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-configurable-throws.js new file mode 100644 index 0000000000..970f59f008 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-configurable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & non-configurable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + ii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, return false. +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + configurable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42n, + writable: true, + enumerable: true, + configurable: false, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable-throws.js new file mode 100644 index 0000000000..a8878645dd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & non-enumerable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iii. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + enumerable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42n, + writable: true, + enumerable: false, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.js new file mode 100644 index 0000000000..104cf33d0f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-enumerable.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-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: 42n, + configurable: false, + enumerable: false, + writable: true + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable-throws.js new file mode 100644 index 0000000000..6ddf3303df --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & non-writable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + v. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, return false. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + writable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42n, + writable: false, + enumerable: true, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.js new file mode 100644 index 0000000000..48adf6678e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex-desc-not-writable.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-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: 42n, + configurable: false, + enumerable: true, + writable: false + }), + false, + "defineProperty's result" + ); + assert.sameValue(sample[0], 0n, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex.js new file mode 100644 index 0000000000..aaadd22433 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-numericindex.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: > + 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 + ... + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 42n]); + + assert.sameValue(Reflect.defineProperty(sample, '0', { + value: 8n, + configurable: true, + enumerable: true, + writable: true + }), true, 'Reflect.defineProperty(sample, "0", {value: 8n, configurable: true, enumerable: true, writable: true}) must return true'); + + assert.sameValue(sample[0], 8n, 'The value of sample[0] is 8n'); + var desc = Object.getOwnPropertyDescriptor(sample, '0'); + assert.sameValue(desc.value, 8n, 'The value of desc.value is 8n'); + assert.sameValue(desc.configurable, true, 'The value of desc.configurable is true'); + assert.sameValue(desc.enumerable, true, 'The value of desc.enumerable is true'); + assert.sameValue(desc.writable, true, 'The value of desc.writable is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..ec5fed280c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/key-is-symbol.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-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([42n, 43n]); + + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-new-key.js new file mode 100644 index 0000000000..0f6624e723 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-new-key.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-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([42n, 43n]); + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.js new file mode 100644 index 0000000000..6db2aa90ca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/non-extensible-redefine-key.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-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([42n, 43n]); + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/set-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/set-value.js new file mode 100644 index 0000000000..6998041783 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/set-value.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: > + 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([0n, 0n]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", {value: 1n}), + true, + "set value for sample[0] returns true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1", {value: 2n}), + true, + "set value for sample[1] returns true" + ); + + assert.sameValue(sample[0], 1n, "sample[0]"); + assert.sameValue(sample[1], 2n, "sample[1]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/this-is-not-extensible.js new file mode 100644 index 0000000000..f3e20f5bea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/this-is-not-extensible.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-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([42n, 43n]); + + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..c10b7a5579 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,61 @@ +// 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 return + true 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var ta = new TA([17n]); + + var desc = { + value: { + valueOf() { + $DETACHBUFFER(ta.buffer); + return 42n; + } + } + }; + + assert.sameValue( + Reflect.defineProperty(ta, 0, desc), + true, + 'Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42n;}}}) must return true' + ); + + assert.sameValue(ta[0], undefined, 'The value of ta[0] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js new file mode 100644 index 0000000000..ca15783625 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation-consistent-nan.js @@ -0,0 +1,100 @@ +// Copyright (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: Consistent canonicalization of NaN values +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + [[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). + ... + + #sec-integerindexedelementset + IntegerIndexedElementSet ( O, index, value ) + + ... + 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue). + ... + + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + NumberToRawBytes( type, value, isLittleEndian ) + + 1. 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 either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. 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 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. + ... + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(FA) { + var precision = FA === Float32Array ? "single" : "double"; + var samples = new FA(1); + var controls, idx, aNaN; + + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx]; + controls = new FA([aNaN, aNaN, aNaN]); + + Object.defineProperty(samples, "0", { value: aNaN }); + + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + `samples (index=${idx}) produces a valid NaN (${precision} precision)` + ); + + assert( + controls[i] !== controls[i], + `controls (index=${idx}) produces a valid NaN (${precision} precision)` + ); + } + } +}, [Float32Array, Float64Array]); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.js new file mode 100644 index 0000000000..9cb1a271c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/conversion-operation.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-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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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] +features: [TypedArray] +---*/ + +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/desc-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/desc-value-throws.js new file mode 100644 index 0000000000..987400e098 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/desc-value-throws.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: > + 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.throws(Test262Error, function() { + Object.defineProperty(sample, "0", {value: obj}); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws-realm.js new file mode 100644 index 0000000000..e0bc4aa960 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws-realm.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: > + Throws TypeError for valid descriptor & canonical numeric string if buffer is detached. + (honoring the Realm of the current execution context) +info: | + [[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 ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA([0]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws.js new file mode 100644 index 0000000000..0508818e9d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer-throws.js @@ -0,0 +1,50 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid descriptor & canonical numeric string if buffer is detached. +info: | + [[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 ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false. +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + $DETACHBUFFER(sample.buffer); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer.js new file mode 100644 index 0000000000..5bca5e6893 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/detached-buffer.js @@ -0,0 +1,143 @@ +// Copyright (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 this 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +var desc = { + value: 0, + configurable: false, + enumerable: true, + writable: true +}; + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.defineProperty(sample, "0", desc), + false, + 'Reflect.defineProperty(sample, "0", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", desc), + false, + 'Reflect.defineProperty(sample, "-1", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1.1", desc), + false, + 'Reflect.defineProperty(sample, "1.1", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "-0", desc), + false, + 'Reflect.defineProperty(sample, "-0", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "2", { + configurable: true, + enumerable: true, + writable: true, + value: obj + }), + false, + 'Reflect.defineProperty(sample, "2", {configurable: true, enumerable: true, writable: true, value: obj}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "3", { + configurable: false, + enumerable: false, + writable: true, + value: obj + }), + false, + 'Reflect.defineProperty(sample, "3", {configurable: false, enumerable: false, writable: true, value: obj}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "4", { + writable: false, + configurable: false, + enumerable: true, + value: obj + }), + false, + 'Reflect.defineProperty("new TA(42)", "4", {writable: false, configurable: false, enumerable: true, value: obj}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "42", desc), + false, + 'Reflect.defineProperty(sample, "42", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "43", desc), + false, + 'Reflect.defineProperty(sample, "43", {value: 0, configurable: false, enumerable: true, writable: true} ) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "5", { + get: function() {} + }), + false, + 'Reflect.defineProperty(sample, "5", {get: function() {}}) must return false' + ); + + assert.sameValue( + Reflect.defineProperty(sample, "6", { + configurable: false, + enumerable: true, + writable: true + }), + false, + 'Reflect.defineProperty(sample, "6", {configurable: false, enumerable: true, writable: true}) must return false' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..ad49623d94 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-greater-than-last-index.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-lower-than-zero.js new file mode 100644 index 0000000000..bafcc4e84f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-lower-than-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 + ... + ii. Let intIndex be numericIndex. + iv. If intIndex < 0, return false. + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue( + Reflect.defineProperty(sample, "-1", { + value: 42, + configurable: false, + enumerable: true, + writable: true + }), + false, + "-1" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-minus-zero.js new file mode 100644 index 0000000000..970eb231eb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-minus-zero.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(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], 0, "does not change the value for [0]"); + assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-canonical-index.js new file mode 100644 index 0000000000..c667f7ac46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-canonical-index.js @@ -0,0 +1,100 @@ +// Copyright (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: [testTypedArray.js, propertyHelper.js] +features: [Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +var dataDesc = { + value: 42, + writable: true, + configurable: true +}; + +var fnset = function() {}; +var fnget = function() {}; + +var acDesc = { + get: fnget, + set: fnset, + enumerable: true, + configurable: false +}; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample1 = new TA(); + + assert.sameValue( + Reflect.defineProperty(sample1, key, dataDesc), + true, + "return true after defining data property [" + key + "]" + ); + + assert.sameValue(sample1[key], 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); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-integer.js new file mode 100644 index 0000000000..7b1c6c9206 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-integer.js @@ -0,0 +1,126 @@ +// Copyright (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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(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], 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], 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], 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], 0, + "'Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 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], 0, + "'-Infinity' - does not change the value for [0]" + ); + assert.sameValue( + sample[1], 0, + "'-Infinity' - does not change the value for [1]" + ); + assert.sameValue( + sample["-Infinity"], + undefined, + "'-Infinity' - does not define a value for ['-Infinity']" + ); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index-throws.js new file mode 100644 index 0000000000..5dbb162ef3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index-throws.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid descriptor & canonical numeric string that is invalid index. +info: | + [[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 ! IsValidIntegerIndex(O, numericIndex) is false, return false. + + IsValidIntegerIndex ( O, index ) + + [...] + 3. If ! IsIntegralNumber(index) is false, return false. + 4. If index is -0𝔽, return false. + 5. If ℝ(index) < 0 or ℝ(index) ≥ O.[[ArrayLength]], return false. +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + var desc = Object.getOwnPropertyDescriptor(sample, "0"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-1", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "1.5", desc); + }); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "-0", desc); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index.js new file mode 100644 index 0000000000..33b460ede6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-not-numeric-index.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: > + 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: [testTypedArray.js, propertyHelper.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc-throws.js new file mode 100644 index 0000000000..c794dd233d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & accessor descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iv. If IsAccessorDescriptor(Desc) is true, return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42; }, + }); + }, "get accessor"); + assert.sameValue(sample[0], 0, "get accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + set: function(_v) {}, + }); + }, "set accessor"); + assert.sameValue(sample[0], 0, "set accessor - side effect check"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + get: function() { return 42; }, + set: function(_v) {}, + }); + }, "get and set accessors"); + assert.sameValue(sample[0], 0, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.js new file mode 100644 index 0000000000..b382b1fcea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-accessor-desc.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(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], 0, "get accessor - side effect check"); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + set: function() {}, + enumerable: true + }), + false, + "set accessor" + ); + assert.sameValue(sample[0], 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], 0, "get and set accessors - side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.js new file mode 100644 index 0000000000..3e6defb841 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-configurable.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-defineownproperty-p-desc +description: > + Returns true 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 + ... + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + ... +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 42, + configurable: true, + enumerable: true, + writable: true + }), + true, + "defineProperty's result" + ); + assert.sameValue(sample[0], 42, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js new file mode 100644 index 0000000000..12c0ea92de --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-configurable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & non-configurable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + ii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, return false. +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + configurable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42, + writable: true, + enumerable: true, + configurable: false, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable-throws.js new file mode 100644 index 0000000000..3e09508c43 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & non-enumerable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + iii. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + enumerable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42, + writable: true, + enumerable: false, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.js new file mode 100644 index 0000000000..1c8ab48205 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-enumerable.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(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], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable-throws.js new file mode 100644 index 0000000000..99c5579ee8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable-throws.js @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Alexey Shvayka. 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 TypeError for valid index & non-writable descriptor. +info: | + [[DefineOwnProperty]] ( P, Desc ) + + [...] + 3. If Type(P) is String, then + a. Let numericIndex be ! CanonicalNumericIndexString(P). + b. If numericIndex is not undefined, then + [...] + v. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, return false. +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0]); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + writable: false, + }); + }, "partial descriptor"); + + assert.throws(TypeError, function() { + Object.defineProperty(sample, "0", { + value: 42, + writable: false, + enumerable: true, + configurable: true, + }); + }, "complete descriptor"); + + assert.sameValue(sample[0], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.js new file mode 100644 index 0000000000..25d78bf869 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex-desc-not-writable.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(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], 0, "side effect check"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex.js new file mode 100644 index 0000000000..0b45de3189 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-numericindex.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 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 + If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + If IsAccessorDescriptor(Desc) is true, return false. + If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is false, return false. + If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is false, return false. + If Desc has a [[Writable]] field and if Desc.[[Writable]] is false, return false. + If Desc has a [[Value]] field, then + Let value be Desc.[[Value]]. + Return ? IntegerIndexedElementSet(O, numericIndex, value). + +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 42]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", { + value: 8, + configurable: true, + enumerable: true, + writable: true + }), + true + ); + + assert.sameValue(sample[0], 8, "property value was set"); + let descriptor0 = Object.getOwnPropertyDescriptor(sample, "0"); + assert.sameValue(descriptor0.value, 8); + assert.sameValue(descriptor0.configurable, true); + assert.sameValue(descriptor0.enumerable, true); + assert.sameValue(descriptor0.writable, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-symbol.js new file mode 100644 index 0000000000..867f69e9d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/key-is-symbol.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-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: [testTypedArray.js, propertyHelper.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-new-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-new-key.js new file mode 100644 index 0000000000..51a824d248 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-new-key.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-redefine-key.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-redefine-key.js new file mode 100644 index 0000000000..00e67d6fd6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/non-extensible-redefine-key.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-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: [testTypedArray.js, propertyHelper.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/set-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/set-value.js new file mode 100644 index 0000000000..2b81f9777f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/set-value.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: > + 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([0, 0]); + + assert.sameValue( + Reflect.defineProperty(sample, "0", {value: 1}), + true, + "set value for sample[0] returns true" + ); + + assert.sameValue( + Reflect.defineProperty(sample, "1", {value: 2}), + true, + "set value for sample[1] returns true" + ); + + assert.sameValue(sample[0], 1, "sample[0]"); + assert.sameValue(sample[1], 2, "sample[1]"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/shell.js new file mode 100644 index 0000000000..abdb960ca1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/shell.js @@ -0,0 +1,614 @@ +// GENERATED, DO NOT EDIT +// file: byteConversionValues.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Provide a list for original and expected values for different byte + conversions. + This helper is mostly used on tests for TypedArray and DataView, and each + array from the expected values must match the original values array on every + index containing its original value. +defines: [byteConversionValues] +---*/ +var byteConversionValues = { + values: [ + 127, // 2 ** 7 - 1 + 128, // 2 ** 7 + 32767, // 2 ** 15 - 1 + 32768, // 2 ** 15 + 2147483647, // 2 ** 31 - 1 + 2147483648, // 2 ** 31 + 255, // 2 ** 8 - 1 + 256, // 2 ** 8 + 65535, // 2 ** 16 - 1 + 65536, // 2 ** 16 + 4294967295, // 2 ** 32 - 1 + 4294967296, // 2 ** 32 + 9007199254740991, // 2 ** 53 - 1 + 9007199254740992, // 2 ** 53 + 1.1, + 0.1, + 0.5, + 0.50000001, + 0.6, + 0.7, + undefined, + -1, + -0, + -0.1, + -1.1, + NaN, + -127, // - ( 2 ** 7 - 1 ) + -128, // - ( 2 ** 7 ) + -32767, // - ( 2 ** 15 - 1 ) + -32768, // - ( 2 ** 15 ) + -2147483647, // - ( 2 ** 31 - 1 ) + -2147483648, // - ( 2 ** 31 ) + -255, // - ( 2 ** 8 - 1 ) + -256, // - ( 2 ** 8 ) + -65535, // - ( 2 ** 16 - 1 ) + -65536, // - ( 2 ** 16 ) + -4294967295, // - ( 2 ** 32 - 1 ) + -4294967296, // - ( 2 ** 32 ) + Infinity, + -Infinity, + 0 + ], + + expected: { + Int8: [ + 127, // 127 + -128, // 128 + -1, // 32767 + 0, // 32768 + -1, // 2147483647 + 0, // 2147483648 + -1, // 255 + 0, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 0, // 32768 + 255, // 2147483647 + 0, // 2147483648 + 255, // 255 + 0, // 256 + 255, // 65535 + 0, // 65536 + 255, // 4294967295 + 0, // 4294967296 + 255, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 255, // -1 + 0, // -0 + 0, // -0.1 + 255, // -1.1 + 0, // NaN + 129, // -127 + 128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8Clamped: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 255, // 32768 + 255, // 2147483647 + 255, // 2147483648 + 255, // 255 + 255, // 256 + 255, // 65535 + 255, // 65536 + 255, // 4294967295 + 255, // 4294967296 + 255, // 9007199254740991 + 255, // 9007199254740992 + 1, // 1.1, + 0, // 0.1 + 0, // 0.5 + 1, // 0.50000001, + 1, // 0.6 + 1, // 0.7 + 0, // undefined + 0, // -1 + 0, // -0 + 0, // -0.1 + 0, // -1.1 + 0, // NaN + 0, // -127 + 0, // -128 + 0, // -32767 + 0, // -32768 + 0, // -2147483647 + 0, // -2147483648 + 0, // -255 + 0, // -256 + 0, // -65535 + 0, // -65536 + 0, // -4294967295 + 0, // -4294967296 + 255, // Infinity + 0, // -Infinity + 0 + ], + Int16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + -32768, // 32768 + -1, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + -255, // -255 + -256, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 65535, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 0, // 65536 + 65535, // 4294967295 + 0, // 4294967296 + 65535, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 65535, // -1 + 0, // -0 + 0, // -0.1 + 65535, // -1.1 + 0, // NaN + 65409, // -127 + 65408, // -128 + 32769, // -32767 + 32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 65281, // -255 + 65280, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Int32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + -2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 0, // 4294967296 + 4294967295, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 4294967295, // -1 + 0, // -0 + 0, // -0.1 + 4294967295, // -1.1 + 0, // NaN + 4294967169, // -127 + 4294967168, // -128 + 4294934529, // -32767 + 4294934528, // -32768 + 2147483649, // -2147483647 + 2147483648, // -2147483648 + 4294967041, // -255 + 4294967040, // -256 + 4294901761, // -65535 + 4294901760, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Float32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483648, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967296, // 4294967295 + 4294967296, // 4294967296 + 9007199254740992, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.100000023841858, // 1.1 + 0.10000000149011612, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.6000000238418579, // 0.6 + 0.699999988079071, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.10000000149011612, // -0.1 + -1.100000023841858, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483648, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967296, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float64: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 4294967296, // 4294967296 + 9007199254740991, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.1, // 1.1 + 0.1, // 0.1 + 0.5, // 0.5 + 0.50000001, // 0.50000001, + 0.6, // 0.6 + 0.7, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.1, // -0.1 + -1.1, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967295, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ] + } +}; + +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: nans.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/this-is-not-extensible.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/this-is-not-extensible.js new file mode 100644 index 0000000000..466959ed64 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/this-is-not-extensible.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-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: [testTypedArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..62b51f8945 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/DefineOwnProperty/tonumber-value-detached-buffer.js @@ -0,0 +1,64 @@ +// 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 + return true 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). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ta = new TA([17]); + + var desc = + { + value: { + valueOf() { + $DETACHBUFFER(ta.buffer); + return 42; + } + } + }; + + assert.sameValue( + Reflect.defineProperty(ta, 0, desc), + true, + 'Reflect.defineProperty(ta, 0, {value: {valueOf() {$DETACHBUFFER(ta.buffer); return 42;}}} ) must return true' + ); + assert.sameValue(ta[0], undefined, 'The value of ta[0] is expected to equal `undefined`'); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..c39af7873f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... + Return ? OrdinaryDelete(O, P) +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + sample.string = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.string, true, 'The value of `delete sample.string` is true'); + assert.sameValue(delete sample.undef, true, 'The value of `delete sample.undef` is true'); + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..ed0dddfd7b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Calls OrdinaryDelete when key is a Symbol. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + let s = Symbol("1"); + + sample[s] = 1; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..05cc9e7246 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer-realm.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached + (honoring the Realm of the current execution context) +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer.js new file mode 100644 index 0000000000..2879b0cc8f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); + assert.sameValue(delete sample["1.1"], true, 'The value of `delete sample["1.1"]` is true'); + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample["2"], true, 'The value of `delete sample["2"]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-non-strict.js new file mode 100644 index 0000000000..f42faf11d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample[1]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-strict-strict.js new file mode 100644 index 0000000000..b54d66cca8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-ab-strict-strict.js @@ -0,0 +1,55 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample["1"]; + }, '`delete sample["1"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-non-strict.js new file mode 100644 index 0000000000..0f63640193 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-non-strict.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2020 Rick Waldron. 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-delete-p +description: > + Return value from valid numeric index, with SharedArrayBuffer +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample["1"]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-strict-strict.js new file mode 100644 index 0000000000..6677f96548 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/indexed-value-sab-strict-strict.js @@ -0,0 +1,44 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +'use strict'; +// Copyright (C) 2020 Rick Waldron. 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-delete-p +description: > + Throws TypeError exception in strict mode. +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.throws(TypeError, () => { + delete sample["0"]; + }); + assert.throws(TypeError, () => { + delete sample[0]; + }); + assert.throws(TypeError, () => { + delete sample["1"]; + }); + assert.throws(TypeError, () => { + delete sample[1]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/infinity-detached-buffer.js new file mode 100644 index 0000000000..0600fa230f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/infinity-detached-buffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string. Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] ( P, Receiver ) + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + CanonicalNumericIndexString ( argument ) + ... + Let n be ! ToNumber(argument). + If SameValue(! ToString(n), argument) is false, return undefined. + Return n. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.Infinity, true, 'The value of `delete sample.Infinity` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-non-strict.js new file mode 100644 index 0000000000..dbe5370153 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-non-strict.js @@ -0,0 +1,69 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.sameValue( + delete sample[key], false, + 'The value of `delete sample[key]` is false' + ); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-strict-strict.js new file mode 100644 index 0000000000..4435c4ac17 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-canonical-index-strict-strict.js @@ -0,0 +1,69 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.throws(TypeError, () => { + delete sample[key]; + }, '`delete sample[key]` throws TypeError'); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-non-strict.js new file mode 100644 index 0000000000..319764e862 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample[-0], false, 'The value of `delete sample[-0]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-strict-strict.js new file mode 100644 index 0000000000..c0e42e745e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-minus-zero-strict-strict.js @@ -0,0 +1,49 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.throws(TypeError, () => { + delete sample[-0]; + }, '`delete sample[-0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..2cd35158c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-get-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + + Object.defineProperty(sample, "foo", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, () => { + sample.foo; + }, '`sample.foo` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-non-strict.js new file mode 100644 index 0000000000..29c468caa7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.sameValue(delete sample.bar, false, 'The value of `delete sample.bar` is false'); + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-strict-strict.js new file mode 100644 index 0000000000..2a9f7171e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-not-numeric-index-strict-strict.js @@ -0,0 +1,50 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.throws(TypeError, () => { + delete sample.bar; + }, '`delete sample.bar` throws TypeError'); + + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-non-strict.js new file mode 100644 index 0000000000..ee352b1a40 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-non-strict.js @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [noStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-strict-strict.js new file mode 100644 index 0000000000..8d67ba003f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-out-of-bounds-strict-strict.js @@ -0,0 +1,57 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [onlyStrict] +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..9d642c8c6b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is a Symbol +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + let s = Symbol("1"); + + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); + + sample[s] = ""; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..f204b58813 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-not-numeric-index.js @@ -0,0 +1,36 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... + Return ? OrdinaryDelete(O, P) +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + let key = "key"; + sample.string = key; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.string, true, 'The value of `delete sample.string` is true'); + assert.sameValue(delete sample.undef, true, 'The value of `delete sample.undef` is true'); + assert.sameValue(delete sample[key], true, 'The value of `delete sample.string` is true'); + assert.sameValue(delete sample["undef"], true, 'The value of `delete sample.undef` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..ed0dddfd7b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-key-is-symbol.js @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Calls OrdinaryDelete when key is a Symbol. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + let s = Symbol("1"); + + sample[s] = 1; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-realm.js new file mode 100644 index 0000000000..05cc9e7246 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer-realm.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached + (honoring the Realm of the current execution context) +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer.js new file mode 100644 index 0000000000..d55e8b15ee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/detached-buffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.sameValue(delete sample[0], true, 'The value of `delete sample[0]` is true'); + assert.sameValue(delete sample["1.1"], true, 'The value of `delete sample["1.1"]` is true'); + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample["2"], true, 'The value of `delete sample["2"]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-non-strict.js new file mode 100644 index 0000000000..ac273ff0a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample[1]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-strict-strict.js new file mode 100644 index 0000000000..5ac3219bba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-ab-strict-strict.js @@ -0,0 +1,55 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return value from valid numeric index +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(2); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample["1"]; + }, '`delete sample["1"]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-non-strict.js new file mode 100644 index 0000000000..0f63640193 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-non-strict.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// Copyright (C) 2020 Rick Waldron. 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-delete-p +description: > + Return value from valid numeric index, with SharedArrayBuffer +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample["1"], false, 'The value of `delete sample["1"]` is false'); + assert.sameValue(delete sample[1], false, 'The value of `delete sample["1"]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-strict-strict.js new file mode 100644 index 0000000000..6677f96548 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/indexed-value-sab-strict-strict.js @@ -0,0 +1,44 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +'use strict'; +// Copyright (C) 2020 Rick Waldron. 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-delete-p +description: > + Throws TypeError exception in strict mode. +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray, SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["0"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + let sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + let sample = new TA(sab); + + assert.throws(TypeError, () => { + delete sample["0"]; + }); + assert.throws(TypeError, () => { + delete sample[0]; + }); + assert.throws(TypeError, () => { + delete sample["1"]; + }); + assert.throws(TypeError, () => { + delete sample[1]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/infinity-detached-buffer.js new file mode 100644 index 0000000000..735673dcc1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/infinity-detached-buffer.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-integerindexedelementget +description: > + "Infinity" is a canonical numeric string. Returns true when deleting any property if buffer is detached. +info: | + [[Delete]] ( P, Receiver ) + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + + CanonicalNumericIndexString ( argument ) + ... + Let n be ! ToNumber(argument). + If SameValue(! ToString(n), argument) is false, return undefined. + Return n. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(delete sample.Infinity, true, 'The value of `delete sample.Infinity` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-non-strict.js new file mode 100644 index 0000000000..9cd26b2c46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-non-strict.js @@ -0,0 +1,69 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.sameValue( + delete sample[key], false, + 'The value of `delete sample[key]` is false' + ); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-strict-strict.js new file mode 100644 index 0000000000..acd52c7cce --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-canonical-index-strict-strict.js @@ -0,0 +1,69 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is not a CanonicalNumericIndex. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" + ]; + + keys.forEach((key) => { + var sample = new TA(); // <- intentionally empty + + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + TypedArray.prototype[key] = key; + + assert.sameValue( + delete sample[key], + true, + 'The value of `delete sample[key]` is true' + ); + + sample[key] = key; + assert.sameValue( + delete sample[key], true, + 'The value of `delete sample[key]` is true' + ); + + Object.defineProperty(sample, key, { + get() { return key; } + }); + + assert.throws(TypeError, () => { + delete sample[key]; + }, '`delete sample[key]` throws TypeError'); + + delete TypedArray.prototype[key]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-integer.js new file mode 100644 index 0000000000..d8862bd99b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-integer.js @@ -0,0 +1,44 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + 5. If IsInteger(index) is false, return undefined. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "1.1", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["1.1"], true, 'The value of `delete sample["1.1"]` is true'); + assert.sameValue(delete sample[1.1], true, 'The value of `delete sample[1.1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-non-strict.js new file mode 100644 index 0000000000..8a60a14c4c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.sameValue(delete sample[-0], false, 'The value of `delete sample[-0]` is false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-strict-strict.js new file mode 100644 index 0000000000..33bae05317 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-minus-zero-strict-strict.js @@ -0,0 +1,49 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if key is a CanonicalNumericIndex and IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + + ... + + IntegerIndexedElementGet ( O, index ) + + ... + If ! IsValidIntegerIndex(O, index) is false, return undefined. + ... +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + Object.defineProperty(proto, "-0", { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }); + let sample = new TA(1); + + assert.sameValue(delete sample["-0"], true, 'The value of `delete sample["-0"]` is true'); + assert.throws(TypeError, () => { + delete sample[-0]; + }, '`delete sample[-0]` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..5035a5d733 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-get-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + + Object.defineProperty(sample, "foo", { + get() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, () => { + sample.foo; + }, '`sample.foo` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-non-strict.js new file mode 100644 index 0000000000..2b9d9a378e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-non-strict.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.sameValue(delete sample.bar, false, 'The value of `delete sample.bar` is false'); + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-strict-strict.js new file mode 100644 index 0000000000..af6397a576 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-not-numeric-index-strict-strict.js @@ -0,0 +1,50 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is not a CanonicalNumericIndex +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + TypedArray.prototype.baz = "baz"; + let sample = new TA(1); + + assert.sameValue( + delete sample.foo, true, + 'The value of `delete sample.foo` is true' + ); + + sample.foo = "foo"; + assert.sameValue(delete sample.foo, true, 'The value of `delete sample.foo` is true'); + + Object.defineProperty(sample, "bar", { + get() { return "bar"; } + }); + + assert.throws(TypeError, () => { + delete sample.bar; + }, '`delete sample.bar` throws TypeError'); + + assert.sameValue(delete sample.baz, true, 'The value of `delete sample.baz` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-non-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-non-strict.js new file mode 100644 index 0000000000..63130f39a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-non-strict.js @@ -0,0 +1,49 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [noStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + assert.sameValue(delete sample["0"], false, 'The value of `delete sample["0"]` is false'); + assert.sameValue(delete sample[0], false, 'The value of `delete sample[0]` is false'); + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-strict-strict.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-strict-strict.js new file mode 100644 index 0000000000..c668f681c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-out-of-bounds-strict-strict.js @@ -0,0 +1,57 @@ +'use strict'; +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Return true if IsValidIntegerIndex(O, numericIndex) is false. +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return true. + If ! IsValidIntegerIndex(O, numericIndex) is false, return true. + Return false. + ... + Return ? OrdinaryDelete(O, P). + +flags: [onlyStrict] +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let proto = TypedArray.prototype; + let descriptorGetterThrows = { + configurable: true, + get() { + throw new Test262Error("OrdinaryGet was called!"); + } + }; + Object.defineProperties(proto, { + ["-1"]: descriptorGetterThrows, + ["1"]: descriptorGetterThrows, + }); + + let sample = new TA(1); + assert.sameValue(delete sample["-1"], true, 'The value of `delete sample["-1"]` is true'); + assert.sameValue(delete sample[-1], true, 'The value of `delete sample[-1]` is true'); + + assert.throws(TypeError, () => { + delete sample["0"]; + }, '`delete sample["0"]` throws TypeError'); + + assert.throws(TypeError, () => { + delete sample[0]; + }, '`delete sample[0]` throws TypeError'); + + assert.sameValue(delete sample["1"], true, 'The value of `delete sample["1"]` is true'); + assert.sameValue(delete sample[1], true, 'The value of `delete sample[1]` is true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-symbol.js new file mode 100644 index 0000000000..6e25155282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/key-is-symbol.js @@ -0,0 +1,33 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-delete-p +description: > + Use OrdinaryDelete if key is a Symbol +info: | + [[Delete]] (P) + + ... + Assert: IsPropertyKey(P) is true. + Assert: O is an Integer-Indexed exotic object. + If Type(P) is String, then + ... + Return ? OrdinaryDelete(O, P). + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(1); + let s = Symbol("1"); + + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); + + sample[s] = ""; + assert.sameValue(delete sample[s], true, 'The value of `delete sample[s]` is true'); + assert.sameValue(Reflect.has(sample, s), false, 'Reflect.has(sample, s) must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/shell.js new file mode 100644 index 0000000000..f9aa35231b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Delete/shell.js @@ -0,0 +1,142 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..e8296d36f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-not-numeric-index.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-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([42n, 43n]); + sample.foo = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.undef, undefined); + assert.sameValue(sample.foo, "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..a0316ccb2f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-key-is-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-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([42n, 43n]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("1"); + + assert.sameValue(sample[s], undefined); + + sample[s] = "test262"; + assert.sameValue(sample[s], "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..f979db1546 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer-realm.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 undefined if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; + +testWithBigIntTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer.js new file mode 100644 index 0000000000..b7ee084085 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/detached-buffer.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 undefined if key has a numeric index and object has a detached buffer +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); + assert.sameValue(sample["1.1"], undefined, 'The value of sample["1.1"] is expected to equal `undefined`'); + assert.sameValue(sample["-0"], undefined, 'The value of sample["-0"] is expected to equal `undefined`'); + assert.sameValue(sample["-1"], undefined, 'The value of sample["-1"] is expected to equal `undefined`'); + assert.sameValue(sample["1"], undefined, 'The value of sample["1"] is expected to equal `undefined`'); + assert.sameValue(sample["2"], undefined, 'The value of sample["2"] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value-sab.js new file mode 100644 index 0000000000..c3eac9165f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value-sab.js @@ -0,0 +1,31 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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([42n, 1n]); + + assert.sameValue(sample["0"], 42n); + assert.sameValue(sample["1"], 1n); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value.js new file mode 100644 index 0000000000..4c54b6f3d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/indexed-value.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-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([42n, 1n]); + + assert.sameValue(sample["0"], 42n); + assert.sameValue(sample["1"], 1n); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/infinity-detached-buffer.js new file mode 100644 index 0000000000..b1c9e74b09 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.Infinity, undefined, 'The value of sample.Infinity is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..115b604b18 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-canonical-index.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-get-p-receiver +description: > + Use OrdinaryGet 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: [align-detached-buffer-semantics-with-web-reality, 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]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..251231fc65 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-integer.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: > + 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([42n, 43n]); + + assert.sameValue(sample["1.1"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-minus-zero.js new file mode 100644 index 0000000000..99d6d4f7af --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-minus-zero.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: > + 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([42n, 43n]); + + assert.sameValue(sample["-0"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..9073ee159a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index-get-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-get-p-receiver +description: > + Returns abrupt from OrdinaryGet 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: [align-detached-buffer-semantics-with-web-reality, 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; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..7d4e873e52 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-not-numeric-index.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-get-p-receiver +description: > + Use OrdinaryGet 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: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +TypedArray.prototype.baz = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-out-of-bounds.js new file mode 100644 index 0000000000..30ccf64286 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-out-of-bounds.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-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([42n, 43n]); + + assert.sameValue(sample["-1"], undefined); + assert.sameValue(sample["2"], undefined); + assert.sameValue(sample["3"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..0ef9bee129 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/key-is-symbol.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-get-p-receiver +description: > + Use OrdinaryGet 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: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol, TypedArray] +---*/ + +var parentKey = Symbol("2"); +TypedArray.prototype[parentKey] = "test262"; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..85a5dd2845 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-not-numeric-index.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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + sample.foo = "test262"; + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.undef, undefined); + assert.sameValue(sample.foo, "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..5d7d4fcb48 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-key-is-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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + $DETACHBUFFER(sample.buffer); + + var s = Symbol("1"); + + assert.sameValue(sample[s], undefined); + + sample[s] = "test262"; + assert.sameValue(sample[s], "test262"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-realm.js new file mode 100644 index 0000000000..5c54ccfa2f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer-realm.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 undefined if key has a numeric index and object has a detached + buffer (honoring the Realm of the current execution context) +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer.js new file mode 100644 index 0000000000..ca6783aa51 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/detached-buffer.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 undefined if key has a numeric index and object has a detached buffer +info: | + [[Get]] ( P, Receiver ) + + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ! IntegerIndexedElementGet(O, numericIndex). + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample[0], undefined, 'The value of sample[0] is expected to equal `undefined`'); + assert.sameValue(sample["1.1"], undefined, 'The value of sample["1.1"] is expected to equal `undefined`'); + assert.sameValue(sample["-0"], undefined, 'The value of sample["-0"] is expected to equal `undefined`'); + assert.sameValue(sample["-1"], undefined, 'The value of sample["-1"] is expected to equal `undefined`'); + assert.sameValue(sample["1"], undefined, 'The value of sample["1"] is expected to equal `undefined`'); + assert.sameValue(sample["2"], undefined, 'The value of sample["2"] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value-sab.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value-sab.js new file mode 100644 index 0000000000..508254c872 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value-sab.js @@ -0,0 +1,31 @@ +// |reftest| skip-if(!this.hasOwnProperty('SharedArrayBuffer')) -- SharedArrayBuffer is not enabled unconditionally +// 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: [testTypedArray.js] +features: [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); + +testWithTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + var sample = new TA(sab); + sample.set([42, 1]); + + assert.sameValue(sample["0"], 42); + assert.sameValue(sample["1"], 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value.js new file mode 100644 index 0000000000..f99235ad50 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/indexed-value.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-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: [testTypedArray.js] +features: [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); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 1]); + + assert.sameValue(sample["0"], 42); + assert.sameValue(sample["1"], 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/infinity-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/infinity-detached-buffer.js new file mode 100644 index 0000000000..64cf13940d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/infinity-detached-buffer.js @@ -0,0 +1,41 @@ +// 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). + ... + + CanonicalNumericIndexString ( argument ) + ... + 3. Let n be ! ToNumber(argument). + 4. If SameValue(! ToString(n), argument) is false, return undefined. + 5. Return n. + + IntegerIndexedElementGet ( O, index ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(0); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(sample.Infinity, undefined, 'The value of sample.Infinity is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-canonical-index.js new file mode 100644 index 0000000000..985516626b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-canonical-index.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-get-p-receiver +description: > + Use OrdinaryGet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(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]; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-integer.js new file mode 100644 index 0000000000..3059457150 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-integer.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: > + 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: [testTypedArray.js] +features: [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"); + } +}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(sample["1.1"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-minus-zero.js new file mode 100644 index 0000000000..2810260d97 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-minus-zero.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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var proto = TypedArray.prototype; +Object.defineProperty(proto, "-0", { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(sample["-0"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index-get-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index-get-throws.js new file mode 100644 index 0000000000..12ad42d27c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index-get-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-get-p-receiver +description: > + Returns abrupt from OrdinaryGet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + get: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262; + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index.js new file mode 100644 index 0000000000..928add152b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-not-numeric-index.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-get-p-receiver +description: > + Use OrdinaryGet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +TypedArray.prototype.baz = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-out-of-bounds.js new file mode 100644 index 0000000000..b8534bf612 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-out-of-bounds.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-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: [testTypedArray.js] +features: [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); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(sample["-1"], undefined); + assert.sameValue(sample["2"], undefined); + assert.sameValue(sample["3"], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-symbol.js new file mode 100644 index 0000000000..c0dcf29c51 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/key-is-symbol.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-get-p-receiver +description: > + Use OrdinaryGet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, TypedArray] +---*/ + +var parentKey = Symbol("2"); +TypedArray.prototype[parentKey] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/shell.js new file mode 100644 index 0000000000..f9aa35231b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Get/shell.js @@ -0,0 +1,142 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..fa599e0e98 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-not-number.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-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([42n, 43n]); + $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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..51c9edc2d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-key-is-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-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([42n, 43n]); + $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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..bb170e21ea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer-realm.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-getownproperty-p +description: > + Returned undefined 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). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, 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.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor("new OtherTA(1)", 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer.js new file mode 100644 index 0000000000..89c1fbecbd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/detached-buffer.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 undefined 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). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor(sample, 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js new file mode 100644 index 0000000000..caaf1aeeee --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/enumerate-detached-buffer.js @@ -0,0 +1,44 @@ +// 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). + ... + + IntegerIndexedElementGet ( O, index ) + ... + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... + + 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: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + let counter = 0; + for (var key in sample) { + counter++; + } + assert.sameValue(counter, 0, 'The value of `counter` is 0'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/index-prop-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/index-prop-desc.js new file mode 100644 index 0000000000..1b5eaf1399 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/index-prop-desc.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 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]]: true}. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + let descriptor0 = Object.getOwnPropertyDescriptor(sample, "0"); + let descriptor1 = Object.getOwnPropertyDescriptor(sample, "1"); + + assert.sameValue(descriptor0.value, 42n); + assert.sameValue(descriptor0.configurable, true); + assert.sameValue(descriptor0.enumerable, true); + assert.sameValue(descriptor0.writable, true); + + assert.sameValue(descriptor1.value, 43n); + assert.sameValue(descriptor1.configurable, true); + assert.sameValue(descriptor1.enumerable, true); + assert.sameValue(descriptor1.writable, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..473501b28e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-minus-zero.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: 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([42n]); + + // -0 as a number value is converted to "0" before calling [[GetOwnProperty]] + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-0"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..1c613c4538 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-canonical-index.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-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([42n, 43n]); + + 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 + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..bfccde6239 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-integer.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: 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([42n, 43n]); + + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1.1"), undefined); + assert.sameValue(Object.getOwnPropertyDescriptor(sample, "0.1"), undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..db2cef9856 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-not-numeric-index.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-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([42n, 43n]); + + 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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.js new file mode 100644 index 0000000000..de31a8d0bc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-out-of-bounds.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 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([42n]); + + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..d6570d764a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/key-is-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-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([42n, 43n]); + + var s = Symbol("foo"); + Object.defineProperty(sample, s, { value: "baz" }); + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, s).value, + "baz", + "return value from a Symbol key" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..59696d38ea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-not-number.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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..38d405b94b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-key-is-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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-realm.js new file mode 100644 index 0000000000..dfb0d554f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer-realm.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-getownproperty-p +description: > + Returned undefined 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). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor(sample, 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer.js new file mode 100644 index 0000000000..c1a7151ae0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/detached-buffer.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 undefined 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). + ii. If value is undefined, return undefined. + ... + + IntegerIndexedElementGet ( O, index ) + + ... + Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + If IsDetachedBuffer(buffer) is true, return undefined. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Object.getOwnPropertyDescriptor(sample, 0), + undefined, + 'Object.getOwnPropertyDescriptor(sample, 0) must return undefined' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js new file mode 100644 index 0000000000..8611cfb434 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/enumerate-detached-buffer.js @@ -0,0 +1,44 @@ +// 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). + ... + + IntegerIndexedElementGet ( O, index ) + ... + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return undefined. + ... + + 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: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(42); + $DETACHBUFFER(sample.buffer); + + let count = 0; + for (var key in sample) { + count++; + } + assert.sameValue(count, 0, 'The value of `count` is 0'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js new file mode 100644 index 0000000000..4238cd9e66 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/index-prop-desc.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2020 Apple Inc. 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]]: true}. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + let descriptor0 = Object.getOwnPropertyDescriptor(sample, "0"); + let descriptor1 = Object.getOwnPropertyDescriptor(sample, "1"); + + assert.sameValue(descriptor0.value, 42); + assert.sameValue(descriptor0.configurable, true); + assert.sameValue(descriptor0.enumerable, true); + assert.sameValue(descriptor0.writable, true); + + assert.sameValue(descriptor1.value, 43); + assert.sameValue(descriptor1.configurable, true); + assert.sameValue(descriptor1.enumerable, true); + assert.sameValue(descriptor1.writable, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-minus-zero.js new file mode 100644 index 0000000000..752f3f6204 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-minus-zero.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: 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-canonical-index.js new file mode 100644 index 0000000000..c9fa3e8b54 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-canonical-index.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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([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 + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-integer.js new file mode 100644 index 0000000000..297e1b14a3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-integer.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: 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-numeric-index.js new file mode 100644 index 0000000000..0f78950189 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-not-numeric-index.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-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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-out-of-bounds.js new file mode 100644 index 0000000000..c4cda461fb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-out-of-bounds.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 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-symbol.js new file mode 100644 index 0000000000..d686d07edb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/key-is-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-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: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/shell.js new file mode 100644 index 0000000000..f9aa35231b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/GetOwnProperty/shell.js @@ -0,0 +1,142 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.js new file mode 100644 index 0000000000..fcec3e4db7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/abrupt-from-ordinary-has-parent-hasproperty.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-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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... + + 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] +features: [align-detached-buffer-semantics-with-web-reality, 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, + 'Reflect.has(sample, 0) must return true' + ); + assert.sameValue( + Reflect.has(sample, 1), false, + 'Reflect.has(sample, 1) must return false' + ); + + assert.throws(Test262Error, function() { + Reflect.has(sample, "foo"); + }, '`Reflect.has(sample, "foo")` throws Test262Error'); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue( + Reflect.has(sample, "foo"), + true, + 'Reflect.has(sample, "foo") must return true' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..011a63acd1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-not-number.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-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([42n, 43n]); + Object.defineProperty(sample, "bar", { value: 42 }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "foo"), false); + assert.sameValue(Reflect.has(sample, "bar"), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..e24e8e58ea --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-key-is-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-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([42n, 43n]); + Object.defineProperty(sample, s1, { value: "baz" }); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, s1), true); + assert.sameValue(Reflect.has(sample, s2), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..298c79428b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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: > + Returns false 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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, 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.sameValue(Reflect.has(sample, '0'), false, 'Reflect.has(sample, "0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer.js new file mode 100644 index 0000000000..7e58bd2473 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/detached-buffer.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: Returns false 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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "0"), false, 'Reflect.has(sample, "0") must return false'); + assert.sameValue(Reflect.has(sample, "-0"), false, 'Reflect.has(sample, "-0") must return false'); + assert.sameValue(Reflect.has(sample, "1.1"), false, 'Reflect.has(sample, "1.1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/indexed-value.js new file mode 100644 index 0000000000..6773bd1487 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/indexed-value.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 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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + iv. Return true. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + assert.sameValue(Reflect.has(sample, 0), true, 'Reflect.has(sample, 0) must return true'); + assert.sameValue(Reflect.has(sample, 1), true, 'Reflect.has(sample, 1) must return true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/infinity-with-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/infinity-with-detached-buffer.js new file mode 100644 index 0000000000..80a9f396cf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/infinity-with-detached-buffer.js @@ -0,0 +1,48 @@ +// 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, return false. + ... + + 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: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let counter = 0; + + let n = { + valueOf() { + counter++; + return 9n; + } + }; + + assert.sameValue(counter, 0, 'The value of `counter` is 0'); + let ta = new TA([n]); + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + $DETACHBUFFER(ta.buffer); + + with (ta) { + Infinity; + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/inherited-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/inherited-property.js new file mode 100644 index 0000000000..d2ec511afd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/inherited-property.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-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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..3c51c7f6df --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-greater-than-last-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 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 + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, 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, 'Reflect.has(sample, "1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-lower-than-zero.js new file mode 100644 index 0000000000..e445238631 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-lower-than-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-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 + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, 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, 'Reflect.has(sample, "-1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..f8e938299b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-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-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 + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, 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, 'Reflect.has(sample, "-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..828aa9b570 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-canonical-index.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-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: 42n}); + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with own key [" + key + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..196ad49ef3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-integer.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 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..e29503e510 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-not-numeric-index.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: > + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..d86caa85b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/key-is-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-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js new file mode 100644 index 0000000000..3513862b71 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.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-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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... + + 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, Proxy, TypedArray] +---*/ + +var handler = { + has: function() { + throw new Test262Error(); + } +}; + +var proxy = new Proxy(TypedArray.prototype, handler); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.setPrototypeOf(sample, proxy); + + assert.sameValue( + Reflect.has(sample, 0), true, + 'Reflect.has(sample, 0) must return true' + ); + assert.sameValue( + Reflect.has(sample, 1), false, + 'Reflect.has(sample, 1) must return false' + ); + + assert.throws(Test262Error, function() { + Reflect.has(sample, "foo"); + }, '`Reflect.has(sample, "foo")` throws Test262Error'); + + Object.defineProperty(sample, "foo", { value: 42 }); + + assert.sameValue( + Reflect.has(sample, "foo"), + true, + 'Reflect.has(sample, "foo") must return true' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-not-number.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-not-number.js new file mode 100644 index 0000000000..3a8d2511e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-not-number.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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..80810d3d8c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-key-is-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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("foo"); +var s2 = Symbol("bar"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer-realm.js new file mode 100644 index 0000000000..d9be7d2e18 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/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-hasproperty-p +description: > + Returns false 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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, Reflect, TypedArray] +---*/ + +var other = $262.createRealm().global; + +testWithTypedArrayConstructors(function(TA) { + var OtherTA = other[TA.name]; + var sample = new OtherTA(1); + + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, '0'), false, 'Reflect.has(sample, "0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer.js new file mode 100644 index 0000000000..80f3d2aaf3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/detached-buffer.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 false 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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + + assert.sameValue(Reflect.has(sample, "0"), false, 'Reflect.has(sample, "0") must return false'); + assert.sameValue(Reflect.has(sample, "-0"), false, 'Reflect.has(sample, "-0") must return false'); + assert.sameValue(Reflect.has(sample, "1.1"), false, 'Reflect.has(sample, "1.1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/indexed-value.js new file mode 100644 index 0000000000..3cb63c33ba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/indexed-value.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 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 O.[[ViewedArrayBuffer]]. + ii. If IsDetachedBuffer(buffer) is true, return false. + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + iv. Return true. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42, 43]); + + assert.sameValue(Reflect.has(sample, 0), true, 'Reflect.has("new TA([42, 43])", 0) must return true'); + assert.sameValue(Reflect.has(sample, 1), true, 'Reflect.has("new TA([42, 43])", 1) must return true'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/infinity-with-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/infinity-with-detached-buffer.js new file mode 100644 index 0000000000..b71d009764 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/infinity-with-detached-buffer.js @@ -0,0 +1,52 @@ +// 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, return false. + ... + + 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: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let counter = 0; + let n = { + valueOf() { + counter++; + return 9; + } + }; + + assert.sameValue(counter, 0, 'The value of `counter` is 0'); + + let ta = new TA([n]); + + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + + $DETACHBUFFER(ta.buffer); + + with (ta) { + Infinity; + assert.sameValue(counter, 1, 'The value of `counter` is 1'); + } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/inherited-property.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/inherited-property.js new file mode 100644 index 0000000000..eb736978dc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/inherited-property.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +TypedArray.prototype.foo = 42; +TypedArray.prototype[42] = true; + +testWithTypedArrayConstructors(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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-greater-than-last-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-greater-than-last-index.js new file mode 100644 index 0000000000..1c930e4005 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-greater-than-last-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 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 + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[1] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "1"), false, 'Reflect.has(sample, "1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-lower-than-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-lower-than-zero.js new file mode 100644 index 0000000000..3cbe081f30 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-lower-than-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-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 + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype[-1] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-1"), false, 'Reflect.has(sample, "-1") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-minus-zero.js new file mode 100644 index 0000000000..870cc9a039 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-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-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 + ... + iii. If ! IsValidIntegerIndex(O, numericIndex) is false, return false. + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["-0"] = "test262"; + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + assert.sameValue(Reflect.has(sample, "-0"), false, 'Reflect.has(sample, "-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-canonical-index.js new file mode 100644 index 0000000000..4207b866e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-canonical-index.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-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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(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: 42}); + + assert.sameValue( + Reflect.has(sample, key), true, + "returns true with own key [" + key + "]" + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-integer.js new file mode 100644 index 0000000000..3b9b39bae2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-integer.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 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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + + +// Prevents false positives using OrdinaryHasProperty +TypedArray.prototype["1.1"] = "test262"; +TypedArray.prototype["0.000001"] = "test262"; + +testWithTypedArrayConstructors(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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-numeric-index.js new file mode 100644 index 0000000000..acb5905ae0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-not-numeric-index.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: > + 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: [testTypedArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-symbol.js new file mode 100644 index 0000000000..915af90334 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/key-is-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-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: [testTypedArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("foo"); + +testWithTypedArrayConstructors(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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js new file mode 100644 index 0000000000..223834ba20 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-auto.js @@ -0,0 +1,64 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: returned keys reflect resized ArrayBuffer for a dynamically-sized TypedArray +includes: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +function inspect(array) { + return [ + Reflect.has(array, 0), + Reflect.has(array, 1), + Reflect.has(array, 2), + Reflect.has(array, 3), + Reflect.has(array, 4) + ].join(","); +} + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = "true,true,true,false,false"; + + assert.sameValue(inspect(array), expected, "initial"); + + try { + ab.resize(BPE * 5); + expected = "true,true,true,true,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = "true,true,false,false,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following shrink (within bounds)"); + + try { + ab.resize(BPE); + expected = "false,false,false,false,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following shrink (on boundary)"); + + try { + ab.resize(0); + expected = "false,false,false,false,false"; + } catch (_) {} + + assert.sameValue(inspect(array), expected, "following shrink (out of bounds)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..6e63fbe2b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/resizable-array-buffer-fixed.js @@ -0,0 +1,57 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-hasproperty-p +description: returned keys reflect resized ArrayBuffer for a fixed-sized TypedArray +includes: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +function inspect(array) { + return [ + Reflect.has(array, 0), + Reflect.has(array, 1), + Reflect.has(array, 2), + Reflect.has(array, 3), + Reflect.has(array, 4) + ].join(","); +} + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(inspect(array), "true,true,false,false,false", "initial"); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(inspect(array), "true,true,false,false,false", "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue(inspect(array), "true,true,false,false,false", "following shrink (within bounds)"); + + var expected; + try { + ab.resize(BPE * 2); + expected = "false,false,false,false,false"; + } catch (_) { + expected = "true,true,false,false,false"; + } + + assert.sameValue(inspect(array), expected, "following shrink (out of bounds)"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/shell.js new file mode 100644 index 0000000000..f9aa35231b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/HasProperty/shell.js @@ -0,0 +1,142 @@ +// GENERATED, DO NOT EDIT +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.js new file mode 100644 index 0000000000..4aa72e5416 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-and-symbol-keys-.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-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([42n, 42n, 42n]); + 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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.js new file mode 100644 index 0000000000..5867283bf8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes-and-string-keys.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-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([42n, 42n, 42n]); + 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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes.js new file mode 100644 index 0000000000..596d2d59a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/integer-indexes.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-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([42n, 42n, 42n]); + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.js new file mode 100644 index 0000000000..06439e1441 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/not-enumerable-keys.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-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])); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.js new file mode 100644 index 0000000000..ebf707791b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-and-symbol-keys-.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-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: [testTypedArray.js, compareArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-keys.js new file mode 100644 index 0000000000..00532ce8b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-and-string-keys.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-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: [testTypedArray.js, compareArray.js] +features: [Reflect, TypedArray] +---*/ + +TypedArray.prototype[3] = 42; +TypedArray.prototype.bar = 42; + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js new file mode 100644 index 0000000000..a2ae71b171 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-auto.js @@ -0,0 +1,70 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: returned keys reflect resized ArrayBuffer for a dynamically-sized TypedArray +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let getBufferByteLength be ! + MakeIdempotentArrayBufferByteLengthGetter(SeqCst). + 4. Let len be IntegerIndexedObjectLength(O, getBufferByteLength). + 5. 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: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE); + var expected = "0,1,2"; + + assert.sameValue(Reflect.ownKeys(array).join(","), expected, "initial"); + + try { + ab.resize(BPE * 5); + expected = "0,1,2,3"; + } catch (_) {} + + assert.sameValue(Reflect.ownKeys(array).join(","), expected, "following grow"); + + try { + ab.resize(BPE * 3); + expected = "0,1"; + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (within bounds)" + ); + + try { + ab.resize(BPE); + expected = ""; + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (on boundary)" + ); + + try { + ab.resize(0); + expected = ""; + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (out of bounds)" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-fixed.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-fixed.js new file mode 100644 index 0000000000..0c0b90db6d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes-resizable-array-buffer-fixed.js @@ -0,0 +1,61 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-integer-indexed-exotic-objects-ownpropertykeys +description: returned keys reflect resized ArrayBuffer for a fixed-sized TypedArray +info: | + 9.4.5.6 [[OwnPropertyKeys]] () + + ... + 3. Let getBufferByteLength be ! + MakeIdempotentArrayBufferByteLengthGetter(SeqCst). + 4. Let len be IntegerIndexedObjectLength(O, getBufferByteLength). + 5. 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: [testTypedArray.js] +features: [Reflect, TypedArray, resizable-arraybuffer] +---*/ + +// If the host chooses to throw as allowed by the specification, the observed +// behavior will be identical to the case where `ArrayBuffer.prototype.resize` +// has not been implemented. The following assertion prevents this test from +// passing in runtimes which have not implemented the method. +assert.sameValue(typeof ArrayBuffer.prototype.resize, "function"); + +testWithTypedArrayConstructors(function(TA) { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + assert.sameValue(Reflect.ownKeys(array).join(","), "0,1", "initial"); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + assert.sameValue(Reflect.ownKeys(array).join(","), "0,1", "following grow"); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + assert.sameValue( + Reflect.ownKeys(array).join(","), "0,1", "following shrink (within bounds)" + ); + + var expected; + try { + ab.resize(BPE * 2); + expected = ""; + } catch (_) { + expected = "0,1"; + } + + assert.sameValue( + Reflect.ownKeys(array).join(","), expected, "following shrink (out of bounds)" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes.js new file mode 100644 index 0000000000..b731decd95 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/integer-indexes.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-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: [testTypedArray.js, compareArray.js] +features: [Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample1 = new TA([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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/not-enumerable-keys.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/not-enumerable-keys.js new file mode 100644 index 0000000000..9c78932877 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/not-enumerable-keys.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-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: [testTypedArray.js, compareArray.js] +features: [Reflect, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(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])); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/shell.js new file mode 100644 index 0000000000..e9580b3113 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/OwnPropertyKeys/shell.js @@ -0,0 +1,124 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js new file mode 100644 index 0000000000..fac2234818 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobigint64.js @@ -0,0 +1,102 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of BigInts +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + 16. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, "Unordered"). + 17. Return true. + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigInt64 + Conversion Operation: ToBigInt64 + + ToBigInt64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. If int64bit ≥ 2^63, return int64bit - 2^64; otherwise return int64bit. + +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +// 2n ** 64n + 2n +// 2n ** 63n + 2n +// -(2n ** 63n) - 2n +// -(2n ** 64n) - 2n +// 2n - 2n ** 63n +// 2n ** 63n - 2 +var vals = [ + 18446744073709551618n, + 9223372036854775810n, + 2n, + 0n, + -2n, + -9223372036854775810n, + -18446744073709551618n +]; + +var typedArray = new BigInt64Array(1); +typedArray[0] = vals[0]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[1]; +assert.sameValue(typedArray[0], -9223372036854775806n, 'The value of typedArray[0] is -9223372036854775806n'); +typedArray[0] = vals[2]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[3]; +assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); +typedArray[0] = vals[4]; +assert.sameValue(typedArray[0], -2n, 'The value of typedArray[0] is -2n'); +typedArray[0] = vals[5]; +assert.sameValue(typedArray[0], 9223372036854775806n, 'The value of typedArray[0] is 9223372036854775806n'); +typedArray[0] = vals[6]; +assert.sameValue(typedArray[0], -2n, 'The value of typedArray[0] is -2n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js new file mode 100644 index 0000000000..d1b8b9067e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/bigint-tobiguint64.js @@ -0,0 +1,104 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of BigInts +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + 16. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, "Unordered"). + 17. Return true. + + SetValueInBuffer ( arrayBuffer, byteIndex, type, value, isTypedArray, order [ , isLittleEndian ] ) + ... + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + ... + + NumberToRawBytes( type, value, isLittleEndian ) + ... + 3. Else, + a. Let n be the Number value of the Element Size specified in Table + [The TypedArray Constructors] for Element Type type. + b. Let convOp be the abstract operation named in the Conversion Operation + column in Table 9 for Element Type type. + + The TypedArray Constructors + Element Type: BigUint64 + Conversion Operation: ToBigUint64 + + ToBigUint64 ( argument ) + The abstract operation ToBigInt64 converts argument to one of 264 integer + values in the range -2^63 through 2^63-1, inclusive. + This abstract operation functions as follows: + 1. Let n be ? ToBigInt(argument). + 2. Let int64bit be n modulo 2^64. + 3. Return int64bit. + +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +// 2n ** 64n + 2n +// 2n ** 63n + 2n +// -(2n ** 63n) - 2n +// -(2n ** 64n) - 2n +// 2n ** 63n + 2n +// 2n ** 64n - 2n +// 2n ** 63n - 2n +// 2n ** 64n - 2n +var vals = [ + 18446744073709551618n, + 9223372036854775810n, + 2n, + 0n, + -2n, + -9223372036854775810n, + -18446744073709551618n +]; + +var typedArray = new BigUint64Array(1); +typedArray[0] = vals[0]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[1]; +assert.sameValue(typedArray[0], 9223372036854775810n, 'The value of typedArray[0] is 9223372036854775810n'); +typedArray[0] = vals[2]; +assert.sameValue(typedArray[0], 2n, 'The value of typedArray[0] is 2n'); +typedArray[0] = vals[3]; +assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); +typedArray[0] = vals[4]; +assert.sameValue(typedArray[0], 18446744073709551614n, 'The value of typedArray[0] is 18446744073709551614n'); +typedArray[0] = vals[5]; +assert.sameValue(typedArray[0], 9223372036854775806n, 'The value of typedArray[0] is 9223372036854775806n'); +typedArray[0] = vals[6]; +assert.sameValue(typedArray[0], 18446744073709551614n, 'The value of typedArray[0] is 18446744073709551614n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js new file mode 100644 index 0000000000..e41c023d36 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/boolean-tobigint.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for assigning Booleans to BigInt TypedArray +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Boolean + Result: Return 1n if prim is true and 0n if prim is false. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(2); + typedArray[0] = false; + typedArray[1] = true; + assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); + assert.sameValue(typedArray[1], 1n, 'The value of typedArray[1] is 1n'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..27d868a915 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-not-numeric-index.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-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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, 'foo', 'test262'), + true, + 'Reflect.set(sample, "foo", "test262") must return true' + ); + + assert.sameValue(sample.foo, 'test262', 'The value of sample.foo is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..5a34f8f6d9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-key-is-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-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: [align-detached-buffer-semantics-with-web-reality, BigInt, Symbol, Reflect, TypedArray] +---*/ +var s = Symbol('1'); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, s, 'test262'), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "test262") must return true' + ); + + assert.sameValue(sample[s], 'test262', 'The value of sample[s] is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.js new file mode 100644 index 0000000000..ed67be5eaa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer-realm.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-set-p-v-receiver +description: > + Returns false 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; +testWithBigIntTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + $DETACHBUFFER(sample.buffer); + sample[0] = 1n; + assert.sameValue(sample[0], undefined, '`sample[0]` is undefined'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.js new file mode 100644 index 0000000000..d4b7ea8ba3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/detached-buffer.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns false when setting the value of any CanonicalNumericIndexString if buffer is detached. +info: | + [[Set]] ( P, V, Receiver) + + ... + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA([42n]); + $DETACHBUFFER(sample.buffer); + sample[0] = 1n; + assert.sameValue(sample[0], undefined, '`sample[0] = 1n` is undefined'); + sample['1.1'] = 1n; + assert.sameValue(sample['1.1'], undefined, '`sample["1.1"] = 1n` is undefined'); + sample['-0'] = 1n; + assert.sameValue(sample['-0'], undefined, '`sample["-0"] = 1n` is undefined'); + sample['-1'] = 1n; + assert.sameValue(sample['-1'], undefined, '`sample["-1"] = 1n` is undefined'); + sample['1'] = 1n; + assert.sameValue(sample['1'], undefined, '`sample["1"] = 1n` is undefined'); + sample['2'] = 1n; + assert.sameValue(sample['2'], undefined, '`sample["2"] = 1n` is undefined'); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample["0"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.js new file mode 100644 index 0000000000..60d0b4b736 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/indexed-value.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 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +let proto = TypedArray.prototype; +let throwDesc = { + set: function() { + throw new Test262Error('OrdinarySet was called!'); + } +}; + +Object.defineProperty(proto, '0', throwDesc); +Object.defineProperty(proto, '1', throwDesc); + +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA(2); + assert.sameValue(Reflect.set(sample, '0', 1n), true, 'Reflect.set(sample, "0", 1n) must return true'); + assert.sameValue(sample[0], 1n, 'The value of sample[0] is 1n'); + assert.sameValue(Reflect.set(sample, '1', 42n), true, 'Reflect.set(sample, "1", 42n) must return true'); + assert.sameValue(sample[1], 42n, 'The value of sample[1] is 42n'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.js new file mode 100644 index 0000000000..a8027b8002 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-minus-zero.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: > + Returns true, even if index is -0 +info: | + [[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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '-0', 1n), true, 'Reflect.set("new TA([42n])", "-0", 1n) must return true'); + assert.sameValue(sample.hasOwnProperty('-0'), false, 'sample.hasOwnProperty("-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.js new file mode 100644 index 0000000000..380c18c935 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-canonical-index.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +var keys = ['1.0', '+1', '1000000000000000000000', '0.0000001']; + +testWithBigIntTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, key, 'ecma262'), + true, + 'Reflect.set("new TA([42n])", key, "ecma262") must return true' + ); + + assert.sameValue(sample[key], 'ecma262', 'The value of sample[key] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, key, 'es3000'), + true, + 'Reflect.set("new TA([42n])", key, "es3000") must return true' + ); + + assert.sameValue(sample[key], 'es3000', 'The value of sample[key] is "es3000"'); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + + assert.sameValue(Reflect.set(sample, key, 42), false, 'Reflect.set("new TA([42n])", key, 42) must return false'); + assert.sameValue(sample[key], undefined, 'The value of sample[key] is expected to equal `undefined`'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.js new file mode 100644 index 0000000000..cb8fa7a526 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-integer.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-set-p-v-receiver +description: > + Returns true, even if index is not CanonicalNumericIndexString +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '1.1', 1n), true, 'Reflect.set("new TA([42n])", "1.1", 1n) must return true'); + + assert.sameValue( + Reflect.set(sample, '0.0001', 1n), + true, + 'Reflect.set("new TA([42n])", "0.0001", 1n) must return true' + ); + + assert.sameValue(sample.hasOwnProperty('1.1'), false, 'sample.hasOwnProperty("1.1") must return false'); + assert.sameValue(sample.hasOwnProperty('0.0001'), false, 'sample.hasOwnProperty("0.0001") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-throws.js new file mode 100644 index 0000000000..5b8dd12f01 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index-set-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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, 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; + }, '`sample.test262 = 1` throws Test262Error'); + + assert.sameValue(sample.test262, undefined, 'The value of sample.test262 is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-not-numeric-index.js new file mode 100644 index 0000000000..04f4deab89 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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 OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, 'test262', 'ecma262'), + true, + 'Reflect.set("new TA([42n])", "test262", "ecma262") must return true' + ); + + assert.sameValue(sample.test262, 'ecma262', 'The value of sample.test262 is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, 'test262', 'es3000'), + true, + 'Reflect.set("new TA([42n])", "test262", "es3000") must return true' + ); + + assert.sameValue(sample.test262, 'es3000', 'The value of sample.test262 is "es3000"'); + + Object.defineProperty(sample, 'foo', { + writable: false, + value: undefined + }); + + assert.sameValue(Reflect.set(sample, 'foo', 42), false, 'Reflect.set("new TA([42n])", "foo", 42) must return false'); + assert.sameValue(sample.foo, undefined, 'The value of sample.foo is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-out-of-bounds.js new file mode 100644 index 0000000000..5fe02832bd --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/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 true, even 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + 9.4.5.11 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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + assert.sameValue(Reflect.set(sample, '-1', 1n), true, 'Reflect.set("new TA([42n])", "-1", 1n) must return false'); + assert.sameValue(Reflect.set(sample, '1', 1n), true, 'Reflect.set("new TA([42n])", "1", 1n) must return false'); + assert.sameValue(Reflect.set(sample, '2', 1n), true, 'Reflect.set("new TA([42n])", "2", 1n) must return false'); + assert.sameValue(sample.hasOwnProperty('-1'), false, 'sample.hasOwnProperty("-1") must return false'); + assert.sameValue(sample.hasOwnProperty('1'), false, 'sample.hasOwnProperty("1") must return false'); + assert.sameValue(sample.hasOwnProperty('2'), false, 'sample.hasOwnProperty("2") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.js new file mode 100644 index 0000000000..0fc2d9ec46 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-symbol.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-set-p-v-receiver +description: > + Use OrdinarySet 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: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, Symbol, TypedArray] +---*/ +var s1 = Symbol('1'); +var s2 = Symbol('2'); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n]); + + assert.sameValue( + Reflect.set(sample, s1, 'ecma262'), + true, + 'Reflect.set("new TA([42n])", "Symbol(\\"1\\")", "ecma262") must return true' + ); + + assert.sameValue(sample[s1], 'ecma262', 'The value of sample[s1] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, s1, 'es3000'), + true, + 'Reflect.set("new TA([42n])", "Symbol(\\"1\\")", "es3000") must return true' + ); + + assert.sameValue(sample[s1], 'es3000', 'The value of sample[s1] is "es3000"'); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + 'Reflect.set("new TA([42n])", "Symbol(\\"2\\")", 42) must return false' + ); + + assert.sameValue(sample[s2], undefined, 'The value of sample[s2] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js new file mode 100644 index 0000000000..104c5a8509 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/null-tobigint.js @@ -0,0 +1,63 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on null +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Null + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = null; + }, '`typedArray[0] = null` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js new file mode 100644 index 0000000000..b7724a0aed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/number-tobigint.js @@ -0,0 +1,87 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on Number +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Number + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = 1; + }, '`typedArray[0] = 1` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = Math.pow(2, 63); + }, '`typedArray[0] = Math.pow(2, 63)` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = +0; + }, '`typedArray[0] = +0` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = -0; + }, '`typedArray[0] = -0` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = Infinity; + }, '`typedArray[0] = Infinity` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = -Infinity; + }, '`typedArray[0] = -Infinity` throws TypeError'); + + assert.throws(TypeError, function() { + typedArray[0] = NaN; + }, '`typedArray[0] = NaN` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js new file mode 100644 index 0000000000..f0646cc025 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-nan-tobigint.js @@ -0,0 +1,67 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt String, when StringToBigInt returns NaN +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + ... + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(SyntaxError, function() { + typedArray[0] = "definately not a number"; + }, '`typedArray[0] = "definately not a number"` throws SyntaxError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js new file mode 100644 index 0000000000..ff5aa4145a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/string-tobigint.js @@ -0,0 +1,87 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Behavior for input array of Strings, successful conversion +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: String + Result: + 1. Let n be StringToBigInt(prim). + 2. If n is NaN, throw a SyntaxError exception. + 3. Return n. + + StringToBigInt (argument) + Apply the algorithm in 3.1.3.1 with the following changes: + * Replace the StrUnsignedDecimalLiteral production with DecimalDigits to + not allow Infinity, decimal points, or exponents. + * If the MV is NaN, return NaN, otherwise return the BigInt which exactly + corresponds to the MV, rather than rounding to a Number. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + typedArray[0] = ''; + assert.sameValue(typedArray[0], 0n, 'The value of typedArray[0] is 0n'); + typedArray[0] = '1'; + assert.sameValue(typedArray[0], 1n, 'The value of typedArray[0] is 1n'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1n'; + }, '`typedArray[0] = "1n"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = 'Infinity'; + }, '`typedArray[0] = "Infinity"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1.1'; + }, '`typedArray[0] = "1.1"` throws SyntaxError'); + + assert.throws(SyntaxError, function() { + typedArray[0] = '1e7'; + }, '`typedArray[0] = "1e7"` throws SyntaxError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js new file mode 100644 index 0000000000..6b5618b568 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/symbol-tobigint.js @@ -0,0 +1,65 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on Symbol +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Symbol + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray, Symbol] +---*/ + +var s = Symbol() + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1) + + assert.throws(TypeError, function() { + typedArray[0] = s; + }, '`typedArray[0] = s` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..974de14c4a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-detached-buffer.js @@ -0,0 +1,40 @@ +// 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, + will always return true. +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, Reflect, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + let ta = new TA(1); + let isDetached = false; + let result = Reflect.set(ta, 0, { + valueOf() { + $DETACHBUFFER(ta.buffer); + isDetached = true; + return 42n; + } + }); + + assert.sameValue(result, true); + assert.sameValue(ta[0], undefined); + assert.sameValue(isDetached, true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-throws.js new file mode 100644 index 0000000000..665d19b195 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/tonumber-value-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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + ... +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithBigIntTypedArrayConstructors(function(TA) { + let sample = new TA([42n]); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample["0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['1.1'] = obj; + }, '`sample["1.1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['-0'] = obj; + }, '`sample["-0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['-1'] = obj; + }, '`sample["-1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['1'] = obj; + }, '`sample["1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample['2'] = obj; + }, '`sample["2"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js new file mode 100644 index 0000000000..a2152d98f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/BigInt/undefined-tobigint.js @@ -0,0 +1,64 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on undefined +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + ... + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + ... + + ToBigInt ( argument ) + Object, Apply the following steps: + 1. Let prim be ? ToPrimitive(argument, hint Number). + 2. Return the value that prim corresponds to in Table [BigInt Conversions] + + BigInt Conversions + Argument Type: Undefined + Result: Throw a TypeError exception. + +includes: [testBigIntTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = undefined; + }, '`typedArray[0] = undefined` throws TypeError'); + +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js new file mode 100644 index 0000000000..d2355a13c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/bigint-tonumber.js @@ -0,0 +1,61 @@ +// Copyright (C) 2018 Valerie Young. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-assignment-operators-runtime-semantics-evaluation +description: > + Return abrupt on BigInt +info: | + Runtime Semantics: Evaluation + AssignmentExpression : LeftHandSideExpression = AssignmentExpression + 1. If LeftHandSideExpression is neither an ObjectLiteral nor an ArrayLiteral, then + ... + f. Perform ? PutValue(lref, rval). + ... + + PutValue ( V, W ) + ... + 6. Else if IsPropertyReference(V) is true, then + a. If HasPrimitiveBase(V) is true, then + i. Assert: In this case, base will never be undefined or null. + ii. Set base to ! ToObject(base). + b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W, GetThisValue(V)). + c. If succeeded is false and IsStrictReference(V) is true, throw a TypeError + exception. + d. Return. + + [[Set]] ( P, V, Receiver ) + When the [[Set]] internal method of an Integer-Indexed exotic object O is + called with property key P, value V, and ECMAScript language value Receiver, + the following steps are taken: + 1. Assert: IsPropertyKey(P) is true. + 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). + + IntegerIndexedElementSet ( O, index, value ) + 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", + let numValue be ? ToBigInt(value). + 6. Otherwise, let numValue be ? ToNumber(value). + ... + + ToNumber ( argument ) + The abstract operation ToNumber converts argument to a value of type Number + according to: + + Number Conversion + Argument Type: BigInt + Result: Throw a TypeError Exception + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray] +---*/ +testWithTypedArrayConstructors(function(TA) { + var typedArray = new TA(1); + + assert.throws(TypeError, function() { + typedArray[0] = 1n; + }, '`typedArray[0] = 1n` throws TypeError'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js new file mode 100644 index 0000000000..d51afcab7a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation-consistent-nan.js @@ -0,0 +1,107 @@ +// Copyright (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: Consistent canonicalization of NaN values +info: | + This test does not compare the actual byte values, instead it simply checks that + the value is some valid NaN encoding. + + --- + + [[Set]] ( P, V, Receiver) + + ... + 2. If Type(P) is String, then + ... + b. If numericIndex is not undefined, then + i. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + #sec-setvalueinbuffer + SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) + + 8. Let rawBytes be NumberToRawBytes(type, value, isLittleEndian). + + #sec-numbertorawbytes + + NumberToRawBytes( type, value, isLittleEndian ) + + 1. 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 either the same encoding + for each implementation distinguishable *NaN* value, or an + implementation-defined canonical value. + 2. 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 + binary64 format Not-a-Number encoding. An implementation must + always choose either the same encoding for each implementation + distinguishable *NaN* value, or an implementation-defined + canonical value. + ... + + #sec-isnan-number + + NOTE: A reliable way for ECMAScript code to test if a value X is a NaN is + an expression of the form X !== X. The result will be true if and only + if X is a NaN. +includes: [nans.js, testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(FA) { + var precision = FA === Float32Array ? "single" : "double"; + var samples = new FA(1); + var controls, idx, aNaN; + + for (idx = 0; idx < NaNs.length; ++idx) { + aNaN = NaNs[idx]; + controls = new FA([aNaN, aNaN, aNaN]); + + samples[0] = aNaN; + + for (var i = 0; i < samples.length; i++) { + var sample = samples[i]; + var control = controls[i]; + + assert( + samples[i] !== samples[i], + 'The result of `(samples[i] !== samples[i])` is true' + ); + + assert( + controls[i] !== controls[i], + 'The result of `(controls[i] !== controls[i])` is true' + ); + } + } +}, [Float32Array, Float64Array]); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.js new file mode 100644 index 0000000000..786b0c4bec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/conversion-operation.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 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] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + var sample = new TA([initial]); + + sample[0] = value; + + assert.sameValue(sample[0], expected, 'The value of sample[0] is expected to equal the value of expected'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.js new file mode 100644 index 0000000000..81a22ef437 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-not-numeric-index.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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, "foo", "test262"), + true, + 'Reflect.set(sample, "foo", "test262") must return true' + ); + assert.sameValue(sample.foo, "test262", 'The value of sample.foo is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-symbol.js new file mode 100644 index 0000000000..183070c85b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-key-is-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-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: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Symbol, Reflect, TypedArray] +---*/ + +let s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(2); + $DETACHBUFFER(sample.buffer); + + assert.sameValue( + Reflect.set(sample, s, "test262"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "test262") must return true' + ); + assert.sameValue(sample[s], "test262", 'The value of sample[s] is "test262"'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.js new file mode 100644 index 0000000000..5e6269b2e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer-realm.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, cross-realm, TypedArray] +---*/ + +let other = $262.createRealm().global; +testWithTypedArrayConstructors(function(TA) { + let OtherTA = other[TA.name]; + let sample = new OtherTA(1); + $DETACHBUFFER(sample.buffer); + sample[0] = 1; + assert.sameValue(sample[0], undefined, '`sample[0]` is undefined'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.js new file mode 100644 index 0000000000..705b22dca5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/detached-buffer.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-set-p-v-receiver +description: > + Returns false if key has a numeric index and object has a detached buffer +info: | + [[Set]] ( P, V, Receiver) + + ... + If Type(P) is String, then + Let numericIndex be ! CanonicalNumericIndexString(P). + If numericIndex is not undefined, then + Return ? IntegerIndexedElementSet(O, numericIndex, V). + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is true, return false. + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ +testWithTypedArrayConstructors(function(TA) { + let sample = new TA([42]); + $DETACHBUFFER(sample.buffer); + sample[0] = 1; + + assert.sameValue(sample[0], undefined, '`sample[0] = 1` is undefined'); + sample['1.1'] = 1; + assert.sameValue(sample['1.1'], undefined, '`sample[\'1.1\'] = 1` is undefined'); + sample['-0'] = 1; + assert.sameValue(sample['-0'], undefined, '`sample[\'-0\'] = 1` is undefined'); + sample['-1'] = 1; + assert.sameValue(sample['-1'], undefined, '`sample[\'-1\'] = 1` is undefined'); + sample['1'] = 1; + assert.sameValue(sample['1'], undefined, '`sample[\'1\'] = 1` is undefined'); + sample['2'] = 1; + assert.sameValue(sample['2'], undefined, '`sample[\'2\'] = 1` is undefined'); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample['0'] = obj; + }, '`sample[\'0\'] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.js new file mode 100644 index 0000000000..66cf4571ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/indexed-value.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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +let proto = TypedArray.prototype; +let throwDesc = { + set: function() { + throw new Test262Error('OrdinarySet was called!'); + } +}; + +Object.defineProperty(proto, '0', throwDesc); +Object.defineProperty(proto, '1', throwDesc); + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA(2); + assert.sameValue(Reflect.set(sample, '0', 1), true, 'Reflect.set(sample, "0", 1) must return true'); + assert.sameValue(sample[0], 1, 'The value of sample[0] is 1'); + assert.sameValue(Reflect.set(sample, '1', 42), true, 'Reflect.set(sample, "1", 42) must return true'); + assert.sameValue(sample[1], 42, 'The value of sample[1] is 42'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.js new file mode 100644 index 0000000000..c171aa1a3c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-minus-zero.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-set-p-v-receiver +description: > + Returns true, even 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "-0", 1), true, 'Reflect.set(sample, "-0", 1) must return true'); + assert.sameValue(sample.hasOwnProperty("-0"), false, 'sample.hasOwnProperty("-0") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.js new file mode 100644 index 0000000000..72d1f7769a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-canonical-index.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +var keys = [ + "1.0", + "+1", + "1000000000000000000000", + "0.0000001" +]; + +testWithTypedArrayConstructors(function(TA) { + keys.forEach(function(key) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, key, "ecma262"), + true, + 'Reflect.set(sample, key, "ecma262") must return true' + ); + assert.sameValue(sample[key], "ecma262", 'The value of sample[key] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, key, "es3000"), + true, + 'Reflect.set(sample, key, "es3000") must return true' + ); + assert.sameValue(sample[key], "es3000", 'The value of sample[key] is "es3000"'); + + Object.defineProperty(sample, key, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, key, 42), + false, + 'Reflect.set(sample, key, 42) must return false' + ); + assert.sameValue( + sample[key], undefined, 'The value of sample[key] is expected to equal `undefined`' + ); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.js new file mode 100644 index 0000000000..a13b9cfe79 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-integer.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-set-p-v-receiver +description: > + Returns true, even if index is not CanonicalNumericIndexString +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "1.1", 1), true, 'Reflect.set(sample, "1.1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "0.0001", 1), true, 'Reflect.set(sample, "0.0001", 1) must return true'); + + assert.sameValue(sample.hasOwnProperty("1.1"), false, 'sample.hasOwnProperty("1.1") must return false'); + assert.sameValue( + sample.hasOwnProperty("0.0001"), + false, + 'sample.hasOwnProperty("0.0001") must return false' + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-throws.js new file mode 100644 index 0000000000..13360bfa55 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index-set-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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Returns abrupt from OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + + Object.defineProperty(sample, "test262", { + set: function() { + throw new Test262Error(); + } + }); + + assert.throws(Test262Error, function() { + sample.test262 = 1; + }, '`sample.test262 = 1` throws Test262Error'); + + assert.sameValue(sample.test262, undefined, 'The value of sample.test262 is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.js new file mode 100644 index 0000000000..9db75bd292 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-not-numeric-index.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-integer-indexed-exotic-objects-set-p-v-receiver +description: > + Use OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, "test262", "ecma262"), + true, + 'Reflect.set(sample, "test262", "ecma262") must return true' + ); + assert.sameValue(sample.test262, "ecma262", 'The value of sample.test262 is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, "test262", "es3000"), + true, + 'Reflect.set(sample, "test262", "es3000") must return true' + ); + assert.sameValue(sample.test262, "es3000", 'The value of sample.test262 is "es3000"'); + + Object.defineProperty(sample, "foo", { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, "foo", 42), + false, + 'Reflect.set(sample, "foo", 42) must return false' + ); + assert.sameValue(sample.foo, undefined, 'The value of sample.foo is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-out-of-bounds.js new file mode 100644 index 0000000000..5470398b71 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/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-set-p-v-receiver +description: > + Returns true even 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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue(Reflect.set(sample, "-1", 1), true, 'Reflect.set(sample, "-1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "1", 1), true, 'Reflect.set(sample, "1", 1) must return true'); + assert.sameValue(Reflect.set(sample, "2", 1), true, 'Reflect.set(sample, "2", 1) must return true'); + + assert.sameValue(sample.hasOwnProperty("-1"), false, 'sample.hasOwnProperty("-1") must return false'); + assert.sameValue(sample.hasOwnProperty("1"), false, 'sample.hasOwnProperty("1") must return false'); + assert.sameValue(sample.hasOwnProperty("2"), false, 'sample.hasOwnProperty("2") must return false'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.js new file mode 100644 index 0000000000..fe624e4725 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/key-is-symbol.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: > + Use OrdinarySet 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: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, Symbol, TypedArray] +---*/ + +var s1 = Symbol("1"); +var s2 = Symbol("2"); + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA([42]); + + assert.sameValue( + Reflect.set(sample, s1, "ecma262"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "ecma262") must return true' + ); + assert.sameValue(sample[s1], "ecma262", 'The value of sample[s1] is "ecma262"'); + + assert.sameValue( + Reflect.set(sample, s1, "es3000"), + true, + 'Reflect.set(sample, "Symbol(\\"1\\")", "es3000") must return true' + ); + assert.sameValue(sample[s1], "es3000", 'The value of sample[s1] is "es3000"'); + + Object.defineProperty(sample, s2, { + writable: false, + value: undefined + }); + assert.sameValue( + Reflect.set(sample, s2, 42), + false, + 'Reflect.set(sample, "Symbol(\\"2\\")", 42) must return false' + ); + assert.sameValue(sample[s2], undefined, 'The value of sample[s2] is expected to equal `undefined`'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js new file mode 100644 index 0000000000..abdb960ca1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/shell.js @@ -0,0 +1,614 @@ +// GENERATED, DO NOT EDIT +// file: byteConversionValues.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Provide a list for original and expected values for different byte + conversions. + This helper is mostly used on tests for TypedArray and DataView, and each + array from the expected values must match the original values array on every + index containing its original value. +defines: [byteConversionValues] +---*/ +var byteConversionValues = { + values: [ + 127, // 2 ** 7 - 1 + 128, // 2 ** 7 + 32767, // 2 ** 15 - 1 + 32768, // 2 ** 15 + 2147483647, // 2 ** 31 - 1 + 2147483648, // 2 ** 31 + 255, // 2 ** 8 - 1 + 256, // 2 ** 8 + 65535, // 2 ** 16 - 1 + 65536, // 2 ** 16 + 4294967295, // 2 ** 32 - 1 + 4294967296, // 2 ** 32 + 9007199254740991, // 2 ** 53 - 1 + 9007199254740992, // 2 ** 53 + 1.1, + 0.1, + 0.5, + 0.50000001, + 0.6, + 0.7, + undefined, + -1, + -0, + -0.1, + -1.1, + NaN, + -127, // - ( 2 ** 7 - 1 ) + -128, // - ( 2 ** 7 ) + -32767, // - ( 2 ** 15 - 1 ) + -32768, // - ( 2 ** 15 ) + -2147483647, // - ( 2 ** 31 - 1 ) + -2147483648, // - ( 2 ** 31 ) + -255, // - ( 2 ** 8 - 1 ) + -256, // - ( 2 ** 8 ) + -65535, // - ( 2 ** 16 - 1 ) + -65536, // - ( 2 ** 16 ) + -4294967295, // - ( 2 ** 32 - 1 ) + -4294967296, // - ( 2 ** 32 ) + Infinity, + -Infinity, + 0 + ], + + expected: { + Int8: [ + 127, // 127 + -128, // 128 + -1, // 32767 + 0, // 32768 + -1, // 2147483647 + 0, // 2147483648 + -1, // 255 + 0, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 0, // 32768 + 255, // 2147483647 + 0, // 2147483648 + 255, // 255 + 0, // 256 + 255, // 65535 + 0, // 65536 + 255, // 4294967295 + 0, // 4294967296 + 255, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 255, // -1 + 0, // -0 + 0, // -0.1 + 255, // -1.1 + 0, // NaN + 129, // -127 + 128, // -128 + 1, // -32767 + 0, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 1, // -255 + 0, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint8Clamped: [ + 127, // 127 + 128, // 128 + 255, // 32767 + 255, // 32768 + 255, // 2147483647 + 255, // 2147483648 + 255, // 255 + 255, // 256 + 255, // 65535 + 255, // 65536 + 255, // 4294967295 + 255, // 4294967296 + 255, // 9007199254740991 + 255, // 9007199254740992 + 1, // 1.1, + 0, // 0.1 + 0, // 0.5 + 1, // 0.50000001, + 1, // 0.6 + 1, // 0.7 + 0, // undefined + 0, // -1 + 0, // -0 + 0, // -0.1 + 0, // -1.1 + 0, // NaN + 0, // -127 + 0, // -128 + 0, // -32767 + 0, // -32768 + 0, // -2147483647 + 0, // -2147483648 + 0, // -255 + 0, // -256 + 0, // -65535 + 0, // -65536 + 0, // -4294967295 + 0, // -4294967296 + 255, // Infinity + 0, // -Infinity + 0 + ], + Int16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + -32768, // 32768 + -1, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + -1, // 65535 + 0, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + -255, // -255 + -256, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint16: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 65535, // 2147483647 + 0, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 0, // 65536 + 65535, // 4294967295 + 0, // 4294967296 + 65535, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 65535, // -1 + 0, // -0 + 0, // -0.1 + 65535, // -1.1 + 0, // NaN + 65409, // -127 + 65408, // -128 + 32769, // -32767 + 32768, // -32768 + 1, // -2147483647 + 0, // -2147483648 + 65281, // -255 + 65280, // -256 + 1, // -65535 + 0, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Int32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + -2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + -1, // 4294967295 + 0, // 4294967296 + -1, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + -1, // -1 + 0, // -0 + 0, // -0.1 + -1, // -1.1 + 0, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Uint32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 0, // 4294967296 + 4294967295, // 9007199254740991 + 0, // 9007199254740992 + 1, // 1.1 + 0, // 0.1 + 0, // 0.5 + 0, // 0.50000001, + 0, // 0.6 + 0, // 0.7 + 0, // undefined + 4294967295, // -1 + 0, // -0 + 0, // -0.1 + 4294967295, // -1.1 + 0, // NaN + 4294967169, // -127 + 4294967168, // -128 + 4294934529, // -32767 + 4294934528, // -32768 + 2147483649, // -2147483647 + 2147483648, // -2147483648 + 4294967041, // -255 + 4294967040, // -256 + 4294901761, // -65535 + 4294901760, // -65536 + 1, // -4294967295 + 0, // -4294967296 + 0, // Infinity + 0, // -Infinity + 0 + ], + Float32: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483648, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967296, // 4294967295 + 4294967296, // 4294967296 + 9007199254740992, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.100000023841858, // 1.1 + 0.10000000149011612, // 0.1 + 0.5, // 0.5 + 0.5, // 0.50000001, + 0.6000000238418579, // 0.6 + 0.699999988079071, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.10000000149011612, // -0.1 + -1.100000023841858, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483648, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967296, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ], + Float64: [ + 127, // 127 + 128, // 128 + 32767, // 32767 + 32768, // 32768 + 2147483647, // 2147483647 + 2147483648, // 2147483648 + 255, // 255 + 256, // 256 + 65535, // 65535 + 65536, // 65536 + 4294967295, // 4294967295 + 4294967296, // 4294967296 + 9007199254740991, // 9007199254740991 + 9007199254740992, // 9007199254740992 + 1.1, // 1.1 + 0.1, // 0.1 + 0.5, // 0.5 + 0.50000001, // 0.50000001, + 0.6, // 0.6 + 0.7, // 0.7 + NaN, // undefined + -1, // -1 + -0, // -0 + -0.1, // -0.1 + -1.1, // -1.1 + NaN, // NaN + -127, // -127 + -128, // -128 + -32767, // -32767 + -32768, // -32768 + -2147483647, // -2147483647 + -2147483648, // -2147483648 + -255, // -255 + -256, // -256 + -65535, // -65535 + -65536, // -65536 + -4294967295, // -4294967295 + -4294967296, // -4294967296 + Infinity, // Infinity + -Infinity, // -Infinity + 0 + ] + } +}; + +// file: detachArrayBuffer.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A function used in the process of asserting correctness of TypedArray objects. + + $262.detachArrayBuffer is defined by a host. +defines: [$DETACHBUFFER] +---*/ + +function $DETACHBUFFER(buffer) { + if (!$262 || typeof $262.detachArrayBuffer !== "function") { + throw new Test262Error("No method available to detach an ArrayBuffer"); + } + $262.detachArrayBuffer(buffer); +} + +// file: nans.js +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + A collection of NaN values produced from expressions that have been observed + to create distinct bit representations on various platforms. These provide a + weak basis for assertions regarding the consistent canonicalization of NaN + values in Array buffers. +defines: [NaNs] +---*/ + +var NaNs = [ + NaN, + Number.NaN, + NaN * 0, + 0/0, + Infinity/Infinity, + -(0/0), + Math.pow(-1, 0.5), + -Math.pow(-1, 0.5), + Number("Not-a-Number"), +]; + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js new file mode 100644 index 0000000000..bdb3a74ae9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-detached-buffer.js @@ -0,0 +1,52 @@ +// 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, will return true. +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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + 9.4.5.11 IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let ta = new TA(1); + let result = Reflect.set(ta, 0, { + valueOf() { + $DETACHBUFFER(ta.buffer); + return 42; + } + }); + + assert.sameValue(result, true); + assert.sameValue(ta[0], undefined); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-throws.js new file mode 100644 index 0000000000..08f17de272 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/Set/tonumber-value-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-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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + Assert: Type(index) is Number. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + ... +includes: [testTypedArray.js] +features: [align-detached-buffer-semantics-with-web-reality, TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + let sample = new TA([42]); + + let obj = { + valueOf() { + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + sample["0"] = obj; + }, '`sample["0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["1.1"] = obj; + }, '`sample["1.1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["-0"] = obj; + }, '`sample["-0"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["-1"] = obj; + }, '`sample["-1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["1"] = obj; + }, '`sample["1"] = obj` throws Test262Error'); + + assert.throws(Test262Error, function() { + sample["2"] = obj; + }, '`sample["2"] = obj` throws Test262Error'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/internals/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/argument-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/argument-is-symbol-throws.js new file mode 100644 index 0000000000..86ebdca0c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/argument-is-symbol-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%.of +description: > + Throws a TypeError if argument is a Symbol +info: | + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.of(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/argument-number-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/argument-number-value-throws.js new file mode 100644 index 0000000000..c04362855e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/argument-number-value-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%.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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var lastValue = false; + + var obj1 = { + valueOf() { + lastValue = "obj1"; + return 42n; + } + }; + var obj2 = { + valueOf() { + lastValue = "obj2"; + throw new Test262Error(); + } + }; + + assert.throws(Test262Error, function() { + TA.of(obj1, obj2, obj1); + }); + + assert.sameValue(lastValue, "obj2"); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-does-not-instantiate-ta-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000..faa4a0dbc1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-does-not-instantiate-ta-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%.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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.of.call(ctor, 42n); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-returns-other-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-returns-other-instance.js new file mode 100644 index 0000000000..9651789f07 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-returns-other-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: > + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var result; + var custom = new TA(3); + var ctor = function() { + return custom; + }; + + result = TypedArray.of.call(ctor, 1n, 2n, 3n); + assert.sameValue(result, custom, "using iterator, same length"); + + result = TypedArray.of.call(ctor, 1n, 2n); + assert.sameValue(result, custom, "using iterator, higher length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-returns-smaller-instance-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 0000000000..22d23ca509 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor-returns-smaller-instance-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: > + 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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var ctor = function() { + return new TA(1); + }; + + assert.throws(TypeError, function() { + TypedArray.of.call(ctor, 1n, 2n); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor.js new file mode 100644 index 0000000000..1feb266994 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/custom-ctor.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%.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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var called = 0; + var ctor = function() { + called++; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + TA.of.call(ctor, 42n); + }); + + assert.sameValue(called, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/inherited.js new file mode 100644 index 0000000000..f10783f101 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/inherited.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%.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] +---*/ + +testWithBigIntTypedArrayConstructors(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'" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/invoked-as-func.js new file mode 100644 index 0000000000..406b3d56ed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/invoked-as-func.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.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] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var of = TA.of; + + assert.throws(TypeError, function() { + of(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance-empty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance-empty.js new file mode 100644 index 0000000000..6a9669ee89 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance-empty.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%.of +description: > + Return a new empty TypedArray +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.of(); + assert.sameValue(result.length, 0); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance-using-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000..2d933c8b06 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/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%.of +description: > + Return a new TypedArray using a custom Constructor +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(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, 42n, 43n, 42n); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result[2], 42n); + assert.sameValue(result.constructor, TA); + assert.sameValue(called, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance.js new file mode 100644 index 0000000000..85dca677b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/new-instance.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%.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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var result = TA.of(42n, 43n, 0n); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42n); + assert.sameValue(result[1], 43n); + assert.sameValue(result[2], 0n); + assert.sameValue(result.constructor, TA); + assert.sameValue(Object.getPrototypeOf(result), TA.prototype); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/this-is-not-constructor.js new file mode 100644 index 0000000000..b62da04aae --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/BigInt/this-is-not-constructor.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%.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; + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.of.call(m, 0n); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/argument-is-symbol-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/argument-is-symbol-throws.js new file mode 100644 index 0000000000..ced8ecb0c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/argument-is-symbol-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%.of +description: > + Throws a TypeError if argument is a Symbol +info: | + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var s = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.of(s); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/argument-number-value-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/argument-number-value-throws.js new file mode 100644 index 0000000000..620165d5bb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/argument-number-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%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var lastValue; + +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); + }); + + assert.sameValue(lastValue, "obj2"); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-does-not-instantiate-ta-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-does-not-instantiate-ta-throws.js new file mode 100644 index 0000000000..8e6695a8ec --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-does-not-instantiate-ta-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%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ctor = function() {}; + + assert.throws(TypeError, function() { + TA.of.call(ctor, 42); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-returns-other-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-returns-other-instance.js new file mode 100644 index 0000000000..965a569166 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-returns-other-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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result; + var custom = new TA(3); + var ctor = function() { + return custom; + }; + + result = TypedArray.of.call(ctor, 1, 2, 3); + assert.sameValue(result, custom, "using iterator, same length"); + + result = TypedArray.of.call(ctor, 1, 2); + assert.sameValue(result, custom, "using iterator, higher length"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-returns-smaller-instance-throws.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-returns-smaller-instance-throws.js new file mode 100644 index 0000000000..28f5cda441 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor-returns-smaller-instance-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: > + 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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var ctor = function() { + return new TA(1); + }; + + assert.throws(TypeError, function() { + TypedArray.of.call(ctor, 1, 2); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor.js new file mode 100644 index 0000000000..7599583a84 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/custom-ctor.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%.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: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/inherited.js new file mode 100644 index 0000000000..99f528b8a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/inherited.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%.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: [testTypedArray.js] +features: [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'" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/invoked-as-func.js new file mode 100644 index 0000000000..ed3b8c02e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/invoked-as-func.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var of = TA.of; + + assert.throws(TypeError, function() { + of(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/nan-conversion.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/nan-conversion.js new file mode 100644 index 0000000000..cd09885912 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/nan-conversion.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%.of +description: > + Test NaN conversions +info: | + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + + 24.1.1.6 SetValueInBuffer ( arrayBuffer, byteIndex, type, value [ , + isLittleEndian ] ) +includes: [testTypedArray.js] +features: [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 +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-empty.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-empty.js new file mode 100644 index 0000000000..d6ee42b662 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-empty.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%.of +description: > + Return a new empty TypedArray +includes: [testTypedArray.js] +features: [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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-from-zero.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-from-zero.js new file mode 100644 index 0000000000..3bcac16072 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-from-zero.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%.of +description: > + Return a new TypedArray using -0 and +0 values +includes: [testTypedArray.js] +features: [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 +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-using-custom-ctor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance-using-custom-ctor.js new file mode 100644 index 0000000000..f806a5b711 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/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%.of +description: > + Return a new TypedArray using a custom Constructor +includes: [testTypedArray.js] +features: [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, 42, 43, 42); + assert.sameValue(result.length, 3); + assert.sameValue(result[0], 42); + assert.sameValue(result[1], 43); + assert.sameValue(result[2], 42); + assert.sameValue(result.constructor, TA); + assert.sameValue(called, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance.js new file mode 100644 index 0000000000..3ae4eed98a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/new-instance.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%.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. Perform ? IntegerIndexedElementSet(O, numericIndex, V). + ii. Return true. + ... + + IntegerIndexedElementSet ( O, index, value ) + + Assert: O is an Integer-Indexed exotic object. + If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value). + Otherwise, let numValue be ? ToNumber(value). + Let buffer be O.[[ViewedArrayBuffer]]. + If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then + Let offset be O.[[ByteOffset]]. + Let arrayTypeName be the String value of O.[[TypedArrayName]]. + Let elementSize be the Element Size value specified in Table 62 for arrayTypeName. + Let indexedPosition be (ℝ(index) × elementSize) + offset. + Let elementType be the Element Type value in Table 62 for arrayTypeName. + Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered). + Return NormalCompletion(undefined). + +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var result = TA.of(42, 43, null); + assert.sameValue(result.length, 3); + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/shell.js new file mode 100644 index 0000000000..e9580b3113 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/shell.js @@ -0,0 +1,124 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/of/this-is-not-constructor.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/this-is-not-constructor.js new file mode 100644 index 0000000000..16e1765df3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/of/this-is-not-constructor.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%.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: [testTypedArray.js] +features: [TypedArray] +---*/ + +var m = { m() {} }.m; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + TA.of.call(m, []); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.iterator.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.iterator.js new file mode 100644 index 0000000000..6e2f2b41e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.iterator.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/bigint-inherited.js new file mode 100644 index 0000000000..7b660850a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/bigint-inherited.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-get-%typedarray%.prototype-@@tostringtag +description: > + _TypedArray_.prototype[@@toStringTag] is inherited from %TypedArray% + _TypedArray_.prototype has no own property @@toStringTag +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol.toStringTag, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty(Symbol.toStringTag), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/inherited.js new file mode 100644 index 0000000000..d60d3c4b7d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/inherited.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-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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/Symbol.toStringTag/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/bigint-Symbol.iterator.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/bigint-Symbol.iterator.js new file mode 100644 index 0000000000..58eaa99291 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/bigint-Symbol.iterator.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, Symbol.iterator, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty(Symbol.iterator), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/bigint-inherited.js new file mode 100644 index 0000000000..becb7ba814 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("buffer"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/inherited.js new file mode 100644 index 0000000000..00fdd19d1b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/inherited.js @@ -0,0 +1,15 @@ +// Copyright (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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/buffer/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/bigint-inherited.js new file mode 100644 index 0000000000..54eec7c5cf --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("byteLength"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/inherited.js new file mode 100644 index 0000000000..67aa9848a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/inherited.js @@ -0,0 +1,15 @@ +// Copyright (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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteLength/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/bigint-inherited.js new file mode 100644 index 0000000000..2b5e5135f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("byteOffset"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/inherited.js new file mode 100644 index 0000000000..874d4abd88 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/inherited.js @@ -0,0 +1,15 @@ +// Copyright (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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/byteOffset/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/bigint-inherited.js new file mode 100644 index 0000000000..4211626dca --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("copyWithin"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/inherited.js new file mode 100644 index 0000000000..e831c04e99 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/copyWithin/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/bigint-inherited.js new file mode 100644 index 0000000000..97f91a12b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("entries"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/inherited.js new file mode 100644 index 0000000000..217462a687 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/entries/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/bigint-inherited.js new file mode 100644 index 0000000000..8ffd18c52b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("every"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/inherited.js new file mode 100644 index 0000000000..b61168bd9e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/every/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/bigint-inherited.js new file mode 100644 index 0000000000..9f549a255a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("fill"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/inherited.js new file mode 100644 index 0000000000..0a01168f76 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/fill/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/bigint-inherited.js new file mode 100644 index 0000000000..368f95cc45 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("filter"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/inherited.js new file mode 100644 index 0000000000..42c177812e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/filter/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/bigint-inherited.js new file mode 100644 index 0000000000..c69858aab6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("find"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/inherited.js new file mode 100644 index 0000000000..1895450c9a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/find/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/bigint-inherited.js new file mode 100644 index 0000000000..9c09040393 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("findIndex"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/inherited.js new file mode 100644 index 0000000000..902a419db4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/findIndex/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/bigint-inherited.js new file mode 100644 index 0000000000..0fd1cef33a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("forEach"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/inherited.js new file mode 100644 index 0000000000..bead9ffae5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/forEach/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/bigint-inherited.js new file mode 100644 index 0000000000..0f0cc9cbdc --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("indexOf"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/inherited.js new file mode 100644 index 0000000000..398ba4e107 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/indexOf/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/bigint-inherited.js new file mode 100644 index 0000000000..5547b47ea4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("join"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/inherited.js new file mode 100644 index 0000000000..37badbec58 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/join/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/bigint-inherited.js new file mode 100644 index 0000000000..3c5109f19e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("keys"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/inherited.js new file mode 100644 index 0000000000..a2c0289d1b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/keys/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/bigint-inherited.js new file mode 100644 index 0000000000..e228a33678 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("lastIndexOf"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/inherited.js new file mode 100644 index 0000000000..f9d7dd8626 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/lastIndexOf/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/bigint-inherited.js new file mode 100644 index 0000000000..187ffcb6a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("length"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/inherited.js new file mode 100644 index 0000000000..e2b9ea33c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/inherited.js @@ -0,0 +1,15 @@ +// Copyright (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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/length/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/bigint-inherited.js new file mode 100644 index 0000000000..644c206ea6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("map"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/inherited.js new file mode 100644 index 0000000000..591322dfe3 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/map/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/bigint-inherited.js new file mode 100644 index 0000000000..3cec96d789 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("reduce"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/inherited.js new file mode 100644 index 0000000000..758118a5d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/inherited.js @@ -0,0 +1,15 @@ +// Copyright (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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduce/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/bigint-inherited.js new file mode 100644 index 0000000000..b265f5293d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("reduceRight"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/inherited.js new file mode 100644 index 0000000000..334b156c1e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reduceRight/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/bigint-inherited.js new file mode 100644 index 0000000000..6f755a6481 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("reverse"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/inherited.js new file mode 100644 index 0000000000..e6758c7916 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/reverse/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/bigint-inherited.js new file mode 100644 index 0000000000..780c7ede57 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("set"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/inherited.js new file mode 100644 index 0000000000..90822be1b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/set/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/shell.js new file mode 100644 index 0000000000..1157ee5318 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/shell.js @@ -0,0 +1,166 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} + +// file: testTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of TypedArray objects. +defines: + - typedArrayConstructors + - floatArrayConstructors + - intArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +/** + * Array containing every typed array constructor. + */ +var typedArrayConstructors = [ + Float64Array, + Float32Array, + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + Uint8ClampedArray +]; + +var floatArrayConstructors = typedArrayConstructors.slice(0, 2); +var intArrayConstructors = typedArrayConstructors.slice(2, 7); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Float64Array, + Float32Array, + Uint8ClampedArray + ]); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * 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 testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(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); + }); + }); +} diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/bigint-inherited.js new file mode 100644 index 0000000000..835ec76617 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("slice"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/inherited.js new file mode 100644 index 0000000000..0c4578ee12 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/slice/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/bigint-inherited.js new file mode 100644 index 0000000000..20f9f7a526 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("some"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/inherited.js new file mode 100644 index 0000000000..74aefc5a0f --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/some/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/bigint-inherited.js new file mode 100644 index 0000000000..d265d2605d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("sort"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/inherited.js new file mode 100644 index 0000000000..e42774b2be --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/sort/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/bigint-inherited.js new file mode 100644 index 0000000000..da10e7e7fa --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("subarray"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/inherited.js new file mode 100644 index 0000000000..63609b2124 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/subarray/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/bigint-inherited.js new file mode 100644 index 0000000000..26a0962969 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("toLocaleString"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/inherited.js new file mode 100644 index 0000000000..bd2d3caaf5 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toLocaleString/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/bigint-inherited.js new file mode 100644 index 0000000000..a6c505e814 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("toString"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/inherited.js new file mode 100644 index 0000000000..b79a9b7b20 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/toString/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/bigint-inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/bigint-inherited.js new file mode 100644 index 0000000000..38750dc92e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/bigint-inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + assert.sameValue(TA.prototype.hasOwnProperty("values"), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/browser.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/inherited.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/inherited.js new file mode 100644 index 0000000000..0283231b6b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/inherited.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/prototype/values/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArrayConstructors/shell.js b/js/src/tests/test262/built-ins/TypedArrayConstructors/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArrayConstructors/shell.js |