diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/toReversed')
12 files changed, 317 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/ignores-species.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/ignores-species.js new file mode 100644 index 0000000000..361cadfe58 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/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.toReversed +description: > + %TypedArray%.prototype.toReversed ignores @@species +info: | + %TypedArray%.prototype.toReversed ( ) + + ... + 4. Let A be ? TypedArrayCreateSameType(O, « 𝔽(length) »). + ... + + 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(); + ta.constructor = TA === Uint8Array ? Int32Array : Uint8Array; + assert.sameValue(Object.getPrototypeOf(ta.toReversed()), TA.prototype); + + ta = new TA(); + ta.constructor = { + [Symbol.species]: TA === Uint8Array ? Int32Array : Uint8Array, + }; + assert.sameValue(Object.getPrototypeOf(ta.toReversed()), TA.prototype); + + ta = new TA(); + Object.defineProperty(ta, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } + }); + ta.toReversed(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/immutable.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/immutable.js new file mode 100644 index 0000000000..1e74812171 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/immutable.js @@ -0,0 +1,21 @@ +// |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.toReversed +description: > + %TypedArray%.prototype.toReversed does not mutate its this value +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([0, 1, 2]); + ta.toReversed(); + + assert.compareArray(ta, [0, 1, 2]); + assert.notSameValue(ta.toReversed(), ta); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/length-property-ignored.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/length-property-ignored.js new file mode 100644 index 0000000000..b4c6f56470 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/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.toReversed +description: > + %TypedArray%.prototype.toReversed does not read a "length" property +info: | + %TypedArray%.prototype.toReversed ( ) + + ... + 3. Let length be O.[[ArrayLength]]. + ... +includes: [testTypedArray.js, compareArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +testWithTypedArrayConstructors(TA => { + var ta = new TA([0, 1, 2]); + Object.defineProperty(ta, "length", { value: 2 }) + var res = ta.toReversed(); + assert.compareArray(res, [2, 1, 0]); + assert.sameValue(res.length, 3); + + ta = new TA([0, 1, 2]); + Object.defineProperty(ta, "length", { value: 5 }); + res = ta.toReversed(); + assert.compareArray(res, [2, 1, 0]); + assert.sameValue(res.length, 3); +}); + +function setLength(length) { + Object.defineProperty(TypedArray.prototype, "length", { + get: () => length, + }); +} + +testWithTypedArrayConstructors(TA => { + var ta = new TA([0, 1, 2]); + + setLength(2); + var res = ta.toReversed(); + setLength(3); + assert.compareArray(res, [2, 1, 0]); + + setLength(5); + res = ta.toReversed(); + setLength(3); + assert.compareArray(res, [2, 1, 0]); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/length.js new file mode 100644 index 0000000000..96d6407c1a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/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.toReversed +description: > + The "length" property of %TypedArray%.prototype.toReversed +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: [propertyHelper.js, testTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(TypedArray.prototype.toReversed, "length", { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/name.js new file mode 100644 index 0000000000..8d5c00e098 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/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.toReversed +description: > + %TypedArray%.prototype.toReversed.name is "toReversed". +info: | + %TypedArray%.prototype.toReversed ( ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +verifyProperty(TypedArray.prototype.toReversed, "name", { + value: "toReversed", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/property-descriptor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/property-descriptor.js new file mode 100644 index 0000000000..acd093a292 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/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.toReversed +description: > + "toReversed" 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: [propertyHelper.js, testTypedArray.js] +features: [TypedArray, change-array-by-copy] +---*/ + +assert.sameValue(typeof TypedArray.prototype.toReversed, "function", "typeof"); + +verifyProperty(TypedArray.prototype, "toReversed", { + value: TypedArray.prototype.toReversed, + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/metadata/shell.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/not-a-constructor.js new file mode 100644 index 0000000000..7eeb9e651c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/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.toReversed 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.toReversed), + false, + 'isConstructor(TypedArray.prototype.toReversed) must return false' +); + +assert.throws(TypeError, () => { + new TypedArray.prototype.toReversed(); +}, '`new TypedArray.prototype.toReversed()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/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/toReversed/this-value-invalid.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/this-value-invalid.js new file mode 100644 index 0000000000..cb15ea1240 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toReversed/this-value-invalid.js @@ -0,0 +1,47 @@ +// |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.toReversed +description: > + %TypedArray%.prototype.toReversed throws if the receiver is not a valid TypedArray +info: | + %TypedArray%.prototype.toReversed ( ) + + 1. Let O be the this value. + 2. Perform ? ValidateTypedArray(O). + ... +includes: [detachArrayBuffer.js, 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, + '1n': 1n, +}; + +Object.entries(invalidValues).forEach(value => { + assert.throws(TypeError, () => { + TypedArray.prototype.toReversed.call(value[1]); + }, `${value[0]} is not a valid TypedArray`); +}); + +testWithTypedArrayConstructors(function(TA) { + let buffer = new ArrayBuffer(8); + let sample = new TA(buffer, 0, 1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, () => { + sample.toReversed(); + }, `array has a detached buffer`); +}); + +reportCompare(0, 0); |