summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/toSorted
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/toSorted')
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-called-after-get-elements.js45
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-not-a-function.js35
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-stop-after-error.js44
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/frozen-this-value.js20
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/holes-not-preserved.js27
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/ignores-species.js32
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/immutable.js18
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/length-casted-to-zero.js22
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/length-decreased-while-iterating.js33
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/length-exceeding-array-length-limit.js41
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/length-increased-while-iterating.js31
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/length-tolength.js31
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/length.js32
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/name.js30
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/property-descriptor.js27
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/this-value-boolean.js32
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/this-value-nullish.js24
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/zero-or-one-element.js22
23 files changed, 581 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/browser.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/browser.js
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-called-after-get-elements.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-called-after-get-elements.js
new file mode 100644
index 0000000000..41f7db3663
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-called-after-get-elements.js
@@ -0,0 +1,45 @@
+// 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.toSorted
+description: >
+ Array.prototype.toSorted reads all the array elements before calling compareFn
+info: |
+ SortIndexedProperties ( obj, len, SortCompare, skipHoles )
+
+ ...
+ 3. Repeat, while k < len,
+ a. Let Pk be ! ToString(š¯”½(k)).
+ ...
+ i. Let kValue be ? Get(O, Pk).
+ ...
+ 4. Sort items using an implementation-defined sequence of
+ calls to SortCompare. If any such call returns an abrupt
+ completion, stop before performing any further calls to
+ SortCompare or steps in this algorithm and return that
+ Completion Record.
+ ...
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+var getCalls = [];
+
+var arrayLike = {
+ length: 3,
+ get 0() { getCalls.push(0); return 2; },
+ get 1() { getCalls.push(1); return 1; },
+ get 2() { getCalls.push(2); return 3; },
+
+}
+
+assert.throws(Test262Error, function() {
+ Array.prototype.toSorted.call(arrayLike, () => {
+ throw new Test262Error();
+ });
+});
+
+assert.compareArray(getCalls, [0, 1, 2]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-not-a-function.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-not-a-function.js
new file mode 100644
index 0000000000..3a3e64627e
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-not-a-function.js
@@ -0,0 +1,35 @@
+// 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.toSorted
+description: >
+ Array.prototype.toSorted verifies that the comparator is callable before reading the length.
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception.
+ 2. ...
+ 3. Let len be ? LengthOfArrayLike(O).
+features: [change-array-by-copy]
+---*/
+
+var getLengthThrow = {
+ get length() {
+ throw new Test262Error("IsCallable(comparefn) should be observed before this.length");
+ }
+};
+
+var invalidComparators = [null, true, false, "", /a/g, 42, 42n, [], {}, Symbol()];
+
+for (var i = 0; i < invalidComparators.length; i++) {
+ assert.throws(TypeError, function() {
+ [1].toSorted(invalidComparators[i]);
+ }, String(invalidComparators[i]) + " on an array");
+
+ assert.throws(TypeError, function() {
+ Array.prototype.toSorted.call(getLengthThrow, invalidComparators[i]);
+ }, String(invalidComparators[i]) + " on an object whose 'length' throws");
+}
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-stop-after-error.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-stop-after-error.js
new file mode 100644
index 0000000000..6b36b3dccf
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-stop-after-error.js
@@ -0,0 +1,44 @@
+// 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.toSorted
+description: >
+ Array.prototype.toSorted doesn't call compareFn if there is an error
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 7. Sort items using an implementation-defined sequence of
+ calls to SortCompare. If any such call returns an abrupt
+ completion, stop before performing any further calls to
+ SortCompare or steps in this algorithm and return that completion.
+ ...
+features: [change-array-by-copy]
+---*/
+
+var arrayLike = {
+ length: 1,
+ get 0() { throw new Test262Error(); },
+};
+
+var called = false;
+assert.throws(Test262Error, function() {
+ Array.prototype.toSorted.call(arrayLike, () => {
+ called = true;
+ });
+});
+assert.sameValue(called, false);
+
+called = 0;
+assert.throws(Test262Error, function() {
+ [1, 2, 3].toSorted(() => {
+ ++called;
+ if (called === 1) {
+ throw new Test262Error();
+ }
+ });
+});
+assert.sameValue(called, 1);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/frozen-this-value.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/frozen-this-value.js
new file mode 100644
index 0000000000..0e4767e598
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/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.toSorted
+description: >
+ Array.prototype.toSorted works on frozen objects
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+var arr = Object.freeze([2, 0, 1]);
+var result = arr.toSorted();
+assert.compareArray(result, [0, 1, 2]);
+
+var arrayLike = Object.freeze({ length: 3, 0: 2, 1: 0, 2: 1 });
+result = Array.prototype.toSorted.call(arrayLike);
+assert.compareArray(result, [0, 1, 2]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/holes-not-preserved.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/holes-not-preserved.js
new file mode 100644
index 0000000000..1a88422f0d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/holes-not-preserved.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.toSorted
+description: >
+ Array.prototype.toSorted does not preserve holes in the array
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 8. Repeat, while j < len,
+ a. Perform ! CreateDataPropertyOrThrow(A, ! ToString(š¯”½(j)), sortedList[j]).
+ b. Set j to j + 1.
+ ...
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+var arr = [3, /* hole */, 4, /* hole */, 1];
+Array.prototype[3] = 2;
+
+var sorted = arr.toSorted();
+assert.compareArray(sorted, [1, 2, 3, 4, undefined]);
+assert(sorted.hasOwnProperty(4));
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/ignores-species.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/ignores-species.js
new file mode 100644
index 0000000000..78c9656550
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/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.toSorted
+description: >
+ Array.prototype.toSorted ignores @@species
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 8. Let A be ? ArrayCreate(š¯”½(len)).
+ ...
+features: [change-array-by-copy]
+---*/
+
+var a = [];
+a.constructor = {};
+a.constructor[Symbol.species] = function () {}
+
+assert.sameValue(Object.getPrototypeOf(a.toSorted()), Array.prototype);
+
+var b = [];
+Object.defineProperty(b, "constructor", {
+ get() {
+ throw new Test262Error("Should not get .constructor");
+ }
+});
+
+b.toSorted();
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/immutable.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/immutable.js
new file mode 100644
index 0000000000..2fb611d109
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/immutable.js
@@ -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.toSorted
+description: >
+ Array.prototype.toSorted does not mutate its this value
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+var arr = [2, 0, 1];
+arr.toSorted();
+
+assert.compareArray(arr, [2, 0, 1]);
+assert.notSameValue(arr.toSorted(), arr);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-casted-to-zero.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-casted-to-zero.js
new file mode 100644
index 0000000000..c058ba8d8c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-casted-to-zero.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.toSorted
+description: >
+ Array.prototype.toSorted creates an empty array if the this value .length is not a positive integer.
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 3. Let len be ? LengthOfArrayLike(O).
+ ...
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+assert.compareArray(Array.prototype.toSorted.call({ length: -2 }), []);
+assert.compareArray(Array.prototype.toSorted.call({ length: "dog" }), []);
+assert.compareArray(Array.prototype.toSorted.call({ length: NaN }), []);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-decreased-while-iterating.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-decreased-while-iterating.js
new file mode 100644
index 0000000000..ce48724aa9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-decreased-while-iterating.js
@@ -0,0 +1,33 @@
+// 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.toSorted
+description: >
+ Array.prototype.toSorted caches the length getting the array elements.
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 3. Let len be ? LengthOfArrayLike(O).
+ ...
+ 6. Let sortedList be ? SortIndexedProperties(obj, len, SortCompare, false).
+ ...
+
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+var arr = [5, 1, 4, 6, 3];
+Array.prototype[3] = 2;
+
+Object.defineProperty(arr, "2", {
+ get() {
+ arr.length = 1;
+ return 4;
+ }
+});
+
+assert.compareArray(arr.toSorted(), [1, 2, 4, 5, undefined]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-exceeding-array-length-limit.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-exceeding-array-length-limit.js
new file mode 100644
index 0000000000..a6619963f4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-exceeding-array-length-limit.js
@@ -0,0 +1,41 @@
+// 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.toSorted
+description: >
+ Array.prototype.toSorted limits the length to 2 ** 32 - 1
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 3. Let len be ? LengthOfArrayLike(O).
+ ...
+ 8. Let A be ? ArrayCreate(š¯”½(len)).
+ ...
+
+ 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 2147483648");
+ },
+ get "4294967296" () { // 2 ** 32
+ throw new Test262Error("Get 2147483648");
+ },
+ length: 2 ** 32
+};
+
+assert.throws(RangeError, function() {
+ Array.prototype.toSorted.call(arrayLike);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-increased-while-iterating.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-increased-while-iterating.js
new file mode 100644
index 0000000000..2843d92f54
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-increased-while-iterating.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.toSorted
+description: >
+ Array.prototype.toSorted caches the length getting the array elements.
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 3. Let len be ? LengthOfArrayLike(O).
+ ...
+ 6. Let sortedList be ? SortIndexedProperties(obj, len, SortCompare, false).
+ ...
+
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+var arr = [5, 0, 3];
+Object.defineProperty(arr, "0", {
+ get() {
+ arr.push(1);
+ return 5;
+ }
+});
+
+assert.compareArray(arr.toSorted(), [0, 3, 5]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-tolength.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/length-tolength.js
new file mode 100644
index 0000000000..4e6344428d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/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.toSorted
+description: >
+ Array.prototype.toSorted converts the this value length to a number.
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ ...
+ 3. Let len be ? LengthOfArrayLike(O).
+ ...
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+assert.compareArray(Array.prototype.toSorted.call({ length: "2", 0: 4, 1: 0, 2: 1 }), [0, 4]);
+
+var arrayLike = {
+ length: {
+ valueOf: () => 2
+ },
+ 0: 4,
+ 1: 0,
+ 2: 1,
+};
+
+assert.compareArray(Array.prototype.toSorted.call(arrayLike), [0, 4]);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/browser.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/browser.js
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/length.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/length.js
new file mode 100644
index 0000000000..196bf5b3b1
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/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.toSorted
+description: >
+ The "length" property of Array.prototype.toSorted
+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.toSorted, "length", {
+ value: 1,
+ writable: false,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/name.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/name.js
new file mode 100644
index 0000000000..f2d7a8bf68
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/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.toSorted
+description: >
+ Array.prototype.toSorted.name is "toSorted".
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ 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.toSorted, "name", {
+ value: "toSorted",
+ writable: false,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/property-descriptor.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/property-descriptor.js
new file mode 100644
index 0000000000..cc58c83d0f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/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.toSorted
+description: >
+ "toSorted" 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.toSorted, "function", "typeof");
+
+verifyProperty(Array.prototype, "toSorted", {
+ value: Array.prototype.toSorted,
+ writable: true,
+ enumerable: false,
+ configurable: true,
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/shell.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/metadata/shell.js
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/not-a-constructor.js
new file mode 100644
index 0000000000..dda671c3ee
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/not-a-constructor.js
@@ -0,0 +1,35 @@
+// 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.toSorted 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.toSorted),
+ false,
+ 'isConstructor(Array.prototype.toSorted) must return false'
+);
+
+assert.throws(TypeError, () => {
+ new Array.prototype.toSorted();
+}, '`new Array.prototype.toSorted()` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/shell.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/shell.js
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/this-value-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/this-value-boolean.js
new file mode 100644
index 0000000000..323b8df9f5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/this-value-boolean.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.toSorted
+description: >
+ Array.prototype.toSorted converts booleans to objects
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ 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.toSorted.call(true), []);
+assert.compareArray(Array.prototype.toSorted.call(false), []);
+
+
+/* Add length and indexed properties to `Boolean.prototype` */
+Boolean.prototype.length = 3;
+assert.compareArray(Array.prototype.toSorted.call(true), [undefined, undefined, undefined]);
+assert.compareArray(Array.prototype.toSorted.call(false), [undefined, undefined, undefined]);
+delete Boolean.prototype.length;
+Boolean.prototype[0] = "monkeys";
+Boolean.prototype[2] = "bogus";
+assert.compareArray(Array.prototype.toSorted.call(true), []);
+assert.compareArray(Array.prototype.toSorted.call(false), []);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/this-value-nullish.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/this-value-nullish.js
new file mode 100644
index 0000000000..65690075df
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/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.toSorted
+description: >
+ Array.prototype.toSorted throws if the receiver is null or undefined
+info: |
+ Array.prototype.toSorted ( compareFn )
+
+ 1. Let O be ? ToObject(this value).
+ ...
+features: [change-array-by-copy]
+---*/
+
+assert.throws(TypeError, () => {
+ Array.prototype.toSorted.call(null);
+}, '`Array.prototype.toSorted.call(null)` throws TypeError');
+
+assert.throws(TypeError, () => {
+ Array.prototype.toSorted.call(undefined);
+}, '`Array.prototype.toSorted.call(undefined)` throws TypeError');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/Array/prototype/toSorted/zero-or-one-element.js b/js/src/tests/test262/built-ins/Array/prototype/toSorted/zero-or-one-element.js
new file mode 100644
index 0000000000..42026d538f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/prototype/toSorted/zero-or-one-element.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.toSorted
+description: >
+ Array.prototype.toSorted returns a new array even if it has zero or one elements
+features: [change-array-by-copy]
+includes: [compareArray.js]
+---*/
+
+var zero = [];
+var zeroReversed = zero.toSorted();
+assert.notSameValue(zero, zeroReversed);
+assert.compareArray(zero, zeroReversed);
+
+var one = [1];
+var oneReversed = one.toSorted();
+assert.notSameValue(one, oneReversed);
+assert.compareArray(one, oneReversed);
+
+reportCompare(0, 0);