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

Side by Side Diff: src/scopes.h

Issue 1097283003: Resolve references to "this" the same way as normal variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Add tests for "this" scoping in arrow functions Created 5 years, 8 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
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Declare an implicit global variable in this scope which must be a 136 // Declare an implicit global variable in this scope which must be a
137 // script scope. The variable was introduced (possibly from an inner 137 // script scope. The variable was introduced (possibly from an inner
138 // scope) by a reference to an unresolved variable with no intervening 138 // scope) by a reference to an unresolved variable with no intervening
139 // with statements or eval calls. 139 // with statements or eval calls.
140 Variable* DeclareDynamicGlobal(const AstRawString* name); 140 Variable* DeclareDynamicGlobal(const AstRawString* name);
141 141
142 // Create a new unresolved variable. 142 // Create a new unresolved variable.
143 VariableProxy* NewUnresolved(AstNodeFactory* factory, 143 VariableProxy* NewUnresolved(AstNodeFactory* factory,
144 const AstRawString* name, 144 const AstRawString* name,
145 int start_position = RelocInfo::kNoPosition, 145 int start_position = RelocInfo::kNoPosition,
146 int end_position = RelocInfo::kNoPosition) { 146 int end_position = RelocInfo::kNoPosition,
147 Variable::Kind kind = Variable::NORMAL) {
147 // Note that we must not share the unresolved variables with 148 // Note that we must not share the unresolved variables with
148 // the same name because they may be removed selectively via 149 // the same name because they may be removed selectively via
149 // RemoveUnresolved(). 150 // RemoveUnresolved().
150 DCHECK(!already_resolved()); 151 DCHECK(!already_resolved());
151 VariableProxy* proxy = factory->NewVariableProxy( 152 VariableProxy* proxy =
152 name, Variable::NORMAL, start_position, end_position); 153 factory->NewVariableProxy(name, kind, start_position, end_position);
153 unresolved_.Add(proxy, zone_); 154 unresolved_.Add(proxy, zone_);
154 return proxy; 155 return proxy;
155 } 156 }
156 157
157 // Remove a unresolved variable. During parsing, an unresolved variable 158 // Remove a unresolved variable. During parsing, an unresolved variable
158 // may have been added optimistically, but then only the variable name 159 // may have been added optimistically, but then only the variable name
159 // was used (typically for labels). If the variable was not declared, the 160 // was used (typically for labels). If the variable was not declared, the
160 // addition introduced a new unresolved variable which may end up being 161 // addition introduced a new unresolved variable which may end up being
161 // allocated globally as a "ghost" variable. RemoveUnresolved removes 162 // allocated globally as a "ghost" variable. RemoveUnresolved removes
162 // such a variable again if it was added; otherwise this is a no-op. 163 // such a variable again if it was added; otherwise this is a no-op.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 338
338 // The type of this scope. 339 // The type of this scope.
339 ScopeType scope_type() const { return scope_type_; } 340 ScopeType scope_type() const { return scope_type_; }
340 341
341 FunctionKind function_kind() const { return function_kind_; } 342 FunctionKind function_kind() const { return function_kind_; }
342 343
343 // The language mode of this scope. 344 // The language mode of this scope.
344 LanguageMode language_mode() const { return language_mode_; } 345 LanguageMode language_mode() const { return language_mode_; }
345 346
346 // The variable corresponding to the 'this' value. 347 // The variable corresponding to the 'this' value.
347 Variable* receiver() { return receiver_; } 348 Variable* receiver() {
349 CHECK(has_this_declaration());
350 CHECK_NOT_NULL(receiver_);
adamk 2015/04/22 15:50:54 These should probably be DCHECKs.
wingo 2015/04/23 14:16:02 Done.
351 return receiver_;
352 }
353
354 Variable* LookupThis() { return Lookup(ast_value_factory_->this_string()); }
355
356 bool has_this_declaration() const {
357 return (is_function_scope() && !is_arrow_scope()) || is_module_scope() ||
358 is_script_scope();
359 }
348 360
349 // The variable corresponding to the 'new.target' value. 361 // The variable corresponding to the 'new.target' value.
350 Variable* new_target_var() { return new_target_; } 362 Variable* new_target_var() { return new_target_; }
351 363
352 // The variable holding the function literal for named function 364 // The variable holding the function literal for named function
353 // literals, or NULL. Only valid for function scopes. 365 // literals, or NULL. Only valid for function scopes.
354 VariableDeclaration* function() const { 366 VariableDeclaration* function() const {
355 DCHECK(is_function_scope()); 367 DCHECK(is_function_scope());
356 return function_; 368 return function_;
357 } 369 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 bool MustAllocateInContext(Variable* var); 700 bool MustAllocateInContext(Variable* var);
689 bool HasArgumentsParameter(Isolate* isolate); 701 bool HasArgumentsParameter(Isolate* isolate);
690 702
691 // Variable allocation. 703 // Variable allocation.
692 void AllocateStackSlot(Variable* var); 704 void AllocateStackSlot(Variable* var);
693 void AllocateHeapSlot(Variable* var); 705 void AllocateHeapSlot(Variable* var);
694 void AllocateParameterLocals(Isolate* isolate); 706 void AllocateParameterLocals(Isolate* isolate);
695 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); 707 void AllocateNonParameterLocal(Isolate* isolate, Variable* var);
696 void AllocateNonParameterLocals(Isolate* isolate); 708 void AllocateNonParameterLocals(Isolate* isolate);
697 void AllocateVariablesRecursively(Isolate* isolate); 709 void AllocateVariablesRecursively(Isolate* isolate);
710 void AllocateParameter(Variable* var, int index);
711 void AllocateReceiver();
698 void AllocateModules(); 712 void AllocateModules();
699 713
700 // Resolve and fill in the allocation information for all variables 714 // Resolve and fill in the allocation information for all variables
701 // in this scopes. Must be called *after* all scopes have been 715 // in this scopes. Must be called *after* all scopes have been
702 // processed (parsed) to ensure that unresolved variables can be 716 // processed (parsed) to ensure that unresolved variables can be
703 // resolved properly. 717 // resolved properly.
704 // 718 //
705 // In the case of code compiled and run using 'eval', the context 719 // In the case of code compiled and run using 'eval', the context
706 // parameter is the context in which eval was called. In all other 720 // parameter is the context in which eval was called. In all other
707 // cases the context parameter is an empty handle. 721 // cases the context parameter is an empty handle.
(...skipping 22 matching lines...) Expand all
730 744
731 AstValueFactory* ast_value_factory_; 745 AstValueFactory* ast_value_factory_;
732 Zone* zone_; 746 Zone* zone_;
733 747
734 PendingCompilationErrorHandler pending_error_handler_; 748 PendingCompilationErrorHandler pending_error_handler_;
735 }; 749 };
736 750
737 } } // namespace v8::internal 751 } } // namespace v8::internal
738 752
739 #endif // V8_SCOPES_H_ 753 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/scopes.cc » ('j') | src/x64/full-codegen-x64.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698