OpenJDK / portola / portola
changeset 27819:74baae50e5cd
8066238: AssertionError in parser when syntax errors appeared in non finished Blocks
Reviewed-by: hannesw, sundar, lagergren
Contributed-by: andreas.gabrielsson@oracle.com
author | lagergren |
---|---|
date | Mon, 01 Dec 2014 13:17:24 +0100 |
parents | 6bf1e00c7229 |
children | cd39dfeab986 |
files | nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java nashorn/test/script/basic/JDK-8066238.js |
diffstat | 2 files changed, 58 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java Fri Nov 28 11:02:54 2014 +0100 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java Mon Dec 01 13:17:24 2014 +0100 @@ -2291,9 +2291,14 @@ final ParserContextFunctionNode functionNode = createParserContextFunctionNode(getNameNode, getSetToken, FunctionNode.Kind.GETTER, functionLine, Collections.<IdentNode>emptyList()); lc.push(functionNode); - final Block functionBody = functionBody(functionNode); - - lc.pop(functionNode); + Block functionBody; + + + try { + functionBody = functionBody(functionNode); + } finally { + lc.pop(functionNode); + } final FunctionNode function = createFunctionNode( functionNode, @@ -2331,9 +2336,13 @@ final ParserContextFunctionNode functionNode = createParserContextFunctionNode(setNameNode, getSetToken, FunctionNode.Kind.SETTER, functionLine, parameters); lc.push(functionNode); - final Block functionBody = functionBody(functionNode); - - lc.pop(functionNode); + Block functionBody; + try { + functionBody = functionBody(functionNode); + } finally { + lc.pop(functionNode); + } + final FunctionNode function = createFunctionNode( functionNode,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8066238.js Mon Dec 01 13:17:24 2014 +0100 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010, 2014, 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. + */ + +/** + * Parser should not crash on invalid property function bodies. + * + * @test + * @run + */ +try { + eval("function f() { L: ({ set prop(){0 = null} }); }"); +} catch (e) { + if (!(e instanceof ReferenceError)) { + throw e; + } +} +try { + eval("function g() { do ; while({ get x()1-- }); }"); +} catch (e) { + if (!(e instanceof ReferenceError)) { + throw e; + } +}