Skip to content

Commit 9f40698

Browse files
committed
[GR-22188] Fixing an incorrect cast of lastIndex in RegExp.prototype[Symbol.replace].
PullRequest: js/1447
2 parents 1a9f79d + 3b95147 commit 9f40698

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/RegExpPrototypeBuiltins.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,13 @@ private String replaceAccordingToSpec(DynamicObject rx, String s, Object replace
11831183
}
11841184
if (global) {
11851185
if (matchLength == 0) {
1186-
int lastI = (int) toLength(getLastIndex(rx));
1187-
setLastIndex(rx, fullUnicode ? advanceStringIndexUnicode(s, lastI) : lastI + 1);
1186+
long lastI = toLength(getLastIndex(rx));
1187+
long nextIndex = lastI + 1;
1188+
if (JSRuntime.longIsRepresentableAsInt(nextIndex)) {
1189+
setLastIndex(rx, fullUnicode ? advanceStringIndexUnicode(s, (int) lastI) : (int) nextIndex);
1190+
} else {
1191+
setLastIndex(rx, (double) nextIndex);
1192+
}
11881193
}
11891194
} else {
11901195
break;

graal-js/test/test262.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,10 +1623,6 @@
16231623
"filePath" : "built-ins/RegExp/property-escapes/generated/XID_Start.js",
16241624
"status" : "SKIP",
16251625
"comment" : "Long-running generated Unicode tests."
1626-
}, {
1627-
"filePath" : "built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex.js",
1628-
"status" : "FAIL",
1629-
"comment" : "new failures update 2020-04-01"
16301626
}, {
16311627
"filePath" : "built-ins/String/prototype/toLowerCase/Final_Sigma_U180E.js",
16321628
"status" : "FAIL",

graal-js/test/testV8.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,10 +1442,6 @@
14421442
"filePath" : "mjsunit/regress/regress-798.js",
14431443
"status" : "SKIP",
14441444
"comment" : "spurious failures\njava.lang.IllegalStateException: This node cannot be replaced, because it does not yet have a parent. at com.oracle.truffle.api.nodes.Node.replaceHelper(Node.java:293), com.oracle.truffle.api.nodes.NodeUtil.nonAtomicReplace(NodeUtil.java:207), com.oracle.truffle.api.dsl.internal.SpecializationNode.insertAt(SpecializationNode.java:537), com.oracle.truffle.api.dsl.internal.SpecializationNode$InsertionEvent1.call(SpecializationNode.java:663), com.oracle.truffle.api.dsl.internal.SpecializationNode$InsertionEvent1.call(SpecializationNode.java:647)"
1445-
}, {
1446-
"filePath" : "mjsunit/regress/regress-799813.js",
1447-
"status" : "FAIL",
1448-
"comment" : "TODO: evaluate (V8 tests update 2018-10-29)"
14491445
}, {
14501446
"filePath" : "mjsunit/regress/regress-8033.js",
14511447
"status" : "FAIL",

0 commit comments

Comments
 (0)