8058561: NPE in LocalVariableTypesCalculator
Reviewed-by: lagergren, sundar
This commit is contained in:
parent
62f4b355b5
commit
00019f9c03
nashorn
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen
test/script/basic
@ -558,7 +558,7 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
|
|||||||
// of the compilation that the object being iterated over must use strings for property
|
// of the compilation that the object being iterated over must use strings for property
|
||||||
// names (e.g., it is a native JS object or array), then we'll not bother trying to treat
|
// names (e.g., it is a native JS object or array), then we'll not bother trying to treat
|
||||||
// the property names optimistically.
|
// the property names optimistically.
|
||||||
!forNode.isForEach() && compiler.hasStringPropertyIterator(iterable.getExpression()));
|
!compiler.useOptimisticTypes() || (!forNode.isForEach() && compiler.hasStringPropertyIterator(iterable.getExpression())));
|
||||||
} else {
|
} else {
|
||||||
if(init != null) {
|
if(init != null) {
|
||||||
init.accept(this);
|
init.accept(this);
|
||||||
@ -686,6 +686,10 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enterReturnNode(final ReturnNode returnNode) {
|
public boolean enterReturnNode(final ReturnNode returnNode) {
|
||||||
|
if(!reachable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final Expression returnExpr = returnNode.getExpression();
|
final Expression returnExpr = returnNode.getExpression();
|
||||||
final Type returnExprType;
|
final Type returnExprType;
|
||||||
if(returnExpr != null) {
|
if(returnExpr != null) {
|
||||||
@ -701,6 +705,9 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enterSplitNode(final SplitNode splitNode) {
|
public boolean enterSplitNode(final SplitNode splitNode) {
|
||||||
|
if(!reachable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Need to visit inside of split nodes. While it's true that they don't have local variables, we need to visit
|
// Need to visit inside of split nodes. While it's true that they don't have local variables, we need to visit
|
||||||
// breaks, continues, and returns in them.
|
// breaks, continues, and returns in them.
|
||||||
if(topSplit == null) {
|
if(topSplit == null) {
|
||||||
@ -950,6 +957,9 @@ final class LocalVariableTypesCalculator extends NodeVisitor<LexicalContext>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enterVarNode(final VarNode varNode) {
|
public boolean enterVarNode(final VarNode varNode) {
|
||||||
|
if (!reachable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
final Expression init = varNode.getInit();
|
final Expression init = varNode.getInit();
|
||||||
if(init != null) {
|
if(init != null) {
|
||||||
init.accept(this);
|
init.accept(this);
|
||||||
|
42
nashorn/test/script/basic/JDK-8058561.js
Normal file
42
nashorn/test/script/basic/JDK-8058561.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JDK-8058561: NPE in LocalVariableTypesCalculator
|
||||||
|
*
|
||||||
|
* @test
|
||||||
|
* @run
|
||||||
|
* @option --lazy-compilation=false
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Just attempting to compile this caused the NPE
|
||||||
|
function func(x, y) {
|
||||||
|
while(true) {
|
||||||
|
switch (y[0]) {
|
||||||
|
case "bar":
|
||||||
|
x = 'xxx';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user