summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/reduceRight/length-near-integer-limit.js
blob: 165ecebf1d554a4540929c9e344aef43a095783f (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
55
56
57
58
59
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-array.prototype.reduceright
description: >
  Elements are processed in an array-like object
  whose "length" property is near the integer limit.
info: |
  Array.prototype.reduceRight ( callbackfn [ , initialValue ] )

  1. Let O be ? ToObject(this value).
  2. Let len be ? LengthOfArrayLike(O).
  [...]
  9. Repeat, while k ≥ 0
    a. Let Pk be ! ToString(k).
    b. Let kPresent be ? HasProperty(O, Pk).
    c. If kPresent is true, then
      i. Let kValue be ? Get(O, Pk).
      ii. Set accumulator to ? Call(callbackfn, undefined, « accumulator, kValue, k, O »).
    [...]
includes: [compareArray.js]
---*/

var arrayLike = {
  length: Number.MAX_SAFE_INTEGER,
};

arrayLike[Number.MAX_SAFE_INTEGER - 1] = 1;
arrayLike[Number.MAX_SAFE_INTEGER - 3] = 3;

var accumulator = function(acc, el, index) {
  acc.push([el, index]);

  if (el === 3) {
    throw acc;
  }

  return acc;
};

try {
  Array.prototype.reduceRight.call(arrayLike, accumulator, []);
  throw new Test262Error("should not be called");
} catch (acc) {
  assert.sameValue(acc.length, 2, 'The value of acc.length is expected to be 2');
  assert.compareArray(
    acc[0],
    [1, Number.MAX_SAFE_INTEGER - 1],
    'The value of acc[0] is expected to be [1, Number.MAX_SAFE_INTEGER - 1]'
  );
  assert.compareArray(
    acc[1],
    [3, Number.MAX_SAFE_INTEGER - 3],
    'The value of acc[1] is expected to be [3, Number.MAX_SAFE_INTEGER - 3]'
  );
}

reportCompare(0, 0);