blob: ed390cd2ed70a7fbd21ed5a1088f9ba7672a8686 (
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
|
// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Behavior when position is decremented during result accumulation
es6id: 21.2.5.8
info: |
16. Repeat, for each result in results,
[...]
p. If position ≥ nextSourcePosition, then
i. NOTE position should not normally move backwards. If it does, it
is an indication of an ill-behaving RegExp subclass or use of an
access triggered side-effect to change the global flag or other
characteristics of rx. In such cases, the corresponding
substitution is ignored.
ii. Let accumulatedResult be the String formed by concatenating the
code units of the current value of accumulatedResult with the
substring of S consisting of the code units from
nextSourcePosition (inclusive) up to position (exclusive) and
with the code units of replacement.
iii. Let nextSourcePosition be position + matchLength.
features: [Symbol.replace]
---*/
var r = /./g;
var callCount = 0;
r.exec = function() {
callCount += 1;
if (callCount === 1) {
return { index: 3, length: 1, 0: 0 };
} else if (callCount === 2) {
return { index: 1, length: 1, 0: 0 };
}
return null;
};
assert.sameValue(r[Symbol.replace]('abcde', 'X'), 'abcXe');
assert.sameValue(callCount, 3);
reportCompare(0, 0);
|