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

Side by Side Diff: src/scopes.cc

Issue 868883002: Remove the dependency of Zone on Isolate (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix compilation issues Created 5 years, 11 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/scopes.h ('k') | src/type-info.h » ('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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/scopes.h" 7 #include "src/scopes.h"
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 DCHECK(p->value != NULL); 60 DCHECK(p->value != NULL);
61 return reinterpret_cast<Variable*>(p->value); 61 return reinterpret_cast<Variable*>(p->value);
62 } 62 }
63 return NULL; 63 return NULL;
64 } 64 }
65 65
66 66
67 // ---------------------------------------------------------------------------- 67 // ----------------------------------------------------------------------------
68 // Implementation of Scope 68 // Implementation of Scope
69 69
70 Scope::Scope(Scope* outer_scope, ScopeType scope_type, 70 Scope::Scope(Isolate* isolate, Zone* zone, Scope* outer_scope,
71 AstValueFactory* ast_value_factory, Zone* zone) 71 ScopeType scope_type, AstValueFactory* ast_value_factory)
72 : isolate_(zone->isolate()), 72 : isolate_(isolate),
73 inner_scopes_(4, zone), 73 inner_scopes_(4, zone),
74 variables_(zone), 74 variables_(zone),
75 internals_(4, zone), 75 internals_(4, zone),
76 temps_(4, zone), 76 temps_(4, zone),
77 params_(4, zone), 77 params_(4, zone),
78 unresolved_(16, zone), 78 unresolved_(16, zone),
79 decls_(4, zone), 79 decls_(4, zone),
80 interface_(FLAG_harmony_modules && 80 interface_(FLAG_harmony_modules && (scope_type == MODULE_SCOPE ||
81 (scope_type == MODULE_SCOPE || scope_type == SCRIPT_SCOPE) 81 scope_type == SCRIPT_SCOPE)
82 ? Interface::NewModule(zone) : NULL), 82 ? Interface::NewModule(zone)
83 : NULL),
83 already_resolved_(false), 84 already_resolved_(false),
84 ast_value_factory_(ast_value_factory), 85 ast_value_factory_(ast_value_factory),
85 zone_(zone) { 86 zone_(zone) {
86 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null()); 87 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null());
87 // The outermost scope must be a script scope. 88 // The outermost scope must be a script scope.
88 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); 89 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL);
89 DCHECK(!HasIllegalRedeclaration()); 90 DCHECK(!HasIllegalRedeclaration());
90 } 91 }
91 92
92 93
93 Scope::Scope(Scope* inner_scope, 94 Scope::Scope(Isolate* isolate, Zone* zone, Scope* inner_scope,
94 ScopeType scope_type, 95 ScopeType scope_type, Handle<ScopeInfo> scope_info,
95 Handle<ScopeInfo> scope_info, 96 AstValueFactory* value_factory)
96 AstValueFactory* value_factory, 97 : isolate_(isolate),
97 Zone* zone)
98 : isolate_(zone->isolate()),
99 inner_scopes_(4, zone), 98 inner_scopes_(4, zone),
100 variables_(zone), 99 variables_(zone),
101 internals_(4, zone), 100 internals_(4, zone),
102 temps_(4, zone), 101 temps_(4, zone),
103 params_(4, zone), 102 params_(4, zone),
104 unresolved_(16, zone), 103 unresolved_(16, zone),
105 decls_(4, zone), 104 decls_(4, zone),
106 interface_(NULL), 105 interface_(NULL),
107 already_resolved_(true), 106 already_resolved_(true),
108 ast_value_factory_(value_factory), 107 ast_value_factory_(value_factory),
109 zone_(zone) { 108 zone_(zone) {
110 SetDefaults(scope_type, NULL, scope_info); 109 SetDefaults(scope_type, NULL, scope_info);
111 if (!scope_info.is_null()) { 110 if (!scope_info.is_null()) {
112 num_heap_slots_ = scope_info_->ContextLength(); 111 num_heap_slots_ = scope_info_->ContextLength();
113 } 112 }
114 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. 113 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
115 num_heap_slots_ = Max(num_heap_slots_, 114 num_heap_slots_ = Max(num_heap_slots_,
116 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); 115 static_cast<int>(Context::MIN_CONTEXT_SLOTS));
117 AddInnerScope(inner_scope); 116 AddInnerScope(inner_scope);
118 } 117 }
119 118
120 119
121 Scope::Scope(Scope* inner_scope, const AstRawString* catch_variable_name, 120 Scope::Scope(Isolate* isolate, Zone* zone, Scope* inner_scope,
122 AstValueFactory* value_factory, Zone* zone) 121 const AstRawString* catch_variable_name,
123 : isolate_(zone->isolate()), 122 AstValueFactory* value_factory)
123 : isolate_(isolate),
124 inner_scopes_(1, zone), 124 inner_scopes_(1, zone),
125 variables_(zone), 125 variables_(zone),
126 internals_(0, zone), 126 internals_(0, zone),
127 temps_(0, zone), 127 temps_(0, zone),
128 params_(0, zone), 128 params_(0, zone),
129 unresolved_(0, zone), 129 unresolved_(0, zone),
130 decls_(0, zone), 130 decls_(0, zone),
131 interface_(NULL), 131 interface_(NULL),
132 already_resolved_(true), 132 already_resolved_(true),
133 ast_value_factory_(value_factory), 133 ast_value_factory_(value_factory),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 scope_info_ = scope_info; 185 scope_info_ = scope_info;
186 start_position_ = RelocInfo::kNoPosition; 186 start_position_ = RelocInfo::kNoPosition;
187 end_position_ = RelocInfo::kNoPosition; 187 end_position_ = RelocInfo::kNoPosition;
188 if (!scope_info.is_null()) { 188 if (!scope_info.is_null()) {
189 scope_calls_eval_ = scope_info->CallsEval(); 189 scope_calls_eval_ = scope_info->CallsEval();
190 strict_mode_ = scope_info->strict_mode(); 190 strict_mode_ = scope_info->strict_mode();
191 } 191 }
192 } 192 }
193 193
194 194
195 Scope* Scope::DeserializeScopeChain(Context* context, Scope* script_scope, 195 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
196 Zone* zone) { 196 Context* context, Scope* script_scope) {
197 // Reconstruct the outer scope chain from a closure's context chain. 197 // Reconstruct the outer scope chain from a closure's context chain.
198 Scope* current_scope = NULL; 198 Scope* current_scope = NULL;
199 Scope* innermost_scope = NULL; 199 Scope* innermost_scope = NULL;
200 bool contains_with = false; 200 bool contains_with = false;
201 while (!context->IsNativeContext()) { 201 while (!context->IsNativeContext()) {
202 if (context->IsWithContext()) { 202 if (context->IsWithContext()) {
203 Scope* with_scope = new(zone) Scope(current_scope, 203 Scope* with_scope = new (zone)
204 WITH_SCOPE, 204 Scope(isolate, zone, current_scope, WITH_SCOPE,
205 Handle<ScopeInfo>::null(), 205 Handle<ScopeInfo>::null(), script_scope->ast_value_factory_);
206 script_scope->ast_value_factory_,
207 zone);
208 current_scope = with_scope; 206 current_scope = with_scope;
209 // All the inner scopes are inside a with. 207 // All the inner scopes are inside a with.
210 contains_with = true; 208 contains_with = true;
211 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) { 209 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) {
212 s->scope_inside_with_ = true; 210 s->scope_inside_with_ = true;
213 } 211 }
214 } else if (context->IsScriptContext()) { 212 } else if (context->IsScriptContext()) {
215 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); 213 ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
216 current_scope = new(zone) Scope(current_scope, 214 current_scope = new (zone) Scope(
217 SCRIPT_SCOPE, 215 isolate, zone, current_scope, SCRIPT_SCOPE,
218 Handle<ScopeInfo>(scope_info), 216 Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
219 script_scope->ast_value_factory_,
220 zone);
221 } else if (context->IsModuleContext()) { 217 } else if (context->IsModuleContext()) {
222 ScopeInfo* scope_info = ScopeInfo::cast(context->module()->scope_info()); 218 ScopeInfo* scope_info = ScopeInfo::cast(context->module()->scope_info());
223 current_scope = new(zone) Scope(current_scope, 219 current_scope = new (zone) Scope(
224 MODULE_SCOPE, 220 isolate, zone, current_scope, MODULE_SCOPE,
225 Handle<ScopeInfo>(scope_info), 221 Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
226 script_scope->ast_value_factory_,
227 zone);
228 } else if (context->IsFunctionContext()) { 222 } else if (context->IsFunctionContext()) {
229 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); 223 ScopeInfo* scope_info = context->closure()->shared()->scope_info();
230 current_scope = new(zone) Scope(current_scope, 224 current_scope = new (zone) Scope(
231 FUNCTION_SCOPE, 225 isolate, zone, current_scope, FUNCTION_SCOPE,
232 Handle<ScopeInfo>(scope_info), 226 Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
233 script_scope->ast_value_factory_,
234 zone);
235 if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true; 227 if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true;
236 if (scope_info->IsAsmModule()) current_scope->asm_module_ = true; 228 if (scope_info->IsAsmModule()) current_scope->asm_module_ = true;
237 } else if (context->IsBlockContext()) { 229 } else if (context->IsBlockContext()) {
238 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); 230 ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
239 current_scope = new(zone) Scope(current_scope, 231 current_scope = new (zone) Scope(
240 BLOCK_SCOPE, 232 isolate, zone, current_scope, BLOCK_SCOPE,
241 Handle<ScopeInfo>(scope_info), 233 Handle<ScopeInfo>(scope_info), script_scope->ast_value_factory_);
242 script_scope->ast_value_factory_,
243 zone);
244 } else { 234 } else {
245 DCHECK(context->IsCatchContext()); 235 DCHECK(context->IsCatchContext());
246 String* name = String::cast(context->extension()); 236 String* name = String::cast(context->extension());
247 current_scope = new (zone) Scope( 237 current_scope = new (zone) Scope(
248 current_scope, 238 isolate, zone, current_scope,
249 script_scope->ast_value_factory_->GetString(Handle<String>(name)), 239 script_scope->ast_value_factory_->GetString(Handle<String>(name)),
250 script_scope->ast_value_factory_, zone); 240 script_scope->ast_value_factory_);
251 } 241 }
252 if (contains_with) current_scope->RecordWithStatement(); 242 if (contains_with) current_scope->RecordWithStatement();
253 if (innermost_scope == NULL) innermost_scope = current_scope; 243 if (innermost_scope == NULL) innermost_scope = current_scope;
254 244
255 // Forget about a with when we move to a context for a different function. 245 // Forget about a with when we move to a context for a different function.
256 if (context->previous()->closure() != context->closure()) { 246 if (context->previous()->closure() != context->closure()) {
257 contains_with = false; 247 contains_with = false;
258 } 248 }
259 context = context->previous(); 249 context = context->previous();
260 } 250 }
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 Scope* scope = this; 741 Scope* scope = this;
752 while (!scope->is_declaration_scope()) { 742 while (!scope->is_declaration_scope()) {
753 scope = scope->outer_scope(); 743 scope = scope->outer_scope();
754 } 744 }
755 return scope; 745 return scope;
756 } 746 }
757 747
758 748
759 Handle<ScopeInfo> Scope::GetScopeInfo() { 749 Handle<ScopeInfo> Scope::GetScopeInfo() {
760 if (scope_info_.is_null()) { 750 if (scope_info_.is_null()) {
761 scope_info_ = ScopeInfo::Create(this, zone()); 751 scope_info_ = ScopeInfo::Create(isolate(), zone(), this);
762 } 752 }
763 return scope_info_; 753 return scope_info_;
764 } 754 }
765 755
766 756
767 void Scope::GetNestedScopeChain( 757 void Scope::GetNestedScopeChain(
768 List<Handle<ScopeInfo> >* chain, 758 List<Handle<ScopeInfo> >* chain,
769 int position) { 759 int position) {
770 if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo())); 760 if (!is_eval_scope()) chain->Add(Handle<ScopeInfo>(GetScopeInfo()));
771 761
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 } 1423 }
1434 1424
1435 1425
1436 int Scope::ContextLocalCount() const { 1426 int Scope::ContextLocalCount() const {
1437 if (num_heap_slots() == 0) return 0; 1427 if (num_heap_slots() == 0) return 0;
1438 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1428 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1439 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1429 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1440 } 1430 }
1441 1431
1442 } } // namespace v8::internal 1432 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/type-info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698