summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-lastindex-set.js
blob: f5ff21f3557b359f002f9ae97616029b81069539 (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
// Copyright (C) 2021 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
    lastIndex is set to 0 after exhausting the string when global and/or sticky are set.
esid: sec-regexpbuiltinexec
info: |
    RegExpBuiltinExec (
      _R_: an initialized RegExp instance,
      _S_: a String,
    )
    ...
    1. Let _length_ be the number of code units in _S_.
    2. Let _lastIndex_ be ℝ(? ToLength(? Get(_R_, *"lastIndex"*))).
    3. Let _flags_ be _R_.[[OriginalFlags]].
    4. If _flags_ contains *"g"*, let _global_ be *true*; else let _global_ be *false*.
    5. If _flags_ contains *"y"*, let _sticky_ be *true*; else let _sticky_ be *false*.
    ...
    9. Let _matchSucceeded_ be *false*.
    10. Repeat, while _matchSucceeded_ is *false*,
      a. If _lastIndex_ > _length_, then
        i. If _global_ is *true* or _sticky_ is *true*, then
          1. Perform ? Set(_R_, *"lastIndex"*, *+0*<sub>𝔽</sub>, *true*).
        ii. Return *null*.
features: [exponentiation]
---*/

var R_g = /./g, R_y = /./y, R_gy = /./gy;

var S = "test";

var lastIndex;
var bigLastIndexes = [
  Infinity,
  Number.MAX_VALUE,
  Number.MAX_SAFE_INTEGER,
  Number.MAX_SAFE_INTEGER - 1,
  2**32 + 4,
  2**32 + 3,
  2**32 + 2,
  2**32 + 1,
  2**32,
  2**32 - 1,
  5
];
for ( var i = 0; i < bigLastIndexes.length; i++ ) {
  lastIndex = bigLastIndexes[i];
  R_g.lastIndex = lastIndex;
  R_y.lastIndex = lastIndex;
  R_gy.lastIndex = lastIndex;

  assert.sameValue(R_g.exec(S), null,
      "global RegExp instance must fail to match against '" + S +
      "' at lastIndex " + lastIndex);
  assert.sameValue(R_y.exec(S), null,
      "sticky RegExp instance must fail to match against '" + S +
      "' at lastIndex " + lastIndex);
  assert.sameValue(R_gy.exec(S), null,
      "global sticky RegExp instance must fail to match against '" + S +
      "' at lastIndex " + lastIndex);

  assert.sameValue(R_g.lastIndex, 0,
      "global RegExp instance lastIndex must be reset after " + lastIndex +
      " exceeds string length");
  assert.sameValue(R_y.lastIndex, 0,
      "sticky RegExp instance lastIndex must be reset after " + lastIndex +
      " exceeds string length");
  assert.sameValue(R_gy.lastIndex, 0,
      "global sticky RegExp instance lastIndex must be reset after " + lastIndex +
      " exceeds string length");
}

reportCompare(0, 0);