Thu, 14 Feb 2013 14:07:53 +0100
8008198: java.lang.AssertionError: Invalid break target class jdk.nashorn.internal.ir.TryNode
Reviewed-by: attila, jlaskey
1.1 --- a/src/jdk/nashorn/internal/ir/LabelNode.java Thu Feb 14 13:51:54 2013 +0100 1.2 +++ b/src/jdk/nashorn/internal/ir/LabelNode.java Thu Feb 14 14:07:53 2013 +0100 1.3 @@ -125,6 +125,7 @@ 1.4 * @param breakNode the break node 1.5 */ 1.6 public void setBreakNode(final Node breakNode) { 1.7 + assert breakNode instanceof BreakableNode || breakNode instanceof Block : "Invalid break node: " + breakNode; 1.8 this.breakNode = breakNode; 1.9 } 1.10 1.11 @@ -141,6 +142,7 @@ 1.12 * @param continueNode the continue node 1.13 */ 1.14 public void setContinueNode(final Node continueNode) { 1.15 + assert continueNode instanceof WhileNode : "invalid continue node: " + continueNode; 1.16 this.continueNode = continueNode; 1.17 } 1.18
2.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Thu Feb 14 13:51:54 2013 +0100 2.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Thu Feb 14 14:07:53 2013 +0100 2.3 @@ -498,10 +498,11 @@ 2.4 */ 2.5 private void pushControlNode(final Node node) { 2.6 final boolean isLoop = node instanceof WhileNode; 2.7 + final boolean isBreakable = node instanceof BreakableNode || node instanceof Block; 2.8 function.getControlStack().push(node); 2.9 2.10 for (final LabelNode labelNode : function.getLabelStack()) { 2.11 - if (labelNode.getBreakNode() == null) { 2.12 + if (isBreakable && labelNode.getBreakNode() == null) { 2.13 labelNode.setBreakNode(node); 2.14 } 2.15
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/script/basic/JDK-8008198.js Thu Feb 14 14:07:53 2013 +0100 3.3 @@ -0,0 +1,55 @@ 3.4 +/* 3.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/** 3.28 + * JDK-8008198 : java.lang.AssertionError: Invalid break target class jdk.nashorn.internal.ir.TryNode 3.29 + * 3.30 + * @test 3.31 + * @run 3.32 + */ 3.33 + 3.34 +a: try { 3.35 + print("try"); 3.36 + break a; 3.37 + print("wrong"); 3.38 +} catch (e) { 3.39 + print("error"); 3.40 +} finally { 3.41 + print("finally"); 3.42 +} 3.43 +print("done"); 3.44 + 3.45 +a: b: if (true) { 3.46 + c: d: with({}) { 3.47 + print("with"); 3.48 + break c; 3.49 + print("wrong"); 3.50 + } 3.51 + print("if"); 3.52 + break a; 3.53 + print("wrong"); 3.54 +} 3.55 +print("done"); 3.56 + 3.57 + 3.58 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/script/basic/JDK-8008198.js.EXPECTED Thu Feb 14 14:07:53 2013 +0100 4.3 @@ -0,0 +1,6 @@ 4.4 +try 4.5 +finally 4.6 +done 4.7 +with 4.8 +if 4.9 +done