summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/toSpliced/discarded-element-not-read.js
blob: 1544086f47b553a4a8e41a1a43051bc9bd7b74fc (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
46
47
48
49
50
51
52
53
54
// 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.toSpliced
description: Array.prototype.toSpliced does not Get the discarded elements in the original array
info: |
  22.1.3.25 Array.prototype.toSpliced (start, deleteCount , ...items )

  ...
  3. Let relativeStart be ? ToIntegerOrInfinity(start).
  ...
  6. Else, let actualStart be min(relativeStart, len).
  ...
  8. If start is not present, then
    a. Let actualDeleteCount be 0.
  9. Else if deleteCount is not present, then
    a. Let actualDeleteCount be len - actualStart.
  10. Else,
    a. Let dc be ? ToIntegerOrInfinity(deleteCount).
    b. Let actualDeleteCount be the result of clamping dc between 0 and len - actualStart.
  11. Let newLen be len + insertCount - actualDeleteCount.
  ...
  15. Let r be actualStart + actualDeleteCount.
  ...
  18. Repeat, while i < newLen,
    a. Let Pi be ! ToString(𝔽(i)).
    b. Let from be ! ToString(𝔽(r)).
    c. Let fromValue be ? Get(O, from).
    d. Perform ! CreateDataPropertyOrThrow(A, Pi, fromValue).
    e. Set i to i + 1.
    f. Set r to r + 1.

features: [change-array-by-copy]
includes: [compareArray.js]
---*/

var arrayLike = {
  0: "a",
  1: "b",
  get 2() { throw new Test262Error(); },
  3: "c",
  length: 4,
};

/*
 * In this example, just before step 18, i == 2 and r == 3.
 * So A[2] is set to arrayLike[3] and arrayLike[2] is never read
 * (since i and r both increase monotonically).
 */
var result = Array.prototype.toSpliced.call(arrayLike, 2, 1);
assert.compareArray(result, ["a", "b", "c"]);

reportCompare(0, 0);