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

Side by Side Diff: src/scopes.h

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