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

Side by Side Diff: src/scopes.h

Issue 1134003003: Revert "Resolve references to "this" the same way as normal variables" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
« 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/pending-compilation-error-handler.h" 9 #include "src/pending-compilation-error-handler.h"
10 #include "src/zone.h" 10 #include "src/zone.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 // Declare an implicit global variable in this scope which must be a 138 // Declare an implicit global variable in this scope which must be a
139 // script scope. The variable was introduced (possibly from an inner 139 // script scope. The variable was introduced (possibly from an inner
140 // scope) by a reference to an unresolved variable with no intervening 140 // scope) by a reference to an unresolved variable with no intervening
141 // with statements or eval calls. 141 // with statements or eval calls.
142 Variable* DeclareDynamicGlobal(const AstRawString* name); 142 Variable* DeclareDynamicGlobal(const AstRawString* name);
143 143
144 // Create a new unresolved variable. 144 // Create a new unresolved variable.
145 VariableProxy* NewUnresolved(AstNodeFactory* factory, 145 VariableProxy* NewUnresolved(AstNodeFactory* factory,
146 const AstRawString* name, 146 const AstRawString* name,
147 Variable::Kind kind = Variable::NORMAL,
148 int start_position = RelocInfo::kNoPosition, 147 int start_position = RelocInfo::kNoPosition,
149 int end_position = RelocInfo::kNoPosition) { 148 int end_position = RelocInfo::kNoPosition) {
150 // Note that we must not share the unresolved variables with 149 // Note that we must not share the unresolved variables with
151 // the same name because they may be removed selectively via 150 // the same name because they may be removed selectively via
152 // RemoveUnresolved(). 151 // RemoveUnresolved().
153 DCHECK(!already_resolved()); 152 DCHECK(!already_resolved());
154 VariableProxy* proxy = 153 VariableProxy* proxy = factory->NewVariableProxy(
155 factory->NewVariableProxy(name, kind, start_position, end_position); 154 name, Variable::NORMAL, start_position, end_position);
156 unresolved_.Add(proxy, zone_); 155 unresolved_.Add(proxy, zone_);
157 return proxy; 156 return proxy;
158 } 157 }
159 158
160 // Remove a unresolved variable. During parsing, an unresolved variable 159 // Remove a unresolved variable. During parsing, an unresolved variable
161 // may have been added optimistically, but then only the variable name 160 // may have been added optimistically, but then only the variable name
162 // was used (typically for labels). If the variable was not declared, the 161 // was used (typically for labels). If the variable was not declared, the
163 // addition introduced a new unresolved variable which may end up being 162 // addition introduced a new unresolved variable which may end up being
164 // allocated globally as a "ghost" variable. RemoveUnresolved removes 163 // allocated globally as a "ghost" variable. RemoveUnresolved removes
165 // such a variable again if it was added; otherwise this is a no-op. 164 // such a variable again if it was added; otherwise this is a no-op.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 210
212 // Inform the scope that the corresponding code contains an eval call. 211 // Inform the scope that the corresponding code contains an eval call.
213 void RecordEvalCall() { if (!is_script_scope()) scope_calls_eval_ = true; } 212 void RecordEvalCall() { if (!is_script_scope()) scope_calls_eval_ = true; }
214 213
215 // Inform the scope that the corresponding code uses "arguments". 214 // Inform the scope that the corresponding code uses "arguments".
216 void RecordArgumentsUsage() { scope_uses_arguments_ = true; } 215 void RecordArgumentsUsage() { scope_uses_arguments_ = true; }
217 216
218 // Inform the scope that the corresponding code uses "super". 217 // Inform the scope that the corresponding code uses "super".
219 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; } 218 void RecordSuperPropertyUsage() { scope_uses_super_property_ = true; }
220 219
220 // Inform the scope that the corresponding code uses "this".
221 void RecordThisUsage() { scope_uses_this_ = true; }
222
221 // Set the language mode flag (unless disabled by a global flag). 223 // Set the language mode flag (unless disabled by a global flag).
222 void SetLanguageMode(LanguageMode language_mode) { 224 void SetLanguageMode(LanguageMode language_mode) {
223 language_mode_ = language_mode; 225 language_mode_ = language_mode;
224 } 226 }
225 227
226 // Set the ASM module flag. 228 // Set the ASM module flag.
227 void SetAsmModule() { asm_module_ = true; } 229 void SetAsmModule() { asm_module_ = true; }
228 230
229 // Position in the source where this scope begins and ends. 231 // Position in the source where this scope begins and ends.
230 // 232 //
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // Does this scope access "arguments". 316 // Does this scope access "arguments".
315 bool uses_arguments() const { return scope_uses_arguments_; } 317 bool uses_arguments() const { return scope_uses_arguments_; }
316 // Does any inner scope access "arguments". 318 // Does any inner scope access "arguments".
317 bool inner_uses_arguments() const { return inner_scope_uses_arguments_; } 319 bool inner_uses_arguments() const { return inner_scope_uses_arguments_; }
318 // Does this scope access "super" property (super.foo). 320 // Does this scope access "super" property (super.foo).
319 bool uses_super_property() const { return scope_uses_super_property_; } 321 bool uses_super_property() const { return scope_uses_super_property_; }
320 // Does any inner scope access "super" property. 322 // Does any inner scope access "super" property.
321 bool inner_uses_super_property() const { 323 bool inner_uses_super_property() const {
322 return inner_scope_uses_super_property_; 324 return inner_scope_uses_super_property_;
323 } 325 }
326 // Does this scope access "this".
327 bool uses_this() const { return scope_uses_this_; }
328 // Does any inner scope access "this".
329 bool inner_uses_this() const { return inner_scope_uses_this_; }
324 330
325 const Scope* NearestOuterEvalScope() const { 331 const Scope* NearestOuterEvalScope() const {
326 if (is_eval_scope()) return this; 332 if (is_eval_scope()) return this;
327 if (outer_scope() == nullptr) return nullptr; 333 if (outer_scope() == nullptr) return nullptr;
328 return outer_scope()->NearestOuterEvalScope(); 334 return outer_scope()->NearestOuterEvalScope();
329 } 335 }
330 336
331 // --------------------------------------------------------------------------- 337 // ---------------------------------------------------------------------------
332 // Accessors. 338 // Accessors.
333 339
334 // The type of this scope. 340 // The type of this scope.
335 ScopeType scope_type() const { return scope_type_; } 341 ScopeType scope_type() const { return scope_type_; }
336 342
337 FunctionKind function_kind() const { return function_kind_; } 343 FunctionKind function_kind() const { return function_kind_; }
338 344
339 // The language mode of this scope. 345 // The language mode of this scope.
340 LanguageMode language_mode() const { return language_mode_; } 346 LanguageMode language_mode() const { return language_mode_; }
341 347
342 // The variable corresponding to the 'this' value. 348 // The variable corresponding to the 'this' value.
343 Variable* receiver() { 349 Variable* receiver() { return receiver_; }
344 DCHECK(has_this_declaration());
345 DCHECK_NOT_NULL(receiver_);
346 return receiver_;
347 }
348
349 Variable* LookupThis() { return Lookup(ast_value_factory_->this_string()); }
350
351 // TODO(wingo): Add a GLOBAL_SCOPE scope type which will lexically allocate
352 // "this" (and no other variable) on the native context. Script scopes then
353 // will not have a "this" declaration.
354 bool has_this_declaration() const {
355 return (is_function_scope() && !is_arrow_scope()) || is_module_scope() ||
356 is_script_scope();
357 }
358 350
359 // The variable corresponding to the 'new.target' value. 351 // The variable corresponding to the 'new.target' value.
360 Variable* new_target_var() { return new_target_; } 352 Variable* new_target_var() { return new_target_; }
361 353
362 // The variable holding the function literal for named function 354 // The variable holding the function literal for named function
363 // literals, or NULL. Only valid for function scopes. 355 // literals, or NULL. Only valid for function scopes.
364 VariableDeclaration* function() const { 356 VariableDeclaration* function() const {
365 DCHECK(is_function_scope()); 357 DCHECK(is_function_scope());
366 return function_; 358 return function_;
367 } 359 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 bool scope_inside_with_; 570 bool scope_inside_with_;
579 // This scope contains a 'with' statement. 571 // This scope contains a 'with' statement.
580 bool scope_contains_with_; 572 bool scope_contains_with_;
581 // This scope or a nested catch scope or with scope contain an 'eval' call. At 573 // This scope or a nested catch scope or with scope contain an 'eval' call. At
582 // the 'eval' call site this scope is the declaration scope. 574 // the 'eval' call site this scope is the declaration scope.
583 bool scope_calls_eval_; 575 bool scope_calls_eval_;
584 // This scope uses "arguments". 576 // This scope uses "arguments".
585 bool scope_uses_arguments_; 577 bool scope_uses_arguments_;
586 // This scope uses "super" property ('super.foo'). 578 // This scope uses "super" property ('super.foo').
587 bool scope_uses_super_property_; 579 bool scope_uses_super_property_;
580 // This scope uses "this".
581 bool scope_uses_this_;
588 // This scope contains an "use asm" annotation. 582 // This scope contains an "use asm" annotation.
589 bool asm_module_; 583 bool asm_module_;
590 // This scope's outer context is an asm module. 584 // This scope's outer context is an asm module.
591 bool asm_function_; 585 bool asm_function_;
592 // The language mode of this scope. 586 // The language mode of this scope.
593 LanguageMode language_mode_; 587 LanguageMode language_mode_;
594 // Source positions. 588 // Source positions.
595 int start_position_; 589 int start_position_;
596 int end_position_; 590 int end_position_;
597 591
598 // Computed via PropagateScopeInfo. 592 // Computed via PropagateScopeInfo.
599 bool outer_scope_calls_sloppy_eval_; 593 bool outer_scope_calls_sloppy_eval_;
600 bool inner_scope_calls_eval_; 594 bool inner_scope_calls_eval_;
601 bool inner_scope_uses_arguments_; 595 bool inner_scope_uses_arguments_;
602 bool inner_scope_uses_super_property_; 596 bool inner_scope_uses_super_property_;
597 bool inner_scope_uses_this_;
603 bool force_eager_compilation_; 598 bool force_eager_compilation_;
604 bool force_context_allocation_; 599 bool force_context_allocation_;
605 600
606 // True if it doesn't need scope resolution (e.g., if the scope was 601 // True if it doesn't need scope resolution (e.g., if the scope was
607 // constructed based on a serialized scope info or a catch context). 602 // constructed based on a serialized scope info or a catch context).
608 bool already_resolved_; 603 bool already_resolved_;
609 604
610 // Computed as variables are declared. 605 // Computed as variables are declared.
611 int num_var_or_const_; 606 int num_var_or_const_;
612 607
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 bool MustAllocateInContext(Variable* var); 699 bool MustAllocateInContext(Variable* var);
705 bool HasArgumentsParameter(Isolate* isolate); 700 bool HasArgumentsParameter(Isolate* isolate);
706 701
707 // Variable allocation. 702 // Variable allocation.
708 void AllocateStackSlot(Variable* var); 703 void AllocateStackSlot(Variable* var);
709 void AllocateHeapSlot(Variable* var); 704 void AllocateHeapSlot(Variable* var);
710 void AllocateParameterLocals(Isolate* isolate); 705 void AllocateParameterLocals(Isolate* isolate);
711 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); 706 void AllocateNonParameterLocal(Isolate* isolate, Variable* var);
712 void AllocateNonParameterLocals(Isolate* isolate); 707 void AllocateNonParameterLocals(Isolate* isolate);
713 void AllocateVariablesRecursively(Isolate* isolate); 708 void AllocateVariablesRecursively(Isolate* isolate);
714 void AllocateParameter(Variable* var, int index);
715 void AllocateReceiver();
716 void AllocateModules(); 709 void AllocateModules();
717 710
718 // Resolve and fill in the allocation information for all variables 711 // Resolve and fill in the allocation information for all variables
719 // in this scopes. Must be called *after* all scopes have been 712 // in this scopes. Must be called *after* all scopes have been
720 // processed (parsed) to ensure that unresolved variables can be 713 // processed (parsed) to ensure that unresolved variables can be
721 // resolved properly. 714 // resolved properly.
722 // 715 //
723 // In the case of code compiled and run using 'eval', the context 716 // In the case of code compiled and run using 'eval', the context
724 // parameter is the context in which eval was called. In all other 717 // parameter is the context in which eval was called. In all other
725 // cases the context parameter is an empty handle. 718 // cases the context parameter is an empty handle.
(...skipping 26 matching lines...) Expand all
752 PendingCompilationErrorHandler pending_error_handler_; 745 PendingCompilationErrorHandler pending_error_handler_;
753 746
754 // For tracking which classes are declared consecutively. Needed for strong 747 // For tracking which classes are declared consecutively. Needed for strong
755 // mode. 748 // mode.
756 int class_declaration_group_start_; 749 int class_declaration_group_start_;
757 }; 750 };
758 751
759 } } // namespace v8::internal 752 } } // namespace v8::internal
760 753
761 #endif // V8_SCOPES_H_ 754 #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