# HG changeset patch # User hannesw # Date 1377185030 -7200 # Node ID 8ad9bcb04e6d288791bde2b6ddadfbd28e7903ab # Parent 54f60d91024c2da0dd1e61df7ada263db0bfd519 8023531: new RegExp('').toString() should return '/(?:)/' Reviewed-by: sundar, jlaskey diff -r 54f60d91024c -r 8ad9bcb04e6d src/jdk/nashorn/internal/runtime/ScriptObject.java --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Aug 22 18:46:26 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Aug 22 17:23:50 2013 +0200 @@ -1008,10 +1008,6 @@ return getMap().findProperty(key); } - static String convertKey(final Object key) { - return (key instanceof String) ? (String)key : JSType.toString(key); - } - /** * Overridden by {@link jdk.nashorn.internal.objects.NativeArguments} class (internal use.) * Used for argument access in a vararg function using parameter name. @@ -2374,7 +2370,7 @@ return array.getInt(index); } - return getInt(index, convertKey(key)); + return getInt(index, JSType.toString(key)); } @Override @@ -2386,7 +2382,7 @@ return array.getInt(index); } - return getInt(index, convertKey(key)); + return getInt(index, JSType.toString(key)); } @Override @@ -2398,7 +2394,7 @@ return array.getInt(index); } - return getInt(index, convertKey(key)); + return getInt(index, JSType.toString(key)); } @Override @@ -2409,7 +2405,7 @@ return array.getInt(key); } - return getInt(key, convertKey(key)); + return getInt(key, JSType.toString(key)); } private long getLong(final int index, final String key) { @@ -2451,7 +2447,7 @@ return array.getLong(index); } - return getLong(index, convertKey(key)); + return getLong(index, JSType.toString(key)); } @Override @@ -2463,7 +2459,7 @@ return array.getLong(index); } - return getLong(index, convertKey(key)); + return getLong(index, JSType.toString(key)); } @Override @@ -2475,7 +2471,7 @@ return array.getLong(index); } - return getLong(index, convertKey(key)); + return getLong(index, JSType.toString(key)); } @Override @@ -2486,7 +2482,7 @@ return array.getLong(key); } - return getLong(key, convertKey(key)); + return getLong(key, JSType.toString(key)); } private double getDouble(final int index, final String key) { @@ -2528,7 +2524,7 @@ return array.getDouble(index); } - return getDouble(index, convertKey(key)); + return getDouble(index, JSType.toString(key)); } @Override @@ -2540,7 +2536,7 @@ return array.getDouble(index); } - return getDouble(index, convertKey(key)); + return getDouble(index, JSType.toString(key)); } @Override @@ -2552,7 +2548,7 @@ return array.getDouble(index); } - return getDouble(index, convertKey(key)); + return getDouble(index, JSType.toString(key)); } @Override @@ -2563,7 +2559,7 @@ return array.getDouble(key); } - return getDouble(key, convertKey(key)); + return getDouble(key, JSType.toString(key)); } private Object get(final int index, final String key) { @@ -2605,7 +2601,7 @@ return array.getObject(index); } - return get(index, convertKey(key)); + return get(index, JSType.toString(key)); } @Override @@ -2617,7 +2613,7 @@ return array.getObject(index); } - return get(index, convertKey(key)); + return get(index, JSType.toString(key)); } @Override @@ -2629,7 +2625,7 @@ return array.getObject(index); } - return get(index, convertKey(key)); + return get(index, JSType.toString(key)); } @Override @@ -2640,7 +2636,7 @@ return array.getObject(key); } - return get(key, convertKey(key)); + return get(key, JSType.toString(key)); } /** @@ -2655,7 +2651,7 @@ final long longIndex = index & JSType.MAX_UINT; if (!getArray().has(index)) { - final String key = convertKey(longIndex); + final String key = JSType.toString(longIndex); final FindProperty find = findProperty(key, true); if (find != null) { @@ -2801,7 +2797,7 @@ return; } - final String propName = convertKey(key); + final String propName = JSType.toString(key); final FindProperty find = findProperty(propName, true); setObject(find, strict, propName, value); @@ -3023,7 +3019,7 @@ } } - final FindProperty find = findProperty(convertKey(key), true); + final FindProperty find = findProperty(JSType.toString(key), true); return find != null; } @@ -3040,7 +3036,7 @@ } } - final FindProperty find = findProperty(convertKey(key), true); + final FindProperty find = findProperty(JSType.toString(key), true); return find != null; } @@ -3057,7 +3053,7 @@ } } - final FindProperty find = findProperty(convertKey(key), true); + final FindProperty find = findProperty(JSType.toString(key), true); return find != null; } @@ -3074,7 +3070,7 @@ } } - final FindProperty find = findProperty(convertKey(key), true); + final FindProperty find = findProperty(JSType.toString(key), true); return find != null; } @@ -3087,7 +3083,7 @@ return true; } - final FindProperty find = findProperty(convertKey(key), false); + final FindProperty find = findProperty(JSType.toString(key), false); return find != null; } @@ -3100,7 +3096,7 @@ return true; } - final FindProperty find = findProperty(convertKey(key), false); + final FindProperty find = findProperty(JSType.toString(key), false); return find != null; } @@ -3113,7 +3109,7 @@ return true; } - final FindProperty find = findProperty(convertKey(key), false); + final FindProperty find = findProperty(JSType.toString(key), false); return find != null; } @@ -3126,7 +3122,7 @@ return true; } - final FindProperty find = findProperty(convertKey(key), false); + final FindProperty find = findProperty(JSType.toString(key), false); return find != null; } @@ -3196,7 +3192,7 @@ } private boolean deleteObject(final Object key, final boolean strict) { - final String propName = convertKey(key); + final String propName = JSType.toString(key); final FindProperty find = findProperty(propName, false); if (find == null) { diff -r 54f60d91024c -r 8ad9bcb04e6d src/jdk/nashorn/internal/runtime/WithObject.java --- a/src/jdk/nashorn/internal/runtime/WithObject.java Thu Aug 22 18:46:26 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Thu Aug 22 17:23:50 2013 +0200 @@ -73,7 +73,7 @@ public boolean delete(final Object key, final boolean strict) { if (expression instanceof ScriptObject) { final ScriptObject self = (ScriptObject)expression; - final String propName = ScriptObject.convertKey(key); + final String propName = JSType.toString(key); final FindProperty find = self.findProperty(propName, true); diff -r 54f60d91024c -r 8ad9bcb04e6d src/jdk/nashorn/internal/runtime/regexp/RegExp.java --- a/src/jdk/nashorn/internal/runtime/regexp/RegExp.java Thu Aug 22 18:46:26 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/regexp/RegExp.java Thu Aug 22 17:23:50 2013 +0200 @@ -60,7 +60,7 @@ * @param flags the flags string */ protected RegExp(final String source, final String flags) { - this.source = source; + this.source = source.length() == 0 ? "(?:)" : source; for (int i = 0; i < flags.length(); i++) { final char ch = flags.charAt(i); switch (ch) { diff -r 54f60d91024c -r 8ad9bcb04e6d test/script/basic/JDK-8023531.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8023531.js Thu Aug 22 17:23:50 2013 +0200 @@ -0,0 +1,106 @@ +/* + * 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-8023531: new RegExp('').toString() should return '/(?:)/' + * + * @test + * @run + */ + +if (new RegExp("").toString() !== "/(?:)/") { + throw new Error(); +} else if (!(new RegExp("").test(""))) { + throw new Error(); +} + +if (new RegExp("", "g").toString() !== "/(?:)/g") { + throw new Error(); +} else if (!(new RegExp("", "g").test(""))) { + throw new Error(); +} + +if (new RegExp("", "i").toString() !== "/(?:)/i") { + throw new Error(); +} else if (!(new RegExp("", "i").test(""))) { + throw new Error(); +} + +if (new RegExp("", "m").toString() !== "/(?:)/m") { + throw new Error(); +} else if (!(new RegExp("", "m").test(""))) { + throw new Error(); +} + +if (RegExp("").toString() !== "/(?:)/") { + throw new Error(); +} else if (!RegExp("").test("")) { + throw new Error(); +} + +if (RegExp("", "g").toString() !== "/(?:)/g") { + throw new Error(); +} else if (!RegExp("", "g").test("")) { + throw new Error(); +} + +if (RegExp("", "i").toString() !== "/(?:)/i") { + throw new Error(); +} else if (!RegExp("", "i").test("")) { + throw new Error(); +} + +if (RegExp("", "m").toString() !== "/(?:)/m") { + throw new Error(); +} else if (!RegExp("", "m").test("")) { + throw new Error(); +} + +var re = /abc/; +re.compile(""); +if (re.toString() !== "/(?:)/") { + throw new Error(); +} else if (!re.test("")) { + throw new Error(); +} + +re.compile("", "g"); +if (re.toString() !== "/(?:)/g") { + throw new Error(); +} else if (!re.test("")) { + throw new Error(); +} + +re.compile("", "i"); +if (re.toString() !== "/(?:)/i") { + throw new Error(); +} else if (!re.test("")) { + throw new Error(); +} + +re.compile("", "m"); +if (re.toString() !== "/(?:)/m") { + throw new Error(); +} else if (!re.test("")) { + throw new Error(); +}