Index: src/scopes.h |
diff --git a/src/scopes.h b/src/scopes.h |
index 2917a63bba553a3a141acae6875ab83279c0f176..782589b0e6319c1d3eccab49df8a74a12e0db230 100644 |
--- a/src/scopes.h |
+++ b/src/scopes.h |
@@ -94,7 +94,8 @@ class Scope: public ZoneObject { |
FUNCTION_SCOPE, // The top-level scope for a function. |
GLOBAL_SCOPE, // The top-level scope for a program or a top-level eval. |
CATCH_SCOPE, // The scope introduced by catch. |
- BLOCK_SCOPE // The scope introduced by a new block. |
+ BLOCK_SCOPE, // The scope introduced by a new block. |
+ WITH_SCOPE // The scope introduced by with. |
}; |
Scope(Scope* outer_scope, Type type); |
@@ -210,11 +211,16 @@ class Scope: public ZoneObject { |
// Predicates. |
// Specific scope types. |
+ Type type() const { return type_; } |
Kevin Millikin (Chromium)
2011/09/15 09:38:13
Don't introduce this until you have a caller for i
Steven
2011/09/15 19:54:06
Will remove it for for now. But I will need it lat
|
bool is_eval_scope() const { return type_ == EVAL_SCOPE; } |
bool is_function_scope() const { return type_ == FUNCTION_SCOPE; } |
bool is_global_scope() const { return type_ == GLOBAL_SCOPE; } |
bool is_catch_scope() const { return type_ == CATCH_SCOPE; } |
bool is_block_scope() const { return type_ == BLOCK_SCOPE; } |
+ bool is_with_scope() const { return type_ == WITH_SCOPE; } |
+ bool is_declaration_scope() const { |
+ return is_eval_scope() || is_function_scope() || is_global_scope(); |
+ } |
bool is_strict_mode() const { return strict_mode_; } |
bool is_strict_mode_eval_scope() const { |
return is_eval_scope() && is_strict_mode(); |
@@ -396,7 +402,7 @@ class Scope: public ZoneObject { |
// Computed as variables are declared. |
int num_var_or_const_; |
- // Computed via AllocateVariables; function scopes only. |
+ // Computed via AllocateVariables; function, block and catch scopes only. |
int num_stack_slots_; |
int num_heap_slots_; |
@@ -409,9 +415,35 @@ class Scope: public ZoneObject { |
Variable* NonLocal(Handle<String> name, Variable::Mode mode); |
// Variable resolution. |
- Variable* LookupRecursive(Handle<String> name, |
- bool from_inner_function, |
- Variable** invalidated_local); |
+ |
+ // Possible results of a variable lookup. |
+ enum LookupResult { |
+ // The variable could be statically resolved to a non-global outer |
+ // scope. There is no 'with' statement in between and no in between |
+ // scope calls 'eval'. |
+ FOUND, |
Kevin Millikin (Chromium)
2011/09/15 09:38:13
Since GLOBAL can also be found, perhaps it's clear
Steven
2011/09/15 19:54:06
Done.
|
+ |
+ // The variable could be statically resolved to a non-global outer |
+ // scope, but an in between scope calls 'eval' that might possibly |
+ // introduce variables shadowing the found one. Thus the found variable |
+ // is just a guess. |
+ FOUND_EVAL, |
+ |
+ // We may have statically resolved a variable to a non-global outer |
+ // scope, but there is a 'with' statement in between. The 'with' object |
+ // may have a property with the same name, so if a variable has been |
+ // found, it is just a guess. |
+ FOUND_WITH, |
Kevin Millikin (Chromium)
2011/09/15 09:38:13
On the other hand, this case includes the case of
Steven
2011/09/15 19:54:06
Done.
|
+ |
+ // The variable could not be resolved to any local binding and is thus |
+ // a global variable unless it is shadowed by an eval-introduced variable. |
+ GLOBAL |
Kevin Millikin (Chromium)
2011/09/15 09:38:13
This case is also used for when the variable is re
Steven
2011/09/15 19:54:06
Done.
|
+ }; |
+ |
+ // Lookup a variable starting with this scope. |
+ LookupResult LookupRecursive(Handle<String> name, |
+ bool from_inner_scope, |
+ Variable** var); |
void ResolveVariable(Scope* global_scope, |
Handle<Context> context, |
VariableProxy* proxy); |