summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/includes/length-boundaries.js
blob: 56811d9ca8f10daa55563afdac409b309e214d62 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-array.prototype.includes
description: length boundaries from ToLength operation
info: |
  22.1.3.11 Array.prototype.includes ( searchElement [ , fromIndex ] )

  ...
  2. Let len be ? ToLength(? Get(O, "length")).
  ...

  7.1.15 ToLength ( argument )

  1. Let len be ? ToInteger(argument).
  2. If len ≤ +0, return +0.
  3. If len is +∞, return 2**53-1.
  4. Return min(len, 2**53-1).
features: [Array.prototype.includes]
---*/

var obj = {
  "0": "a",
  "1": "b",
  "9007199254740990": "c", // 2 ** 53 - 2
  "9007199254740991": "d", // 2 ** 53 - 1
  "9007199254740992": "e", // 2 ** 53
};

obj.length = -0;
assert.sameValue([].includes.call(obj, "a"), false, "-0");

obj.length = -1;
assert.sameValue([].includes.call(obj, "a"), false, "-1");

obj.length = -0.1;
assert.sameValue([].includes.call(obj, "a"), false, "-0.1");

obj.length = -Infinity;
assert.sameValue([].includes.call(obj, "a"), false, "-Infinity");

var fromIndex = 9007199254740990;

obj.length = 9007199254740991;
assert.sameValue(
  [].includes.call(obj, "c", fromIndex),
  true,
  "2**53-1, found value at 2**53-2"
);

obj.length = 9007199254740991;
assert.sameValue(
  [].includes.call(obj, "d", fromIndex),
  false,
  "2**53-1, ignores indexes >= 2**53-1"
);

obj.length = 9007199254740992;
assert.sameValue(
  [].includes.call(obj, "d", fromIndex),
  false,
  "2**53, ignores indexes >= 2**53-1"
);

obj.length = 9007199254740993;
assert.sameValue(
  [].includes.call(obj, "d", fromIndex),
  false,
  "2**53+1, ignores indexes >= 2**53-1"
);

obj.length = Infinity;
assert.sameValue(
  [].includes.call(obj, "c", fromIndex),
  true,
  "Infinity, found item"
);
assert.sameValue(
  [].includes.call(obj, "d", fromIndex),
  false,
  "Infinity, ignores indexes >= 2**53-1"
);

reportCompare(0, 0);