Details
-
Sub-task
-
Resolution: Fixed
-
P4
-
None
-
None
-
b86
-
generic
-
generic
-
Verified
Description
(re = RegExp(), re.lastIndex = {valueOf:function(){print("lastIndex"); return 0}}, re.test(""))
=> should print "lastIndex"
ECMA 15.10.6.2 RegExp.prototype.exec(string)
Steps 5 to 7 are as follows:
4. Let lastIndex be the result of calling the [[Get]] internal method of R with argument "lastIndex"..
5. Let i be the value of ToInteger(lastIndex).
6. Let global be the result of calling the [[Get]] internal method of R with argument "global".
7. If global is false, then let i = 0
Nashorn code avoids [[Get]] on "lastIndex" when global is false - which prevents valueOf side-effect call.
The following diff fixes the issue:
diff -r 82fed56d8dce src/jdk/nashorn/internal/objects/NativeRegExp.java
--- a/src/jdk/nashorn/internal/objects/NativeRegExp.java Wed Apr 03 20:17:05 2013 +0530
+++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java Wed Apr 03 21:59:29 2013 +0530
@@ -523,8 +523,11 @@
}
private RegExpResult execInner(final String string) {
+ int start = getLastIndex();
+ if (! regexp.isGlobal()) {
+ start = 0;
+ }
- final int start = regexp.isGlobal() ? getLastIndex() : 0;
if (start < 0 || start > string.length()) {
setLastIndex(0);
return null;