Commit ff40125e authored by verwaest's avatar verwaest Committed by Commit bot

Let LookupRecursive bind to NonLocals properly.

This gets rid of the BindingsKind flag. It replaces the factory argument with a bool that indicates whether free variables should be resolved as well.

BUG=

Review-Url: https://codereview.chromium.org/2262393004
Cr-Commit-Position: refs/heads/master@{#38844}
parent 6122465c
This diff is collapsed.
...@@ -530,63 +530,18 @@ class Scope: public ZoneObject { ...@@ -530,63 +530,18 @@ class Scope: public ZoneObject {
Variable* NonLocal(const AstRawString* name, VariableMode mode); Variable* NonLocal(const AstRawString* name, VariableMode mode);
// Variable resolution. // Variable resolution.
// Possible results of a recursive variable lookup telling if and how a
// variable is bound. These are returned in the output parameter *binding_kind
// of the LookupRecursive function.
enum BindingKind {
// The variable reference could be statically resolved to a variable binding
// which is returned. There is no 'with' statement between the reference and
// the binding and no scope between the reference scope (inclusive) and
// binding scope (exclusive) makes a sloppy 'eval' call.
BOUND,
// The variable reference could be statically resolved to a variable binding
// which is returned. There is no 'with' statement between the reference and
// the binding, but some scope between the reference scope (inclusive) and
// binding scope (exclusive) makes a sloppy 'eval' call, that might
// possibly introduce variable bindings shadowing the found one. Thus the
// found variable binding is just a guess.
BOUND_EVAL_SHADOWED,
// The variable reference could not be statically resolved to any binding
// and thus should be considered referencing a global variable. NULL is
// returned. The variable reference is not inside any 'with' statement and
// no scope between the reference scope (inclusive) and script scope
// (exclusive) makes a sloppy 'eval' call.
UNBOUND,
// The variable reference could not be statically resolved to any binding
// NULL is returned. The variable reference is not inside any 'with'
// statement, but some scope between the reference scope (inclusive) and
// script scope (exclusive) makes a sloppy 'eval' call, that might
// possibly introduce a variable binding. Thus the reference should be
// considered referencing a global variable unless it is shadowed by an
// 'eval' introduced binding.
UNBOUND_EVAL_SHADOWED,
// The variable could not be statically resolved and needs to be looked up
// dynamically. NULL is returned. There are two possible reasons:
// * A 'with' statement has been encountered and there is no variable
// binding for the name between the variable reference and the 'with'.
// The variable potentially references a property of the 'with' object.
// * The code is being executed as part of a call to 'eval' and the calling
// context chain contains either a variable binding for the name or it
// contains a 'with' context.
DYNAMIC_LOOKUP
};
// Lookup a variable reference given by name recursively starting with this // Lookup a variable reference given by name recursively starting with this
// scope, and stopping when reaching the outer_scope_end scope. If the code is // scope, and stopping when reaching the outer_scope_end scope. If the code is
// executed because of a call to 'eval', the context parameter should be set // executed because of a call to 'eval', the context parameter should be set
// to the calling context of 'eval'. // to the calling context of 'eval'.
Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, // {declare_free} indicates whether nullptr should be returned for free
AstNodeFactory* factory, // variables when falling off outer_scope_end, or whether they should be
Scope* outer_scope_end = nullptr); // declared automatically as non-locals.
void ResolveTo(ParseInfo* info, BindingKind binding_kind, Variable* LookupRecursive(VariableProxy* proxy, bool declare_free,
VariableProxy* proxy, Variable* var); Scope* outer_scope_end);
void ResolveVariable(ParseInfo* info, VariableProxy* proxy, void ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var);
AstNodeFactory* factory); void ResolveVariable(ParseInfo* info, VariableProxy* proxy);
void ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); void ResolveVariablesRecursively(ParseInfo* info);
// Finds free variables of this scope. This mutates the unresolved variables // Finds free variables of this scope. This mutates the unresolved variables
// list along the way, so full resolution cannot be done afterwards. // list along the way, so full resolution cannot be done afterwards.
...@@ -681,6 +636,12 @@ class DeclarationScope : public Scope { ...@@ -681,6 +636,12 @@ class DeclarationScope : public Scope {
IsClassConstructor(function_kind()))); IsClassConstructor(function_kind())));
} }
void SetScriptScopeInfo(Handle<ScopeInfo> scope_info) {
DCHECK(is_script_scope());
DCHECK(scope_info_.is_null());
scope_info_ = scope_info;
}
bool asm_module() const { return asm_module_; } bool asm_module() const { return asm_module_; }
void set_asm_module() { asm_module_ = true; } void set_asm_module() { asm_module_ = true; }
bool asm_function() const { return asm_function_; } bool asm_function() const { return asm_function_; }
...@@ -832,7 +793,7 @@ class DeclarationScope : public Scope { ...@@ -832,7 +793,7 @@ class DeclarationScope : public Scope {
// In the case of code compiled and run using 'eval', the context // In the case of code compiled and run using 'eval', the context
// parameter is the context in which eval was called. In all other // parameter is the context in which eval was called. In all other
// cases the context parameter is an empty handle. // cases the context parameter is an empty handle.
void AllocateVariables(ParseInfo* info, AstNodeFactory* factory); void AllocateVariables(ParseInfo* info);
// To be called during parsing. Do just enough scope analysis that we can // To be called during parsing. Do just enough scope analysis that we can
// discard the Scope for lazily compiled functions. In particular, this // discard the Scope for lazily compiled functions. In particular, this
......
...@@ -115,8 +115,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, ...@@ -115,8 +115,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
CollectNonLocals(info.get(), scope); CollectNonLocals(info.get(), scope);
} }
if (!ignore_nested_scopes) { if (!ignore_nested_scopes) {
AstNodeFactory ast_node_factory(info.get()->ast_value_factory()); scope->AllocateVariables(info.get());
scope->AllocateVariables(info.get(), &ast_node_factory);
RetrieveScopeChain(scope); RetrieveScopeChain(scope);
} }
} else if (!ignore_nested_scopes) { } else if (!ignore_nested_scopes) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment