changeset 69:819b5485949d

8007522: IllegalStateException thrown from String.prototype.search function Reviewed-by: jlaskey
author sundar
date Tue, 05 Feb 2013 21:00:04 +0530
parents c48e8a28da90
children f05d4dae30f7
files src/jdk/nashorn/internal/objects/NativeRegExp.java test/script/basic/JDK-8007522.js
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Feb 05 18:44:54 2013 +0530
+++ b/src/jdk/nashorn/internal/objects/NativeRegExp.java	Tue Feb 05 21:00:04 2013 +0530
@@ -675,7 +675,7 @@
         start = matcher.find(start) ? matcher.start() : -1;
 
         if (global) {
-            setLastIndex(matcher.end());
+            setLastIndex(start == -1? -1 : matcher.end());
         }
 
         return start;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8007522.js	Tue Feb 05 21:00:04 2013 +0530
@@ -0,0 +1,13 @@
+/**
+ * JDK-8007522: IllegalStateException thrown from String.prototype.search function
+ *
+ * @test
+ * @run
+ */
+
+var str = "hello";
+// search used to result in IllegalStateException
+if (str.search(/foo/g) != -1) {
+    fail("String.prototype.search failed");
+}
+