summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/RegExp/replace-local-tolength-lastindex.js
blob: 7ba840e000bb29d94e90a03e0f35ee1f645c4a68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// RegExp.prototype[@@replace] always executes ToLength(regExp.lastIndex) for
// non-global RegExps.

for (var flag of ["", "g", "y", "gy"]) {
    var regExp = new RegExp("a", flag);

    var called = false;
    regExp.lastIndex = {
        valueOf() {
            assertEq(called, false);
            called = true;
            return 0;
        }
    };

    assertEq(called, false);
    regExp[Symbol.replace]("");
    assertEq(called, !flag.includes("g"));
}

if (typeof reportCompare === "function")
    reportCompare(true, true);