summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/toSorted/holes-not-preserved.js
blob: 1a88422f0dc862615433e4c672a877a8b94182c3 (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
// 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);