diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/with')
20 files changed, 568 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js new file mode 100644 index 0000000000..0c32af8a93 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/early-type-coercion-bigint.js @@ -0,0 +1,34 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with invokes ToNumber before copying +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 7. If _O_.[[ContentType]] is ~BigInt~, set _value_ to ? ToBigInt(_value_). + 8. Else, set _value_ to ? ToNumber(_value_). + ... +features: [BigInt, TypedArray, change-array-by-copy] +includes: [testBigIntTypedArray.js, compareArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var arr = new TA([0n, 1n, 2n]); + + var value = { + valueOf() { + arr[0] = 3n; + return 4n; + } + }; + + assert.compareArray(arr.with(1, value), [3n, 4n, 2n]); + assert.compareArray(arr, [3n, 1n, 2n]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/early-type-coercion.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/early-type-coercion.js new file mode 100644 index 0000000000..b0e012ebed --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/early-type-coercion.js @@ -0,0 +1,34 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with invokes ToNumber before copying +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 7. If _O_.[[ContentType]] is ~BigInt~, set _value_ to ? ToBigInt(_value_). + 8. Else, set _value_ to ? ToNumber(_value_). + ... +features: [TypedArray, change-array-by-copy] +includes: [testTypedArray.js, compareArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + var value = { + valueOf() { + arr[0] = 3; + return 4; + } + }; + + assert.compareArray(arr.with(1, value), [3, 4, 2]); + assert.compareArray(arr, [3, 1, 2]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/ignores-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/ignores-species.js new file mode 100644 index 0000000000..7049fcf2a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/ignores-species.js @@ -0,0 +1,44 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with ignores @@species +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 10. Let A be ? TypedArrayCreateSameType(O, « 𝔽(len) »). + ... + + TypedArrayCreateSameType ( exemplar, argumentList ) + ... + 2. Let constructor be the intrinsic object listed in column one of Table 63 for exemplar.[[TypedArrayName]]. + ... +includes: [testTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([1, 2, 3]); + ta.constructor = TA === Uint8Array ? Int32Array : Uint8Array; + assert.sameValue(Object.getPrototypeOf(ta.with(0, 2)), TA.prototype); + + ta = new TA([1, 2, 3]); + ta.constructor = { + [Symbol.species]: TA === Uint8Array ? Int32Array : Uint8Array, + }; + assert.sameValue(Object.getPrototypeOf(ta.with(0, 2)), TA.prototype); + + ta = new TA([1, 2, 3]); + Object.defineProperty(ta, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } + }); + ta.with(0, 2); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/immutable.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/immutable.js new file mode 100644 index 0000000000..97746a08f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/immutable.js @@ -0,0 +1,22 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with does not mutate its this value +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + ta.with(0, 2); + + assert.compareArray(ta, [3, 1, 2]); + assert.notSameValue(ta.with(0, 2), ta); + assert.notSameValue(ta.with(0, 3), ta); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js new file mode 100644 index 0000000000..02eb24acac --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-bigger-or-eq-than-length.js @@ -0,0 +1,43 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typed%array%.prototype.with +description: > + %TypedArray%.prototype.with throws if the index is bigger than or equal to the array length. +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 3. Let len be O.[[ArrayLength]]. + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If ! IsValidIntegerIndex(O, actualIndex) is false, throw a *RangeError* exception. + ... +includes: [testTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + assert.throws(RangeError, function() { + arr.with(3, 7); + }); + + assert.throws(RangeError, function() { + arr.with(10, 7); + }); + + assert.throws(RangeError, function() { + arr.with(2 ** 53 + 2, 7); + }); + + assert.throws(RangeError, function() { + arr.with(Infinity, 7); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-casted-to-number.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-casted-to-number.js new file mode 100644 index 0000000000..9b5993be7a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-casted-to-number.js @@ -0,0 +1,32 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with casts the index to an integer. +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + ... +features: [TypedArray, change-array-by-copy] +includes: [testTypedArray.js, compareArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 4, 16]); + + assert.compareArray(arr.with(1.2, 7), [0, 7, 16]); + assert.compareArray(arr.with("1", 3), [0, 3, 16]); + assert.compareArray(arr.with("-1", 5), [0, 4, 5]); + assert.compareArray(arr.with(NaN, 2), [2, 4, 16]); + assert.compareArray(arr.with("dog", 33), [33, 4, 16]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-negative.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-negative.js new file mode 100644 index 0000000000..3ac59b6926 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-negative.js @@ -0,0 +1,31 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with adds length to index if it's negative. +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + ... +features: [TypedArray, change-array-by-copy] +includes: [testTypedArray.js, compareArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + assert.compareArray(arr.with(-1, 4), [0, 1, 4]); + assert.compareArray(arr.with(-3, 4), [4, 1, 2]); + // -0 is not negative. + assert.compareArray(arr.with(-0, 4), [4, 1, 2]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-smaller-than-minus-length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-smaller-than-minus-length.js new file mode 100644 index 0000000000..a9e9d2c8c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/index-smaller-than-minus-length.js @@ -0,0 +1,43 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with throws if the (negative) index is smaller than -length. +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeIndex be ? ToIntegerOrInfinity(index). + 4. If index >= 0, let actualIndex be relativeIndex. + 5. Else, let actualIndex be len + relativeIndex. + 6. If actualIndex >= len or actualIndex < 0, throw a *RangeError* exception. + ... +features: [TypedArray, change-array-by-copy] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(TA => { + var arr = new TA([0, 1, 2]); + + assert.throws(RangeError, function() { + arr.with(-4, 7); + }); + + assert.throws(RangeError, function() { + arr.with(-10, 7); + }); + + assert.throws(RangeError, function() { + arr.with(-(2 ** 53) - 2, 7); + }); + + assert.throws(RangeError, function() { + arr.with(-Infinity, 7); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/length-property-ignored.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/length-property-ignored.js new file mode 100644 index 0000000000..a7217ba15b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/length-property-ignored.js @@ -0,0 +1,53 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with reads the TypedArray length ignoring the .length property +info: | + %TypedArray%.prototype.with ( index, value ) + + ... + 3. Let len be O.[[ArrayLength]]. + ... +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + Object.defineProperty(ta, "length", { value: 2 }) + var res = ta.with(0, 0); + assert.compareArray(res, [0, 1, 2]); + assert.sameValue(res.length, 3); + + ta = new TA([3, 1, 2]); + Object.defineProperty(ta, "length", { value: 5 }); + res = ta.with(0, 0); + assert.compareArray(res, [0, 1, 2]); + assert.sameValue(res.length, 3); +}); + +function setLength(length) { + Object.defineProperty(TypedArray.prototype, "length", { + get: () => length, + }); +} + +testWithTypedArrayConstructors(TA => { + var ta = new TA([3, 1, 2]); + + setLength(2); + var res = ta.with(0, 0); + setLength(3); + assert.compareArray(res, [0, 1, 2]); + + setLength(5); + res = ta.with(0, 0); + setLength(3); + assert.compareArray(res, [0, 1, 2]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/length.js new file mode 100644 index 0000000000..bc67b8ca53 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/length.js @@ -0,0 +1,33 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + The "length" property of %TypedArray%.prototype.with +info: | + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [testTypedArray.js, propertyHelper.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(TypedArray.prototype.with, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/name.js new file mode 100644 index 0000000000..f223fac392 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/name.js @@ -0,0 +1,31 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with.name is "with". +info: | + %TypedArray%.prototype.with ( index, value ) + + 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: [testTypedArray.js, propertyHelper.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(TypedArray.prototype.with, "name", { + value: "with", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js new file mode 100644 index 0000000000..f892d722a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/property-descriptor.js @@ -0,0 +1,28 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + "with" property of %TypedArray%.prototype +info: | + 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: [testTypedArray.js, propertyHelper.js] +features: [TypedArray, change-array-by-copy] +---*/ + +assert.sameValue(typeof TypedArray.prototype.with, "function", "typeof"); + +verifyProperty(TypedArray.prototype, "with", { + value: TypedArray.prototype.with, + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/metadata/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/not-a-constructor.js new file mode 100644 index 0000000000..fb1cd4b92c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/not-a-constructor.js @@ -0,0 +1,36 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + %TypedArray%.prototype.with does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, testTypedArray.js] +features: [TypedArray, change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(TypedArray.prototype.with), + false, + 'isConstructor(TypedArray.prototype.with) must return false' +); + +assert.throws(TypeError, () => { + new TypedArray.prototype.with(0, 1); +}, '`new %TypedArray%.prototype.with()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/with/this-value-invalid.js b/js/src/tests/test262/built-ins/TypedArray/prototype/with/this-value-invalid.js new file mode 100644 index 0000000000..c256138afe --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/with/this-value-invalid.js @@ -0,0 +1,38 @@ +// |reftest| shell-option(--enable-change-array-by-copy) skip-if(!Array.prototype.with||!xulRuntime.shell) -- change-array-by-copy is not enabled unconditionally, requires shell-options +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.with +description: > + %TypedArray%.prototype.with throws if the receiver is null or undefined +info: | + %TypedArray%.prototype.with ( index, value ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... +includes: [testTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +var invalidValues = { + 'null': null, + 'undefined': undefined, + 'true': true, + '"abc"': "abc", + '12': 12, + 'Symbol()': Symbol(), + '[1, 2, 3]': [1, 2, 3], + '{ 0: 1, 1: 2, 2: 3, length: 3 }': { 0: 1, 1: 2, 2: 3, length: 3 }, + 'Uint8Array.prototype': Uint8Array.prototype, +}; + +Object.keys(invalidValues).forEach(desc => { + var value = invalidValues[desc]; + assert.throws(TypeError, () => { + TypedArray.prototype.with.call(value, 0, 0); + }, `${desc} is not a valid TypedArray`); +}); + +reportCompare(0, 0); |