summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/toSorted/comparefn-called-after-get-elements.js
blob: 41f7db3663327b33478ca15712ca3b19eaa16761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);