OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/ast/context-slot-cache.h" | 7 #include "src/ast/context-slot-cache.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/ast/variables.h" | 9 #include "src/ast/variables.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 FunctionKindField::encode(function_kind) | | 168 FunctionKindField::encode(function_kind) | |
169 HasOuterScopeInfoField::encode(has_outer_scope_info); | 169 HasOuterScopeInfoField::encode(has_outer_scope_info); |
170 scope_info->SetFlags(flags); | 170 scope_info->SetFlags(flags); |
171 | 171 |
172 scope_info->SetParameterCount(parameter_count); | 172 scope_info->SetParameterCount(parameter_count); |
173 scope_info->SetStackLocalCount(stack_local_count); | 173 scope_info->SetStackLocalCount(stack_local_count); |
174 scope_info->SetContextLocalCount(context_local_count); | 174 scope_info->SetContextLocalCount(context_local_count); |
175 | 175 |
176 int index = kVariablePartIndex; | 176 int index = kVariablePartIndex; |
177 // Add parameters. | 177 // Add parameters. |
178 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); | 178 DCHECK_EQ(index, scope_info->ParameterNamesIndex()); |
179 if (scope->is_declaration_scope()) { | 179 if (scope->is_declaration_scope()) { |
180 for (int i = 0; i < parameter_count; ++i) { | 180 for (int i = 0; i < parameter_count; ++i) { |
181 scope_info->set(index++, | 181 scope_info->set(index++, |
182 *scope->AsDeclarationScope()->parameter(i)->name()); | 182 *scope->AsDeclarationScope()->parameter(i)->name()); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 // Add stack locals' names, context locals' names and info, module variables' | 186 // Add stack locals' names, context locals' names and info, module variables' |
187 // names and info. We are assuming that the stack locals' slots are allocated | 187 // names and info. We are assuming that the stack locals' slots are allocated |
188 // in increasing order, so we can simply add them to the ScopeInfo object. | 188 // in increasing order, so we can simply add them to the ScopeInfo object. |
189 // Context locals are added using their index. | 189 // Context locals are added using their index. |
190 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 190 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); |
191 scope_info->set(index++, Smi::FromInt(first_slot_index)); | 191 scope_info->set(index++, Smi::FromInt(first_slot_index)); |
192 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); | 192 DCHECK_EQ(index, scope_info->StackLocalNamesIndex()); |
193 | 193 |
194 int stack_local_base = index; | 194 int stack_local_base = index; |
195 int context_local_base = stack_local_base + stack_local_count; | 195 int context_local_base = stack_local_base + stack_local_count; |
196 int context_local_info_base = context_local_base + context_local_count; | 196 int context_local_info_base = context_local_base + context_local_count; |
197 int module_var_entry = scope_info->ModuleVariableEntriesIndex(); | 197 int module_var_entry = scope_info->ModuleVariablesIndex(); |
198 | 198 |
199 for (int i = 0; i < locals->length(); ++i) { | 199 for (int i = 0; i < locals->length(); ++i) { |
200 Variable* var = locals->at(i); | 200 Variable* var = locals->at(i); |
201 switch (var->location()) { | 201 switch (var->location()) { |
202 case VariableLocation::LOCAL: { | 202 case VariableLocation::LOCAL: { |
203 int local_index = var->index() - first_slot_index; | 203 int local_index = var->index() - first_slot_index; |
204 DCHECK_LE(0, local_index); | 204 DCHECK_LE(0, local_index); |
205 DCHECK_LT(local_index, stack_local_count); | 205 DCHECK_LT(local_index, stack_local_count); |
206 scope_info->set(stack_local_base + local_index, *var->name()); | 206 scope_info->set(stack_local_base + local_index, *var->name()); |
207 break; | 207 break; |
(...skipping 27 matching lines...) Expand all Loading... |
235 break; | 235 break; |
236 } | 236 } |
237 default: | 237 default: |
238 break; | 238 break; |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 index += stack_local_count + 2 * context_local_count; | 242 index += stack_local_count + 2 * context_local_count; |
243 | 243 |
244 // If the receiver is allocated, add its index. | 244 // If the receiver is allocated, add its index. |
245 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); | 245 DCHECK_EQ(index, scope_info->ReceiverInfoIndex()); |
246 if (has_receiver) { | 246 if (has_receiver) { |
247 int var_index = scope->AsDeclarationScope()->receiver()->index(); | 247 int var_index = scope->AsDeclarationScope()->receiver()->index(); |
248 scope_info->set(index++, Smi::FromInt(var_index)); | 248 scope_info->set(index++, Smi::FromInt(var_index)); |
249 // ?? DCHECK(receiver_info != CONTEXT || var_index == | 249 // ?? DCHECK(receiver_info != CONTEXT || var_index == |
250 // scope_info->ContextLength() - 1); | 250 // scope_info->ContextLength() - 1); |
251 } | 251 } |
252 | 252 |
253 // If present, add the function variable name and its index. | 253 // If present, add the function variable name and its index. |
254 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); | 254 DCHECK_EQ(index, scope_info->FunctionNameInfoIndex()); |
255 if (has_function_name) { | 255 if (has_function_name) { |
256 int var_index = scope->AsDeclarationScope()->function_var()->index(); | 256 int var_index = scope->AsDeclarationScope()->function_var()->index(); |
257 scope_info->set(index++, | 257 scope_info->set(index++, |
258 *scope->AsDeclarationScope()->function_var()->name()); | 258 *scope->AsDeclarationScope()->function_var()->name()); |
259 scope_info->set(index++, Smi::FromInt(var_index)); | 259 scope_info->set(index++, Smi::FromInt(var_index)); |
260 DCHECK(function_name_info != CONTEXT || | 260 DCHECK(function_name_info != CONTEXT || |
261 var_index == scope_info->ContextLength() - 1); | 261 var_index == scope_info->ContextLength() - 1); |
262 } | 262 } |
263 | 263 |
264 // If present, add the outer scope info. | 264 // If present, add the outer scope info. |
265 DCHECK(index == scope_info->OuterScopeInfoEntryIndex()); | 265 DCHECK(index == scope_info->OuterScopeInfoIndex()); |
266 if (has_outer_scope_info) { | 266 if (has_outer_scope_info) { |
267 scope_info->set(index++, *outer_scope.ToHandleChecked()); | 267 scope_info->set(index++, *outer_scope.ToHandleChecked()); |
268 } | 268 } |
269 | 269 |
270 // Module-specific information (only for module scopes). | 270 // Module-specific information (only for module scopes). |
271 if (scope->is_module_scope()) { | 271 if (scope->is_module_scope()) { |
272 Handle<ModuleInfo> module_info = | 272 Handle<ModuleInfo> module_info = |
273 ModuleInfo::New(isolate, scope->AsModuleScope()->module()); | 273 ModuleInfo::New(isolate, scope->AsModuleScope()->module()); |
274 DCHECK_EQ(index, scope_info->ModuleInfoEntryIndex()); | 274 DCHECK_EQ(index, scope_info->ModuleInfoIndex()); |
275 scope_info->set(index++, *module_info); | 275 scope_info->set(index++, *module_info); |
276 DCHECK_EQ(index, scope_info->ModuleVariableCountIndex()); | 276 DCHECK_EQ(index, scope_info->ModuleVariableCountIndex()); |
277 scope_info->set(index++, Smi::FromInt(module_vars_count)); | 277 scope_info->set(index++, Smi::FromInt(module_vars_count)); |
278 DCHECK_EQ(index, scope_info->ModuleVariableEntriesIndex()); | 278 DCHECK_EQ(index, scope_info->ModuleVariablesIndex()); |
279 // The variable entries themselves have already been written above. | 279 // The variable entries themselves have already been written above. |
280 index += kModuleVariableEntryLength * module_vars_count; | 280 index += kModuleVariableEntryLength * module_vars_count; |
281 } | 281 } |
282 | 282 |
283 DCHECK_EQ(index, scope_info->length()); | 283 DCHECK_EQ(index, scope_info->length()); |
284 DCHECK_EQ(scope->num_parameters(), scope_info->ParameterCount()); | 284 DCHECK_EQ(scope->num_parameters(), scope_info->ParameterCount()); |
285 DCHECK_EQ(scope->num_heap_slots(), scope_info->ContextLength()); | 285 DCHECK_EQ(scope->num_heap_slots(), scope_info->ContextLength()); |
286 return scope_info; | 286 return scope_info; |
287 } | 287 } |
288 | 288 |
(...skipping 14 matching lines...) Expand all Loading... |
303 AsmFunctionField::encode(false) | HasSimpleParametersField::encode(true) | | 303 AsmFunctionField::encode(false) | HasSimpleParametersField::encode(true) | |
304 FunctionKindField::encode(kNormalFunction) | | 304 FunctionKindField::encode(kNormalFunction) | |
305 HasOuterScopeInfoField::encode(has_outer_scope_info); | 305 HasOuterScopeInfoField::encode(has_outer_scope_info); |
306 scope_info->SetFlags(flags); | 306 scope_info->SetFlags(flags); |
307 | 307 |
308 scope_info->SetParameterCount(0); | 308 scope_info->SetParameterCount(0); |
309 scope_info->SetStackLocalCount(0); | 309 scope_info->SetStackLocalCount(0); |
310 scope_info->SetContextLocalCount(0); | 310 scope_info->SetContextLocalCount(0); |
311 | 311 |
312 int index = kVariablePartIndex; | 312 int index = kVariablePartIndex; |
313 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); | 313 DCHECK_EQ(index, scope_info->ParameterNamesIndex()); |
314 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 314 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); |
315 scope_info->set(index++, Smi::FromInt(0)); | 315 scope_info->set(index++, Smi::FromInt(0)); |
316 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); | 316 DCHECK_EQ(index, scope_info->StackLocalNamesIndex()); |
317 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); | 317 DCHECK_EQ(index, scope_info->ReceiverInfoIndex()); |
318 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); | 318 DCHECK_EQ(index, scope_info->FunctionNameInfoIndex()); |
319 DCHECK(index == scope_info->OuterScopeInfoEntryIndex()); | 319 DCHECK(index == scope_info->OuterScopeInfoIndex()); |
320 if (has_outer_scope_info) { | 320 if (has_outer_scope_info) { |
321 scope_info->set(index++, *outer_scope.ToHandleChecked()); | 321 scope_info->set(index++, *outer_scope.ToHandleChecked()); |
322 } | 322 } |
323 DCHECK_EQ(index, scope_info->length()); | 323 DCHECK_EQ(index, scope_info->length()); |
324 DCHECK_EQ(0, scope_info->ParameterCount()); | 324 DCHECK_EQ(0, scope_info->ParameterCount()); |
325 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, scope_info->ContextLength()); | 325 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, scope_info->ContextLength()); |
326 return scope_info; | 326 return scope_info; |
327 } | 327 } |
328 | 328 |
329 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | 329 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
(...skipping 28 matching lines...) Expand all Loading... |
358 HasOuterScopeInfoField::encode(has_outer_scope_info); | 358 HasOuterScopeInfoField::encode(has_outer_scope_info); |
359 scope_info->SetFlags(flags); | 359 scope_info->SetFlags(flags); |
360 scope_info->SetParameterCount(parameter_count); | 360 scope_info->SetParameterCount(parameter_count); |
361 scope_info->SetStackLocalCount(stack_local_count); | 361 scope_info->SetStackLocalCount(stack_local_count); |
362 scope_info->SetContextLocalCount(context_local_count); | 362 scope_info->SetContextLocalCount(context_local_count); |
363 | 363 |
364 int index = kVariablePartIndex; | 364 int index = kVariablePartIndex; |
365 const int first_slot_index = 0; | 365 const int first_slot_index = 0; |
366 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 366 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); |
367 scope_info->set(index++, Smi::FromInt(first_slot_index)); | 367 scope_info->set(index++, Smi::FromInt(first_slot_index)); |
368 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); | 368 DCHECK_EQ(index, scope_info->StackLocalNamesIndex()); |
369 | 369 |
370 // Here we add info for context-allocated "this". | 370 // Here we add info for context-allocated "this". |
371 DCHECK_EQ(index, scope_info->ContextLocalNameEntriesIndex()); | 371 DCHECK_EQ(index, scope_info->ContextLocalNamesIndex()); |
372 scope_info->set(index++, *isolate->factory()->this_string()); | 372 scope_info->set(index++, *isolate->factory()->this_string()); |
373 DCHECK_EQ(index, scope_info->ContextLocalInfoEntriesIndex()); | 373 DCHECK_EQ(index, scope_info->ContextLocalInfosIndex()); |
374 const uint32_t value = VariableModeField::encode(CONST) | | 374 const uint32_t value = VariableModeField::encode(CONST) | |
375 InitFlagField::encode(kCreatedInitialized) | | 375 InitFlagField::encode(kCreatedInitialized) | |
376 MaybeAssignedFlagField::encode(kNotAssigned); | 376 MaybeAssignedFlagField::encode(kNotAssigned); |
377 scope_info->set(index++, Smi::FromInt(value)); | 377 scope_info->set(index++, Smi::FromInt(value)); |
378 | 378 |
379 // And here we record that this scopeinfo binds a receiver. | 379 // And here we record that this scopeinfo binds a receiver. |
380 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); | 380 DCHECK_EQ(index, scope_info->ReceiverInfoIndex()); |
381 const int receiver_index = Context::MIN_CONTEXT_SLOTS + 0; | 381 const int receiver_index = Context::MIN_CONTEXT_SLOTS + 0; |
382 scope_info->set(index++, Smi::FromInt(receiver_index)); | 382 scope_info->set(index++, Smi::FromInt(receiver_index)); |
383 | 383 |
384 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); | 384 DCHECK_EQ(index, scope_info->FunctionNameInfoIndex()); |
385 DCHECK_EQ(index, scope_info->OuterScopeInfoEntryIndex()); | 385 DCHECK_EQ(index, scope_info->OuterScopeInfoIndex()); |
386 | |
387 DCHECK_EQ(index, scope_info->length()); | 386 DCHECK_EQ(index, scope_info->length()); |
388 DCHECK_EQ(scope_info->ParameterCount(), 0); | 387 DCHECK_EQ(scope_info->ParameterCount(), 0); |
389 DCHECK_EQ(scope_info->ContextLength(), Context::MIN_CONTEXT_SLOTS + 1); | 388 DCHECK_EQ(scope_info->ContextLength(), Context::MIN_CONTEXT_SLOTS + 1); |
390 | 389 |
391 return scope_info; | 390 return scope_info; |
392 } | 391 } |
393 | 392 |
394 | 393 |
395 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { | 394 ScopeInfo* ScopeInfo::Empty(Isolate* isolate) { |
396 return reinterpret_cast<ScopeInfo*>(isolate->heap()->empty_fixed_array()); | 395 return reinterpret_cast<ScopeInfo*>(isolate->heap()->empty_fixed_array()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 } | 500 } |
502 | 501 |
503 | 502 |
504 bool ScopeInfo::HasContext() { | 503 bool ScopeInfo::HasContext() { |
505 return ContextLength() > 0; | 504 return ContextLength() > 0; |
506 } | 505 } |
507 | 506 |
508 | 507 |
509 String* ScopeInfo::FunctionName() { | 508 String* ScopeInfo::FunctionName() { |
510 DCHECK(HasFunctionName()); | 509 DCHECK(HasFunctionName()); |
511 return String::cast(get(FunctionNameEntryIndex())); | 510 return String::cast(get(FunctionNameInfoIndex())); |
512 } | 511 } |
513 | 512 |
514 ScopeInfo* ScopeInfo::OuterScopeInfo() { | 513 ScopeInfo* ScopeInfo::OuterScopeInfo() { |
515 DCHECK(HasOuterScopeInfo()); | 514 DCHECK(HasOuterScopeInfo()); |
516 return ScopeInfo::cast(get(OuterScopeInfoEntryIndex())); | 515 return ScopeInfo::cast(get(OuterScopeInfoIndex())); |
517 } | 516 } |
518 | 517 |
519 ModuleInfo* ScopeInfo::ModuleDescriptorInfo() { | 518 ModuleInfo* ScopeInfo::ModuleDescriptorInfo() { |
520 DCHECK(scope_type() == MODULE_SCOPE); | 519 DCHECK(scope_type() == MODULE_SCOPE); |
521 return static_cast<ModuleInfo*>(get(ModuleInfoEntryIndex())); | 520 return static_cast<ModuleInfo*>(get(ModuleInfoIndex())); |
522 } | 521 } |
523 | 522 |
524 String* ScopeInfo::ParameterName(int var) { | 523 String* ScopeInfo::ParameterName(int var) { |
525 DCHECK_LE(0, var); | 524 DCHECK_LE(0, var); |
526 DCHECK_LT(var, ParameterCount()); | 525 DCHECK_LT(var, ParameterCount()); |
527 int info_index = ParameterEntriesIndex() + var; | 526 int info_index = ParameterNamesIndex() + var; |
528 return String::cast(get(info_index)); | 527 return String::cast(get(info_index)); |
529 } | 528 } |
530 | 529 |
531 | 530 |
532 String* ScopeInfo::LocalName(int var) { | 531 String* ScopeInfo::LocalName(int var) { |
533 DCHECK_LE(0, var); | 532 DCHECK_LE(0, var); |
534 DCHECK_LT(var, LocalCount()); | 533 DCHECK_LT(var, LocalCount()); |
535 DCHECK(StackLocalEntriesIndex() + StackLocalCount() == | 534 DCHECK(StackLocalNamesIndex() + StackLocalCount() == |
536 ContextLocalNameEntriesIndex()); | 535 ContextLocalNamesIndex()); |
537 int info_index = StackLocalEntriesIndex() + var; | 536 int info_index = StackLocalNamesIndex() + var; |
538 return String::cast(get(info_index)); | 537 return String::cast(get(info_index)); |
539 } | 538 } |
540 | 539 |
541 | 540 |
542 String* ScopeInfo::StackLocalName(int var) { | 541 String* ScopeInfo::StackLocalName(int var) { |
543 DCHECK_LE(0, var); | 542 DCHECK_LE(0, var); |
544 DCHECK_LT(var, StackLocalCount()); | 543 DCHECK_LT(var, StackLocalCount()); |
545 int info_index = StackLocalEntriesIndex() + var; | 544 int info_index = StackLocalNamesIndex() + var; |
546 return String::cast(get(info_index)); | 545 return String::cast(get(info_index)); |
547 } | 546 } |
548 | 547 |
549 | 548 |
550 int ScopeInfo::StackLocalIndex(int var) { | 549 int ScopeInfo::StackLocalIndex(int var) { |
551 DCHECK_LE(0, var); | 550 DCHECK_LE(0, var); |
552 DCHECK_LT(var, StackLocalCount()); | 551 DCHECK_LT(var, StackLocalCount()); |
553 int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value(); | 552 int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value(); |
554 return first_slot_index + var; | 553 return first_slot_index + var; |
555 } | 554 } |
556 | 555 |
557 | 556 |
558 String* ScopeInfo::ContextLocalName(int var) { | 557 String* ScopeInfo::ContextLocalName(int var) { |
559 DCHECK_LE(0, var); | 558 DCHECK_LE(0, var); |
560 DCHECK_LT(var, ContextLocalCount()); | 559 DCHECK_LT(var, ContextLocalCount()); |
561 int info_index = ContextLocalNameEntriesIndex() + var; | 560 int info_index = ContextLocalNamesIndex() + var; |
562 return String::cast(get(info_index)); | 561 return String::cast(get(info_index)); |
563 } | 562 } |
564 | 563 |
565 | 564 |
566 VariableMode ScopeInfo::ContextLocalMode(int var) { | 565 VariableMode ScopeInfo::ContextLocalMode(int var) { |
567 DCHECK_LE(0, var); | 566 DCHECK_LE(0, var); |
568 DCHECK_LT(var, ContextLocalCount()); | 567 DCHECK_LT(var, ContextLocalCount()); |
569 int info_index = ContextLocalInfoEntriesIndex() + var; | 568 int info_index = ContextLocalInfosIndex() + var; |
570 int value = Smi::cast(get(info_index))->value(); | 569 int value = Smi::cast(get(info_index))->value(); |
571 return VariableModeField::decode(value); | 570 return VariableModeField::decode(value); |
572 } | 571 } |
573 | 572 |
574 | 573 |
575 InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) { | 574 InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) { |
576 DCHECK_LE(0, var); | 575 DCHECK_LE(0, var); |
577 DCHECK_LT(var, ContextLocalCount()); | 576 DCHECK_LT(var, ContextLocalCount()); |
578 int info_index = ContextLocalInfoEntriesIndex() + var; | 577 int info_index = ContextLocalInfosIndex() + var; |
579 int value = Smi::cast(get(info_index))->value(); | 578 int value = Smi::cast(get(info_index))->value(); |
580 return InitFlagField::decode(value); | 579 return InitFlagField::decode(value); |
581 } | 580 } |
582 | 581 |
583 | 582 |
584 MaybeAssignedFlag ScopeInfo::ContextLocalMaybeAssignedFlag(int var) { | 583 MaybeAssignedFlag ScopeInfo::ContextLocalMaybeAssignedFlag(int var) { |
585 DCHECK_LE(0, var); | 584 DCHECK_LE(0, var); |
586 DCHECK_LT(var, ContextLocalCount()); | 585 DCHECK_LT(var, ContextLocalCount()); |
587 int info_index = ContextLocalInfoEntriesIndex() + var; | 586 int info_index = ContextLocalInfosIndex() + var; |
588 int value = Smi::cast(get(info_index))->value(); | 587 int value = Smi::cast(get(info_index))->value(); |
589 return MaybeAssignedFlagField::decode(value); | 588 return MaybeAssignedFlagField::decode(value); |
590 } | 589 } |
591 | 590 |
592 bool ScopeInfo::VariableIsSynthetic(String* name) { | 591 bool ScopeInfo::VariableIsSynthetic(String* name) { |
593 // There's currently no flag stored on the ScopeInfo to indicate that a | 592 // There's currently no flag stored on the ScopeInfo to indicate that a |
594 // variable is a compiler-introduced temporary. However, to avoid conflict | 593 // variable is a compiler-introduced temporary. However, to avoid conflict |
595 // with user declarations, the current temporaries like .generator_object and | 594 // with user declarations, the current temporaries like .generator_object and |
596 // .result start with a dot, so we can use that as a flag. It's a hack! | 595 // .result start with a dot, so we can use that as a flag. It's a hack! |
597 return name->length() == 0 || name->Get(0) == '.' || | 596 return name->length() == 0 || name->Get(0) == '.' || |
598 name->Equals(name->GetHeap()->this_string()); | 597 name->Equals(name->GetHeap()->this_string()); |
599 } | 598 } |
600 | 599 |
601 | 600 |
602 int ScopeInfo::StackSlotIndex(String* name) { | 601 int ScopeInfo::StackSlotIndex(String* name) { |
603 DCHECK(name->IsInternalizedString()); | 602 DCHECK(name->IsInternalizedString()); |
604 if (length() > 0) { | 603 if (length() > 0) { |
605 int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value(); | 604 int first_slot_index = Smi::cast(get(StackLocalFirstSlotIndex()))->value(); |
606 int start = StackLocalEntriesIndex(); | 605 int start = StackLocalNamesIndex(); |
607 int end = start + StackLocalCount(); | 606 int end = start + StackLocalCount(); |
608 for (int i = start; i < end; ++i) { | 607 for (int i = start; i < end; ++i) { |
609 if (name == get(i)) { | 608 if (name == get(i)) { |
610 return i - start + first_slot_index; | 609 return i - start + first_slot_index; |
611 } | 610 } |
612 } | 611 } |
613 } | 612 } |
614 return -1; | 613 return -1; |
615 } | 614 } |
616 | 615 |
617 int ScopeInfo::ModuleIndex(Handle<String> name, VariableMode* mode, | 616 int ScopeInfo::ModuleIndex(Handle<String> name, VariableMode* mode, |
618 InitializationFlag* init_flag, | 617 InitializationFlag* init_flag, |
619 MaybeAssignedFlag* maybe_assigned_flag) { | 618 MaybeAssignedFlag* maybe_assigned_flag) { |
620 DCHECK_EQ(scope_type(), MODULE_SCOPE); | 619 DCHECK_EQ(scope_type(), MODULE_SCOPE); |
621 DCHECK(name->IsInternalizedString()); | 620 DCHECK(name->IsInternalizedString()); |
622 DCHECK_NOT_NULL(mode); | 621 DCHECK_NOT_NULL(mode); |
623 DCHECK_NOT_NULL(init_flag); | 622 DCHECK_NOT_NULL(init_flag); |
624 DCHECK_NOT_NULL(maybe_assigned_flag); | 623 DCHECK_NOT_NULL(maybe_assigned_flag); |
625 | 624 |
626 int module_vars_count = Smi::cast(get(ModuleVariableCountIndex()))->value(); | 625 int module_vars_count = Smi::cast(get(ModuleVariableCountIndex()))->value(); |
627 int entry = ModuleVariableEntriesIndex(); | 626 int entry = ModuleVariablesIndex(); |
628 for (int i = 0; i < module_vars_count; ++i) { | 627 for (int i = 0; i < module_vars_count; ++i) { |
629 if (*name == get(entry + kModuleVariableNameOffset)) { | 628 if (*name == get(entry + kModuleVariableNameOffset)) { |
630 int index = Smi::cast(get(entry + kModuleVariableIndexOffset))->value(); | 629 int index = Smi::cast(get(entry + kModuleVariableIndexOffset))->value(); |
631 int properties = | 630 int properties = |
632 Smi::cast(get(entry + kModuleVariablePropertiesOffset))->value(); | 631 Smi::cast(get(entry + kModuleVariablePropertiesOffset))->value(); |
633 *mode = VariableModeField::decode(properties); | 632 *mode = VariableModeField::decode(properties); |
634 *init_flag = InitFlagField::decode(properties); | 633 *init_flag = InitFlagField::decode(properties); |
635 *maybe_assigned_flag = MaybeAssignedFlagField::decode(properties); | 634 *maybe_assigned_flag = MaybeAssignedFlagField::decode(properties); |
636 return index; | 635 return index; |
637 } | 636 } |
(...skipping 15 matching lines...) Expand all Loading... |
653 if (scope_info->length() > 0) { | 652 if (scope_info->length() > 0) { |
654 ContextSlotCache* context_slot_cache = | 653 ContextSlotCache* context_slot_cache = |
655 scope_info->GetIsolate()->context_slot_cache(); | 654 scope_info->GetIsolate()->context_slot_cache(); |
656 int result = context_slot_cache->Lookup(*scope_info, *name, mode, init_flag, | 655 int result = context_slot_cache->Lookup(*scope_info, *name, mode, init_flag, |
657 maybe_assigned_flag); | 656 maybe_assigned_flag); |
658 if (result != ContextSlotCache::kNotFound) { | 657 if (result != ContextSlotCache::kNotFound) { |
659 DCHECK_LT(result, scope_info->ContextLength()); | 658 DCHECK_LT(result, scope_info->ContextLength()); |
660 return result; | 659 return result; |
661 } | 660 } |
662 | 661 |
663 int start = scope_info->ContextLocalNameEntriesIndex(); | 662 int start = scope_info->ContextLocalNamesIndex(); |
664 int end = start + scope_info->ContextLocalCount(); | 663 int end = start + scope_info->ContextLocalCount(); |
665 for (int i = start; i < end; ++i) { | 664 for (int i = start; i < end; ++i) { |
666 if (*name == scope_info->get(i)) { | 665 if (*name == scope_info->get(i)) { |
667 int var = i - start; | 666 int var = i - start; |
668 *mode = scope_info->ContextLocalMode(var); | 667 *mode = scope_info->ContextLocalMode(var); |
669 *init_flag = scope_info->ContextLocalInitFlag(var); | 668 *init_flag = scope_info->ContextLocalInitFlag(var); |
670 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); | 669 *maybe_assigned_flag = scope_info->ContextLocalMaybeAssignedFlag(var); |
671 result = Context::MIN_CONTEXT_SLOTS + var; | 670 result = Context::MIN_CONTEXT_SLOTS + var; |
672 | 671 |
673 context_slot_cache->Update(scope_info, name, *mode, *init_flag, | 672 context_slot_cache->Update(scope_info, name, *mode, *init_flag, |
(...skipping 19 matching lines...) Expand all Loading... |
693 | 692 |
694 | 693 |
695 int ScopeInfo::ParameterIndex(String* name) { | 694 int ScopeInfo::ParameterIndex(String* name) { |
696 DCHECK(name->IsInternalizedString()); | 695 DCHECK(name->IsInternalizedString()); |
697 if (length() > 0) { | 696 if (length() > 0) { |
698 // We must read parameters from the end since for | 697 // We must read parameters from the end since for |
699 // multiply declared parameters the value of the | 698 // multiply declared parameters the value of the |
700 // last declaration of that parameter is used | 699 // last declaration of that parameter is used |
701 // inside a function (and thus we need to look | 700 // inside a function (and thus we need to look |
702 // at the last index). Was bug# 1110337. | 701 // at the last index). Was bug# 1110337. |
703 int start = ParameterEntriesIndex(); | 702 int start = ParameterNamesIndex(); |
704 int end = start + ParameterCount(); | 703 int end = start + ParameterCount(); |
705 for (int i = end - 1; i >= start; --i) { | 704 for (int i = end - 1; i >= start; --i) { |
706 if (name == get(i)) { | 705 if (name == get(i)) { |
707 return i - start; | 706 return i - start; |
708 } | 707 } |
709 } | 708 } |
710 } | 709 } |
711 return -1; | 710 return -1; |
712 } | 711 } |
713 | 712 |
714 | 713 |
715 int ScopeInfo::ReceiverContextSlotIndex() { | 714 int ScopeInfo::ReceiverContextSlotIndex() { |
716 if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) | 715 if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) |
717 return Smi::cast(get(ReceiverEntryIndex()))->value(); | 716 return Smi::cast(get(ReceiverInfoIndex()))->value(); |
718 return -1; | 717 return -1; |
719 } | 718 } |
720 | 719 |
721 int ScopeInfo::FunctionContextSlotIndex(String* name) { | 720 int ScopeInfo::FunctionContextSlotIndex(String* name) { |
722 DCHECK(name->IsInternalizedString()); | 721 DCHECK(name->IsInternalizedString()); |
723 if (length() > 0) { | 722 if (length() > 0) { |
724 if (FunctionVariableField::decode(Flags()) == CONTEXT && | 723 if (FunctionVariableField::decode(Flags()) == CONTEXT && |
725 FunctionName() == name) { | 724 FunctionName() == name) { |
726 return Smi::cast(get(FunctionNameEntryIndex() + 1))->value(); | 725 return Smi::cast(get(FunctionNameInfoIndex() + 1))->value(); |
727 } | 726 } |
728 } | 727 } |
729 return -1; | 728 return -1; |
730 } | 729 } |
731 | 730 |
732 | 731 |
733 FunctionKind ScopeInfo::function_kind() { | 732 FunctionKind ScopeInfo::function_kind() { |
734 return FunctionKindField::decode(Flags()); | 733 return FunctionKindField::decode(Flags()); |
735 } | 734 } |
736 | 735 |
737 | 736 int ScopeInfo::ParameterNamesIndex() { |
738 int ScopeInfo::ParameterEntriesIndex() { | |
739 DCHECK_LT(0, length()); | 737 DCHECK_LT(0, length()); |
740 return kVariablePartIndex; | 738 return kVariablePartIndex; |
741 } | 739 } |
742 | 740 |
743 | 741 |
744 int ScopeInfo::StackLocalFirstSlotIndex() { | 742 int ScopeInfo::StackLocalFirstSlotIndex() { |
745 return ParameterEntriesIndex() + ParameterCount(); | 743 return ParameterNamesIndex() + ParameterCount(); |
746 } | 744 } |
747 | 745 |
| 746 int ScopeInfo::StackLocalNamesIndex() { return StackLocalFirstSlotIndex() + 1; } |
748 | 747 |
749 int ScopeInfo::StackLocalEntriesIndex() { | 748 int ScopeInfo::ContextLocalNamesIndex() { |
750 return StackLocalFirstSlotIndex() + 1; | 749 return StackLocalNamesIndex() + StackLocalCount(); |
751 } | 750 } |
752 | 751 |
753 | 752 int ScopeInfo::ContextLocalInfosIndex() { |
754 int ScopeInfo::ContextLocalNameEntriesIndex() { | 753 return ContextLocalNamesIndex() + ContextLocalCount(); |
755 return StackLocalEntriesIndex() + StackLocalCount(); | |
756 } | 754 } |
757 | 755 |
758 int ScopeInfo::ContextLocalInfoEntriesIndex() { | 756 int ScopeInfo::ReceiverInfoIndex() { |
759 return ContextLocalNameEntriesIndex() + ContextLocalCount(); | 757 return ContextLocalInfosIndex() + ContextLocalCount(); |
760 } | 758 } |
761 | 759 |
762 int ScopeInfo::ReceiverEntryIndex() { | 760 int ScopeInfo::FunctionNameInfoIndex() { |
763 return ContextLocalInfoEntriesIndex() + ContextLocalCount(); | 761 return ReceiverInfoIndex() + (HasAllocatedReceiver() ? 1 : 0); |
764 } | 762 } |
765 | 763 |
766 int ScopeInfo::FunctionNameEntryIndex() { | 764 int ScopeInfo::OuterScopeInfoIndex() { |
767 return ReceiverEntryIndex() + (HasAllocatedReceiver() ? 1 : 0); | 765 return FunctionNameInfoIndex() + (HasFunctionName() ? 2 : 0); |
768 } | 766 } |
769 | 767 |
770 int ScopeInfo::OuterScopeInfoEntryIndex() { | 768 int ScopeInfo::ModuleInfoIndex() { |
771 return FunctionNameEntryIndex() + (HasFunctionName() ? 2 : 0); | 769 return OuterScopeInfoIndex() + (HasOuterScopeInfo() ? 1 : 0); |
772 } | 770 } |
773 | 771 |
774 int ScopeInfo::ModuleInfoEntryIndex() { | 772 int ScopeInfo::ModuleVariableCountIndex() { return ModuleInfoIndex() + 1; } |
775 return OuterScopeInfoEntryIndex() + (HasOuterScopeInfo() ? 1 : 0); | |
776 } | |
777 | 773 |
778 int ScopeInfo::ModuleVariableCountIndex() { return ModuleInfoEntryIndex() + 1; } | 774 int ScopeInfo::ModuleVariablesIndex() { return ModuleVariableCountIndex() + 1; } |
779 | |
780 int ScopeInfo::ModuleVariableEntriesIndex() { | |
781 return ModuleVariableCountIndex() + 1; | |
782 } | |
783 | 775 |
784 #ifdef DEBUG | 776 #ifdef DEBUG |
785 | 777 |
786 static void PrintList(const char* list_name, | 778 static void PrintList(const char* list_name, |
787 int nof_internal_slots, | 779 int nof_internal_slots, |
788 int start, | 780 int start, |
789 int end, | 781 int end, |
790 ScopeInfo* scope_info) { | 782 ScopeInfo* scope_info) { |
791 if (start < end) { | 783 if (start < end) { |
792 PrintF("\n // %s\n", list_name); | 784 PrintF("\n // %s\n", list_name); |
(...skipping 12 matching lines...) Expand all Loading... |
805 void ScopeInfo::Print() { | 797 void ScopeInfo::Print() { |
806 PrintF("ScopeInfo "); | 798 PrintF("ScopeInfo "); |
807 if (HasFunctionName()) { | 799 if (HasFunctionName()) { |
808 FunctionName()->ShortPrint(); | 800 FunctionName()->ShortPrint(); |
809 } else { | 801 } else { |
810 PrintF("/* no function name */"); | 802 PrintF("/* no function name */"); |
811 } | 803 } |
812 PrintF("{"); | 804 PrintF("{"); |
813 | 805 |
814 if (length() > 0) { | 806 if (length() > 0) { |
815 PrintList("parameters", 0, ParameterEntriesIndex(), | 807 PrintList("parameters", 0, ParameterNamesIndex(), |
816 ParameterEntriesIndex() + ParameterCount(), this); | 808 ParameterNamesIndex() + ParameterCount(), this); |
817 PrintList("stack slots", 0, StackLocalEntriesIndex(), | 809 PrintList("stack slots", 0, StackLocalNamesIndex(), |
818 StackLocalEntriesIndex() + StackLocalCount(), this); | 810 StackLocalNamesIndex() + StackLocalCount(), this); |
819 PrintList("context slots", Context::MIN_CONTEXT_SLOTS, | 811 PrintList("context slots", Context::MIN_CONTEXT_SLOTS, |
820 ContextLocalNameEntriesIndex(), | 812 ContextLocalNamesIndex(), |
821 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); | 813 ContextLocalNamesIndex() + ContextLocalCount(), this); |
822 } | 814 } |
823 | 815 |
824 PrintF("}\n"); | 816 PrintF("}\n"); |
825 } | 817 } |
826 #endif // DEBUG | 818 #endif // DEBUG |
827 | 819 |
828 Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, ModuleDescriptor* descr) { | 820 Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, ModuleDescriptor* descr) { |
829 // Serialize special exports. | 821 // Serialize special exports. |
830 Handle<FixedArray> special_exports = | 822 Handle<FixedArray> special_exports = |
831 isolate->factory()->NewFixedArray(descr->special_exports().length()); | 823 isolate->factory()->NewFixedArray(descr->special_exports().length()); |
(...skipping 15 matching lines...) Expand all Loading... |
847 } | 839 } |
848 | 840 |
849 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); | 841 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); |
850 result->set(kSpecialExportsIndex, *special_exports); | 842 result->set(kSpecialExportsIndex, *special_exports); |
851 result->set(kRegularExportsIndex, *regular_exports); | 843 result->set(kRegularExportsIndex, *regular_exports); |
852 return result; | 844 return result; |
853 } | 845 } |
854 | 846 |
855 } // namespace internal | 847 } // namespace internal |
856 } // namespace v8 | 848 } // namespace v8 |
OLD | NEW |