-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Change Array by Copy" tests (stage 3) (#3464)
Co-authored-by: Ashley Claymore <acutmore@users.noreply.github.com> Co-authored-by: Tim Chevalier <tjc@igalia.com> Co-authored-by: Ms2ger <Ms2ger@igalia.com>
- Loading branch information
1 parent
77b559c
commit 6f4601d
Showing
119 changed files
with
3,626 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/built-ins/Array/prototype/Symbol.unscopables/change-array-by-copy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2021 Igalia. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: sec-array.prototype-@@unscopables | ||
description: > | ||
Initial value of `Symbol.unscopables` property | ||
info: | | ||
22.1.3.32 Array.prototype [ @@unscopables ] | ||
... | ||
12. Perform ! CreateDataPropertyOrThrow(unscopableList, "toReversed", true). | ||
13. Perform ! CreateDataPropertyOrThrow(unscopableList, "toSorted", true). | ||
14. Perform ! CreateDataPropertyOrThrow(unscopableList, "toSpliced", true). | ||
... | ||
includes: [propertyHelper.js] | ||
features: [Symbol.unscopables, change-array-by-copy] | ||
---*/ | ||
|
||
var unscopables = Array.prototype[Symbol.unscopables]; | ||
|
||
for (const unscopable of ["toReversed", "toSorted", "toSpliced"]) { | ||
verifyProperty(unscopables, unscopable, { | ||
value: true, | ||
writable: true, | ||
configurable: true | ||
}) | ||
}; | ||
|
||
assert.sameValue(Object.hasOwnProperty.call(unscopables, "with"), false, "does not have `with`"); |
18 changes: 18 additions & 0 deletions
18
test/built-ins/Array/prototype/toReversed/frozen-this-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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.toReversed | ||
description: > | ||
Array.prototype.toReversed works on frozen objects | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
var arr = Object.freeze([0, 1, 2]); | ||
var result = arr.toReversed(); | ||
assert.compareArray(result, [2, 1, 0]); | ||
|
||
var arrayLike = Object.freeze({ length: 3, 0: 0, 1: 1, 2: 2 }); | ||
result = Array.prototype.toReversed.call(arrayLike); | ||
assert.compareArray(result, [2, 1, 0]); |
49 changes: 49 additions & 0 deletions
49
test/built-ins/Array/prototype/toReversed/get-descending-order.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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.toReversed | ||
description: > | ||
Array.prototype.toReversed gets the array elements from the last one to the first one. | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
... | ||
5. Repeat, while k < len | ||
a. Let from be ! ToString(𝔽(len - k - 1)). | ||
... | ||
c. Let fromValue be ? Get(O, from). | ||
... | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
var order = []; | ||
var arrayLike = { | ||
length: 3, | ||
get 0() { | ||
order.push(0); | ||
}, | ||
get 1() { | ||
order.push(1); | ||
}, | ||
get 2() { | ||
order.push(2); | ||
}, | ||
}; | ||
|
||
Array.prototype.toReversed.call(arrayLike); | ||
|
||
assert.compareArray(order, [2, 1, 0]); | ||
|
||
order = []; | ||
var arr = [0, 1, 2]; | ||
Object.defineProperty(arr, 0, { get: function() { order.push(0); } }); | ||
Object.defineProperty(arr, 1, { get: function() { order.push(1); } }); | ||
Object.defineProperty(arr, 2, { get: function() { order.push(2); } }); | ||
|
||
Array.prototype.toReversed.call(arr); | ||
|
||
assert.compareArray(order, [2, 1, 0]); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Array/prototype/toReversed/holes-not-preserved.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.toReversed | ||
description: > | ||
Array.prototype.toReversed does not preserve holes in the array | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
... | ||
5. Repeat, while k < len | ||
a. Let from be ! ToString(𝔽(len - k - 1)). | ||
... | ||
c. Let fromValue be ? Get(O, from). | ||
d. Perform ? CreateDataPropertyOrThrow(A, Pk, fromValue). | ||
... | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
var arr = [0, /* hole */, 2, /* hole */, 4]; | ||
Array.prototype[3] = 3; | ||
|
||
var reversed = arr.toReversed(); | ||
assert.compareArray(reversed, [4, 3, 2, undefined, 0]); | ||
assert(reversed.hasOwnProperty(3)); |
31 changes: 31 additions & 0 deletions
31
test/built-ins/Array/prototype/toReversed/ignores-species.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.toReversed | ||
description: > | ||
Array.prototype.toReversed ignores @@species | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
3. Let A be ? ArrayCreate(𝔽(len)). | ||
... | ||
features: [change-array-by-copy] | ||
---*/ | ||
|
||
var a = []; | ||
a.constructor = {}; | ||
a.constructor[Symbol.species] = function () {} | ||
|
||
assert.sameValue(Object.getPrototypeOf(a.toReversed()), Array.prototype); | ||
|
||
var b = []; | ||
|
||
Object.defineProperty(b, "constructor", { | ||
get() { | ||
throw new Test262Error("Should not get .constructor"); | ||
} | ||
}); | ||
|
||
b.toReversed(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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.toReversed | ||
description: > | ||
Array.prototype.toReversed does not mutate its this value | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
var arr = [0, 1, 2]; | ||
arr.toReversed(); | ||
|
||
assert.compareArray(arr, [0, 1, 2]); | ||
assert.notSameValue(arr.toReversed(), arr); |
20 changes: 20 additions & 0 deletions
20
test/built-ins/Array/prototype/toReversed/length-casted-to-zero.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.toReversed | ||
description: > | ||
Array.prototype.toReversed creates an empty array if the this value .length is not a positive integer. | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
... | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
assert.compareArray(Array.prototype.toReversed.call({ length: -2 }), []); | ||
assert.compareArray(Array.prototype.toReversed.call({ length: "dog" }), []); | ||
assert.compareArray(Array.prototype.toReversed.call({ length: NaN }), []); |
32 changes: 32 additions & 0 deletions
32
test/built-ins/Array/prototype/toReversed/length-decreased-while-iterating.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.toReversed | ||
description: > | ||
Array.prototype.toReversed caches the length getting the array elements. | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
... | ||
5. Repeat, while k < len | ||
... | ||
c. Let fromValue be ? Get(O, from). | ||
... | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
var arr = [0, 1, 2, 3, 4]; | ||
Array.prototype[1] = 5; | ||
|
||
Object.defineProperty(arr, "3", { | ||
get() { | ||
arr.length = 1; | ||
return 3; | ||
} | ||
}); | ||
|
||
assert.compareArray(arr.toReversed(), [4, 3, undefined, 5, 0]); |
38 changes: 38 additions & 0 deletions
38
test/built-ins/Array/prototype/toReversed/length-exceeding-array-length-limit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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.toReversed | ||
description: > | ||
Array.prototype.toReversed limits the length to 2 ** 32 - 1 | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
3. Let A be ? ArrayCreate(𝔽(len)). | ||
... | ||
ArrayCreate ( length [, proto ] ) | ||
1. If length > 2 ** 32 - 1, throw a RangeError exception. | ||
features: [change-array-by-copy] | ||
---*/ | ||
|
||
// Object with large "length" property | ||
var arrayLike = { | ||
get "0"() { | ||
throw new Test262Error("Get 0"); | ||
}, | ||
get "4294967295" () { // 2 ** 32 - 1 | ||
throw new Test262Error("Get 2147483648"); | ||
}, | ||
get "4294967296" () { // 2 ** 32 | ||
throw new Test262Error("Get 2147483648"); | ||
}, | ||
length: 2 ** 32 | ||
}; | ||
|
||
assert.throws(RangeError, function() { | ||
Array.prototype.toReversed.call(arrayLike); | ||
}); |
30 changes: 30 additions & 0 deletions
30
test/built-ins/Array/prototype/toReversed/length-increased-while-iterating.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.toReversed | ||
description: > | ||
Array.prototype.toReversed caches the length getting the array elements. | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
... | ||
5. Repeat, while k < len | ||
... | ||
c. Let fromValue be ? Get(O, from). | ||
... | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
var arr = [0, 1, 2]; | ||
Object.defineProperty(arr, "0", { | ||
get() { | ||
arr.push(4); | ||
return 0; | ||
} | ||
}); | ||
|
||
assert.compareArray(arr.toReversed(), [2, 1, 0]); |
29 changes: 29 additions & 0 deletions
29
test/built-ins/Array/prototype/toReversed/length-tolength.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.toReversed | ||
description: > | ||
Array.prototype.toReversed converts the this value length to a number. | ||
info: | | ||
Array.prototype.toReversed ( ) | ||
... | ||
2. Let len be ? LengthOfArrayLike(O). | ||
... | ||
features: [change-array-by-copy] | ||
includes: [compareArray.js] | ||
---*/ | ||
|
||
assert.compareArray(Array.prototype.toReversed.call({ length: "2", 0: 1, 1: 2, 2: 3 }), [2, 1]); | ||
|
||
var arrayLike = { | ||
length: { | ||
valueOf: () => 2 | ||
}, | ||
0: 1, | ||
1: 2, | ||
2: 3, | ||
}; | ||
|
||
assert.compareArray(Array.prototype.toReversed.call(arrayLike), [2, 1]); |
30 changes: 30 additions & 0 deletions
30
test/built-ins/Array/prototype/toReversed/metadata/length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.toReversed | ||
description: > | ||
The "length" property of Array.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] | ||
features: [change-array-by-copy] | ||
---*/ | ||
|
||
verifyProperty(Array.prototype.toReversed, "length", { | ||
value: 0, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
}); |
Oops, something went wrong.