summaryrefslogtreecommitdiff
path: root/deps/v8/src/scopes.h
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-07-08 16:40:11 -0700
committerRyan Dahl <ry@tinyclouds.org>2011-07-08 16:40:11 -0700
commite5564a3f29e0a818832a97c7c3b28d7c8b3b0460 (patch)
tree4b48a6577080d5e44da4d2cbebb7fe7951660de8 /deps/v8/src/scopes.h
parent0df2f74d364826053641395b01c2fcb1345057a9 (diff)
downloadnode-new-e5564a3f29e0a818832a97c7c3b28d7c8b3b0460.tar.gz
Upgrade V8 to 3.4.10
Diffstat (limited to 'deps/v8/src/scopes.h')
-rw-r--r--deps/v8/src/scopes.h146
1 files changed, 55 insertions, 91 deletions
diff --git a/deps/v8/src/scopes.h b/deps/v8/src/scopes.h
index 4a48a4c453..a493d57520 100644
--- a/deps/v8/src/scopes.h
+++ b/deps/v8/src/scopes.h
@@ -1,4 +1,4 @@
-// Copyright 2010 the V8 project authors. All rights reserved.
+// Copyright 2011 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -90,15 +90,14 @@ class Scope: public ZoneObject {
// Construction
enum Type {
- EVAL_SCOPE, // the top-level scope for an 'eval' source
- FUNCTION_SCOPE, // the top-level scope for a function
- GLOBAL_SCOPE // the top-level scope for a program or a top-level eval
+ EVAL_SCOPE, // The top-level scope for an eval source.
+ 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.
};
Scope(Scope* outer_scope, Type type);
- virtual ~Scope() { }
-
// Compute top scope and allocate variables. For lazy compilation the top
// scope only contains the single lazily compiled function, so this
// doesn't re-allocate variables repeatedly.
@@ -110,31 +109,31 @@ class Scope: public ZoneObject {
// The scope name is only used for printing/debugging.
void SetScopeName(Handle<String> scope_name) { scope_name_ = scope_name; }
- virtual void Initialize(bool inside_with);
-
- // Called just before leaving a scope.
- virtual void Leave() {
- // No cleanup or fixup necessary.
- }
+ void Initialize(bool inside_with);
// ---------------------------------------------------------------------------
// Declarations
// Lookup a variable in this scope. Returns the variable or NULL if not found.
- virtual Variable* LocalLookup(Handle<String> name);
+ Variable* LocalLookup(Handle<String> name);
// Lookup a variable in this scope or outer scopes.
// Returns the variable or NULL if not found.
- virtual Variable* Lookup(Handle<String> name);
+ Variable* Lookup(Handle<String> name);
// Declare the function variable for a function literal. This variable
// is in an intermediate scope between this function scope and the the
// outer scope. Only possible for function scopes; at most one variable.
Variable* DeclareFunctionVar(Handle<String> name);
+ // Declare a parameter in this scope. When there are duplicated
+ // parameters the rightmost one 'wins'. However, the implementation
+ // expects all parameters to be declared and from left to right.
+ void DeclareParameter(Handle<String> name);
+
// Declare a local variable in this scope. If the variable has been
// declared before, the previously declared variable is returned.
- virtual Variable* DeclareLocal(Handle<String> name, Variable::Mode mode);
+ Variable* DeclareLocal(Handle<String> name, Variable::Mode mode);
// Declare an implicit global variable in this scope which must be a
// global scope. The variable was introduced (possibly from an inner
@@ -142,14 +141,10 @@ class Scope: public ZoneObject {
// with statements or eval calls.
Variable* DeclareGlobal(Handle<String> name);
- // Add a parameter to the parameter list. The parameter must have been
- // declared via Declare. The same parameter may occur more than once in
- // the parameter list; they must be added in source order, from left to
- // right.
- void AddParameter(Variable* var);
-
// Create a new unresolved variable.
- virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with);
+ VariableProxy* NewUnresolved(Handle<String> name,
+ bool inside_with,
+ int position = RelocInfo::kNoPosition);
// Remove a unresolved variable. During parsing, an unresolved variable
// may have been added optimistically, but then only the variable name
@@ -163,7 +158,7 @@ class Scope: public ZoneObject {
// for printing and cannot be used to find the variable. In particular,
// the only way to get hold of the temporary is by keeping the Variable*
// around.
- virtual Variable* NewTemporary(Handle<String> name);
+ Variable* NewTemporary(Handle<String> name);
// Adds the specific declaration node to the list of declarations in
// this scope. The declarations are processed as part of entering
@@ -196,6 +191,10 @@ class Scope: public ZoneObject {
// Inform the scope that the corresponding code contains an eval call.
void RecordEvalCall() { scope_calls_eval_ = true; }
+ // Enable strict mode for the scope (unless disabled by a global flag).
+ void EnableStrictMode() {
+ strict_mode_ = FLAG_strict_mode;
+ }
// ---------------------------------------------------------------------------
// Predicates.
@@ -204,10 +203,18 @@ class Scope: public ZoneObject {
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_strict_mode() const { return strict_mode_; }
+ bool is_strict_mode_eval_scope() const {
+ return is_eval_scope() && is_strict_mode();
+ }
// Information about which scopes calls eval.
bool calls_eval() const { return scope_calls_eval_; }
bool outer_scope_calls_eval() const { return outer_scope_calls_eval_; }
+ bool outer_scope_calls_non_strict_eval() const {
+ return outer_scope_calls_non_strict_eval_;
+ }
// Is this scope inside a with statement.
bool inside_with() const { return scope_inside_with_; }
@@ -220,13 +227,8 @@ class Scope: public ZoneObject {
// ---------------------------------------------------------------------------
// Accessors.
- // A new variable proxy corresponding to the (function) receiver.
- VariableProxy* receiver() const {
- VariableProxy* proxy =
- new VariableProxy(Factory::this_symbol(), true, false);
- proxy->BindTo(receiver_);
- return proxy;
- }
+ // The variable corresponding the 'this' value.
+ Variable* receiver() { return receiver_; }
// The variable holding the function literal for named function
// literals, or NULL.
@@ -246,18 +248,12 @@ class Scope: public ZoneObject {
int num_parameters() const { return params_.length(); }
// The local variable 'arguments' if we need to allocate it; NULL otherwise.
- // If arguments() exist, arguments_shadow() exists, too.
Variable* arguments() const { return arguments_; }
- // The '.arguments' shadow variable if we need to allocate it; NULL otherwise.
- // If arguments_shadow() exist, arguments() exists, too.
- Variable* arguments_shadow() const { return arguments_shadow_; }
-
// Declarations list.
ZoneList<Declaration*>* declarations() { return &decls_; }
-
// ---------------------------------------------------------------------------
// Variable allocation.
@@ -275,6 +271,9 @@ class Scope: public ZoneObject {
// cases the context parameter is an empty handle.
void AllocateVariables(Handle<Context> context);
+ // Current number of var or const locals.
+ int num_var_or_const() { return num_var_or_const_; }
+
// Result of variable allocation.
int num_stack_slots() const { return num_stack_slots_; }
int num_heap_slots() const { return num_heap_slots_; }
@@ -286,11 +285,15 @@ class Scope: public ZoneObject {
bool AllowsLazyCompilation() const;
// True if the outer context of this scope is always the global context.
- virtual bool HasTrivialOuterContext() const;
+ bool HasTrivialOuterContext() const;
// The number of contexts between this and scope; zero if this == scope.
int ContextChainLength(Scope* scope);
+ // Find the first function, global, or eval scope. This is the scope
+ // where var declarations will be hoisted to in the implementation.
+ Scope* DeclarationScope();
+
// ---------------------------------------------------------------------------
// Strict mode support.
bool IsDeclared(Handle<String> name) {
@@ -348,8 +351,6 @@ class Scope: public ZoneObject {
Variable* function_;
// Convenience variable; function scopes only.
Variable* arguments_;
- // Convenience variable; function scopes only.
- Variable* arguments_shadow_;
// Illegal redeclaration.
Expression* illegal_redecl_;
@@ -358,20 +359,29 @@ class Scope: public ZoneObject {
bool scope_inside_with_; // this scope is inside a 'with' of some outer scope
bool scope_contains_with_; // this scope contains a 'with' statement
bool scope_calls_eval_; // this scope contains an 'eval' call
+ bool strict_mode_; // this scope is a strict mode scope
// Computed via PropagateScopeInfo.
bool outer_scope_calls_eval_;
+ bool outer_scope_calls_non_strict_eval_;
bool inner_scope_calls_eval_;
bool outer_scope_is_eval_scope_;
bool force_eager_compilation_;
+ // True if it doesn't need scope resolution (e.g., if the scope was
+ // constructed based on a serialized scope info or a catch context).
+ bool already_resolved_;
+
+ // Computed as variables are declared.
+ int num_var_or_const_;
+
// Computed via AllocateVariables; function scopes only.
int num_stack_slots_;
int num_heap_slots_;
// Serialized scopes support.
Handle<SerializedScopeInfo> scope_info_;
- bool resolved() { return !scope_info_.is_null(); }
+ bool already_resolved() { return already_resolved_; }
// Create a non-local variable with a given name.
// These variables are looked up dynamically at runtime.
@@ -389,6 +399,7 @@ class Scope: public ZoneObject {
// Scope analysis.
bool PropagateScopeInfo(bool outer_scope_calls_eval,
+ bool outer_scope_calls_non_strict_eval,
bool outer_scope_is_eval_scope);
bool HasTrivialContext() const;
@@ -406,8 +417,12 @@ class Scope: public ZoneObject {
void AllocateVariablesRecursively();
private:
+ // Construct a function scope based on the scope info.
Scope(Scope* inner_scope, Handle<SerializedScopeInfo> scope_info);
+ // Construct a catch scope with a binding for the name.
+ Scope(Scope* inner_scope, Handle<String> catch_variable_name);
+
void AddInnerScope(Scope* inner_scope) {
if (inner_scope != NULL) {
inner_scopes_.Add(inner_scope);
@@ -420,57 +435,6 @@ class Scope: public ZoneObject {
Handle<SerializedScopeInfo> scope_info);
};
-
-// Scope used during pre-parsing.
-class DummyScope : public Scope {
- public:
- DummyScope()
- : Scope(GLOBAL_SCOPE),
- nesting_level_(1), // Allows us to Leave the initial scope.
- inside_with_level_(kNotInsideWith) {
- outer_scope_ = this;
- scope_inside_with_ = false;
- }
-
- virtual void Initialize(bool inside_with) {
- nesting_level_++;
- if (inside_with && inside_with_level_ == kNotInsideWith) {
- inside_with_level_ = nesting_level_;
- }
- ASSERT(inside_with_level_ <= nesting_level_);
- }
-
- virtual void Leave() {
- nesting_level_--;
- ASSERT(nesting_level_ >= 0);
- if (nesting_level_ < inside_with_level_) {
- inside_with_level_ = kNotInsideWith;
- }
- ASSERT(inside_with_level_ <= nesting_level_);
- }
-
- virtual Variable* Lookup(Handle<String> name) { return NULL; }
-
- virtual VariableProxy* NewUnresolved(Handle<String> name, bool inside_with) {
- return NULL;
- }
-
- virtual Variable* NewTemporary(Handle<String> name) { return NULL; }
-
- virtual bool HasTrivialOuterContext() const {
- return (nesting_level_ == 0 || inside_with_level_ <= 0);
- }
-
- private:
- static const int kNotInsideWith = -1;
- // Number of surrounding scopes of the current scope.
- int nesting_level_;
- // Nesting level of outermost scope that is contained in a with statement,
- // or kNotInsideWith if there are no with's around the current scope.
- int inside_with_level_;
-};
-
-
} } // namespace v8::internal
#endif // V8_SCOPES_H_