8055042: Compile-time expression evaluator was missing variables

Reviewed-by: jlaskey, lagergren
This commit is contained in:
Attila Szegedi 2014-08-14 14:35:44 +02:00
parent a98a0d19e1
commit dbb42efd61
2 changed files with 24 additions and 4 deletions

View File

@ -382,10 +382,6 @@ final class AssignSymbols extends NodeOperatorVisitor<LexicalContext> implements
symbol.setFlags(flags);
}
if((isVar || isParam) && compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
compiler.declareLocalSymbol(name);
}
return symbol;
}
@ -687,6 +683,22 @@ final class AssignSymbols extends NodeOperatorVisitor<LexicalContext> implements
return binaryNode;
}
@Override
public Node leaveBlock(final Block block) {
// It's not necessary to guard the marking of symbols as locals with this "if"condition for correctness, it's
// just an optimization -- runtime type calculation is not used when the compilation is not an on-demand
// optimistic compilation, so we can skip locals marking then.
if (compiler.useOptimisticTypes() && compiler.isOnDemandCompilation()) {
for (final Symbol symbol: block.getSymbols()) {
if (!symbol.isScope()) {
assert symbol.isVar() || symbol.isParam();
compiler.declareLocalSymbol(symbol.getName());
}
}
}
return block;
}
@Override
public Node leaveDELETE(final UnaryNode unaryNode) {
final FunctionNode currentFunctionNode = lc.getCurrentFunction();

View File

@ -115,6 +115,14 @@ final class TypeEvaluator {
return Type.typeFor(JSType.unboxedFieldType(value));
}
/**
* Declares a symbol name as belonging to a non-scoped local variable during an on-demand compilation of a single
* function. This method will add an explicit Undefined binding for the local into the runtime scope if it's
* otherwise implicitly undefined so that when an expression is evaluated for the name, it won't accidentally find
* an unrelated value higher up the scope chain. It is only required to call this method when doing an optimistic
* on-demand compilation.
* @param symbolName the name of the symbol that is to be declared as being a non-scoped local variable.
*/
void declareLocalSymbol(final String symbolName) {
assert
compiler.useOptimisticTypes() &&