Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Change Array by Copy" tests (stage 3) #3464

Merged
merged 86 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
81a3f4d
Add `change-array-by-copy` feature flag
nicolo-ribaudo Dec 8, 2021
d4011b1
Add `Array.prototype.toReversed` tests
nicolo-ribaudo Dec 9, 2021
d3978b6
Add `Array.prototype.toSorted` tests
nicolo-ribaudo Dec 10, 2021
2a2dbd2
Add `Array.prototype.toSpliced` tests
nicolo-ribaudo Dec 13, 2021
81df178
Add `Array.prototype.with` tests
nicolo-ribaudo Dec 13, 2021
5ec6cfb
Add new `Array.prototype[Symbol.unscopables]` test
nicolo-ribaudo Dec 13, 2021
4ddf0c9
Add tests for `%TypedArray%.prototype.toReversed`
nicolo-ribaudo Dec 13, 2021
a37b2a3
Add `%TypedArray%.prototype.toSorted` tests
nicolo-ribaudo Dec 20, 2021
3dbcdda
Add `TypedArray%.prototype.toSpliced` tests
nicolo-ribaudo Dec 21, 2021
2148f66
Include `deepEqual.js` where needed
nicolo-ribaudo Dec 24, 2021
7ae0999
Fix many test bugs
nicolo-ribaudo Dec 27, 2021
205c8d9
%TypedArray%.prototype.with
nicolo-ribaudo Dec 28, 2021
c34e9b4
Fix max array length tests
nicolo-ribaudo Dec 31, 2021
cf150c6
Fix TypedArray `length-property-ignored` tests
nicolo-ribaudo Jan 3, 2022
447e95f
Fix `Array#toSpliced` `length-clamped-to-2pow53minus1.js
nicolo-ribaudo Jan 3, 2022
dd3eca4
Fix `with/index-casted-to-number.js` tests
nicolo-ribaudo Jan 3, 2022
a2557f4
`TypedArray#with` casts `-0` index to `0`
nicolo-ribaudo Jan 3, 2022
0368e08
Fix Array#toSpliced length-exceeding-array-length-limit.js
acutmore Jan 9, 2022
9e692b8
Test additional cases for long arrays in Array#toSpliced
catamorphism Mar 31, 2022
09b2d04
Add feature flags to TypedArray/prototype/toSpliced/deleteCount-undef…
catamorphism Apr 2, 2022
8446c3d
Add boundary test for long arrays in Array#toSpliced
acutmore Apr 2, 2022
a1e186c
Fix linting
nicolo-ribaudo Apr 4, 2022
2d89a31
Jordan's review
nicolo-ribaudo Apr 24, 2022
e924b8f
Use `compareArray` instead of `deepEqual`
nicolo-ribaudo Apr 24, 2022
81e4fe1
Verify results in frozen-this-value tests
catamorphism May 30, 2022
399af89
Check that array methods don't return the same value as `this` in imm…
catamorphism May 30, 2022
b14685d
Throw Test262Error in toSorted() tests
catamorphism May 30, 2022
07a732a
Add array cases to toReversed/get-descending-order and toSpliced/elem…
catamorphism Jun 2, 2022
2dcbe3b
Test TypedArray#with coverts number before loop
acutmore Jun 23, 2022
65845ba
add missing includes to frozen-this-value tests
acutmore Jun 23, 2022
4ebcca2
refer to TypedArray as %TypedArray%
acutmore Jun 24, 2022
22631f7
update test description
acutmore Jun 29, 2022
cf785ae
fixup: yaml is now valid
acutmore Jun 30, 2022
11663bb
fixup: typo toSpliced -> with
acutmore Jul 27, 2022
48f3a51
TypedArray toSpliced tests are no longer needed
acutmore Jul 27, 2022
23b7e34
BigIntTypedArray::with early type coercion tested
acutmore Aug 5, 2022
4064cce
Update test/built-ins/Array/prototype/toSorted/comparefn-called-after…
catamorphism Oct 4, 2022
5bf00ff
Update test/built-ins/Array/prototype/toSorted/comparefn-not-a-functi…
catamorphism Oct 4, 2022
e8ac5c2
Update test/built-ins/Array/prototype/toSorted/this-value-boolean.js
catamorphism Oct 4, 2022
6c9c853
Update test/built-ins/Array/prototype/toSpliced/deleteCount-clamped-b…
catamorphism Oct 4, 2022
29bd33f
Update test/built-ins/Array/prototype/toSpliced/discarded-element-not…
catamorphism Oct 4, 2022
9e24641
Update test/built-ins/Array/prototype/toSpliced/elements-read-in-orde…
catamorphism Oct 4, 2022
11aa06f
Update test/built-ins/TypedArray/prototype/with/index-negative.js
catamorphism Oct 4, 2022
af1ba68
Update test/built-ins/Array/prototype/toSorted/comparefn-stop-after-e…
catamorphism Oct 5, 2022
eb3c90c
Update test/built-ins/Array/prototype/toSorted/ignores-species.js
catamorphism Oct 5, 2022
9e1bd10
Update test/built-ins/Array/prototype/toSpliced/ignores-species.js
catamorphism Oct 5, 2022
f9b6b27
Update test/built-ins/Array/prototype/toSpliced/not-a-constructor.js
catamorphism Oct 5, 2022
dcb2706
Update test/built-ins/Array/prototype/toSpliced/start-bigger-than-len…
catamorphism Oct 5, 2022
ce64f8e
Update test/built-ins/Array/prototype/toSpliced/start-neg-infinity-is…
catamorphism Oct 5, 2022
8844e39
Update test/built-ins/Array/prototype/toSpliced/start-neg-less-than-m…
catamorphism Oct 5, 2022
b98572c
Update test/built-ins/Array/prototype/toSpliced/start-neg-subtracted-…
catamorphism Oct 5, 2022
8b3ddd2
Update test/built-ins/Array/prototype/toSpliced/this-value-boolean.js
catamorphism Oct 5, 2022
9847c33
Update test/built-ins/Array/prototype/with/index-bigger-or-eq-than-le…
catamorphism Oct 5, 2022
ed6b418
Update test/built-ins/TypedArray/prototype/toReversed/ignores-species.js
catamorphism Oct 5, 2022
f0faa9d
Update test/built-ins/TypedArray/prototype/toReversed/length-property…
catamorphism Oct 5, 2022
2a79ead
Update test/built-ins/TypedArray/prototype/toSorted/comparefn-not-a-f…
catamorphism Oct 5, 2022
11cc50a
Update test/built-ins/TypedArray/prototype/toSorted/comparefn-stop-af…
catamorphism Oct 5, 2022
0ed49b4
Update test/built-ins/TypedArray/prototype/toSorted/ignores-species.js
catamorphism Oct 5, 2022
ab0fce2
Update test/built-ins/TypedArray/prototype/toSorted/this-value-invali…
catamorphism Oct 5, 2022
0be6d47
Symbol.unscopables/change-array-by-copy: renumber steps
catamorphism Oct 4, 2022
0bc64ee
Rename length-integer-string.js to length-tolength.js
catamorphism Oct 4, 2022
0381a1a
Test boolean prototype mutation in this-value-boolean.js
catamorphism Oct 4, 2022
b5028f2
Array.prototype.toSorted: Test a BigInt value as an invalid comparator
catamorphism Oct 4, 2022
e821dae
Fix steps in toSpliced/delete-count-undefined
catamorphism Oct 4, 2022
24b3cc1
Fix steps in toSpliced/discarded-element-not-read
catamorphism Oct 4, 2022
2dbaace
Add hasOwnProperty checks to toSpliced/holes-not-preserved
catamorphism Oct 4, 2022
48144a9
Fix steps in with/ignores-species
catamorphism Oct 4, 2022
3c3c1ff
Fix info in with/this-value-invalid
catamorphism Oct 4, 2022
52e7b96
Fix steps in toSpliced/elements-read-in-order
catamorphism Oct 5, 2022
0395352
Fix steps in toSorted/holes-not-preserved
catamorphism Oct 5, 2022
d20bc23
Change 'Igalia' to 'Igalia, S.L.' in copyright block
catamorphism Oct 5, 2022
4e6094f
Clarify comment in toSpliced/length-casted-to-zero
catamorphism Oct 5, 2022
15b2595
Add a test for Array.toSpliced on an array with getters that mutate o…
catamorphism Oct 5, 2022
9c56d74
Rename toSpliced/length-integer-string to toSpliced/length-to-length
catamorphism Oct 5, 2022
17a5bac
Use verifyProperty in unscopables test
catamorphism Oct 5, 2022
90c8d70
Update steps for toSorted tests
catamorphism Oct 5, 2022
77c919f
Rename length-integer-string to length-tolength
catamorphism Oct 5, 2022
7cc9a9e
Check for notSameValue in toSpliced tests
catamorphism Oct 5, 2022
c5bbdcf
Update steps in toReversed tests
catamorphism Oct 5, 2022
8e9df5e
Fixes for TypedArray length-property-ignored and this-value-invalid t…
catamorphism Oct 5, 2022
d0c6700
Require calls <= 1 in toSorted/comparefn-stop-after-error
catamorphism Oct 5, 2022
9f81c96
Update test/built-ins/TypedArray/prototype/toReversed/this-value-inva…
catamorphism Oct 17, 2022
25aa62f
Update test/built-ins/TypedArray/prototype/toSorted/this-value-invali…
catamorphism Oct 18, 2022
67504a6
Update test/built-ins/Array/prototype/Symbol.unscopables/change-array…
catamorphism Oct 18, 2022
5fa7561
Test with Boolean.prototype.length set to a number in this-value-bool…
catamorphism Oct 17, 2022
b8c381f
Expand steps in comments in toSpliced/elements-read-in-order
catamorphism Oct 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ regexp-duplicate-named-groups
# https://github.com/tc39/proposal-symbols-as-weakmap-keys
symbols-as-weakmap-keys

# Array.prototype.toReversed, Array.prototype.toSorted, Array.prototype.toSpliced,
# Array.prototype.with and the equivalent TypedArray methods.
# https://github.com/tc39/proposal-change-array-by-copy/
change-array-by-copy

## Standard language features
#
# Language features that have been included in a published version of the
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2021 Igalia. All rights reserved.
catamorphism marked this conversation as resolved.
Show resolved Hide resolved
// 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 test/built-ins/Array/prototype/toReversed/frozen-this-value.js
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]);
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);
catamorphism marked this conversation as resolved.
Show resolved Hide resolved

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]);
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 test/built-ins/Array/prototype/toReversed/ignores-species.js
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();
16 changes: 16 additions & 0 deletions test/built-ins/Array/prototype/toReversed/immutable.js
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]);
catamorphism marked this conversation as resolved.
Show resolved Hide resolved
assert.notSameValue(arr.toReversed(), arr);
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 }), []);
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]);
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);
});
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 test/built-ins/Array/prototype/toReversed/length-tolength.js
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 test/built-ins/Array/prototype/toReversed/metadata/length.js
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,
});