mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-19 23:05:28 +00:00
Merge
This commit is contained in:
commit
34bd48765e
@ -191,23 +191,21 @@ public final class NativeRegExp extends ScriptObject {
|
||||
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 @@ public final class NativeRegExp extends ScriptObject {
|
||||
appendReplacement(matcher, string, replacement, sb);
|
||||
}
|
||||
|
||||
// ECMA 15.5.4.10 String.prototype.match(regexp)
|
||||
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)
|
||||
if (thisIndex == previousLastIndex) {
|
||||
setLastIndex(thisIndex + 1);
|
||||
previousLastIndex = thisIndex + 1;
|
||||
@ -883,7 +886,7 @@ public final class NativeRegExp extends ScriptObject {
|
||||
* @return last index property as int
|
||||
*/
|
||||
public int getLastIndex() {
|
||||
return JSType.toInt32(lastIndex);
|
||||
return JSType.toInteger(lastIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -90,6 +90,7 @@ public final class GlobalFunctions {
|
||||
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 @@ public final class GlobalFunctions {
|
||||
}
|
||||
|
||||
boolean stripPrefix = true;
|
||||
int radix = JSType.toInt32(rad);
|
||||
|
||||
if (radix != 0) {
|
||||
if (radix < 2 || radix > 36) {
|
||||
@ -211,7 +211,7 @@ loop:
|
||||
switch (ch) {
|
||||
case '.':
|
||||
// dot allowed only once
|
||||
if (dotSeen) {
|
||||
if (exponentOffset != -1 || dotSeen) {
|
||||
break loop;
|
||||
}
|
||||
dotSeen = true;
|
||||
|
||||
37
nashorn/test/script/basic/JDK-8025197.js
Normal file
37
nashorn/test/script/basic/JDK-8025197.js
Normal file
@ -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'));
|
||||
7
nashorn/test/script/basic/JDK-8025197.js.EXPECTED
Normal file
7
nashorn/test/script/basic/JDK-8025197.js.EXPECTED
Normal file
@ -0,0 +1,7 @@
|
||||
dogs
|
||||
dos
|
||||
dog
|
||||
dogs
|
||||
dogs
|
||||
doss
|
||||
doss
|
||||
35
nashorn/test/script/basic/JDK-8025312.js
Normal file
35
nashorn/test/script/basic/JDK-8025312.js
Normal file
@ -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'");
|
||||
}
|
||||
});
|
||||
1
nashorn/test/script/basic/JDK-8025312.js.EXPECTED
Normal file
1
nashorn/test/script/basic/JDK-8025312.js.EXPECTED
Normal file
@ -0,0 +1 @@
|
||||
inside valueOf of 'radix'
|
||||
35
nashorn/test/script/basic/JDK-8025325.js
Normal file
35
nashorn/test/script/basic/JDK-8025325.js
Normal file
@ -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. "));
|
||||
5
nashorn/test/script/basic/JDK-8025325.js.EXPECTED
Normal file
5
nashorn/test/script/basic/JDK-8025325.js.EXPECTED
Normal file
@ -0,0 +1,5 @@
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
200
|
||||
66
nashorn/test/script/basic/JDK-8025434.js
Normal file
66
nashorn/test/script/basic/JDK-8025434.js
Normal file
@ -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");
|
||||
}
|
||||
55
nashorn/test/script/basic/JDK-8025486.js
Normal file
55
nashorn/test/script/basic/JDK-8025486.js
Normal file
@ -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);
|
||||
}
|
||||
3
nashorn/test/script/basic/JDK-8025486.js.EXPECTED
Normal file
3
nashorn/test/script/basic/JDK-8025486.js.EXPECTED
Normal file
@ -0,0 +1,3 @@
|
||||
source
|
||||
flags
|
||||
TypeError: Cannot supply flags when constructing one RegExp from another
|
||||
Loading…
x
Reference in New Issue
Block a user