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/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 | 13 |
| 14 // An entry in ModuleVariableEntries consists of several slots: |
| 15 enum ModuleVariableEntryOffset { |
| 16 kModuleVariableNameOffset, |
| 17 kModuleVariableIndexOffset, |
| 18 kModuleVariablePropertiesOffset, |
| 19 kModuleVariableEntryLength // Sentinel value. |
| 20 }; |
14 | 21 |
15 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, | 22 Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, |
16 Scope* scope) { | 23 Scope* scope) { |
17 // Collect variables. | 24 // Collect variables. |
18 ZoneList<Variable*>* locals = scope->locals(); | 25 ZoneList<Variable*>* locals = scope->locals(); |
19 int stack_local_count = 0; | 26 int stack_local_count = 0; |
20 int context_local_count = 0; | 27 int context_local_count = 0; |
| 28 int module_vars_count = 0; |
21 // Stack allocated block scope variables are allocated in the parent | 29 // Stack allocated block scope variables are allocated in the parent |
22 // declaration scope, but are recorded in the block scope's scope info. First | 30 // declaration scope, but are recorded in the block scope's scope info. First |
23 // slot index indicates at which offset a particular scope starts in the | 31 // slot index indicates at which offset a particular scope starts in the |
24 // parent declaration scope. | 32 // parent declaration scope. |
25 int first_slot_index = 0; | 33 int first_slot_index = 0; |
26 for (int i = 0; i < locals->length(); i++) { | 34 for (int i = 0; i < locals->length(); i++) { |
27 Variable* var = locals->at(i); | 35 Variable* var = locals->at(i); |
28 if (var->IsStackLocal()) { | 36 switch (var->location()) { |
29 if (stack_local_count == 0) first_slot_index = var->index(); | 37 case VariableLocation::LOCAL: |
30 stack_local_count++; | 38 if (stack_local_count == 0) first_slot_index = var->index(); |
31 } else if (var->IsContextSlot()) { | 39 stack_local_count++; |
32 context_local_count++; | 40 break; |
| 41 case VariableLocation::CONTEXT: |
| 42 context_local_count++; |
| 43 break; |
| 44 case VariableLocation::MODULE: |
| 45 module_vars_count++; |
| 46 break; |
| 47 default: |
| 48 break; |
33 } | 49 } |
34 } | 50 } |
| 51 DCHECK(module_vars_count == 0 || scope->is_module_scope()); |
35 | 52 |
36 // Make sure we allocate the correct amount. | 53 // Make sure we allocate the correct amount. |
37 DCHECK_EQ(scope->ContextLocalCount(), context_local_count); | 54 DCHECK_EQ(scope->ContextLocalCount(), context_local_count); |
38 | 55 |
39 // Determine use and location of the "this" binding if it is present. | 56 // Determine use and location of the "this" binding if it is present. |
40 VariableAllocationInfo receiver_info; | 57 VariableAllocationInfo receiver_info; |
41 if (scope->is_declaration_scope() && | 58 if (scope->is_declaration_scope() && |
42 scope->AsDeclarationScope()->has_this_declaration()) { | 59 scope->AsDeclarationScope()->has_this_declaration()) { |
43 Variable* var = scope->AsDeclarationScope()->receiver(); | 60 Variable* var = scope->AsDeclarationScope()->receiver(); |
44 if (!var->is_used()) { | 61 if (!var->is_used()) { |
(...skipping 30 matching lines...) Expand all Loading... |
75 } else { | 92 } else { |
76 function_name_info = NONE; | 93 function_name_info = NONE; |
77 function_variable_mode = VAR; | 94 function_variable_mode = VAR; |
78 } | 95 } |
79 | 96 |
80 const bool has_function_name = function_name_info != NONE; | 97 const bool has_function_name = function_name_info != NONE; |
81 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; | 98 const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT; |
82 const int parameter_count = scope->num_parameters(); | 99 const int parameter_count = scope->num_parameters(); |
83 const int length = kVariablePartIndex + parameter_count + | 100 const int length = kVariablePartIndex + parameter_count + |
84 (1 + stack_local_count) + 2 * context_local_count + | 101 (1 + stack_local_count) + 2 * context_local_count + |
85 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0); | 102 (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0) + |
| 103 (scope->is_module_scope() |
| 104 ? 2 + kModuleVariableEntryLength * module_vars_count |
| 105 : 0); |
86 | 106 |
87 Factory* factory = isolate->factory(); | 107 Factory* factory = isolate->factory(); |
88 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); | 108 Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); |
89 | 109 |
90 bool has_simple_parameters = false; | 110 bool has_simple_parameters = false; |
91 bool asm_module = false; | 111 bool asm_module = false; |
92 bool asm_function = false; | 112 bool asm_function = false; |
93 FunctionKind function_kind = kNormalFunction; | 113 FunctionKind function_kind = kNormalFunction; |
94 if (scope->is_function_scope()) { | 114 if (scope->is_function_scope()) { |
95 DeclarationScope* function_scope = scope->AsDeclarationScope(); | 115 DeclarationScope* function_scope = scope->AsDeclarationScope(); |
(...skipping 10 matching lines...) Expand all Loading... |
106 DeclarationScopeField::encode(scope->is_declaration_scope()) | | 126 DeclarationScopeField::encode(scope->is_declaration_scope()) | |
107 ReceiverVariableField::encode(receiver_info) | | 127 ReceiverVariableField::encode(receiver_info) | |
108 HasNewTargetField::encode(has_new_target) | | 128 HasNewTargetField::encode(has_new_target) | |
109 FunctionVariableField::encode(function_name_info) | | 129 FunctionVariableField::encode(function_name_info) | |
110 FunctionVariableMode::encode(function_variable_mode) | | 130 FunctionVariableMode::encode(function_variable_mode) | |
111 AsmModuleField::encode(asm_module) | | 131 AsmModuleField::encode(asm_module) | |
112 AsmFunctionField::encode(asm_function) | | 132 AsmFunctionField::encode(asm_function) | |
113 HasSimpleParametersField::encode(has_simple_parameters) | | 133 HasSimpleParametersField::encode(has_simple_parameters) | |
114 FunctionKindField::encode(function_kind); | 134 FunctionKindField::encode(function_kind); |
115 scope_info->SetFlags(flags); | 135 scope_info->SetFlags(flags); |
| 136 |
116 scope_info->SetParameterCount(parameter_count); | 137 scope_info->SetParameterCount(parameter_count); |
117 scope_info->SetStackLocalCount(stack_local_count); | 138 scope_info->SetStackLocalCount(stack_local_count); |
118 scope_info->SetContextLocalCount(context_local_count); | 139 scope_info->SetContextLocalCount(context_local_count); |
119 | 140 |
120 int index = kVariablePartIndex; | 141 int index = kVariablePartIndex; |
121 // Add parameters. | 142 // Add parameters. |
122 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); | 143 DCHECK_EQ(index, scope_info->ParameterEntriesIndex()); |
123 if (scope->is_declaration_scope()) { | 144 if (scope->is_declaration_scope()) { |
124 for (int i = 0; i < parameter_count; ++i) { | 145 for (int i = 0; i < parameter_count; ++i) { |
125 scope_info->set(index++, | 146 scope_info->set(index++, |
126 *scope->AsDeclarationScope()->parameter(i)->name()); | 147 *scope->AsDeclarationScope()->parameter(i)->name()); |
127 } | 148 } |
128 } | 149 } |
129 | 150 |
130 // Add stack locals' names, context locals' names and info. We are assuming | 151 // Add stack locals' names, context locals' names and info, module variables' |
131 // that the stack locals' slots are allocated in increasing order, so we can | 152 // names and info. We are assuming that the stack locals' slots are allocated |
132 // simply add them to the ScopeInfo object. Context locals are added using | 153 // in increasing order, so we can simply add them to the ScopeInfo object. |
133 // their index. | 154 // Context locals are added using their index. |
134 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); | 155 DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex()); |
135 scope_info->set(index++, Smi::FromInt(first_slot_index)); | 156 scope_info->set(index++, Smi::FromInt(first_slot_index)); |
136 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); | 157 DCHECK_EQ(index, scope_info->StackLocalEntriesIndex()); |
137 | 158 |
138 int stack_local_base = index; | 159 int stack_local_base = index; |
139 int context_local_base = stack_local_base + stack_local_count; | 160 int context_local_base = stack_local_base + stack_local_count; |
140 int context_local_info_base = context_local_base + context_local_count; | 161 int context_local_info_base = context_local_base + context_local_count; |
| 162 int module_var_entry = scope_info->ModuleVariableEntriesIndex(); |
141 | 163 |
142 for (int i = 0; i < locals->length(); ++i) { | 164 for (int i = 0; i < locals->length(); ++i) { |
143 Variable* var = locals->at(i); | 165 Variable* var = locals->at(i); |
144 if (var->IsStackLocal()) { | 166 switch (var->location()) { |
145 int local_index = var->index() - first_slot_index; | 167 case VariableLocation::LOCAL: { |
146 DCHECK_LE(0, local_index); | 168 int local_index = var->index() - first_slot_index; |
147 DCHECK_LT(local_index, stack_local_count); | 169 DCHECK_LE(0, local_index); |
148 scope_info->set(stack_local_base + local_index, *var->name()); | 170 DCHECK_LT(local_index, stack_local_count); |
149 } else if (var->IsContextSlot()) { | 171 scope_info->set(stack_local_base + local_index, *var->name()); |
150 // Due to duplicate parameters, context locals aren't guaranteed to come | 172 break; |
151 // in order. | 173 } |
152 int local_index = var->index() - Context::MIN_CONTEXT_SLOTS; | 174 case VariableLocation::CONTEXT: { |
153 DCHECK_LE(0, local_index); | 175 // Due to duplicate parameters, context locals aren't guaranteed to come |
154 DCHECK_LT(local_index, context_local_count); | 176 // in order. |
155 uint32_t info = VariableModeField::encode(var->mode()) | | 177 int local_index = var->index() - Context::MIN_CONTEXT_SLOTS; |
156 InitFlagField::encode(var->initialization_flag()) | | 178 DCHECK_LE(0, local_index); |
157 MaybeAssignedFlagField::encode(var->maybe_assigned()); | 179 DCHECK_LT(local_index, context_local_count); |
158 scope_info->set(context_local_base + local_index, *var->name()); | 180 uint32_t info = VariableModeField::encode(var->mode()) | |
159 scope_info->set(context_local_info_base + local_index, | 181 InitFlagField::encode(var->initialization_flag()) | |
160 Smi::FromInt(info)); | 182 MaybeAssignedFlagField::encode(var->maybe_assigned()); |
| 183 scope_info->set(context_local_base + local_index, *var->name()); |
| 184 scope_info->set(context_local_info_base + local_index, |
| 185 Smi::FromInt(info)); |
| 186 break; |
| 187 } |
| 188 case VariableLocation::MODULE: { |
| 189 scope_info->set(module_var_entry + kModuleVariableNameOffset, |
| 190 *var->name()); |
| 191 scope_info->set(module_var_entry + kModuleVariableIndexOffset, |
| 192 Smi::FromInt(var->index())); |
| 193 uint32_t properties = |
| 194 VariableModeField::encode(var->mode()) | |
| 195 InitFlagField::encode(var->initialization_flag()) | |
| 196 MaybeAssignedFlagField::encode(var->maybe_assigned()); |
| 197 scope_info->set(module_var_entry + kModuleVariablePropertiesOffset, |
| 198 Smi::FromInt(properties)); |
| 199 module_var_entry += kModuleVariableEntryLength; |
| 200 break; |
| 201 } |
| 202 default: |
| 203 break; |
161 } | 204 } |
162 } | 205 } |
163 | 206 |
164 index += stack_local_count + 2 * context_local_count; | 207 index += stack_local_count + 2 * context_local_count; |
165 | 208 |
166 // If the receiver is allocated, add its index. | 209 // If the receiver is allocated, add its index. |
167 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); | 210 DCHECK_EQ(index, scope_info->ReceiverEntryIndex()); |
168 if (has_receiver) { | 211 if (has_receiver) { |
169 int var_index = scope->AsDeclarationScope()->receiver()->index(); | 212 int var_index = scope->AsDeclarationScope()->receiver()->index(); |
170 scope_info->set(index++, Smi::FromInt(var_index)); | 213 scope_info->set(index++, Smi::FromInt(var_index)); |
171 // ?? DCHECK(receiver_info != CONTEXT || var_index == | 214 // ?? DCHECK(receiver_info != CONTEXT || var_index == |
172 // scope_info->ContextLength() - 1); | 215 // scope_info->ContextLength() - 1); |
173 } | 216 } |
174 | 217 |
175 // If present, add the function variable name and its index. | 218 // If present, add the function variable name and its index. |
176 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); | 219 DCHECK_EQ(index, scope_info->FunctionNameEntryIndex()); |
177 if (has_function_name) { | 220 if (has_function_name) { |
178 int var_index = scope->AsDeclarationScope()->function_var()->index(); | 221 int var_index = scope->AsDeclarationScope()->function_var()->index(); |
179 scope_info->set(index++, | 222 scope_info->set(index++, |
180 *scope->AsDeclarationScope()->function_var()->name()); | 223 *scope->AsDeclarationScope()->function_var()->name()); |
181 scope_info->set(index++, Smi::FromInt(var_index)); | 224 scope_info->set(index++, Smi::FromInt(var_index)); |
182 DCHECK(function_name_info != CONTEXT || | 225 DCHECK(function_name_info != CONTEXT || |
183 var_index == scope_info->ContextLength() - 1); | 226 var_index == scope_info->ContextLength() - 1); |
184 } | 227 } |
185 | 228 |
| 229 // Module-specific information (only for module scopes). |
| 230 if (scope->is_module_scope()) { |
| 231 Handle<ModuleInfo> module_info = |
| 232 ModuleInfo::New(isolate, scope->AsModuleScope()->module()); |
| 233 DCHECK_EQ(index, scope_info->ModuleInfoEntryIndex()); |
| 234 scope_info->set(index++, *module_info); |
| 235 DCHECK_EQ(index, scope_info->ModuleVariableCountIndex()); |
| 236 scope_info->set(index++, Smi::FromInt(module_vars_count)); |
| 237 DCHECK_EQ(index, scope_info->ModuleVariableEntriesIndex()); |
| 238 // The variable entries themselves have already been written above. |
| 239 index += kModuleVariableEntryLength * module_vars_count; |
| 240 } |
| 241 |
186 DCHECK_EQ(index, scope_info->length()); | 242 DCHECK_EQ(index, scope_info->length()); |
187 DCHECK_EQ(scope->num_parameters(), scope_info->ParameterCount()); | 243 DCHECK_EQ(scope->num_parameters(), scope_info->ParameterCount()); |
188 DCHECK_EQ(scope->num_heap_slots(), scope_info->ContextLength()); | 244 DCHECK_EQ(scope->num_heap_slots(), scope_info->ContextLength()); |
189 return scope_info; | 245 return scope_info; |
190 } | 246 } |
191 | 247 |
192 | 248 |
193 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { | 249 Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) { |
194 DCHECK(isolate->bootstrapper()->IsActive()); | 250 DCHECK(isolate->bootstrapper()->IsActive()); |
195 | 251 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 bool ScopeInfo::HasContext() { | 416 bool ScopeInfo::HasContext() { |
361 return ContextLength() > 0; | 417 return ContextLength() > 0; |
362 } | 418 } |
363 | 419 |
364 | 420 |
365 String* ScopeInfo::FunctionName() { | 421 String* ScopeInfo::FunctionName() { |
366 DCHECK(HasFunctionName()); | 422 DCHECK(HasFunctionName()); |
367 return String::cast(get(FunctionNameEntryIndex())); | 423 return String::cast(get(FunctionNameEntryIndex())); |
368 } | 424 } |
369 | 425 |
| 426 ModuleInfo* ScopeInfo::ModuleDescriptorInfo() { |
| 427 DCHECK(scope_type() == MODULE_SCOPE); |
| 428 return static_cast<ModuleInfo*>(get(ModuleInfoEntryIndex())); |
| 429 } |
370 | 430 |
371 String* ScopeInfo::ParameterName(int var) { | 431 String* ScopeInfo::ParameterName(int var) { |
372 DCHECK_LE(0, var); | 432 DCHECK_LE(0, var); |
373 DCHECK_LT(var, ParameterCount()); | 433 DCHECK_LT(var, ParameterCount()); |
374 int info_index = ParameterEntriesIndex() + var; | 434 int info_index = ParameterEntriesIndex() + var; |
375 return String::cast(get(info_index)); | 435 return String::cast(get(info_index)); |
376 } | 436 } |
377 | 437 |
378 | 438 |
379 String* ScopeInfo::LocalName(int var) { | 439 String* ScopeInfo::LocalName(int var) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 int end = start + StackLocalCount(); | 514 int end = start + StackLocalCount(); |
455 for (int i = start; i < end; ++i) { | 515 for (int i = start; i < end; ++i) { |
456 if (name == get(i)) { | 516 if (name == get(i)) { |
457 return i - start + first_slot_index; | 517 return i - start + first_slot_index; |
458 } | 518 } |
459 } | 519 } |
460 } | 520 } |
461 return -1; | 521 return -1; |
462 } | 522 } |
463 | 523 |
| 524 int ScopeInfo::ModuleIndex(Handle<String> name, VariableMode* mode, |
| 525 InitializationFlag* init_flag, |
| 526 MaybeAssignedFlag* maybe_assigned_flag) { |
| 527 DCHECK_EQ(scope_type(), MODULE_SCOPE); |
| 528 DCHECK(name->IsInternalizedString()); |
| 529 DCHECK_NOT_NULL(mode); |
| 530 DCHECK_NOT_NULL(init_flag); |
| 531 DCHECK_NOT_NULL(maybe_assigned_flag); |
| 532 |
| 533 int module_vars_count = Smi::cast(get(ModuleVariableCountIndex()))->value(); |
| 534 int entry = ModuleVariableEntriesIndex(); |
| 535 for (int i = 0; i < module_vars_count; ++i) { |
| 536 if (*name == get(entry + kModuleVariableNameOffset)) { |
| 537 int index = Smi::cast(get(entry + kModuleVariableIndexOffset))->value(); |
| 538 int properties = |
| 539 Smi::cast(get(entry + kModuleVariablePropertiesOffset))->value(); |
| 540 *mode = VariableModeField::decode(properties); |
| 541 *init_flag = InitFlagField::decode(properties); |
| 542 *maybe_assigned_flag = MaybeAssignedFlagField::decode(properties); |
| 543 return index; |
| 544 } |
| 545 entry += kModuleVariableEntryLength; |
| 546 } |
| 547 |
| 548 return -1; |
| 549 } |
464 | 550 |
465 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, | 551 int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info, |
466 Handle<String> name, VariableMode* mode, | 552 Handle<String> name, VariableMode* mode, |
467 InitializationFlag* init_flag, | 553 InitializationFlag* init_flag, |
468 MaybeAssignedFlag* maybe_assigned_flag) { | 554 MaybeAssignedFlag* maybe_assigned_flag) { |
469 DCHECK(name->IsInternalizedString()); | 555 DCHECK(name->IsInternalizedString()); |
470 DCHECK_NOT_NULL(mode); | 556 DCHECK_NOT_NULL(mode); |
471 DCHECK_NOT_NULL(init_flag); | 557 DCHECK_NOT_NULL(init_flag); |
472 DCHECK_NOT_NULL(maybe_assigned_flag); | 558 DCHECK_NOT_NULL(maybe_assigned_flag); |
473 | 559 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 | 658 |
573 int ScopeInfo::StackLocalEntriesIndex() { | 659 int ScopeInfo::StackLocalEntriesIndex() { |
574 return StackLocalFirstSlotIndex() + 1; | 660 return StackLocalFirstSlotIndex() + 1; |
575 } | 661 } |
576 | 662 |
577 | 663 |
578 int ScopeInfo::ContextLocalNameEntriesIndex() { | 664 int ScopeInfo::ContextLocalNameEntriesIndex() { |
579 return StackLocalEntriesIndex() + StackLocalCount(); | 665 return StackLocalEntriesIndex() + StackLocalCount(); |
580 } | 666 } |
581 | 667 |
582 | |
583 int ScopeInfo::ContextLocalInfoEntriesIndex() { | 668 int ScopeInfo::ContextLocalInfoEntriesIndex() { |
584 return ContextLocalNameEntriesIndex() + ContextLocalCount(); | 669 return ContextLocalNameEntriesIndex() + ContextLocalCount(); |
585 } | 670 } |
586 | 671 |
587 | |
588 int ScopeInfo::ReceiverEntryIndex() { | 672 int ScopeInfo::ReceiverEntryIndex() { |
589 return ContextLocalInfoEntriesIndex() + ContextLocalCount(); | 673 return ContextLocalInfoEntriesIndex() + ContextLocalCount(); |
590 } | 674 } |
591 | 675 |
592 | |
593 int ScopeInfo::FunctionNameEntryIndex() { | 676 int ScopeInfo::FunctionNameEntryIndex() { |
594 return ReceiverEntryIndex() + (HasAllocatedReceiver() ? 1 : 0); | 677 return ReceiverEntryIndex() + (HasAllocatedReceiver() ? 1 : 0); |
595 } | 678 } |
596 | 679 |
| 680 int ScopeInfo::ModuleInfoEntryIndex() { |
| 681 return FunctionNameEntryIndex() + (HasFunctionName() ? 2 : 0); |
| 682 } |
| 683 |
| 684 int ScopeInfo::ModuleVariableCountIndex() { return ModuleInfoEntryIndex() + 1; } |
| 685 |
| 686 int ScopeInfo::ModuleVariableEntriesIndex() { |
| 687 return ModuleVariableCountIndex() + 1; |
| 688 } |
| 689 |
597 #ifdef DEBUG | 690 #ifdef DEBUG |
598 | 691 |
599 static void PrintList(const char* list_name, | 692 static void PrintList(const char* list_name, |
600 int nof_internal_slots, | 693 int nof_internal_slots, |
601 int start, | 694 int start, |
602 int end, | 695 int end, |
603 ScopeInfo* scope_info) { | 696 ScopeInfo* scope_info) { |
604 if (start < end) { | 697 if (start < end) { |
605 PrintF("\n // %s\n", list_name); | 698 PrintF("\n // %s\n", list_name); |
606 if (nof_internal_slots > 0) { | 699 if (nof_internal_slots > 0) { |
(...skipping 24 matching lines...) Expand all Loading... |
631 StackLocalEntriesIndex() + StackLocalCount(), this); | 724 StackLocalEntriesIndex() + StackLocalCount(), this); |
632 PrintList("context slots", Context::MIN_CONTEXT_SLOTS, | 725 PrintList("context slots", Context::MIN_CONTEXT_SLOTS, |
633 ContextLocalNameEntriesIndex(), | 726 ContextLocalNameEntriesIndex(), |
634 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); | 727 ContextLocalNameEntriesIndex() + ContextLocalCount(), this); |
635 } | 728 } |
636 | 729 |
637 PrintF("}\n"); | 730 PrintF("}\n"); |
638 } | 731 } |
639 #endif // DEBUG | 732 #endif // DEBUG |
640 | 733 |
| 734 Handle<ModuleInfo> ModuleInfo::New(Isolate* isolate, ModuleDescriptor* descr) { |
| 735 // Serialize special exports. |
| 736 Handle<FixedArray> special_exports = |
| 737 isolate->factory()->NewFixedArray(descr->special_exports().length()); |
| 738 { |
| 739 int i = 0; |
| 740 for (auto entry : descr->special_exports()) { |
| 741 special_exports->set(i++, *entry->Serialize(isolate)); |
| 742 } |
| 743 } |
| 744 |
| 745 // Serialize regular exports. |
| 746 Handle<FixedArray> regular_exports = isolate->factory()->NewFixedArray( |
| 747 static_cast<int>(descr->regular_exports().size())); |
| 748 { |
| 749 int i = 0; |
| 750 for (const auto& it : descr->regular_exports()) { |
| 751 regular_exports->set(i++, *it.second->Serialize(isolate)); |
| 752 } |
| 753 } |
| 754 |
| 755 Handle<ModuleInfo> result = isolate->factory()->NewModuleInfo(); |
| 756 result->set(kSpecialExportsIndex, *special_exports); |
| 757 result->set(kRegularExportsIndex, *regular_exports); |
| 758 return result; |
| 759 } |
641 | 760 |
642 } // namespace internal | 761 } // namespace internal |
643 } // namespace v8 | 762 } // namespace v8 |
OLD | NEW |