diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Array/prototype/toSpliced | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/toSpliced')
34 files changed, 1006 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/browser.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-clamped-between-zero-and-remaining-count.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-clamped-between-zero-and-remaining-count.js new file mode 100644 index 0000000000..7cc84733e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-clamped-between-zero-and-remaining-count.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: deleteCount is clamped between zero and len - actualStart +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 10. Else, + a. Let dc be ? ToIntegerOrInfinity(deleteCount). + b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(2, -1), + [0, 1, 2, 3, 4, 5] +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(-4, -1), + [0, 1, 2, 3, 4, 5] +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(2, 6), + [0, 1] +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].toSpliced(-4, 6), + [0, 1] +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-missing.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-missing.js new file mode 100644 index 0000000000..6e0903c21d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-missing.js @@ -0,0 +1,22 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced deletes the elements after start when called with one argument +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 9. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = ["first", "second", "third"].toSpliced(1); + +assert.compareArray(result, ["first"]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-undefined.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-undefined.js new file mode 100644 index 0000000000..ed1b4dffb7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/deleteCount-undefined.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced(number, undefined) returns a copy of the original array +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + ... + 6. Else, let actualStart be min(relativeStart, len). + ... + 8. If start is not present, then + a. Let actualDeleteCount be 0. + 9. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. + 10. Else, + a. Let dc be ? ToIntegerOrInfinity(deleteCount). + b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = ["first", "second", "third"].toSpliced(1, undefined); + +assert.compareArray(result, ["first", "second", "third"]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/discarded-element-not-read.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/discarded-element-not-read.js new file mode 100644 index 0000000000..1544086f47 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/discarded-element-not-read.js @@ -0,0 +1,54 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced does not Get the discarded elements in the original array +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + ... + 6. Else, let actualStart be min(relativeStart, len). + ... + 8. If start is not present, then + a. Let actualDeleteCount be 0. + 9. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. + 10. Else, + a. Let dc be ? ToIntegerOrInfinity(deleteCount). + b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart. + 11. Let newLen be len + insertCount - actualDeleteCount. + ... + 15. Let r be actualStart + actualDeleteCount. + ... + 18. Repeat, while i < newLen, + a. Let Pi be ! ToString(π½(i)). + b. Let from be ! ToString(π½(r)). + c. Let fromValue be ? Get(O, from). + d. Perform ! CreateDataPropertyOrThrow(A, Pi, fromValue). + e. Set i to i + 1. + f. Set r to r + 1. + +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arrayLike = { + 0: "a", + 1: "b", + get 2() { throw new Test262Error(); }, + 3: "c", + length: 4, +}; + +/* + * In this example, just before step 18, i == 2 and r == 3. + * So A[2] is set to arrayLike[3] and arrayLike[2] is never read + * (since i and r both increase monotonically). + */ +var result = Array.prototype.toSpliced.call(arrayLike, 2, 1); +assert.compareArray(result, ["a", "b", "c"]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/elements-read-in-order.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/elements-read-in-order.js new file mode 100644 index 0000000000..da1b7fc905 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/elements-read-in-order.js @@ -0,0 +1,61 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced reads the items of the original array in order +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 14. Let i be 0. + 15. Let r be actualStart + actualDeleteCount. + 16. Repeat, while i < actualStart, + a. Let Pi be ! ToString(π½(i)). + b. Let iValue be ? Get(O, Pi). + c. Perform ! CreateDataPropertyOrThrow(A, Pi, iValue). + d. Set i to i + 1. + 17. For each element E of items, do + a. Let Pi be ! ToString(π½(i)). + b. Perform ! CreateDataPropertyOrThrow(A, Pi, E). + c. Set i to i + 1. + 18. Repeat, while i < newLen, + a. Let Pi be ! ToString(π½(i)). + b. Let from be ! ToString(π½(r)). + c. Let fromValue be ? Get(O, from). + d. Perform ! CreateDataPropertyOrThrow(A, Pi, fromValue). + e. Set i to i + 1. + f. Set r to r + 1. + ... + +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var order = []; + +var arrayLike = { + get 0() { order.push(0); return "a" }, + get 1() { order.push(1); return "b" }, + 2: "none", + get 3() { order.push(3); return "c" }, + length: 4, +}; + +var result = Array.prototype.toSpliced.call(arrayLike, 2, 1); +assert.compareArray(result, ["a", "b", "c"]); + +assert.compareArray(order, [0, 1, 3]); + +order = []; +var arr = [0, 1, "none", 3]; +Object.defineProperty(arr, 0, { get: function() { order.push(0); return "a" } }); +Object.defineProperty(arr, 1, { get: function() { order.push(1); return "b" } }); +Object.defineProperty(arr, 3, { get: function() { order.push(3); return "c" } }); + +result = Array.prototype.toSpliced.call(arr, 2, 1); +assert.compareArray(result, ["a", "b", "c"]); + +assert.compareArray(order, [0, 1, 3]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/frozen-this-value.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/frozen-this-value.js new file mode 100644 index 0000000000..3013dee9f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/frozen-this-value.js @@ -0,0 +1,20 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced works on frozen objects +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = Object.freeze([2, 0, 1]); +var result = arr.toSpliced(); +assert.compareArray(result, [2, 0, 1]); + +var arrayLike = Object.freeze({ length: 3, 0: 0, 1: 1, 2: 2 }); + +assert.compareArray(Array.prototype.toSpliced.call(arrayLike, 1, 1, 4, 5), [0, 4, 5, 2]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/holes-not-preserved.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/holes-not-preserved.js new file mode 100644 index 0000000000..3fb2e312a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/holes-not-preserved.js @@ -0,0 +1,43 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced does not preserve holes in the array +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 13. Let k be 0. + 14. Repeat, while k < actualStart, + a. Let Pk be ! ToString(π½(k)). + b. Let kValue be ? Get(O, Pk). + c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue). + d. Set k to k + 1. + ... + 16. Repeat, while k < newLen, + a. Let Pk be ! ToString(π½(k)). + b. Let from be ! ToString(π½(k + actualDeleteCount - insertCount)). + c. Let fromValue be ? Get(O, from). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. + ... +includes: [compareArray.js] +features: [change-array-by-copy] +---*/ + +var arr = [0, /* hole */, 2, /* hole */, 4]; +Array.prototype[3] = 3; + +var spliced = arr.toSpliced(0, 0); +assert.compareArray(spliced, [0, undefined, 2, 3, 4]); +assert(spliced.hasOwnProperty(1)); +assert(spliced.hasOwnProperty(3)); + +spliced = arr.toSpliced(0, 0, -1); +assert.compareArray(spliced, [-1, 0, undefined, 2, 3, 4]); +assert(spliced.hasOwnProperty(1)); +assert(spliced.hasOwnProperty(3)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/ignores-species.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/ignores-species.js new file mode 100644 index 0000000000..fd55356656 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/ignores-species.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced ignores @@species +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 12. Let A be ? ArrayCreate(π½(newLen)). + ... +features: [change-array-by-copy] +---*/ + +var a = []; +a.constructor = {}; +a.constructor[Symbol.species] = function () {} + +assert.sameValue(Object.getPrototypeOf(a.toSpliced(0, 0)), Array.prototype); + +var b = []; +Object.defineProperty(b, "constructor", { + get() { + throw new Test262Error("Should not get .constructor"); + } +}); + +b.toSpliced(0, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/immutable.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/immutable.js new file mode 100644 index 0000000000..710da9916c --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/immutable.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced does not mutate its this value +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [2, 0, 1]; +arr.toSpliced(0, 0, -1); + +assert.compareArray(arr, [2, 0, 1]); +assert.notSameValue(arr.toSpliced(0, 0, -1), arr); +assert.notSameValue(arr.toSpliced(0, 1, -1), arr); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-casted-to-zero.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-casted-to-zero.js new file mode 100644 index 0000000000..de36d2c41a --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-casted-to-zero.js @@ -0,0 +1,23 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats its `this` value's `length` property as zero if the + property's value is not a positive integer. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(Array.prototype.toSpliced.call({ length: -2 }, 0, 0, 2, 3), [2, 3]); +assert.compareArray(Array.prototype.toSpliced.call({ length: "dog" }, 0, 0, 2, 3), [2, 3]); +assert.compareArray(Array.prototype.toSpliced.call({ length: NaN }, 0, 0, 2, 3), [2, 3]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-clamped-to-2pow53minus1.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-clamped-to-2pow53minus1.js new file mode 100644 index 0000000000..0ce88ef200 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-clamped-to-2pow53minus1.js @@ -0,0 +1,36 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Length is clamped to 2^53-1 when they exceed the integer limit. +info: | + ... + 2. Let len be ? LengthOfArrayLike(O). + ... + + ToLength ( argument ) + + 1. Let len be ? ToIntegerOrInfinity(argument). + 2. If len β€ 0, return +0π½. + 3. Return π½(min(len, 2^53 - 1)) +features: [change-array-by-copy, exponentiation] +includes: [compareArray.js] +---*/ + +var arrayLike = { + "9007199254740989": 2 ** 53 - 3, + "9007199254740990": 2 ** 53 - 2, + "9007199254740991": 2 ** 53 - 1, + "9007199254740992": 2 ** 53, + "9007199254740994": 2 ** 53 + 2, // NOTE: 2 ** 53 + 1 is 2 ** 53 + length: 2 ** 53 + 20, +}; + +var result = Array.prototype.toSpliced.call(arrayLike, 0, 2 ** 53 - 3); + +assert.sameValue(result.length, 2); +assert.compareArray(result, [2 ** 53 - 3, 2 ** 53 - 2]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-decreased-while-iterating.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-decreased-while-iterating.js new file mode 100644 index 0000000000..35d4767b8f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-decreased-while-iterating.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced caches the length getting the array elements. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... + 11. Let newLen be len + insertCount - actualDeleteCount. + ... + 13. Let k be 0. + 14. Repeat, while k < actualStart, + a. Let Pk be ! ToString(π½(k)). + b. Let kValue be ? Get(O, Pk). + c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue). + d. Set k to k + 1. + ... + 16. Repeat, while k < newLen, + a. Let Pk be ! ToString(π½(k)). + b. Let from be ! ToString(π½(k + actualDeleteCount - insertCount)). + c. Let fromValue be ? Get(O, from). + d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). + e. Set k to k + 1. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2, 3, 4, 5]; +Array.prototype[3] = 6; + +Object.defineProperty(arr, "2", { + get() { + arr.length = 1; + return 2; + } +}); + +assert.compareArray(arr.toSpliced(0, 0), [0, 1, 2, 6, undefined, undefined]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-exceeding-array-length-limit.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-exceeding-array-length-limit.js new file mode 100644 index 0000000000..a8ad3e4624 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-exceeding-array-length-limit.js @@ -0,0 +1,78 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced limits the length to 2 ** 32 - 1 +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 3. Let len be ? LengthOfArrayLike(O). + ... + 11. Let newLen be len + insertCount - actualDeleteCount. + 12. If _newLen_ > 2 ** 53< - 1, throw a *TypeError* exception. + 13. Let A be ? ArrayCreate(π½(newLen)). + ... + + ArrayCreate ( length [, proto ] ) + + 1. If length > 2 ** 32 - 1, throw a RangeError exception. +features: [change-array-by-copy, exponentiation] +---*/ + +// Object with large "length" property +var arrayLike = { + get "0"() { + throw new Test262Error("Get 0"); + }, + get "4294967295" () { // 2 ** 32 - 1 + throw new Test262Error("Get 4294967295"); + }, + get "4294967296" () { // 2 ** 32 + throw new Test262Error("Get 4294967296"); + }, + length: 2 ** 32 +}; + +assert.throws(RangeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0); +}); + +arrayLike.length = 2 ** 32 - 1; +assert.throws(RangeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); + +arrayLike.length = 2 ** 32; +assert.throws(RangeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); + +arrayLike.length = 2 ** 32 + 1; +assert.throws(RangeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); + +arrayLike.length = 2 ** 52 - 2; +assert.throws(RangeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); + +arrayLike.length = 2 ** 53 - 1; +assert.throws(TypeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); + +arrayLike.length = 2 ** 53; +assert.throws(TypeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); + +arrayLike.length = 2 ** 53 + 1; +assert.throws(TypeError, function() { + Array.prototype.toSpliced.call(arrayLike, 0, 0, 1); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-increased-while-iterating.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-increased-while-iterating.js new file mode 100644 index 0000000000..f125316834 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-increased-while-iterating.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced caches the length getting the array elements. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 3. Let len be ? LengthOfArrayLike(O). + ... + 5. Let k be 0. + 6. Repeat, while k < len, + a. Let Pk be ! ToString(π½(k)). + b. Let kValue be ? Get(O, Pk). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2]; +Object.defineProperty(arr, "0", { + get() { + arr.push(10); + return 0; + } +}); +Object.defineProperty(arr, "2", { + get() { + arr.push(11); + return 2; + } +}); + +assert.compareArray(arr.toSpliced(1, 0, 0.5), [0, 0.5, 1, 2]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-tolength.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-tolength.js new file mode 100644 index 0000000000..fc40bb8aa6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/length-tolength.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced converts the this value length to a number. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(Array.prototype.toSpliced.call({ length: "2", 0: 0, 1: 1, 2: 2 }, 0, 0), [0, 1]); + +var arrayLike = { + length: { + valueOf: () => 2 + }, + 0: 0, + 1: 1, + 2: 2, +}; + +assert.compareArray(Array.prototype.toSpliced.call(arrayLike, 0, 0), [0, 1]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/browser.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/length.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/length.js new file mode 100644 index 0000000000..63916778a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + The "length" property of Array.prototype.toSpliced +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] +features: [change-array-by-copy] +---*/ + +verifyProperty(Array.prototype.toSpliced, "length", { + value: 2, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/name.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/name.js new file mode 100644 index 0000000000..9025e4e34f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced.name is "toSpliced". +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + 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: [change-array-by-copy] +---*/ + +verifyProperty(Array.prototype.toSpliced, "name", { + value: "toSpliced", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/property-descriptor.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/property-descriptor.js new file mode 100644 index 0000000000..9c9eadef59 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/property-descriptor.js @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + "toSpliced" property of Array.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] +features: [change-array-by-copy] +---*/ + +assert.sameValue(typeof Array.prototype.toSpliced, "function", "typeof"); + +verifyProperty(Array.prototype, "toSpliced", { + value: Array.prototype.toSpliced, + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/shell.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/metadata/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/mutate-while-iterating.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/mutate-while-iterating.js new file mode 100644 index 0000000000..208976b7cb --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/mutate-while-iterating.js @@ -0,0 +1,52 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced gets array elements one at a time. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 16. Repeat, while i < actualStart, + a. Let Pi be ! ToString(π½(i)). + b. Let iValue be ? Get(O, Pi). + c. Perform ! CreateDataPropertyOrThrow(A, Pi, iValue). + d. Set i to i + 1. + ... + 18. Repeat, while i < newLen, + a. Let Pi be ! ToString(π½(i)). + b. Let from be ! ToString(π½(r)). + c. Let fromValue be ? Get(O, from). + d. Perform ! CreateDataPropertyOrThrow(A, Pi, fromValue). + e. Set i to i + 1. + f. Set r to r + 1. + ... + +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [0, 1, 2, 3]; +var zerothElementStorage = arr[0]; +Object.defineProperty(arr, "0", { + get() { + arr[1] = 42; + return zerothElementStorage; + }, + set(v) { + zerothElementStorage = v; + } +}); +Object.defineProperty(arr, "2", { + get() { + arr[0] = 17; + arr[3] = 37; + return 2; + } +}); + +assert.compareArray(arr.toSpliced(1, 0, 0.5), [0, 0.5, 42, 2, 37]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/not-a-constructor.js new file mode 100644 index 0000000000..533e8c9eaa --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/not-a-constructor.js @@ -0,0 +1,34 @@ +// 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: > + Array.prototype.toSpliced 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] +features: [change-array-by-copy, Reflect.construct] +---*/ + +assert.sameValue( + isConstructor(Array.prototype.toSpliced), + false, + 'isConstructor(Array.prototype.toSpliced) must return false' +); + +assert.throws(TypeError, () => { + new Array.prototype.toSpliced(); +}, '`new Array.prototype.toSpliced()` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/shell.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-and-deleteCount-missing.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-and-deleteCount-missing.js new file mode 100644 index 0000000000..19688d17af --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-and-deleteCount-missing.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced returns a copy of the array if called with zero arguments +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + ... + 6. Else, let actualStart be min(relativeStart, len). + ... + 8. If start is not present, then + a. Let actualDeleteCount be 0. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +let arr = ["first", "second", "third"]; +let result = arr.toSpliced(); + +assert.compareArray(result, arr); +assert.notSameValue(result, arr); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-and-deleteCount-undefineds.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-and-deleteCount-undefineds.js new file mode 100644 index 0000000000..a07388dca2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-and-deleteCount-undefineds.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced(undefined, undefined) returns a copy of the original array +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + ... + 6. Else, let actualStart be min(relativeStart, len). + ... + 8. If start is not present, then + a. Let actualDeleteCount be 0. + 8. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +let arr = ["first", "second", "third"]; +let result = arr.toSpliced(undefined, undefined); + +assert.compareArray(result, arr); +assert.notSameValue(result, arr); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-bigger-than-length.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-bigger-than-length.js new file mode 100644 index 0000000000..ca073db0e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-bigger-than-length.js @@ -0,0 +1,25 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced clamps the start argument to the this value length. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -β, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). + 6. Else, let actualStart be min(relativeStart, len). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(10, 1, 5, 6); +assert.compareArray(result, [0, 1, 2, 3, 4, 5, 6]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-infinity-is-zero.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-infinity-is-zero.js new file mode 100644 index 0000000000..cc025bd98e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-infinity-is-zero.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats negative Infinity as zero for start. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -β, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(-Infinity, 2); +assert.compareArray(result, [2, 3, 4]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-less-than-minus-length-is-zero.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-less-than-minus-length-is-zero.js new file mode 100644 index 0000000000..79ccf7b51b --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-less-than-minus-length-is-zero.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats a value smaller than -length as zero for start. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -β, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(-20, 2); +assert.compareArray(result, [2, 3, 4]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-subtracted-from-length.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-subtracted-from-length.js new file mode 100644 index 0000000000..4bbd45e665 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-neg-subtracted-from-length.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced treats a negative start as relative to the end. +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + ... + 2. Let len be ? LengthOfArrayLike(O). + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + 4. If relativeStart is -β, let actualStart be 0. + 5. Else if relativeStart < 0, let actualStart be max(len + relativeStart, 0). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = [0, 1, 2, 3, 4].toSpliced(-3, 2); +assert.compareArray(result, [0, 1, 4]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-undefined-and-deleteCount-missing.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-undefined-and-deleteCount-missing.js new file mode 100644 index 0000000000..1cc6c57ad9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/start-undefined-and-deleteCount-missing.js @@ -0,0 +1,28 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: Array.prototype.toSpliced(undefined) returns an empty array +info: | + 22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items ) + + ... + 3. Let relativeStart be ? ToIntegerOrInfinity(start). + ... + 6. Else, let actualStart be min(relativeStart, len). + ... + 8. If start is not present, then + a. Let actualDeleteCount be 0. + 8. Else if deleteCount is not present, then + a. Let actualDeleteCount be len - actualStart. + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var result = ["first", "second", "third"].toSpliced(undefined); + +assert.compareArray(result, []); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/this-value-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/this-value-boolean.js new file mode 100644 index 0000000000..0f97abcd1d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/this-value-boolean.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced converts booleans to objects +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + ... +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +assert.compareArray(Array.prototype.toSpliced.call(true, 0, 0), []); +assert.compareArray(Array.prototype.toSpliced.call(false, 0, 0), []); + +/* Add length and indexed properties to `Boolean.prototype` */ +Boolean.prototype.length = 3; +assert.compareArray(Array.prototype.toSpliced.call(true, 0, 0), [undefined, undefined, undefined]); +assert.compareArray(Array.prototype.toSpliced.call(false, 0, 0), [undefined, undefined, undefined]); +delete Boolean.prototype.length; +Boolean.prototype[0] = "monkeys"; +Boolean.prototype[2] = "bogus"; +assert.compareArray(Array.prototype.toSpliced.call(true, 0, 0), []); +assert.compareArray(Array.prototype.toSpliced.call(false, 0, 0), []); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/this-value-nullish.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/this-value-nullish.js new file mode 100644 index 0000000000..1230d05f00 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/this-value-nullish.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced throws if the receiver is null or undefined +info: | + Array.prototype.toSpliced ( start, deleteCount, ...items ) + + 1. Let O be ? ToObject(this value). + ... +features: [change-array-by-copy] +---*/ + +assert.throws(TypeError, () => { + Array.prototype.toSpliced.call(null, 0, 0); +}, '`Array.prototype.toSpliced.call(null)` throws TypeError'); + +assert.throws(TypeError, () => { + Array.prototype.toSpliced.call(undefined, 0, 0); +}, '`Array.prototype.toSpliced.call(undefined)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSpliced/unmodified.js b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/unmodified.js new file mode 100644 index 0000000000..d2983fd830 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/toSpliced/unmodified.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.toSpliced +description: > + Array.prototype.toSpliced returns a new array even if it the result is equal to the original array +features: [change-array-by-copy] +includes: [compareArray.js] +---*/ + +var arr = [1, 2, 3]; +var spliced = arr.toSpliced(1, 0); +assert.notSameValue(arr, spliced); +assert.compareArray(arr, spliced); + +reportCompare(0, 0); |