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

Side by Side Diff: src/scopes.cc

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: more cleanup Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/scopes.h ('k') | src/utils.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 "v8.h" 5 #include "v8.h"
6 6
7 #include "scopes.h" 7 #include "scopes.h"
8 8
9 #include "accessors.h" 9 #include "accessors.h"
10 #include "bootstrapper.h" 10 #include "bootstrapper.h"
11 #include "compiler.h" 11 #include "compiler.h"
12 #include "messages.h" 12 #include "messages.h"
13 #include "scopeinfo.h" 13 #include "scopeinfo.h"
14 14
15 namespace v8 { 15 namespace v8 {
16 namespace internal { 16 namespace internal {
17 17
18 // ---------------------------------------------------------------------------- 18 // ----------------------------------------------------------------------------
19 // Implementation of LocalsMap 19 // Implementation of LocalsMap
20 // 20 //
21 // Note: We are storing the handle locations as key values in the hash map. 21 // Note: We are storing the handle locations as key values in the hash map.
22 // When inserting a new variable via Declare(), we rely on the fact that 22 // When inserting a new variable via Declare(), we rely on the fact that
23 // the handle location remains alive for the duration of that variable 23 // the handle location remains alive for the duration of that variable
24 // use. Because a Variable holding a handle with the same location exists 24 // use. Because a Variable holding a handle with the same location exists
25 // this is ensured. 25 // this is ensured.
26 26
27 static bool Match(void* key1, void* key2) {
28 String* name1 = *reinterpret_cast<String**>(key1);
29 String* name2 = *reinterpret_cast<String**>(key2);
30 ASSERT(name1->IsInternalizedString());
31 ASSERT(name2->IsInternalizedString());
32 return name1 == name2;
33 }
34
35
36 VariableMap::VariableMap(Zone* zone) 27 VariableMap::VariableMap(Zone* zone)
37 : ZoneHashMap(Match, 8, ZoneAllocationPolicy(zone)), 28 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)),
38 zone_(zone) {} 29 zone_(zone) {}
39 VariableMap::~VariableMap() {} 30 VariableMap::~VariableMap() {}
40 31
41 32
42 Variable* VariableMap::Declare( 33 Variable* VariableMap::Declare(
43 Scope* scope, 34 Scope* scope,
44 Handle<String> name, 35 const AstString* name,
45 VariableMode mode, 36 VariableMode mode,
46 bool is_valid_lhs, 37 bool is_valid_lhs,
47 Variable::Kind kind, 38 Variable::Kind kind,
48 InitializationFlag initialization_flag, 39 InitializationFlag initialization_flag,
49 Interface* interface) { 40 Interface* interface) {
50 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), true, 41 // AstStrings are unambiguous, i.e., the same string is always represented by
51 ZoneAllocationPolicy(zone())); 42 // the same AstString*.
43 Entry* p = ZoneHashMap::Lookup(const_cast<AstString*>(name), name->hash(),
44 true, ZoneAllocationPolicy(zone()));
52 if (p->value == NULL) { 45 if (p->value == NULL) {
53 // The variable has not been declared yet -> insert it. 46 // The variable has not been declared yet -> insert it.
54 ASSERT(p->key == name.location()); 47 ASSERT(p->key == name);
55 p->value = new(zone()) Variable(scope, 48 p->value = new(zone()) Variable(scope,
56 name, 49 name,
57 mode, 50 mode,
58 is_valid_lhs, 51 is_valid_lhs,
59 kind, 52 kind,
60 initialization_flag, 53 initialization_flag,
61 interface); 54 interface);
62 } 55 }
63 return reinterpret_cast<Variable*>(p->value); 56 return reinterpret_cast<Variable*>(p->value);
64 } 57 }
65 58
66 59
67 Variable* VariableMap::Lookup(Handle<String> name) { 60 Variable* VariableMap::Lookup(const AstString* name) {
68 Entry* p = ZoneHashMap::Lookup(name.location(), name->Hash(), false, 61 Entry* p = ZoneHashMap::Lookup(const_cast<AstString*>(name), name->hash(),
69 ZoneAllocationPolicy(NULL)); 62 false, ZoneAllocationPolicy(NULL));
70 if (p != NULL) { 63 if (p != NULL) {
71 ASSERT(*reinterpret_cast<String**>(p->key) == *name); 64 ASSERT(reinterpret_cast<const AstString*>(p->key) == name);
72 ASSERT(p->value != NULL); 65 ASSERT(p->value != NULL);
73 return reinterpret_cast<Variable*>(p->value); 66 return reinterpret_cast<Variable*>(p->value);
74 } 67 }
75 return NULL; 68 return NULL;
76 } 69 }
77 70
78 71
79 // ---------------------------------------------------------------------------- 72 // ----------------------------------------------------------------------------
80 // Implementation of Scope 73 // Implementation of Scope
81 74
82 Scope::Scope(Scope* outer_scope, ScopeType scope_type, Zone* zone) 75 Scope::Scope(Scope* outer_scope, ScopeType scope_type,
76 AstStringTable* string_table, Zone* zone)
83 : isolate_(zone->isolate()), 77 : isolate_(zone->isolate()),
84 inner_scopes_(4, zone), 78 inner_scopes_(4, zone),
85 variables_(zone), 79 variables_(zone),
86 internals_(4, zone), 80 internals_(4, zone),
87 temps_(4, zone), 81 temps_(4, zone),
88 params_(4, zone), 82 params_(4, zone),
89 unresolved_(16, zone), 83 unresolved_(16, zone),
90 decls_(4, zone), 84 decls_(4, zone),
91 interface_(FLAG_harmony_modules && 85 interface_(FLAG_harmony_modules &&
92 (scope_type == MODULE_SCOPE || scope_type == GLOBAL_SCOPE) 86 (scope_type == MODULE_SCOPE || scope_type == GLOBAL_SCOPE)
93 ? Interface::NewModule(zone) : NULL), 87 ? Interface::NewModule(zone) : NULL),
94 already_resolved_(false), 88 already_resolved_(false),
89 string_table_(string_table),
95 zone_(zone) { 90 zone_(zone) {
96 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null()); 91 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null());
97 // The outermost scope must be a global scope. 92 // The outermost scope must be a global scope.
98 ASSERT(scope_type == GLOBAL_SCOPE || outer_scope != NULL); 93 ASSERT(scope_type == GLOBAL_SCOPE || outer_scope != NULL);
99 ASSERT(!HasIllegalRedeclaration()); 94 ASSERT(!HasIllegalRedeclaration());
100 } 95 }
101 96
102 97
103 Scope::Scope(Scope* inner_scope, 98 Scope::Scope(Scope* inner_scope,
104 ScopeType scope_type, 99 ScopeType scope_type,
105 Handle<ScopeInfo> scope_info, 100 Handle<ScopeInfo> scope_info,
101 AstStringTable* string_table,
106 Zone* zone) 102 Zone* zone)
107 : isolate_(zone->isolate()), 103 : isolate_(zone->isolate()),
108 inner_scopes_(4, zone), 104 inner_scopes_(4, zone),
109 variables_(zone), 105 variables_(zone),
110 internals_(4, zone), 106 internals_(4, zone),
111 temps_(4, zone), 107 temps_(4, zone),
112 params_(4, zone), 108 params_(4, zone),
113 unresolved_(16, zone), 109 unresolved_(16, zone),
114 decls_(4, zone), 110 decls_(4, zone),
115 interface_(NULL), 111 interface_(NULL),
116 already_resolved_(true), 112 already_resolved_(true),
113 string_table_(string_table),
117 zone_(zone) { 114 zone_(zone) {
118 SetDefaults(scope_type, NULL, scope_info); 115 SetDefaults(scope_type, NULL, scope_info);
119 if (!scope_info.is_null()) { 116 if (!scope_info.is_null()) {
120 num_heap_slots_ = scope_info_->ContextLength(); 117 num_heap_slots_ = scope_info_->ContextLength();
121 } 118 }
122 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. 119 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context.
123 num_heap_slots_ = Max(num_heap_slots_, 120 num_heap_slots_ = Max(num_heap_slots_,
124 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); 121 static_cast<int>(Context::MIN_CONTEXT_SLOTS));
125 AddInnerScope(inner_scope); 122 AddInnerScope(inner_scope);
126 } 123 }
127 124
128 125
129 Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name, Zone* zone) 126 Scope::Scope(Scope* inner_scope, const AstString* catch_variable_name,
127 AstStringTable* string_table, Zone* zone)
130 : isolate_(zone->isolate()), 128 : isolate_(zone->isolate()),
131 inner_scopes_(1, zone), 129 inner_scopes_(1, zone),
132 variables_(zone), 130 variables_(zone),
133 internals_(0, zone), 131 internals_(0, zone),
134 temps_(0, zone), 132 temps_(0, zone),
135 params_(0, zone), 133 params_(0, zone),
136 unresolved_(0, zone), 134 unresolved_(0, zone),
137 decls_(0, zone), 135 decls_(0, zone),
138 interface_(NULL), 136 interface_(NULL),
139 already_resolved_(true), 137 already_resolved_(true),
138 string_table_(string_table),
140 zone_(zone) { 139 zone_(zone) {
141 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); 140 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null());
142 AddInnerScope(inner_scope); 141 AddInnerScope(inner_scope);
143 ++num_var_or_const_; 142 ++num_var_or_const_;
144 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 143 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
145 Variable* variable = variables_.Declare(this, 144 Variable* variable = variables_.Declare(this,
146 catch_variable_name, 145 catch_variable_name,
147 VAR, 146 VAR,
148 true, // Valid left-hand side. 147 true, // Valid left-hand side.
149 Variable::NORMAL, 148 Variable::NORMAL,
150 kCreatedInitialized); 149 kCreatedInitialized);
151 AllocateHeapSlot(variable); 150 AllocateHeapSlot(variable);
152 } 151 }
153 152
154 153
155 void Scope::SetDefaults(ScopeType scope_type, 154 void Scope::SetDefaults(ScopeType scope_type,
156 Scope* outer_scope, 155 Scope* outer_scope,
157 Handle<ScopeInfo> scope_info) { 156 Handle<ScopeInfo> scope_info) {
158 outer_scope_ = outer_scope; 157 outer_scope_ = outer_scope;
159 scope_type_ = scope_type; 158 scope_type_ = scope_type;
160 scope_name_ = isolate_->factory()->empty_string(); 159 scope_name_ = string_table_->empty_string();
161 dynamics_ = NULL; 160 dynamics_ = NULL;
162 receiver_ = NULL; 161 receiver_ = NULL;
163 function_ = NULL; 162 function_ = NULL;
164 arguments_ = NULL; 163 arguments_ = NULL;
165 illegal_redecl_ = NULL; 164 illegal_redecl_ = NULL;
166 scope_inside_with_ = false; 165 scope_inside_with_ = false;
167 scope_contains_with_ = false; 166 scope_contains_with_ = false;
168 scope_calls_eval_ = false; 167 scope_calls_eval_ = false;
169 // Inherit the strict mode from the parent scope. 168 // Inherit the strict mode from the parent scope.
170 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY; 169 strict_mode_ = outer_scope != NULL ? outer_scope->strict_mode_ : SLOPPY;
(...skipping 21 matching lines...) Expand all
192 Zone* zone) { 191 Zone* zone) {
193 // Reconstruct the outer scope chain from a closure's context chain. 192 // Reconstruct the outer scope chain from a closure's context chain.
194 Scope* current_scope = NULL; 193 Scope* current_scope = NULL;
195 Scope* innermost_scope = NULL; 194 Scope* innermost_scope = NULL;
196 bool contains_with = false; 195 bool contains_with = false;
197 while (!context->IsNativeContext()) { 196 while (!context->IsNativeContext()) {
198 if (context->IsWithContext()) { 197 if (context->IsWithContext()) {
199 Scope* with_scope = new(zone) Scope(current_scope, 198 Scope* with_scope = new(zone) Scope(current_scope,
200 WITH_SCOPE, 199 WITH_SCOPE,
201 Handle<ScopeInfo>::null(), 200 Handle<ScopeInfo>::null(),
201 global_scope->string_table_,
202 zone); 202 zone);
203 current_scope = with_scope; 203 current_scope = with_scope;
204 // All the inner scopes are inside a with. 204 // All the inner scopes are inside a with.
205 contains_with = true; 205 contains_with = true;
206 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) { 206 for (Scope* s = innermost_scope; s != NULL; s = s->outer_scope()) {
207 s->scope_inside_with_ = true; 207 s->scope_inside_with_ = true;
208 } 208 }
209 } else if (context->IsGlobalContext()) { 209 } else if (context->IsGlobalContext()) {
210 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); 210 ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
211 current_scope = new(zone) Scope(current_scope, 211 current_scope = new(zone) Scope(current_scope,
212 GLOBAL_SCOPE, 212 GLOBAL_SCOPE,
213 Handle<ScopeInfo>(scope_info), 213 Handle<ScopeInfo>(scope_info),
214 global_scope->string_table_,
214 zone); 215 zone);
215 } else if (context->IsModuleContext()) { 216 } else if (context->IsModuleContext()) {
216 ScopeInfo* scope_info = ScopeInfo::cast(context->module()->scope_info()); 217 ScopeInfo* scope_info = ScopeInfo::cast(context->module()->scope_info());
217 current_scope = new(zone) Scope(current_scope, 218 current_scope = new(zone) Scope(current_scope,
218 MODULE_SCOPE, 219 MODULE_SCOPE,
219 Handle<ScopeInfo>(scope_info), 220 Handle<ScopeInfo>(scope_info),
221 global_scope->string_table_,
220 zone); 222 zone);
221 } else if (context->IsFunctionContext()) { 223 } else if (context->IsFunctionContext()) {
222 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); 224 ScopeInfo* scope_info = context->closure()->shared()->scope_info();
223 current_scope = new(zone) Scope(current_scope, 225 current_scope = new(zone) Scope(current_scope,
224 FUNCTION_SCOPE, 226 FUNCTION_SCOPE,
225 Handle<ScopeInfo>(scope_info), 227 Handle<ScopeInfo>(scope_info),
228 global_scope->string_table_,
226 zone); 229 zone);
227 } else if (context->IsBlockContext()) { 230 } else if (context->IsBlockContext()) {
228 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); 231 ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
229 current_scope = new(zone) Scope(current_scope, 232 current_scope = new(zone) Scope(current_scope,
230 BLOCK_SCOPE, 233 BLOCK_SCOPE,
231 Handle<ScopeInfo>(scope_info), 234 Handle<ScopeInfo>(scope_info),
235 global_scope->string_table_,
232 zone); 236 zone);
233 } else { 237 } else {
234 ASSERT(context->IsCatchContext()); 238 ASSERT(context->IsCatchContext());
235 String* name = String::cast(context->extension()); 239 String* name = String::cast(context->extension());
236 current_scope = new(zone) Scope( 240 current_scope = new(zone)
237 current_scope, Handle<String>(name), zone); 241 Scope(current_scope,
242 global_scope->string_table_->GetString(Handle<String>(name)),
243 global_scope->string_table_, zone);
238 } 244 }
239 if (contains_with) current_scope->RecordWithStatement(); 245 if (contains_with) current_scope->RecordWithStatement();
240 if (innermost_scope == NULL) innermost_scope = current_scope; 246 if (innermost_scope == NULL) innermost_scope = current_scope;
241 247
242 // Forget about a with when we move to a context for a different function. 248 // Forget about a with when we move to a context for a different function.
243 if (context->previous()->closure() != context->closure()) { 249 if (context->previous()->closure() != context->closure()) {
244 contains_with = false; 250 contains_with = false;
245 } 251 }
246 context = context->previous(); 252 context = context->previous();
247 } 253 }
(...skipping 11 matching lines...) Expand all
259 265
260 // Traverse the scope tree up to the first unresolved scope or the global 266 // Traverse the scope tree up to the first unresolved scope or the global
261 // scope and start scope resolution and variable allocation from that scope. 267 // scope and start scope resolution and variable allocation from that scope.
262 while (!top->is_global_scope() && 268 while (!top->is_global_scope() &&
263 !top->outer_scope()->already_resolved()) { 269 !top->outer_scope()->already_resolved()) {
264 top = top->outer_scope(); 270 top = top->outer_scope();
265 } 271 }
266 272
267 // Allocate the variables. 273 // Allocate the variables.
268 { 274 {
269 AstNodeFactory<AstNullVisitor> ast_node_factory(info->zone()); 275 // Passing NULL as AstStringTable is ok, because AllocateVariables doesn't
276 // need to create new strings or values.
277 AstNodeFactory<AstNullVisitor> ast_node_factory(info->zone(), NULL);
270 if (!top->AllocateVariables(info, &ast_node_factory)) return false; 278 if (!top->AllocateVariables(info, &ast_node_factory)) return false;
271 } 279 }
272 280
273 #ifdef DEBUG 281 #ifdef DEBUG
274 if (info->isolate()->bootstrapper()->IsActive() 282 if (info->isolate()->bootstrapper()->IsActive()
275 ? FLAG_print_builtin_scopes 283 ? FLAG_print_builtin_scopes
276 : FLAG_print_scopes) { 284 : FLAG_print_scopes) {
277 scope->Print(); 285 scope->Print();
278 } 286 }
279 287
(...skipping 23 matching lines...) Expand all
303 // Declare and allocate receiver (even for the global scope, and even 311 // Declare and allocate receiver (even for the global scope, and even
304 // if naccesses_ == 0). 312 // if naccesses_ == 0).
305 // NOTE: When loading parameters in the global scope, we must take 313 // NOTE: When loading parameters in the global scope, we must take
306 // care not to access them as properties of the global object, but 314 // care not to access them as properties of the global object, but
307 // instead load them directly from the stack. Currently, the only 315 // instead load them directly from the stack. Currently, the only
308 // such parameter is 'this' which is passed on the stack when 316 // such parameter is 'this' which is passed on the stack when
309 // invoking scripts 317 // invoking scripts
310 if (is_declaration_scope()) { 318 if (is_declaration_scope()) {
311 Variable* var = 319 Variable* var =
312 variables_.Declare(this, 320 variables_.Declare(this,
313 isolate_->factory()->this_string(), 321 string_table_->this_string(),
314 VAR, 322 VAR,
315 false, 323 false,
316 Variable::THIS, 324 Variable::THIS,
317 kCreatedInitialized); 325 kCreatedInitialized);
318 var->AllocateTo(Variable::PARAMETER, -1); 326 var->AllocateTo(Variable::PARAMETER, -1);
319 receiver_ = var; 327 receiver_ = var;
320 } else { 328 } else {
321 ASSERT(outer_scope() != NULL); 329 ASSERT(outer_scope() != NULL);
322 receiver_ = outer_scope()->receiver(); 330 receiver_ = outer_scope()->receiver();
323 } 331 }
324 332
325 if (is_function_scope()) { 333 if (is_function_scope()) {
326 // Declare 'arguments' variable which exists in all functions. 334 // Declare 'arguments' variable which exists in all functions.
327 // Note that it might never be accessed, in which case it won't be 335 // Note that it might never be accessed, in which case it won't be
328 // allocated during variable allocation. 336 // allocated during variable allocation.
329 variables_.Declare(this, 337 variables_.Declare(this,
330 isolate_->factory()->arguments_string(), 338 string_table_->arguments_string(),
331 VAR, 339 VAR,
332 true, 340 true,
333 Variable::ARGUMENTS, 341 Variable::ARGUMENTS,
334 kCreatedInitialized); 342 kCreatedInitialized);
335 } 343 }
336 } 344 }
337 345
338 346
339 Scope* Scope::FinalizeBlockScope() { 347 Scope* Scope::FinalizeBlockScope() {
340 ASSERT(is_block_scope()); 348 ASSERT(is_block_scope());
(...skipping 18 matching lines...) Expand all
359 367
360 // Move unresolved variables 368 // Move unresolved variables
361 for (int i = 0; i < unresolved_.length(); i++) { 369 for (int i = 0; i < unresolved_.length(); i++) {
362 outer_scope()->unresolved_.Add(unresolved_[i], zone()); 370 outer_scope()->unresolved_.Add(unresolved_[i], zone());
363 } 371 }
364 372
365 return NULL; 373 return NULL;
366 } 374 }
367 375
368 376
369 Variable* Scope::LookupLocal(Handle<String> name) { 377 Variable* Scope::LookupLocal(const AstString* name) {
370 Variable* result = variables_.Lookup(name); 378 Variable* result = variables_.Lookup(name);
371 if (result != NULL || scope_info_.is_null()) { 379 if (result != NULL || scope_info_.is_null()) {
372 return result; 380 return result;
373 } 381 }
382 // The Scope is backed up by ScopeInfo. This means it cannot operate in a
383 // heap-independent mode, and all strings must be internalized immediately. So
384 // it's ok to get the Handle<String> here.
385 Handle<String> name_handle = name->string();
374 // If we have a serialized scope info, we might find the variable there. 386 // If we have a serialized scope info, we might find the variable there.
375 // There should be no local slot with the given name. 387 // There should be no local slot with the given name.
376 ASSERT(scope_info_->StackSlotIndex(*name) < 0); 388 ASSERT(scope_info_->StackSlotIndex(*name_handle) < 0);
377 389
378 // Check context slot lookup. 390 // Check context slot lookup.
379 VariableMode mode; 391 VariableMode mode;
380 Variable::Location location = Variable::CONTEXT; 392 Variable::Location location = Variable::CONTEXT;
381 InitializationFlag init_flag; 393 InitializationFlag init_flag;
382 int index = ScopeInfo::ContextSlotIndex(scope_info_, name, &mode, &init_flag); 394 int index =
395 ScopeInfo::ContextSlotIndex(scope_info_, name_handle, &mode, &init_flag);
383 if (index < 0) { 396 if (index < 0) {
384 // Check parameters. 397 // Check parameters.
385 index = scope_info_->ParameterIndex(*name); 398 index = scope_info_->ParameterIndex(*name_handle);
386 if (index < 0) return NULL; 399 if (index < 0) return NULL;
387 400
388 mode = DYNAMIC; 401 mode = DYNAMIC;
389 location = Variable::LOOKUP; 402 location = Variable::LOOKUP;
390 init_flag = kCreatedInitialized; 403 init_flag = kCreatedInitialized;
391 } 404 }
392 405
393 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL, 406 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL,
394 init_flag); 407 init_flag);
395 var->AllocateTo(location, index); 408 var->AllocateTo(location, index);
396 return var; 409 return var;
397 } 410 }
398 411
399 412
400 Variable* Scope::LookupFunctionVar(Handle<String> name, 413 Variable* Scope::LookupFunctionVar(const AstString* name,
401 AstNodeFactory<AstNullVisitor>* factory) { 414 AstNodeFactory<AstNullVisitor>* factory) {
402 if (function_ != NULL && function_->proxy()->name().is_identical_to(name)) { 415 if (function_ != NULL && function_->proxy()->raw_name() == name) {
403 return function_->proxy()->var(); 416 return function_->proxy()->var();
404 } else if (!scope_info_.is_null()) { 417 } else if (!scope_info_.is_null()) {
405 // If we are backed by a scope info, try to lookup the variable there. 418 // If we are backed by a scope info, try to lookup the variable there.
406 VariableMode mode; 419 VariableMode mode;
407 int index = scope_info_->FunctionContextSlotIndex(*name, &mode); 420 int index = scope_info_->FunctionContextSlotIndex(*(name->string()), &mode);
408 if (index < 0) return NULL; 421 if (index < 0) return NULL;
409 Variable* var = new(zone()) Variable( 422 Variable* var = new(zone()) Variable(
410 this, name, mode, true /* is valid LHS */, 423 this, name, mode, true /* is valid LHS */,
411 Variable::NORMAL, kCreatedInitialized); 424 Variable::NORMAL, kCreatedInitialized);
412 VariableProxy* proxy = factory->NewVariableProxy(var); 425 VariableProxy* proxy = factory->NewVariableProxy(var);
413 VariableDeclaration* declaration = factory->NewVariableDeclaration( 426 VariableDeclaration* declaration = factory->NewVariableDeclaration(
414 proxy, mode, this, RelocInfo::kNoPosition); 427 proxy, mode, this, RelocInfo::kNoPosition);
415 DeclareFunctionVar(declaration); 428 DeclareFunctionVar(declaration);
416 var->AllocateTo(Variable::CONTEXT, index); 429 var->AllocateTo(Variable::CONTEXT, index);
417 return var; 430 return var;
418 } else { 431 } else {
419 return NULL; 432 return NULL;
420 } 433 }
421 } 434 }
422 435
423 436
424 Variable* Scope::Lookup(Handle<String> name) { 437 Variable* Scope::Lookup(const AstString* name) {
425 for (Scope* scope = this; 438 for (Scope* scope = this;
426 scope != NULL; 439 scope != NULL;
427 scope = scope->outer_scope()) { 440 scope = scope->outer_scope()) {
428 Variable* var = scope->LookupLocal(name); 441 Variable* var = scope->LookupLocal(name);
429 if (var != NULL) return var; 442 if (var != NULL) return var;
430 } 443 }
431 return NULL; 444 return NULL;
432 } 445 }
433 446
434 447
435 void Scope::DeclareParameter(Handle<String> name, VariableMode mode) { 448 void Scope::DeclareParameter(const AstString* name, VariableMode mode) {
436 ASSERT(!already_resolved()); 449 ASSERT(!already_resolved());
437 ASSERT(is_function_scope()); 450 ASSERT(is_function_scope());
438 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL, 451 Variable* var = variables_.Declare(this, name, mode, true, Variable::NORMAL,
439 kCreatedInitialized); 452 kCreatedInitialized);
440 params_.Add(var, zone()); 453 params_.Add(var, zone());
441 } 454 }
442 455
443 456
444 Variable* Scope::DeclareLocal(Handle<String> name, 457 Variable* Scope::DeclareLocal(const AstString* name,
445 VariableMode mode, 458 VariableMode mode,
446 InitializationFlag init_flag, 459 InitializationFlag init_flag,
447 Interface* interface) { 460 Interface* interface) {
448 ASSERT(!already_resolved()); 461 ASSERT(!already_resolved());
449 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are 462 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are
450 // introduces during variable allocation, INTERNAL variables are allocated 463 // introduces during variable allocation, INTERNAL variables are allocated
451 // explicitly, and TEMPORARY variables are allocated via NewTemporary(). 464 // explicitly, and TEMPORARY variables are allocated via NewTemporary().
452 ASSERT(IsDeclaredVariableMode(mode)); 465 ASSERT(IsDeclaredVariableMode(mode));
453 ++num_var_or_const_; 466 ++num_var_or_const_;
454 return variables_.Declare( 467 return variables_.Declare(
455 this, name, mode, true, Variable::NORMAL, init_flag, interface); 468 this, name, mode, true, Variable::NORMAL, init_flag, interface);
456 } 469 }
457 470
458 471
459 Variable* Scope::DeclareDynamicGlobal(Handle<String> name) { 472 Variable* Scope::DeclareDynamicGlobal(const AstString* name) {
460 ASSERT(is_global_scope()); 473 ASSERT(is_global_scope());
461 return variables_.Declare(this, 474 return variables_.Declare(this,
462 name, 475 name,
463 DYNAMIC_GLOBAL, 476 DYNAMIC_GLOBAL,
464 true, 477 true,
465 Variable::NORMAL, 478 Variable::NORMAL,
466 kCreatedInitialized); 479 kCreatedInitialized);
467 } 480 }
468 481
469 482
470 void Scope::RemoveUnresolved(VariableProxy* var) { 483 void Scope::RemoveUnresolved(VariableProxy* var) {
471 // Most likely (always?) any variable we want to remove 484 // Most likely (always?) any variable we want to remove
472 // was just added before, so we search backwards. 485 // was just added before, so we search backwards.
473 for (int i = unresolved_.length(); i-- > 0;) { 486 for (int i = unresolved_.length(); i-- > 0;) {
474 if (unresolved_[i] == var) { 487 if (unresolved_[i] == var) {
475 unresolved_.Remove(i); 488 unresolved_.Remove(i);
476 return; 489 return;
477 } 490 }
478 } 491 }
479 } 492 }
480 493
481 494
482 Variable* Scope::NewInternal(Handle<String> name) { 495 Variable* Scope::NewInternal(const AstString* name) {
483 ASSERT(!already_resolved()); 496 ASSERT(!already_resolved());
484 Variable* var = new(zone()) Variable(this, 497 Variable* var = new(zone()) Variable(this,
485 name, 498 name,
486 INTERNAL, 499 INTERNAL,
487 false, 500 false,
488 Variable::NORMAL, 501 Variable::NORMAL,
489 kCreatedInitialized); 502 kCreatedInitialized);
490 internals_.Add(var, zone()); 503 internals_.Add(var, zone());
491 return var; 504 return var;
492 } 505 }
493 506
494 507
495 Variable* Scope::NewTemporary(Handle<String> name) { 508 Variable* Scope::NewTemporary(const AstString* name) {
496 ASSERT(!already_resolved()); 509 ASSERT(!already_resolved());
497 Variable* var = new(zone()) Variable(this, 510 Variable* var = new(zone()) Variable(this,
498 name, 511 name,
499 TEMPORARY, 512 TEMPORARY,
500 true, 513 true,
501 Variable::NORMAL, 514 Variable::NORMAL,
502 kCreatedInitialized); 515 kCreatedInitialized);
503 temps_.Add(var, zone()); 516 temps_.Add(var, zone());
504 return var; 517 return var;
505 } 518 }
(...skipping 17 matching lines...) Expand all
523 ASSERT(HasIllegalRedeclaration()); 536 ASSERT(HasIllegalRedeclaration());
524 illegal_redecl_->Accept(visitor); 537 illegal_redecl_->Accept(visitor);
525 } 538 }
526 539
527 540
528 Declaration* Scope::CheckConflictingVarDeclarations() { 541 Declaration* Scope::CheckConflictingVarDeclarations() {
529 int length = decls_.length(); 542 int length = decls_.length();
530 for (int i = 0; i < length; i++) { 543 for (int i = 0; i < length; i++) {
531 Declaration* decl = decls_[i]; 544 Declaration* decl = decls_[i];
532 if (decl->mode() != VAR) continue; 545 if (decl->mode() != VAR) continue;
533 Handle<String> name = decl->proxy()->name(); 546 const AstString* name = decl->proxy()->raw_name();
534 547
535 // Iterate through all scopes until and including the declaration scope. 548 // Iterate through all scopes until and including the declaration scope.
536 Scope* previous = NULL; 549 Scope* previous = NULL;
537 Scope* current = decl->scope(); 550 Scope* current = decl->scope();
538 do { 551 do {
539 // There is a conflict if there exists a non-VAR binding. 552 // There is a conflict if there exists a non-VAR binding.
540 Variable* other_var = current->variables_.Lookup(name); 553 Variable* other_var = current->variables_.Lookup(name);
541 if (other_var != NULL && other_var->mode() != VAR) { 554 if (other_var != NULL && other_var->mode() != VAR) {
542 return decl; 555 return decl;
543 } 556 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 UNREACHABLE(); 779 UNREACHABLE();
767 return NULL; 780 return NULL;
768 } 781 }
769 782
770 783
771 static void Indent(int n, const char* str) { 784 static void Indent(int n, const char* str) {
772 PrintF("%*s%s", n, "", str); 785 PrintF("%*s%s", n, "", str);
773 } 786 }
774 787
775 788
776 static void PrintName(Handle<String> name) { 789 static void PrintName(const AstString* name) {
777 SmartArrayPointer<char> s = name->ToCString(DISALLOW_NULLS); 790 PrintF("%.*s", name->length(), name->raw_data());
778 PrintF("%s", s.get());
779 } 791 }
780 792
781 793
782 static void PrintLocation(Variable* var) { 794 static void PrintLocation(Variable* var) {
783 switch (var->location()) { 795 switch (var->location()) {
784 case Variable::UNALLOCATED: 796 case Variable::UNALLOCATED:
785 break; 797 break;
786 case Variable::PARAMETER: 798 case Variable::PARAMETER:
787 PrintF("parameter[%d]", var->index()); 799 PrintF("parameter[%d]", var->index());
788 break; 800 break;
789 case Variable::LOCAL: 801 case Variable::LOCAL:
790 PrintF("local[%d]", var->index()); 802 PrintF("local[%d]", var->index());
791 break; 803 break;
792 case Variable::CONTEXT: 804 case Variable::CONTEXT:
793 PrintF("context[%d]", var->index()); 805 PrintF("context[%d]", var->index());
794 break; 806 break;
795 case Variable::LOOKUP: 807 case Variable::LOOKUP:
796 PrintF("lookup"); 808 PrintF("lookup");
797 break; 809 break;
798 } 810 }
799 } 811 }
800 812
801 813
802 static void PrintVar(int indent, Variable* var) { 814 static void PrintVar(int indent, Variable* var) {
803 if (var->is_used() || !var->IsUnallocated()) { 815 if (var->is_used() || !var->IsUnallocated()) {
804 Indent(indent, Variable::Mode2String(var->mode())); 816 Indent(indent, Variable::Mode2String(var->mode()));
805 PrintF(" "); 817 PrintF(" ");
806 PrintName(var->name()); 818 PrintName(var->raw_name());
807 PrintF("; // "); 819 PrintF("; // ");
808 PrintLocation(var); 820 PrintLocation(var);
809 if (var->has_forced_context_allocation()) { 821 if (var->has_forced_context_allocation()) {
810 if (!var->IsUnallocated()) PrintF(", "); 822 if (!var->IsUnallocated()) PrintF(", ");
811 PrintF("forced context allocation"); 823 PrintF("forced context allocation");
812 } 824 }
813 PrintF("\n"); 825 PrintF("\n");
814 } 826 }
815 } 827 }
816 828
(...skipping 15 matching lines...) Expand all
832 if (scope_name_->length() > 0) { 844 if (scope_name_->length() > 0) {
833 PrintF(" "); 845 PrintF(" ");
834 PrintName(scope_name_); 846 PrintName(scope_name_);
835 } 847 }
836 848
837 // Print parameters, if any. 849 // Print parameters, if any.
838 if (is_function_scope()) { 850 if (is_function_scope()) {
839 PrintF(" ("); 851 PrintF(" (");
840 for (int i = 0; i < params_.length(); i++) { 852 for (int i = 0; i < params_.length(); i++) {
841 if (i > 0) PrintF(", "); 853 if (i > 0) PrintF(", ");
842 PrintName(params_[i]->name()); 854 PrintName(params_[i]->raw_name());
843 } 855 }
844 PrintF(")"); 856 PrintF(")");
845 } 857 }
846 858
847 PrintF(" { // (%d, %d)\n", start_position(), end_position()); 859 PrintF(" { // (%d, %d)\n", start_position(), end_position());
848 860
849 // Function name, if any (named function literals, only). 861 // Function name, if any (named function literals, only).
850 if (function_ != NULL) { 862 if (function_ != NULL) {
851 Indent(n1, "// (local) function name: "); 863 Indent(n1, "// (local) function name: ");
852 PrintName(function_->proxy()->name()); 864 PrintName(function_->proxy()->raw_name());
853 PrintF("\n"); 865 PrintF("\n");
854 } 866 }
855 867
856 // Scope info. 868 // Scope info.
857 if (HasTrivialOuterContext()) { 869 if (HasTrivialOuterContext()) {
858 Indent(n1, "// scope has trivial outer context\n"); 870 Indent(n1, "// scope has trivial outer context\n");
859 } 871 }
860 if (strict_mode() == STRICT) { 872 if (strict_mode() == STRICT) {
861 Indent(n1, "// strict mode scope\n"); 873 Indent(n1, "// strict mode scope\n");
862 } 874 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 PrintF("\n"); 922 PrintF("\n");
911 inner_scopes_[i]->Print(n1); 923 inner_scopes_[i]->Print(n1);
912 } 924 }
913 } 925 }
914 926
915 Indent(n0, "}\n"); 927 Indent(n0, "}\n");
916 } 928 }
917 #endif // DEBUG 929 #endif // DEBUG
918 930
919 931
920 Variable* Scope::NonLocal(Handle<String> name, VariableMode mode) { 932 Variable* Scope::NonLocal(const AstString* name, VariableMode mode) {
921 if (dynamics_ == NULL) dynamics_ = new(zone()) DynamicScopePart(zone()); 933 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone());
922 VariableMap* map = dynamics_->GetMap(mode); 934 VariableMap* map = dynamics_->GetMap(mode);
923 Variable* var = map->Lookup(name); 935 Variable* var = map->Lookup(name);
924 if (var == NULL) { 936 if (var == NULL) {
925 // Declare a new non-local. 937 // Declare a new non-local.
926 InitializationFlag init_flag = (mode == VAR) 938 InitializationFlag init_flag = (mode == VAR)
927 ? kCreatedInitialized : kNeedsInitialization; 939 ? kCreatedInitialized : kNeedsInitialization;
928 var = map->Declare(NULL, 940 var = map->Declare(NULL,
929 name, 941 name,
930 mode, 942 mode,
931 true, 943 true,
932 Variable::NORMAL, 944 Variable::NORMAL,
933 init_flag); 945 init_flag);
934 // Allocate it by giving it a dynamic lookup. 946 // Allocate it by giving it a dynamic lookup.
935 var->AllocateTo(Variable::LOOKUP, -1); 947 var->AllocateTo(Variable::LOOKUP, -1);
936 } 948 }
937 return var; 949 return var;
938 } 950 }
939 951
940 952
941 Variable* Scope::LookupRecursive(Handle<String> name, 953 Variable* Scope::LookupRecursive(const AstString* name,
942 BindingKind* binding_kind, 954 BindingKind* binding_kind,
943 AstNodeFactory<AstNullVisitor>* factory) { 955 AstNodeFactory<AstNullVisitor>* factory) {
944 ASSERT(binding_kind != NULL); 956 ASSERT(binding_kind != NULL);
945 if (already_resolved() && is_with_scope()) { 957 if (already_resolved() && is_with_scope()) {
946 // Short-cut: if the scope is deserialized from a scope info, variable 958 // Short-cut: if the scope is deserialized from a scope info, variable
947 // allocation is already fixed. We can simply return with dynamic lookup. 959 // allocation is already fixed. We can simply return with dynamic lookup.
948 *binding_kind = DYNAMIC_LOOKUP; 960 *binding_kind = DYNAMIC_LOOKUP;
949 return NULL; 961 return NULL;
950 } 962 }
951 963
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 VariableProxy* proxy, 1017 VariableProxy* proxy,
1006 AstNodeFactory<AstNullVisitor>* factory) { 1018 AstNodeFactory<AstNullVisitor>* factory) {
1007 ASSERT(info->global_scope()->is_global_scope()); 1019 ASSERT(info->global_scope()->is_global_scope());
1008 1020
1009 // If the proxy is already resolved there's nothing to do 1021 // If the proxy is already resolved there's nothing to do
1010 // (functions and consts may be resolved by the parser). 1022 // (functions and consts may be resolved by the parser).
1011 if (proxy->var() != NULL) return true; 1023 if (proxy->var() != NULL) return true;
1012 1024
1013 // Otherwise, try to resolve the variable. 1025 // Otherwise, try to resolve the variable.
1014 BindingKind binding_kind; 1026 BindingKind binding_kind;
1015 Variable* var = LookupRecursive(proxy->name(), &binding_kind, factory); 1027 Variable* var = LookupRecursive(proxy->raw_name(), &binding_kind, factory);
1016 switch (binding_kind) { 1028 switch (binding_kind) {
1017 case BOUND: 1029 case BOUND:
1018 // We found a variable binding. 1030 // We found a variable binding.
1019 break; 1031 break;
1020 1032
1021 case BOUND_EVAL_SHADOWED: 1033 case BOUND_EVAL_SHADOWED:
1022 // We either found a variable binding that might be shadowed by eval or 1034 // We either found a variable binding that might be shadowed by eval or
1023 // gave up on it (e.g. by encountering a local with the same in the outer 1035 // gave up on it (e.g. by encountering a local with the same in the outer
1024 // scope which was not promoted to a context, this can happen if we use 1036 // scope which was not promoted to a context, this can happen if we use
1025 // debugger to evaluate arbitrary expressions at a break point). 1037 // debugger to evaluate arbitrary expressions at a break point).
1026 if (var->IsGlobalObjectProperty()) { 1038 if (var->IsGlobalObjectProperty()) {
1027 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); 1039 var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
1028 } else if (var->is_dynamic()) { 1040 } else if (var->is_dynamic()) {
1029 var = NonLocal(proxy->name(), DYNAMIC); 1041 var = NonLocal(proxy->raw_name(), DYNAMIC);
1030 } else { 1042 } else {
1031 Variable* invalidated = var; 1043 Variable* invalidated = var;
1032 var = NonLocal(proxy->name(), DYNAMIC_LOCAL); 1044 var = NonLocal(proxy->raw_name(), DYNAMIC_LOCAL);
1033 var->set_local_if_not_shadowed(invalidated); 1045 var->set_local_if_not_shadowed(invalidated);
1034 } 1046 }
1035 break; 1047 break;
1036 1048
1037 case UNBOUND: 1049 case UNBOUND:
1038 // No binding has been found. Declare a variable on the global object. 1050 // No binding has been found. Declare a variable on the global object.
1039 var = info->global_scope()->DeclareDynamicGlobal(proxy->name()); 1051 var = info->global_scope()->DeclareDynamicGlobal(proxy->raw_name());
1040 break; 1052 break;
1041 1053
1042 case UNBOUND_EVAL_SHADOWED: 1054 case UNBOUND_EVAL_SHADOWED:
1043 // No binding has been found. But some scope makes a sloppy 'eval' call. 1055 // No binding has been found. But some scope makes a sloppy 'eval' call.
1044 var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); 1056 var = NonLocal(proxy->raw_name(), DYNAMIC_GLOBAL);
1045 break; 1057 break;
1046 1058
1047 case DYNAMIC_LOOKUP: 1059 case DYNAMIC_LOOKUP:
1048 // The variable could not be resolved statically. 1060 // The variable could not be resolved statically.
1049 var = NonLocal(proxy->name(), DYNAMIC); 1061 var = NonLocal(proxy->raw_name(), DYNAMIC);
1050 break; 1062 break;
1051 } 1063 }
1052 1064
1053 ASSERT(var != NULL); 1065 ASSERT(var != NULL);
1054 1066
1055 if (FLAG_harmony_scoping && strict_mode() == STRICT && 1067 if (FLAG_harmony_scoping && strict_mode() == STRICT &&
1056 var->is_const_mode() && proxy->IsLValue()) { 1068 var->is_const_mode() && proxy->IsLValue()) {
1057 // Assignment to const. Throw a syntax error. 1069 // Assignment to const. Throw a syntax error.
1058 MessageLocation location( 1070 MessageLocation location(
1059 info->script(), proxy->position(), proxy->position()); 1071 info->script(), proxy->position(), proxy->position());
1060 Isolate* isolate = info->isolate(); 1072 Isolate* isolate = info->isolate();
1061 Factory* factory = isolate->factory(); 1073 Factory* factory = isolate->factory();
1062 Handle<JSArray> array = factory->NewJSArray(0); 1074 Handle<JSArray> array = factory->NewJSArray(0);
1063 Handle<Object> result = 1075 Handle<Object> result =
1064 factory->NewSyntaxError("harmony_const_assign", array); 1076 factory->NewSyntaxError("harmony_const_assign", array);
1065 isolate->Throw(*result, &location); 1077 isolate->Throw(*result, &location);
1066 return false; 1078 return false;
1067 } 1079 }
1068 1080
1069 if (FLAG_harmony_modules) { 1081 if (FLAG_harmony_modules) {
1070 bool ok; 1082 bool ok;
1071 #ifdef DEBUG 1083 #ifdef DEBUG
1072 if (FLAG_print_interface_details) 1084 if (FLAG_print_interface_details) {
1073 PrintF("# Resolve %s:\n", var->name()->ToAsciiArray()); 1085 PrintF("# Resolve %.*s:\n", var->raw_name()->length(),
1086 var->raw_name()->raw_data());
1087 }
1074 #endif 1088 #endif
1075 proxy->interface()->Unify(var->interface(), zone(), &ok); 1089 proxy->interface()->Unify(var->interface(), zone(), &ok);
1076 if (!ok) { 1090 if (!ok) {
1077 #ifdef DEBUG 1091 #ifdef DEBUG
1078 if (FLAG_print_interfaces) { 1092 if (FLAG_print_interfaces) {
1079 PrintF("SCOPES TYPE ERROR\n"); 1093 PrintF("SCOPES TYPE ERROR\n");
1080 PrintF("proxy: "); 1094 PrintF("proxy: ");
1081 proxy->interface()->Print(); 1095 proxy->interface()->Print();
1082 PrintF("var: "); 1096 PrintF("var: ");
1083 var->interface()->Print(); 1097 var->interface()->Print();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 } 1157 }
1144 1158
1145 return scope_calls_eval_ || inner_scope_calls_eval_; 1159 return scope_calls_eval_ || inner_scope_calls_eval_;
1146 } 1160 }
1147 1161
1148 1162
1149 bool Scope::MustAllocate(Variable* var) { 1163 bool Scope::MustAllocate(Variable* var) {
1150 // Give var a read/write use if there is a chance it might be accessed 1164 // Give var a read/write use if there is a chance it might be accessed
1151 // via an eval() call. This is only possible if the variable has a 1165 // via an eval() call. This is only possible if the variable has a
1152 // visible name. 1166 // visible name.
1153 if ((var->is_this() || var->name()->length() > 0) && 1167 if ((var->is_this() || var->raw_name()->length() > 0) &&
1154 (var->has_forced_context_allocation() || 1168 (var->has_forced_context_allocation() ||
1155 scope_calls_eval_ || 1169 scope_calls_eval_ ||
1156 inner_scope_calls_eval_ || 1170 inner_scope_calls_eval_ ||
1157 scope_contains_with_ || 1171 scope_contains_with_ ||
1158 is_catch_scope() || 1172 is_catch_scope() ||
1159 is_block_scope() || 1173 is_block_scope() ||
1160 is_module_scope() || 1174 is_module_scope() ||
1161 is_global_scope())) { 1175 is_global_scope())) {
1162 var->set_is_used(true); 1176 var->set_is_used(true);
1163 } 1177 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 } 1218 }
1205 1219
1206 1220
1207 void Scope::AllocateHeapSlot(Variable* var) { 1221 void Scope::AllocateHeapSlot(Variable* var) {
1208 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++); 1222 var->AllocateTo(Variable::CONTEXT, num_heap_slots_++);
1209 } 1223 }
1210 1224
1211 1225
1212 void Scope::AllocateParameterLocals() { 1226 void Scope::AllocateParameterLocals() {
1213 ASSERT(is_function_scope()); 1227 ASSERT(is_function_scope());
1214 Variable* arguments = LookupLocal(isolate_->factory()->arguments_string()); 1228 Variable* arguments = LookupLocal(string_table_->arguments_string());
1215 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly 1229 ASSERT(arguments != NULL); // functions have 'arguments' declared implicitly
1216 1230
1217 bool uses_sloppy_arguments = false; 1231 bool uses_sloppy_arguments = false;
1218 1232
1219 if (MustAllocate(arguments) && !HasArgumentsParameter()) { 1233 if (MustAllocate(arguments) && !HasArgumentsParameter()) {
1220 // 'arguments' is used. Unless there is also a parameter called 1234 // 'arguments' is used. Unless there is also a parameter called
1221 // 'arguments', we must be conservative and allocate all parameters to 1235 // 'arguments', we must be conservative and allocate all parameters to
1222 // the context assuming they will be captured by the arguments object. 1236 // the context assuming they will be captured by the arguments object.
1223 // If we have a parameter named 'arguments', a (new) value is always 1237 // If we have a parameter named 'arguments', a (new) value is always
1224 // assigned to it via the function invocation. Then 'arguments' denotes 1238 // assigned to it via the function invocation. Then 'arguments' denotes
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 1359
1346 // Allocation done. 1360 // Allocation done.
1347 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1361 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1348 } 1362 }
1349 1363
1350 1364
1351 void Scope::AllocateModulesRecursively(Scope* host_scope) { 1365 void Scope::AllocateModulesRecursively(Scope* host_scope) {
1352 if (already_resolved()) return; 1366 if (already_resolved()) return;
1353 if (is_module_scope()) { 1367 if (is_module_scope()) {
1354 ASSERT(interface_->IsFrozen()); 1368 ASSERT(interface_->IsFrozen());
1355 Handle<String> name = isolate_->factory()->InternalizeOneByteString(
1356 STATIC_ASCII_VECTOR(".module"));
1357 ASSERT(module_var_ == NULL); 1369 ASSERT(module_var_ == NULL);
1358 module_var_ = host_scope->NewInternal(name); 1370 module_var_ = host_scope->NewInternal(string_table_->dot_module_string());
1359 ++host_scope->num_modules_; 1371 ++host_scope->num_modules_;
1360 } 1372 }
1361 1373
1362 for (int i = 0; i < inner_scopes_.length(); i++) { 1374 for (int i = 0; i < inner_scopes_.length(); i++) {
1363 Scope* inner_scope = inner_scopes_.at(i); 1375 Scope* inner_scope = inner_scopes_.at(i);
1364 inner_scope->AllocateModulesRecursively(host_scope); 1376 inner_scope->AllocateModulesRecursively(host_scope);
1365 } 1377 }
1366 } 1378 }
1367 1379
1368 1380
1369 int Scope::StackLocalCount() const { 1381 int Scope::StackLocalCount() const {
1370 return num_stack_slots() - 1382 return num_stack_slots() -
1371 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); 1383 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1372 } 1384 }
1373 1385
1374 1386
1375 int Scope::ContextLocalCount() const { 1387 int Scope::ContextLocalCount() const {
1376 if (num_heap_slots() == 0) return 0; 1388 if (num_heap_slots() == 0) return 0;
1377 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1389 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1378 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1390 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1379 } 1391 }
1380 1392
1381 } } // namespace v8::internal 1393 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698