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

Side by Side Diff: src/scopes.h

Issue 1414283002: [es6] Fix scoping for default parameters in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased Created 5 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
« no previous file with comments | « src/pattern-rewriter.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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 scope_name_ = scope_name; 105 scope_name_ = scope_name;
106 } 106 }
107 107
108 void Initialize(); 108 void Initialize();
109 109
110 // Checks if the block scope is redundant, i.e. it does not contain any 110 // Checks if the block scope is redundant, i.e. it does not contain any
111 // block scoped declarations. In that case it is removed from the scope 111 // block scoped declarations. In that case it is removed from the scope
112 // tree and its children are reparented. 112 // tree and its children are reparented.
113 Scope* FinalizeBlockScope(); 113 Scope* FinalizeBlockScope();
114 114
115 // Inserts outer_scope into this scope's scope chain (and removes this
116 // from the current outer_scope_'s inner_scopes_).
117 // Assumes outer_scope_ is non-null.
118 void ReplaceOuterScope(Scope* outer_scope);
119
115 Zone* zone() const { return zone_; } 120 Zone* zone() const { return zone_; }
116 121
117 // --------------------------------------------------------------------------- 122 // ---------------------------------------------------------------------------
118 // Declarations 123 // Declarations
119 124
120 // Lookup a variable in this scope. Returns the variable or NULL if not found. 125 // Lookup a variable in this scope. Returns the variable or NULL if not found.
121 Variable* LookupLocal(const AstRawString* name); 126 Variable* LookupLocal(const AstRawString* name);
122 127
123 // This lookup corresponds to a lookup in the "intermediate" scope sitting 128 // This lookup corresponds to a lookup in the "intermediate" scope sitting
124 // between this scope and the outer scope. (ECMA-262, 3rd., requires that 129 // between this scope and the outer scope. (ECMA-262, 3rd., requires that
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Note that we must not share the unresolved variables with 176 // Note that we must not share the unresolved variables with
172 // the same name because they may be removed selectively via 177 // the same name because they may be removed selectively via
173 // RemoveUnresolved(). 178 // RemoveUnresolved().
174 DCHECK(!already_resolved()); 179 DCHECK(!already_resolved());
175 VariableProxy* proxy = 180 VariableProxy* proxy =
176 factory->NewVariableProxy(name, kind, start_position, end_position); 181 factory->NewVariableProxy(name, kind, start_position, end_position);
177 unresolved_.Add(proxy, zone_); 182 unresolved_.Add(proxy, zone_);
178 return proxy; 183 return proxy;
179 } 184 }
180 185
186 void AddUnresolved(VariableProxy* proxy) {
187 DCHECK(!already_resolved());
188 DCHECK(!proxy->is_resolved());
189 unresolved_.Add(proxy, zone_);
190 }
191
181 // Remove a unresolved variable. During parsing, an unresolved variable 192 // Remove a unresolved variable. During parsing, an unresolved variable
182 // may have been added optimistically, but then only the variable name 193 // may have been added optimistically, but then only the variable name
183 // was used (typically for labels). If the variable was not declared, the 194 // was used (typically for labels). If the variable was not declared, the
184 // addition introduced a new unresolved variable which may end up being 195 // addition introduced a new unresolved variable which may end up being
185 // allocated globally as a "ghost" variable. RemoveUnresolved removes 196 // allocated globally as a "ghost" variable. RemoveUnresolved removes
186 // such a variable again if it was added; otherwise this is a no-op. 197 // such a variable again if it was added; otherwise this is a no-op.
187 void RemoveUnresolved(VariableProxy* var); 198 bool RemoveUnresolved(VariableProxy* var);
188 199
189 // Creates a new temporary variable in this scope's TemporaryScope. The 200 // Creates a new temporary variable in this scope's TemporaryScope. The
190 // name is only used for printing and cannot be used to find the variable. 201 // name is only used for printing and cannot be used to find the variable.
191 // In particular, the only way to get hold of the temporary is by keeping the 202 // In particular, the only way to get hold of the temporary is by keeping the
192 // Variable* around. The name should not clash with a legitimate variable 203 // Variable* around. The name should not clash with a legitimate variable
193 // names. 204 // names.
194 Variable* NewTemporary(const AstRawString* name); 205 Variable* NewTemporary(const AstRawString* name);
195 206
196 // Adds the specific declaration node to the list of declarations in 207 // Adds the specific declaration node to the list of declarations in
197 // this scope. The declarations are processed as part of entering 208 // this scope. The declarations are processed as part of entering
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name, 817 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name,
807 AstValueFactory* value_factory); 818 AstValueFactory* value_factory);
808 819
809 void AddInnerScope(Scope* inner_scope) { 820 void AddInnerScope(Scope* inner_scope) {
810 if (inner_scope != NULL) { 821 if (inner_scope != NULL) {
811 inner_scopes_.Add(inner_scope, zone_); 822 inner_scopes_.Add(inner_scope, zone_);
812 inner_scope->outer_scope_ = this; 823 inner_scope->outer_scope_ = this;
813 } 824 }
814 } 825 }
815 826
827 void RemoveInnerScope(Scope* inner_scope) {
828 DCHECK_NOT_NULL(inner_scope);
829 for (int i = 0; i < inner_scopes_.length(); i++) {
830 if (inner_scopes_[i] == inner_scope) {
831 inner_scopes_.Remove(i);
832 break;
833 }
834 }
835 }
836
816 void SetDefaults(ScopeType type, Scope* outer_scope, 837 void SetDefaults(ScopeType type, Scope* outer_scope,
817 Handle<ScopeInfo> scope_info, 838 Handle<ScopeInfo> scope_info,
818 FunctionKind function_kind = kNormalFunction); 839 FunctionKind function_kind = kNormalFunction);
819 840
820 AstValueFactory* ast_value_factory_; 841 AstValueFactory* ast_value_factory_;
821 Zone* zone_; 842 Zone* zone_;
822 843
823 PendingCompilationErrorHandler pending_error_handler_; 844 PendingCompilationErrorHandler pending_error_handler_;
824 845
825 // For tracking which classes are declared consecutively. Needed for strong 846 // For tracking which classes are declared consecutively. Needed for strong
826 // mode. 847 // mode.
827 int class_declaration_group_start_; 848 int class_declaration_group_start_;
828 }; 849 };
829 850
830 } // namespace internal 851 } // namespace internal
831 } // namespace v8 852 } // namespace v8
832 853
833 #endif // V8_SCOPES_H_ 854 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/pattern-rewriter.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698