summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-stop-after-error.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-stop-after-error.js')
-rw-r--r--js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-stop-after-error.js44
1 files changed, 44 insertions, 0 deletions
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);