mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Test lastIndex overwrite with big lastIndex
This commit is contained in:
parent
f1bad717e2
commit
1a655779f0
57
test/built-ins/RegExp/prototype/exec/failure-lastindex-set.js
vendored
Normal file
57
test/built-ins/RegExp/prototype/exec/failure-lastindex-set.js
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// 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*.
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var R_g = /./g, R_y = /./y, R_gy = /./gy;
|
||||||
|
|
||||||
|
var S = "test";
|
||||||
|
|
||||||
|
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++ ) {
|
||||||
|
R_g.lastIndex = bigLastIndexes[i];
|
||||||
|
R_y.lastIndex = bigLastIndexes[i];
|
||||||
|
R_gy.lastIndex = bigLastIndexes[i];
|
||||||
|
|
||||||
|
assert.sameValue(R_g.exec(S), null);
|
||||||
|
assert.sameValue(R_y.exec(S), null);
|
||||||
|
assert.sameValue(R_gy.exec(S), null);
|
||||||
|
|
||||||
|
assert.sameValue(R_g.lastIndex, 0);
|
||||||
|
assert.sameValue(R_y.lastIndex, 0);
|
||||||
|
assert.sameValue(R_gy.lastIndex, 0);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user