OpenJDK / valhalla / valhalla10-old / nashorn
changeset 1998:dbf63d9de2e7 nestmates tip
Merge
author | dholmes |
---|---|
date | Wed, 27 Sep 2017 01:20:57 -0400 |
parents | b9781e5119f6 3397ed166912 |
children | |
files | |
diffstat | 17 files changed, 339 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Wed Sep 20 23:55:37 2017 -0400 +++ b/.hgtags Wed Sep 27 01:20:57 2017 -0400 @@ -436,3 +436,6 @@ bece58f762168a6615bd036626a572a647f6b507 jdk-9+180 47f8d75b8765ff8410ebc89619e537321cc10c32 jdk-9+181 9133969febb50ec683bfd79fc506771fb4f7de6c jdk-10+20 +03d3d3c6bc5a06c1c763ef4615bb43672efe6b3f jdk-10+21 +bd933afd9e2ea9b3ce0ebf8deee5a7f9c7dda76c jdk-10+22 +f5bdafee7f93dd3b3cec626a77198dbe2f80086f jdk-10+23
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/Block.java Wed Sep 20 23:55:37 2017 -0400 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/Block.java Wed Sep 27 01:20:57 2017 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2017, 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 @@ -100,6 +100,12 @@ public static final int IS_SWITCH_BLOCK = 1 << 7; /** + * Is this block tagged as breakable based on its contents + * (block having labelled break statement) + */ + public static final int IS_BREAKABLE = 1 << 8; + + /** * Constructor * * @param token The first token of the block @@ -315,7 +321,7 @@ */ @Override public boolean isTerminal() { - return getFlag(IS_TERMINAL); + return getFlag(IS_TERMINAL) && !getFlag(IS_BREAKABLE); } /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java Wed Sep 20 23:55:37 2017 -0400 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java Wed Sep 27 01:20:57 2017 -0400 @@ -722,7 +722,7 @@ */ public boolean needsCallee() { // NOTE: we only need isSplit() here to ensure that :scope can never drop below slot 2 for splitting array units. - return needsParentScope() || usesSelfSymbol() || isSplit() || (needsArguments() && !isStrict()) || hasApplyToCallSpecialization(); + return needsParentScope() || usesSelfSymbol() || isSplit() || ((needsArguments() || hasApplyToCallSpecialization()) && !isStrict()); } /**
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java Wed Sep 20 23:55:37 2017 -0400 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java Wed Sep 27 01:20:57 2017 -0400 @@ -1605,6 +1605,10 @@ // Skip any whitespace. skipWhitespace(false); + //handle trailing blank lines + lastLinePosition = position; + stringEnd = position; + if (hasHereMarker(identStart, identLength)) { break; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java Wed Sep 20 23:55:37 2017 -0400 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java Wed Sep 27 01:20:57 2017 -0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2017, 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 @@ -2274,6 +2274,11 @@ //targetNode is what we are breaking out from. final String labelName = labelNode == null ? null : labelNode.getLabelName(); final ParserContextBreakableNode targetNode = lc.getBreakable(labelName); + + if( targetNode instanceof ParserContextBlockNode) { + targetNode.setFlag(Block.IS_BREAKABLE); + } + if (targetNode == null) { throw error(AbstractParser.message("illegal.break.stmt"), breakToken); }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Sep 20 23:55:37 2017 -0400 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Sep 27 01:20:57 2017 -0400 @@ -338,17 +338,20 @@ * @return apply to call that perfectly fits this callsite or null if none found */ CompiledFunction lookupExactApplyToCall(final MethodType type) { + // Callsite type always has callee, drop it if this function doesn't need it. + final MethodType adaptedType = needsCallee() ? type : type.dropParameterTypes(0, 1); + for (final CompiledFunction cf : code) { if (!cf.isApplyToCall()) { continue; } final MethodType cftype = cf.type(); - if (cftype.parameterCount() != type.parameterCount()) { + if (cftype.parameterCount() != adaptedType.parameterCount()) { continue; } - if (widen(cftype).equals(widen(type))) { + if (widen(cftype).equals(widen(adaptedType))) { return cf; } }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/LengthNotWritableFilter.java Wed Sep 20 23:55:37 2017 -0400 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/arrays/LengthNotWritableFilter.java Wed Sep 27 01:20:57 2017 -0400 @@ -143,7 +143,7 @@ @Override public ArrayData delete(final int index) { - extraElements.remove(index); + extraElements.remove(ArrayIndex.toLongIndex(index)); underlying = underlying.delete(index); return this; }
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java Wed Sep 20 23:55:37 2017 -0400 +++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java Wed Sep 27 01:20:57 2017 -0400 @@ -213,7 +213,7 @@ @SuppressWarnings("unused") private static Object callToApply(final MethodHandle mh, final JSObject obj, final Object thiz, final Object... args) { - assert args.length >= 2; + assert args.length >= 1; final Object receiver = args[0]; final Object[] arguments = new Object[args.length - 1]; System.arraycopy(args, 1, arguments, 0, arguments.length);
--- a/test/script/basic/JDK-8035312.js.EXPECTED Wed Sep 20 23:55:37 2017 -0400 +++ b/test/script/basic/JDK-8035312.js.EXPECTED Wed Sep 27 01:20:57 2017 -0400 @@ -58,37 +58,37 @@ >>> Pop test Popping from 1,2,3 - array is now [1,2,3] length is = 3 + array is now [1,2,] length is = 3 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter -Popping from 1,2,3 - array is now [1,2,3] length is = 3 +Popping from 1,2, + array is now [1,2,] length is = 3 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter x.length === 3 (should be 3) -x === 1,2,3 -Popping from 1,2,3 - array is now [1,2,3] length is = 3 +x === 1,2, +Popping from 1,2, + array is now [1,2,] length is = 3 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter -Popping from 1,2,3 - array is now [1,2,3] length is = 3 +Popping from 1,2, + array is now [1,2,] length is = 3 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter -Popping from 1,2,3 - array is now [1,2,3] length is = 3 +Popping from 1,2, + array is now [1,2,] length is = 3 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter -Popping from 1,2,3 - array is now [1,2,3] length is = 3 +Popping from 1,2, + array is now [1,2,] length is = 3 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter -Popping from 1,2,3 - array is now [1,2,3] length is = 3 +Popping from 1,2, + array is now [1,2,] length is = 3 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter x.length === 3 (should be 3) -x === 1,2,3 +x === 1,2, class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter Writing 0 class jdk.nashorn.internal.runtime.arrays.LengthNotWritableFilter
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8073640.js Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, 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-8073640: Nashorn scripting: here document with only whitespace gives error + * + * @test + * @option -scripting + * @run + */ + +/*case 1*/ +print(<<EOD); + +EOD + +/*case 2*/ +print(<<EOD); + +line2 +line3 +EOD + +/*case 3*/ +print(<<EOD); +line1 + +line3 +EOD + +/*case 4*/ +print(<<EOD); +line1 +line2 + +EOD + +/*case 5*/ +print(<<EOD); + +line2 + +line4 + +EOD
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8073640.js.EXPECTED Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,15 @@ + + +line2 +line3 +line1 + +line3 +line1 +line2 + + +line2 + +line4 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8169233.js Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, 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-8169233 : LengthNotWritableFilter: extraElements.remove(index) has no effect + * + * @test + * @run + */ + +var array = ['a', 'b', 'c', 'd']; +Object.defineProperty(array, "length", {writable: false}); +try { + array.push('e'); +} catch (e) { +} +print("array : "+array); +print("length : " + array.length); +delete array[0]; +print("array : "+array); +print("length : " + array.length);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8169233.js.EXPECTED Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,4 @@ +array : a,b,c,d +length : 4 +array : ,b,c,d +length : 4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8177691.js Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, 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-8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn + * + * @test + * @run + */ + +function box1() { + label: { + try { + throw 1; + } + catch (e) { + break label; + } + throw 2; + } + return 'OK'; +}; + +function box2() { + label: { + try { + throw 1; + } + finally { + break label; + } + throw 2; + } + return 'OK'; +}; + +function box3() { + label: { + try { + throw 1; + } + finally { + break label; + } + } + return 'OK'; +}; + +print(box1()); +print(box2()); +print(box3());
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8177691.js.EXPECTED Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,3 @@ +OK +OK +OK
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/basic/JDK-8184720.js Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017, 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-8184720: Nashorn engine in strict mode throws a java.lang.ClassCastException + * when calling apply() and passing the arguments object + * + * @test + * @run + * @option -strict + */ + +var yfunc = function () { + (function(){}).apply(null, arguments); +}; + +yfunc();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/src/jdk/nashorn/internal/runtime/linker/test/JDK_8184723_Test.java Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package jdk.nashorn.internal.runtime.linker.test; + +import jdk.nashorn.api.scripting.AbstractJSObject; +import jdk.nashorn.api.scripting.NashornScriptEngine; +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; + +/** + * @test + * @bug 8184723 + * @summary jdk.nashorn.internal.runtime.linker.JSObjectLinker.callToApply erroneously asserts given arguments + * @modules jdk.scripting.nashorn/jdk.nashorn.internal.runtime.linker + * @run main/othervm -ea jdk.nashorn.internal.runtime.linker.test.JDK_8184723_Test + */ + +public class JDK_8184723_Test { + public static void main(String args[]) throws Exception { + NashornScriptEngine engine = (NashornScriptEngine) new NashornScriptEngineFactory().getScriptEngine(); + AbstractJSObject obj = new AbstractJSObject() { + @Override + public Object getMember(String name) { + return this; + } + + @Override + public Object call(Object thiz, Object... args) { + return thiz; + } + + }; + + engine.put("a", obj); + engine.eval("function b(){ a.apply(null,arguments);};b();"); + } +}