--- a/nashorn/src/jdk/nashorn/internal/objects/NativeRegExp.java Mon Sep 23 14:20:45 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/objects/NativeRegExp.java Thu Sep 26 16:37:21 2013 +0530
@@ -191,23 +191,21 @@
public static NativeRegExp newRegExp(final Object regexp, final Object flags) {
String patternString = "";
String flagString = "";
- boolean flagsDefined = false;
-
- if (flags != UNDEFINED) {
- flagsDefined = true;
- flagString = JSType.toString(flags);
- }
if (regexp != UNDEFINED) {
if (regexp instanceof NativeRegExp) {
- if (!flagsDefined) {
- return (NativeRegExp)regexp; // 15.10.3.1 - undefined flags and regexp as
+ if (flags != UNDEFINED) {
+ throw typeError("regex.cant.supply.flags");
}
- throw typeError("regex.cant.supply.flags");
+ return (NativeRegExp)regexp; // 15.10.3.1 - undefined flags and regexp as
}
patternString = JSType.toString(regexp);
}
+ if (flags != UNDEFINED) {
+ flagString = JSType.toString(flags);
+ }
+
return new NativeRegExp(patternString, flagString);
}
@@ -697,8 +695,13 @@
appendReplacement(matcher, string, replacement, sb);
}
+ thisIndex = matcher.end();
+ if (thisIndex == string.length() && matcher.start() == matcher.end()) {
+ // Avoid getting empty match at end of string twice
+ break;
+ }
+
// ECMA 15.5.4.10 String.prototype.match(regexp)
- thisIndex = matcher.end();
if (thisIndex == previousLastIndex) {
setLastIndex(thisIndex + 1);
previousLastIndex = thisIndex + 1;
@@ -883,7 +886,7 @@
* @return last index property as int
*/
public int getLastIndex() {
- return JSType.toInt32(lastIndex);
+ return JSType.toInteger(lastIndex);
}
/**
--- a/nashorn/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Mon Sep 23 14:20:45 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Thu Sep 26 16:37:21 2013 +0530
@@ -90,6 +90,7 @@
public static double parseInt(final Object self, final Object string, final Object rad) {
final String str = JSType.trimLeft(JSType.toString(string));
final int length = str.length();
+ int radix = JSType.toInt32(rad);
// empty string is not valid
if (length == 0) {
@@ -113,7 +114,6 @@
}
boolean stripPrefix = true;
- int radix = JSType.toInt32(rad);
if (radix != 0) {
if (radix < 2 || radix > 36) {
@@ -211,7 +211,7 @@
switch (ch) {
case '.':
// dot allowed only once
- if (dotSeen) {
+ if (exponentOffset != -1 || dotSeen) {
break loop;
}
dotSeen = true;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025197.js Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8025197: String replace method fails with regexp /$/gi
+ *
+ * @test
+ * @run
+ */
+
+print('dog'.replace(/$/gi, 's'));
+print('dog'.replace(/(?:g)$/gi, 's'));
+print('dog'.replace(/(?:a)$/gi, 's'));
+print('dog'.replace(/(?!g)$/gi, 's'));
+print('dog'.replace(/(?!a)$/gi, 's'));
+print('dog'.replace(/g?$/gi, 's'));
+print('dog'.replace(/.?$/gi, 's'));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025197.js.EXPECTED Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,7 @@
+dogs
+dos
+dog
+dogs
+dogs
+doss
+doss
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025312.js Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8025312: parseInt should convert 'radix' argument to ToInt32 even if empty string is parsed
+ *
+ * @test
+ * @run
+ */
+
+parseInt("", {
+ valueOf: function() {
+ print("inside valueOf of 'radix'");
+ }
+});
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025312.js.EXPECTED Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,1 @@
+inside valueOf of 'radix'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025325.js Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8025325: parseFloat does not handle '.' in exponent part
+ *
+ * @test
+ * @run
+ */
+
+print(parseFloat("2e2."));
+print(parseFloat("2e2.3"));
+print(parseFloat("2e2.fdgdf"));
+print(parseFloat("2e2. gdfgdf"));
+print(parseFloat("2e2. "));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025325.js.EXPECTED Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,5 @@
+200
+200
+200
+200
+200
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025434.js Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8025434: RegExp lastIndex can exceed int range
+ *
+ * @test
+ * @run
+ */
+
+var r = /a/g;
+
+r.lastIndex = 0x100000000;
+if (r.test("a")) {
+ throw new Error("Expected no match");
+}
+
+r.lastIndex = 0x100000000000000;
+if (r.test("a")) {
+ throw new Error("Expected no match");
+}
+
+r.lastIndex = -0x100000000;
+if (r.test("a")) {
+ throw new Error("Expected match");
+}
+
+r.lastIndex = -0x100000000000000;
+if (r.test("a")) {
+ throw new Error("Expected no match");
+}
+
+r.lastIndex = 1;
+if (r.test("a")) {
+ throw new Error("Expected no match");
+}
+
+r.lastIndex = -1;
+if (r.test("a")) {
+ throw new Error("Expected no match");
+}
+
+r.lastIndex = 0;
+if (!r.test("a")) {
+ throw new Error("Expected match");
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025486.js Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8025486: RegExp constructor arguments are not evaluated in right order
+ *
+ * @test
+ * @run
+ */
+
+new RegExp({
+ toString: function() {
+ print("source");
+ return "a";
+ }
+}, {
+ toString: function() {
+ print("flags");
+ return "g";
+ }
+});
+
+try {
+ new RegExp(/asdf/, {
+ toString: function() {
+ fail("toString should not be called");
+ }
+ });
+ fail("expected TypeError");
+} catch (e) {
+ if (!(e instanceof TypeError)) {
+ fail("expected TypeError");
+ }
+ print(e);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8025486.js.EXPECTED Thu Sep 26 16:37:21 2013 +0530
@@ -0,0 +1,3 @@
+source
+flags
+TypeError: Cannot supply flags when constructing one RegExp from another