Skip to content

Commit

Permalink
8233195: Don't hoist block-scoped variables from dead code
Browse files Browse the repository at this point in the history
Reviewed-by: sundar
  • Loading branch information
szegedi committed Dec 17, 2020
1 parent 9ac6efe commit cab0c85
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Stat
deadCodeRoot.accept(new SimpleNodeVisitor() {
@Override
public boolean enterVarNode(final VarNode varNode) {
statements.add(varNode.setInit(null));
if (!varNode.isBlockScoped()) {
statements.add(varNode.setInit(null));
}
return false;
}

Expand Down
40 changes: 40 additions & 0 deletions test/nashorn/script/basic/es6/JDK-8233195.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2020, 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-8233195: SyntaxError in constant folding with block scoped vars
*
* @test
* @run
* @option --language=es6
*/

function x() {
if (true) { throw "test"; } { let x = "1"; } { let x = 2; }
}

try {
x();
} catch(e) {
print("Caught: " + e);
}
1 change: 1 addition & 0 deletions test/nashorn/script/basic/es6/JDK-8233195.js.EXPECTED
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Caught: test

0 comments on commit cab0c85

Please sign in to comment.