# HG changeset patch # User sundar # Date 1372770581 -19800 # Node ID f15ea942c8a42ccb35145ddcb8ed341d8c609ca3 # Parent 33f304726f33e4a68d47328d425a24c0a9b51b15# Parent 433fc717df0e192e08edd95e08b57870e73bda29 Merge diff -r 33f304726f33 -r f15ea942c8a4 nashorn/make/build.xml --- a/nashorn/make/build.xml Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/make/build.xml Tue Jul 02 18:39:41 2013 +0530 @@ -124,7 +124,7 @@ - + @@ -139,7 +139,13 @@ - + + + + + + + Builds the javafx shell. @@ -238,7 +244,7 @@ - + @@ -462,24 +468,24 @@ - + - + - + - + - + diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/api/scripting/NashornException.java --- a/nashorn/src/jdk/nashorn/api/scripting/NashornException.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/api/scripting/NashornException.java Tue Jul 02 18:39:41 2013 +0530 @@ -172,12 +172,13 @@ final StringBuilder buf = new StringBuilder(); final StackTraceElement[] frames = getScriptFrames((Throwable)exception); for (final StackTraceElement st : frames) { + buf.append("\tat "); buf.append(st.getMethodName()); - buf.append(" @ "); + buf.append(" ("); buf.append(st.getFileName()); buf.append(':'); buf.append(st.getLineNumber()); - buf.append('\n'); + buf.append(")\n"); } final int len = buf.length(); // remove trailing '\n' diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java --- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Jul 02 18:39:41 2013 +0530 @@ -1110,7 +1110,7 @@ * @return the method generator that was used */ private MethodEmitter loadArray(final ArrayLiteralNode arrayLiteralNode, final ArrayType arrayType) { - assert arrayType == Type.INT_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY; + assert arrayType == Type.INT_ARRAY || arrayType == Type.LONG_ARRAY || arrayType == Type.NUMBER_ARRAY || arrayType == Type.OBJECT_ARRAY; final Node[] nodes = arrayLiteralNode.getValue(); final Object presets = arrayLiteralNode.getPresets(); @@ -1462,7 +1462,9 @@ rhs = tmp; } - if (isNullLiteral(rhs)) { + // this is a null literal check, so if there is implicit coercion + // involved like {D}x=null, we will fail - this is very rare + if (isNullLiteral(rhs) && lhs.getType().isObject()) { final Label trueLabel = new Label("trueLabel"); final Label falseLabel = new Label("falseLabel"); final Label endLabel = new Label("end"); @@ -1845,7 +1847,8 @@ // If expression not int see if we can convert, if not use deflt to trigger default. if (!type.isInteger()) { method.load(deflt); - method.invoke(staticCallNoLookup(ScriptRuntime.class, "switchTagAsInt", int.class, type.getTypeClass(), int.class)); + final Class exprClass = type.getTypeClass(); + method.invoke(staticCallNoLookup(ScriptRuntime.class, "switchTagAsInt", int.class, exprClass.isPrimitive()? exprClass : Object.class, int.class)); } // If reasonable size and not too sparse (80%), use table otherwise use lookup. diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/codegen/types/Type.java --- a/nashorn/src/jdk/nashorn/internal/codegen/types/Type.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/codegen/types/Type.java Tue Jul 02 18:39:41 2013 +0530 @@ -36,6 +36,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.IALOAD; import static jdk.internal.org.objectweb.asm.Opcodes.IASTORE; import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESTATIC; +import static jdk.internal.org.objectweb.asm.Opcodes.LALOAD; import static jdk.internal.org.objectweb.asm.Opcodes.LASTORE; import static jdk.internal.org.objectweb.asm.Opcodes.NEWARRAY; import static jdk.internal.org.objectweb.asm.Opcodes.POP; @@ -43,6 +44,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.SWAP; import static jdk.internal.org.objectweb.asm.Opcodes.T_DOUBLE; import static jdk.internal.org.objectweb.asm.Opcodes.T_INT; +import static jdk.internal.org.objectweb.asm.Opcodes.T_LONG; import java.lang.invoke.MethodHandle; import java.util.Collections; @@ -729,19 +731,19 @@ @Override public Type aload(final MethodVisitor method) { - method.visitInsn(IALOAD); - return INT; + method.visitInsn(LALOAD); + return LONG; } @Override public Type newarray(final MethodVisitor method) { - method.visitIntInsn(NEWARRAY, T_INT); + method.visitIntInsn(NEWARRAY, T_LONG); return this; } @Override public Type getElementType() { - return INT; + return LONG; } }; diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java --- a/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/ir/LiteralNode.java Tue Jul 02 18:39:41 2013 +0530 @@ -621,8 +621,10 @@ elementType = Type.INT; analyzeElements(); - if (elementType == Type.INT) { + if (elementType.isInteger()) { presetIntArray(); + } else if (elementType.isLong()) { + presetLongArray(); } else if (elementType.isNumeric()) { presetNumberArray(); } else { @@ -649,6 +651,25 @@ postsets = Arrays.copyOf(computed, nComputed); } + private void presetLongArray() { + final long[] array = new long[value.length]; + final int[] computed = new int[value.length]; + int nComputed = 0; + + for (int i = 0; i < value.length; i++) { + final Object element = objectAsConstant(value[i]); + + if (element instanceof Number) { + array[i] = ((Number)element).longValue(); + } else { + computed[nComputed++] = i; + } + } + + presets = array; + postsets = Arrays.copyOf(computed, nComputed); + } + private void presetNumberArray() { final double[] array = new double[value.length]; final int[] computed = new int[value.length]; @@ -746,6 +767,8 @@ public Type getType() { if (elementType.isInteger()) { return Type.INT_ARRAY; + } else if (elementType.isLong()) { + return Type.LONG_ARRAY; } else if (elementType.isNumeric()) { return Type.NUMBER_ARRAY; } else { diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/objects/NativeError.java --- a/nashorn/src/jdk/nashorn/internal/objects/NativeError.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/objects/NativeError.java Tue Jul 02 18:39:41 2013 +0530 @@ -30,10 +30,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; -import java.util.ArrayList; -import java.util.List; import jdk.nashorn.api.scripting.NashornException; -import jdk.nashorn.internal.codegen.CompilerConstants; import jdk.nashorn.internal.lookup.MethodHandleFactory; import jdk.nashorn.internal.objects.annotations.Attribute; import jdk.nashorn.internal.objects.annotations.Constructor; @@ -41,7 +38,6 @@ import jdk.nashorn.internal.objects.annotations.Property; import jdk.nashorn.internal.objects.annotations.ScriptClass; import jdk.nashorn.internal.objects.annotations.Where; -import jdk.nashorn.internal.runtime.ECMAErrors; import jdk.nashorn.internal.runtime.ECMAException; import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.PropertyMap; @@ -123,13 +119,14 @@ * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided. * * @param self self reference + * @return undefined */ @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) public static Object captureStackTrace(final Object self, final Object errorObj) { Global.checkObject(errorObj); final ScriptObject sobj = (ScriptObject)errorObj; final ECMAException exp = new ECMAException(sobj, null); - sobj.set("stack", NashornException.getScriptStackString(exp), false); + sobj.set("stack", getScriptStackString(sobj, exp), false); return UNDEFINED; } @@ -288,7 +285,7 @@ final Object exception = ECMAException.getException(sobj); if (exception instanceof Throwable) { - return NashornException.getScriptStackString((Throwable)exception); + return getScriptStackString(sobj, (Throwable)exception); } else { return ""; } @@ -362,4 +359,8 @@ throw new MethodHandleFactory.LookupException(e); } } + + private static String getScriptStackString(final ScriptObject sobj, final Throwable exp) { + return JSType.toString(sobj) + "\n" + NashornException.getScriptStackString(exp); + } } diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java --- a/nashorn/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/objects/NativeRegExpExecResult.java Tue Jul 02 18:39:41 2013 +0530 @@ -61,6 +61,11 @@ this.input = result.getInput(); } + @Override + public String getClassName() { + return "Array"; + } + /** * Length getter * @param self self reference diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/parser/Parser.java --- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java Tue Jul 02 18:39:41 2013 +0530 @@ -535,15 +535,12 @@ if (!(lhs instanceof AccessNode || lhs instanceof IndexNode || lhs instanceof IdentNode)) { - if (env._early_lvalue_error) { - throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken()); - } - return referenceError(lhs, rhs); + return referenceError(lhs, rhs, env._early_lvalue_error); } if (lhs instanceof IdentNode) { if (!checkIdentLValue((IdentNode)lhs)) { - return referenceError(lhs, rhs); + return referenceError(lhs, rhs, false); } verifyStrictIdent((IdentNode)lhs, "assignment"); } @@ -767,8 +764,6 @@ case LBRACE: block(); break; - case RBRACE: - break; case VAR: variableStatement(true); break; @@ -1267,6 +1262,7 @@ case RBRACE: case SEMICOLON: case EOL: + case EOF: break; default: @@ -1314,6 +1310,7 @@ case RBRACE: case SEMICOLON: case EOL: + case EOF: break; default: @@ -1368,6 +1365,7 @@ case RBRACE: case SEMICOLON: case EOL: + case EOF: break; default: @@ -1403,6 +1401,7 @@ case RBRACE: case SEMICOLON: case EOL: + case EOF: break; default: @@ -1928,7 +1927,7 @@ // Object context. // Prepare to accumulate elements. - // final List elements = new ArrayList<>(); + // final List elements = new ArrayList<>(); final Map map = new LinkedHashMap<>(); // Create a block for the object literal. @@ -1941,6 +1940,9 @@ break loop; case COMMARIGHT: + if (commaSeen) { + throw error(AbstractParser.message("expected.property.id", type.getNameOrType())); + } next(); commaSeen = true; break; @@ -2566,7 +2568,7 @@ */ // just expression as function body - final Node expr = expression(); + final Node expr = assignmentExpression(true); assert lc.getCurrentBlock() == lc.getFunctionBody(functionNode); // create a return statement - this creates code in itself and does not need to be // wrapped into an ExecuteNode @@ -2612,7 +2614,10 @@ } } - private static RuntimeNode referenceError(final Node lhs, final Node rhs) { + private RuntimeNode referenceError(final Node lhs, final Node rhs, final boolean earlyError) { + if (earlyError) { + throw error(JSErrorType.REFERENCE_ERROR, AbstractParser.message("invalid.lvalue"), lhs.getToken()); + } final ArrayList args = new ArrayList<>(); args.add(lhs); if (rhs == null) { @@ -2690,18 +2695,18 @@ final Node lhs = leftHandSideExpression(); // ++, -- without operand.. if (lhs == null) { - // error would have been issued when looking for 'lhs' - return null; + throw error(AbstractParser.message("expected.lvalue", type.getNameOrType())); } + if (!(lhs instanceof AccessNode || lhs instanceof IndexNode || lhs instanceof IdentNode)) { - return referenceError(lhs, null); + return referenceError(lhs, null, env._early_lvalue_error); } if (lhs instanceof IdentNode) { if (!checkIdentLValue((IdentNode)lhs)) { - return referenceError(lhs, null); + return referenceError(lhs, null, false); } verifyStrictIdent((IdentNode)lhs, "operand for " + opType.getName() + " operator"); } @@ -2720,16 +2725,21 @@ case DECPREFIX: final TokenType opType = type; final Node lhs = expression; + // ++, -- without operand.. + if (lhs == null) { + throw error(AbstractParser.message("expected.lvalue", type.getNameOrType())); + } + if (!(lhs instanceof AccessNode || lhs instanceof IndexNode || lhs instanceof IdentNode)) { next(); - return referenceError(lhs, null); + return referenceError(lhs, null, env._early_lvalue_error); } if (lhs instanceof IdentNode) { if (!checkIdentLValue((IdentNode)lhs)) { next(); - return referenceError(lhs, null); + return referenceError(lhs, null, false); } verifyStrictIdent((IdentNode)lhs, "operand for " + opType.getName() + " operator"); } diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java --- a/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/runtime/ECMAException.java Tue Jul 02 18:39:41 2013 +0530 @@ -51,7 +51,7 @@ /** Field handle to the{@link ECMAException#thrown} field, so that it can be accessed from generated code */ public static final FieldAccess THROWN = virtualField(ECMAException.class, "thrown", Object.class); - public static final String EXCEPTION_PROPERTY = "nashornException"; + private static final String EXCEPTION_PROPERTY = "nashornException"; /** Object thrown. */ public final Object thrown; diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/runtime/JSType.java --- a/nashorn/src/jdk/nashorn/internal/runtime/JSType.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/runtime/JSType.java Tue Jul 02 18:39:41 2013 +0530 @@ -911,7 +911,7 @@ for (int i = start; i < length ; i++) { if (digit(chars[i], radix) == -1) { - break; + return Double.NaN; } pos++; } diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java --- a/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Tue Jul 02 18:39:41 2013 +0530 @@ -127,6 +127,17 @@ * @param deflt default to use if not convertible. * @return int tag value (or deflt.) */ + public static int switchTagAsInt(final boolean tag, final int deflt) { + return deflt; + } + + /** + * Converts a switch tag value to a simple integer. deflt value if it can't. + * + * @param tag Switch statement tag value. + * @param deflt default to use if not convertible. + * @return int tag value (or deflt.) + */ public static int switchTagAsInt(final long tag, final int deflt) { return isRepresentableAsInt(tag) ? (int)tag : deflt; } diff -r 33f304726f33 -r f15ea942c8a4 nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties --- a/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Jul 02 18:39:41 2013 +0530 @@ -42,6 +42,8 @@ parser.error.expected.operand=Expected an operand but found {0} parser.error.expected.stmt=Expected statement but found {0} parser.error.expected.comma=Expected comma but found {0} +parser.error.expected.property.id=Expected property id but found {0} +parser.error.expected.lvalue=Expected l-value but found {0} parser.error.expected=Expected {0} but found {1} parser.error.invalid.return=Invalid return statement parser.error.no.func.decl.here=Function declarations can only occur at program or function body level. You should use a function expression here instead. diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8014781.js.EXPECTED --- a/nashorn/test/script/basic/JDK-8014781.js.EXPECTED Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/test/script/basic/JDK-8014781.js.EXPECTED Tue Jul 02 18:39:41 2013 +0530 @@ -1,3 +1,4 @@ -MyError @ test/script/basic/JDK-8014781.js:32 -func @ test/script/basic/JDK-8014781.js:36 - @ test/script/basic/JDK-8014781.js:39 +[object Object] + at MyError (test/script/basic/JDK-8014781.js:32) + at func (test/script/basic/JDK-8014781.js:36) + at (test/script/basic/JDK-8014781.js:39) diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8016667.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8016667.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,34 @@ +/* + * 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. + */ + +/** + * Regression test for erroneous shortcut optimization for object null checks + * + * @test + * @run + */ + +function toto() { + var friends = 1; + (joe = friends) == null; +} diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8017082.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8017082.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,33 @@ +/* + * 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. + */ + +/** + * Long array literals were broken + * + * @test + * @run + */ +function f() { + var z= c>>e>>>0; + var x = [z]; +} diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8017950.js.EXPECTED --- a/nashorn/test/script/basic/JDK-8017950.js.EXPECTED Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/test/script/basic/JDK-8017950.js.EXPECTED Tue Jul 02 18:39:41 2013 +0530 @@ -1,4 +1,5 @@ -func @ test/script/basic/JDK-8017950.js:33 -f @ test/script/basic/JDK-8017950.js:40 -g @ test/script/basic/JDK-8017950.js:44 - @ test/script/basic/JDK-8017950.js:47 +Error + at func (test/script/basic/JDK-8017950.js:33) + at f (test/script/basic/JDK-8017950.js:40) + at g (test/script/basic/JDK-8017950.js:44) + at (test/script/basic/JDK-8017950.js:47) diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019226.js --- a/nashorn/test/script/basic/JDK-8019226.js Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/test/script/basic/JDK-8019226.js Tue Jul 02 18:39:41 2013 +0530 @@ -30,7 +30,7 @@ function func1() { func2() } -function func2() { throw new Error() } +function func2() { throw new Error("failed!") } try { func1() diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019226.js.EXPECTED --- a/nashorn/test/script/basic/JDK-8019226.js.EXPECTED Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/test/script/basic/JDK-8019226.js.EXPECTED Tue Jul 02 18:39:41 2013 +0530 @@ -1,3 +1,4 @@ -func2 @ test/script/basic/JDK-8019226.js:33 -func1 @ test/script/basic/JDK-8019226.js:31 - @ test/script/basic/JDK-8019226.js:36 +Error: failed! + at func2 (test/script/basic/JDK-8019226.js:33) + at func1 (test/script/basic/JDK-8019226.js:31) + at (test/script/basic/JDK-8019226.js:36) diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019473.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019473.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,62 @@ +/* + * 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-8019473: Parser issues related to functions and blocks + * + * @test + * @run + */ + +function checkNoError(code) { + try { + Function(code); + } catch (e) { + print("no error expected for: " + code + " , got " + e); + } +} + +// implicit newlines at EOF should be accepted +checkNoError("for(;;) continue") +checkNoError("return") +checkNoError("yield") +checkNoError("for(;;) break") + +function checkError(code) { + try { + eval(code); + print("SyntaxError expected for: " + code); + } catch (e) { + if (! (e instanceof SyntaxError)) { + fail("SyntaxError expected, got " + e); + } + } +} + +checkError("function f() { case0: }"); +checkError("function f() { if(0) }"); +checkError("function f() { if(0); else }"); +checkError("function f() { while(0) }"); + +// comma expression as closure expression +checkError("function sq(x) x, x*x"); diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019478.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019478.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,33 @@ +/* + * 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-8019478: Object.prototype.toString.call(/a/.exec("a")) === "[object Array]" should be true + * + * @test + * @run + */ + +if (Object.prototype.toString.call(/a/.exec("a")) !== "[object Array]") { + fail("Object.prototype.toString.call(/a/.exec('a')) !== '[object Array]'"); +} diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019482.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019482.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,41 @@ +/* + * 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-8019482: Number("0x0.0p0") should evaluate to NaN + * + * @test + * @run + */ + +function checkHexLiteral(str) { + if (! isNaN(Number(str))) { + fail("Number(" + str + ") is not NaN"); + } +} + +checkHexLiteral("0x0.0"); +checkHexLiteral("0x0.0p"); +checkHexLiteral("0x12tu"); +checkHexLiteral("0x12.2e22"); +checkHexLiteral("0xtu"); diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019488.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019488.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,68 @@ +/* + * 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-8019488: switch on literals result in NoSuchMethodError or VerifyError + * + * @test + * @run + */ + +switch("") { + case 0: + break +} + +switch(true) { + case 0: + print("0"); break; + case 1: + print("1"); break; +} + +switch(false) { + case 0: + print("0"); break; + case 1: + print("1"); break; +} + +switch([]) { + case 1: + print("1"); +} + +switch (undefined) { + case 0: + print("0"); +} + +switch (null) { + case 0: + print("0"); +} + +switch({}) { + case 1: + print("1"); +} diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019508.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019508.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,56 @@ +/* + * 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-8019508: Comma handling in object literal parsing is wrong + * + * @test + * @run + */ + +function checkObjLiteral(str) { + try { + eval(str); + fail("SyntaxError expected for: " + str); + } catch (e) { + if (! (e instanceof SyntaxError)) { + fail("expected SyntaxError, got " + e); + } + print(e.message.replace(/\\/g, '/')); + } +} + +// only comma +checkObjLiteral("({,})"); + +// starting with comma +checkObjLiteral("({, a:2 })"); + +// consecutive commas +checkObjLiteral("({a:3,,})"); + +// missing comma +checkObjLiteral("({a:3 b:2}"); + +// single trailing comma is okay! +var obj = { a: 3, }; diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019508.js.EXPECTED --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019508.js.EXPECTED Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,12 @@ +test/script/basic/JDK-8019508.js#33:1:2 Expected property id but found , +({,}) + ^ +test/script/basic/JDK-8019508.js#33:1:2 Expected property id but found , +({, a:2 }) + ^ +test/script/basic/JDK-8019508.js#33:1:6 Expected property id but found , +({a:3,,}) + ^ +test/script/basic/JDK-8019508.js#33:1:6 Expected comma but found ident +({a:3 b:2} + ^ diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019553.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019553.js Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,43 @@ +/* + * 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-8019553: NPE on illegal l-value for increment and decrement + * + * @test + * @run + */ + +function check(str) { + try { + eval(str); + fail("SyntaxError expected for: " + str); + } catch (e) { + print(e.toString().replace(/\\/g, '/')); + } +} + +check("++ +3"); +check("++ -7"); +check("-- +2"); +check("-- -8"); diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/JDK-8019553.js.EXPECTED --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8019553.js.EXPECTED Tue Jul 02 18:39:41 2013 +0530 @@ -0,0 +1,12 @@ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found + +++ +3 + ^ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found - +++ -7 + ^ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found + +-- +2 + ^ +SyntaxError: test/script/basic/JDK-8019553.js#33:1:3 Expected l-value but found - +-- -8 + ^ diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/NASHORN-51.js --- a/nashorn/test/script/basic/NASHORN-51.js Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/test/script/basic/NASHORN-51.js Tue Jul 02 18:39:41 2013 +0530 @@ -35,28 +35,28 @@ eval(literals[i] + "++"); print("ERROR!! post increment : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } try { eval(literals[i] + "--"); print("ERROR!! post decrement : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } try { eval("++" + literals[i]); print("ERROR!! pre increment : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } try { eval("--" + literals[i]); print("ERROR!! pre decrement : " + literals[i]); } catch (e) { - print(e); + print(e.toString().replace(/\\/g, '/')); } } diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/basic/NASHORN-51.js.EXPECTED --- a/nashorn/test/script/basic/NASHORN-51.js.EXPECTED Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/test/script/basic/NASHORN-51.js.EXPECTED Tue Jul 02 18:39:41 2013 +0530 @@ -1,24 +1,72 @@ -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "1" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "0" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "3.14" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "true" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "false" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment -ReferenceError: "null" can not be used as the left-hand side of assignment +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +1++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +1-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++1 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--1 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +0++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +0-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++0 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--0 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +3.14++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +3.14-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++3.14 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--3.14 + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +true++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +true-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++true + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--true + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +false++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +false-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++false + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--false + ^ +ReferenceError: test/script/basic/NASHORN-51.js#35:1:0 Invalid left hand side for assignment +null++ +^ +ReferenceError: test/script/basic/NASHORN-51.js#42:1:0 Invalid left hand side for assignment +null-- +^ +ReferenceError: test/script/basic/NASHORN-51.js#49:1:2 Invalid left hand side for assignment +++null + ^ +ReferenceError: test/script/basic/NASHORN-51.js#56:1:2 Invalid left hand side for assignment +--null + ^ diff -r 33f304726f33 -r f15ea942c8a4 nashorn/test/script/error/NASHORN-57.js.EXPECTED --- a/nashorn/test/script/error/NASHORN-57.js.EXPECTED Fri Jun 28 19:48:01 2013 -0700 +++ b/nashorn/test/script/error/NASHORN-57.js.EXPECTED Tue Jul 02 18:39:41 2013 +0530 @@ -1,3 +1,3 @@ -test/script/error/NASHORN-57.js:35:2 Expected statement but found ; +test/script/error/NASHORN-57.js:35:2 Expected l-value but found ; ++; ^