Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: src/scopes.h

Issue 653603002: Try to fix cross-script global scope (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_SCOPES_H_ 5 #ifndef V8_SCOPES_H_
6 #define V8_SCOPES_H_ 6 #define V8_SCOPES_H_
7 7
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/zone.h" 9 #include "src/zone.h"
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 InitializationFlag init_flag, 136 InitializationFlag init_flag,
137 Interface* interface = Interface::NewValue()); 137 Interface* interface = Interface::NewValue());
138 138
139 // Declare an implicit global variable in this scope which must be a 139 // Declare an implicit global variable in this scope which must be a
140 // global scope. The variable was introduced (possibly from an inner 140 // global scope. The variable was introduced (possibly from an inner
141 // scope) by a reference to an unresolved variable with no intervening 141 // scope) by a reference to an unresolved variable with no intervening
142 // with statements or eval calls. 142 // with statements or eval calls.
143 Variable* DeclareDynamicGlobal(const AstRawString* name); 143 Variable* DeclareDynamicGlobal(const AstRawString* name);
144 144
145 // Create a new unresolved variable. 145 // Create a new unresolved variable.
146 // Note that we must not share the unresolved variables with the same name
147 // because they may be removed selectively via RemoveUnresolved().
146 template<class Visitor> 148 template<class Visitor>
147 VariableProxy* NewUnresolved(AstNodeFactory<Visitor>* factory, 149 VariableProxy* NewUnresolved(AstNodeFactory<Visitor>* factory,
148 const AstRawString* name, 150 const AstRawString* name,
149 Interface* interface = Interface::NewValue(), 151 Interface* interface = Interface::NewValue(),
150 int position = RelocInfo::kNoPosition) { 152 int position = RelocInfo::kNoPosition) {
151 // Note that we must not share the unresolved variables with 153 if (is_global_scope() && outer_scope_ && outer_scope_->is_global_scope()) {
152 // the same name because they may be removed selectively via 154 return outer_scope_->NewUnresolved(factory, name, interface, position);
153 // RemoveUnresolved(). 155 }
154 ASSERT(!already_resolved()); 156 ASSERT(!already_resolved());
155 VariableProxy* proxy = 157 VariableProxy* proxy =
156 factory->NewVariableProxy(name, false, interface, position); 158 factory->NewVariableProxy(name, false, interface, position);
157 unresolved_.Add(proxy, zone_); 159 unresolved_.Add(proxy, zone_);
158 return proxy; 160 return proxy;
159 } 161 }
160 162
161 // Remove a unresolved variable. During parsing, an unresolved variable 163 // Remove a unresolved variable. During parsing, an unresolved variable
162 // may have been added optimistically, but then only the variable name 164 // may have been added optimistically, but then only the variable name
163 // was used (typically for labels). If the variable was not declared, the 165 // was used (typically for labels). If the variable was not declared, the
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Predicates. 262 // Predicates.
261 263
262 // Specific scope types. 264 // Specific scope types.
263 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; } 265 bool is_eval_scope() const { return scope_type_ == EVAL_SCOPE; }
264 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; } 266 bool is_function_scope() const { return scope_type_ == FUNCTION_SCOPE; }
265 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; } 267 bool is_module_scope() const { return scope_type_ == MODULE_SCOPE; }
266 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; } 268 bool is_global_scope() const { return scope_type_ == GLOBAL_SCOPE; }
267 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; } 269 bool is_catch_scope() const { return scope_type_ == CATCH_SCOPE; }
268 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; } 270 bool is_block_scope() const { return scope_type_ == BLOCK_SCOPE; }
269 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; } 271 bool is_with_scope() const { return scope_type_ == WITH_SCOPE; }
272 bool is_script_scope() const { return scope_type_ == SCRIPT_SCOPE; }
270 bool is_declaration_scope() const { 273 bool is_declaration_scope() const {
271 return is_eval_scope() || is_function_scope() || 274 return is_eval_scope() || is_function_scope() || is_module_scope() ||
272 is_module_scope() || is_global_scope(); 275 (is_global_scope() && outer_scope() == NULL);
273 } 276 }
274 bool is_strict_eval_scope() const { 277 bool is_strict_eval_scope() const {
275 return is_eval_scope() && strict_mode_ == STRICT; 278 return is_eval_scope() && strict_mode_ == STRICT;
276 } 279 }
277 280
278 // Information about which scopes calls eval. 281 // Information about which scopes calls eval.
279 bool calls_eval() const { return scope_calls_eval_; } 282 bool calls_eval() const { return scope_calls_eval_; }
280 bool calls_sloppy_eval() { 283 bool calls_sloppy_eval() {
281 return scope_calls_eval_ && strict_mode_ == SLOPPY; 284 return scope_calls_eval_ && strict_mode_ == SLOPPY;
282 } 285 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 Scope* outer_scope, 616 Scope* outer_scope,
614 Handle<ScopeInfo> scope_info); 617 Handle<ScopeInfo> scope_info);
615 618
616 AstValueFactory* ast_value_factory_; 619 AstValueFactory* ast_value_factory_;
617 Zone* zone_; 620 Zone* zone_;
618 }; 621 };
619 622
620 } } // namespace v8::internal 623 } } // namespace v8::internal
621 624
622 #endif // V8_SCOPES_H_ 625 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698