v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
scope-info.cc
Go to the documentation of this file.
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
3// found in the LICENSE file.
4
6
7#include <stdlib.h>
8
9#include "src/ast/scopes.h"
10#include "src/ast/variables.h"
16#include "src/roots/roots.h"
17
18// Has to be the last include (doesn't have include guards):
20
21namespace v8 {
22namespace internal {
23
24// TODO(crbug.com/401059828): make it DEBUG only, once investigation is over.
25bool ScopeInfo::Equals(Tagged<ScopeInfo> other, bool is_live_edit_compare,
26 int* out_last_checked_field) const {
27 if (length() != other->length()) return false;
28 if (Flags() != other->Flags()) return false;
29 for (int index = 0; index < length(); ++index) {
30 if (out_last_checked_field) *out_last_checked_field = index;
31 if (index == kFlags) continue;
32 if (is_live_edit_compare && index >= kPositionInfoStart &&
33 index <= kPositionInfoEnd) {
34 continue;
35 }
36 Tagged<Object> entry = get(index);
37 Tagged<Object> other_entry = other->get(index);
38 if (IsSmi(entry)) {
39 if (entry != other_entry) return false;
40 } else {
41 if (Cast<HeapObject>(entry)->map()->instance_type() !=
42 Cast<HeapObject>(other_entry)->map()->instance_type()) {
43 return false;
44 }
45 if (IsString(entry)) {
46 if (!Cast<String>(entry)->Equals(Cast<String>(other_entry))) {
47 return false;
48 }
49 } else if (IsScopeInfo(entry)) {
50 if (!is_live_edit_compare && !Cast<ScopeInfo>(entry)->Equals(
51 Cast<ScopeInfo>(other_entry), false)) {
52 return false;
53 }
54 } else if (IsSourceTextModuleInfo(entry)) {
55 if (!is_live_edit_compare &&
57 Cast<SourceTextModuleInfo>(other_entry))) {
58 return false;
59 }
60 } else if (IsOddball(entry)) {
61 if (Cast<Oddball>(entry)->kind() !=
62 Cast<Oddball>(other_entry)->kind()) {
63 return false;
64 }
65 } else if (IsDependentCode(entry)) {
66 DCHECK(IsDependentCode(other_entry));
67 // Ignore the dependent code field since all the code have to be
68 // deoptimized anyway in case of a live-edit.
69 } else {
71 }
72 }
73 }
74 return true;
75}
76
77// static
78template <typename IsolateT>
79Handle<ScopeInfo> ScopeInfo::Create(IsolateT* isolate, Zone* zone, Scope* scope,
80 MaybeDirectHandle<ScopeInfo> outer_scope) {
81 // Collect variables.
82 int context_local_count = 0;
83 int module_vars_count = 0;
84 // Stack allocated block scope variables are allocated in the parent
85 // declaration scope, but are recorded in the block scope's scope info. First
86 // slot index indicates at which offset a particular scope starts in the
87 // parent declaration scope.
88 for (Variable* var : *scope->locals()) {
89 switch (var->location()) {
92 context_local_count++;
93 break;
95 module_vars_count++;
96 break;
97 default:
98 break;
99 }
100 }
101 // Determine use and location of the "this" binding if it is present.
102 VariableAllocationInfo receiver_info;
103 if (scope->is_declaration_scope() &&
105 Variable* var = scope->AsDeclarationScope()->receiver();
106 if (!var->is_used()) {
107 receiver_info = VariableAllocationInfo::UNUSED;
108 } else if (var->IsContextSlot()) {
109 receiver_info = VariableAllocationInfo::CONTEXT;
110 } else {
111 DCHECK(var->IsParameter());
112 receiver_info = VariableAllocationInfo::STACK;
113 }
114 } else {
115 receiver_info = VariableAllocationInfo::NONE;
116 }
117
118 DCHECK(module_vars_count == 0 || scope->is_module_scope());
119
120 // Make sure we allocate the correct amount.
121 DCHECK_EQ(scope->ContextLocalCount(), context_local_count);
122
123 // If the number of locals is small, we inline directly
124 // in the scope info object.
125 bool has_inlined_local_names =
126 context_local_count < kScopeInfoMaxInlinedLocalNamesSize;
127
128 const bool has_new_target =
129 scope->is_declaration_scope() &&
130 scope->AsDeclarationScope()->new_target_var() != nullptr;
131 // TODO(cbruni): Don't always waste a field for the inferred name.
132 const bool has_inferred_function_name = scope->is_function_scope();
133
134 // Determine use and location of the function variable if it is present.
135 VariableAllocationInfo function_name_info;
136 if (scope->is_function_scope()) {
137 if (scope->AsDeclarationScope()->function_var() != nullptr) {
138 Variable* var = scope->AsDeclarationScope()->function_var();
139 if (!var->is_used()) {
140 function_name_info = VariableAllocationInfo::UNUSED;
141 } else if (var->IsContextSlot()) {
142 function_name_info = VariableAllocationInfo::CONTEXT;
143 } else {
144 DCHECK(var->IsStackLocal());
145 function_name_info = VariableAllocationInfo::STACK;
146 }
147 } else {
148 // Always reserve space for the debug name in the scope info.
149 function_name_info = VariableAllocationInfo::UNUSED;
150 }
151 } else if (scope->is_module_scope() || scope->is_script_scope() ||
152 scope->is_eval_scope()) {
153 // Always reserve space for the debug name in the scope info.
154 function_name_info = VariableAllocationInfo::UNUSED;
155 } else {
156 function_name_info = VariableAllocationInfo::NONE;
157 }
158
159 const bool has_brand =
160 scope->is_class_scope()
161 ? scope->AsClassScope()->brand() != nullptr
162 : scope->IsConstructorScope() &&
164 const bool should_save_class_variable_index =
165 scope->is_class_scope()
167 : false;
168 const bool has_function_name =
169 function_name_info != VariableAllocationInfo::NONE;
170 const int parameter_count =
171 scope->is_declaration_scope()
173 : 0;
174 const bool has_outer_scope_info = !outer_scope.is_null();
175
177 if (scope->is_module_scope()) {
178 module_info = SourceTextModuleInfo::New(isolate, zone,
179 scope->AsModuleScope()->module());
180 }
181
182 // Make sure the Fields enum agrees with Torque-generated offsets.
183 static_assert(OffsetOfElementAt(kFlags) == kFlagsOffset);
184 static_assert(OffsetOfElementAt(kParameterCount) == kParameterCountOffset);
185 static_assert(OffsetOfElementAt(kContextLocalCount) ==
186 kContextLocalCountOffset);
187
189 bool sloppy_eval_can_extend_vars = false;
190 if (scope->is_declaration_scope()) {
192 sloppy_eval_can_extend_vars =
194 }
195 DCHECK_IMPLIES(sloppy_eval_can_extend_vars, scope->HasContextExtensionSlot());
196
197 const int local_names_container_size =
198 has_inlined_local_names ? context_local_count : 1;
199
200 const int has_dependent_code = sloppy_eval_can_extend_vars;
201 const int length =
202 kVariablePartIndex + local_names_container_size + context_local_count +
203 (should_save_class_variable_index ? 1 : 0) +
204 (has_function_name ? kFunctionNameEntries : 0) +
205 (has_inferred_function_name ? 1 : 0) + (has_outer_scope_info ? 1 : 0) +
206 (scope->is_module_scope()
207 ? 2 + kModuleVariableEntryLength * module_vars_count
208 : 0) +
209 (has_dependent_code ? 1 : 0);
210
211 // Create hash table if local names are not inlined.
212 Handle<NameToIndexHashTable> local_names_hashtable;
213 if (!has_inlined_local_names) {
214 local_names_hashtable = NameToIndexHashTable::New(
215 isolate, context_local_count, AllocationType::kOld);
216 }
217
218 Handle<ScopeInfo> scope_info_handle =
219 isolate->factory()->NewScopeInfo(length);
220 int index = kVariablePartIndex;
221 {
223 Tagged<ScopeInfo> scope_info = *scope_info_handle;
224 WriteBarrierMode mode = scope_info->GetWriteBarrierMode(no_gc);
225
226 bool has_simple_parameters = false;
227 bool is_asm_module = false;
228 if (scope->is_function_scope()) {
229 DeclarationScope* function_scope = scope->AsDeclarationScope();
230 has_simple_parameters = function_scope->has_simple_parameters();
231#if V8_ENABLE_WEBASSEMBLY
232 is_asm_module = function_scope->is_asm_module();
233#endif // V8_ENABLE_WEBASSEMBLY
234 }
235
236 // Encode the flags.
237 uint32_t flags =
238 ScopeTypeBits::encode(scope->scope_type()) |
239 SloppyEvalCanExtendVarsBit::encode(sloppy_eval_can_extend_vars) |
240 LanguageModeBit::encode(scope->language_mode()) |
241 DeclarationScopeBit::encode(scope->is_declaration_scope()) |
242 ReceiverVariableBits::encode(receiver_info) |
243 ClassScopeHasPrivateBrandBit::encode(has_brand) |
244 HasSavedClassVariableBit::encode(should_save_class_variable_index) |
245 HasNewTargetBit::encode(has_new_target) |
246 FunctionVariableBits::encode(function_name_info) |
247 HasInferredFunctionNameBit::encode(has_inferred_function_name) |
248 IsAsmModuleBit::encode(is_asm_module) |
249 HasSimpleParametersBit::encode(has_simple_parameters) |
250 FunctionKindBits::encode(function_kind) |
251 HasOuterScopeInfoBit::encode(has_outer_scope_info) |
252 IsDebugEvaluateScopeBit::encode(scope->is_debug_evaluate_scope()) |
253 ForceContextAllocationBit::encode(
255 PrivateNameLookupSkipsOuterClassBit::encode(
257 HasContextExtensionSlotBit::encode(scope->HasContextExtensionSlot()) |
258 IsHiddenBit::encode(scope->is_hidden()) |
259 IsWrappedFunctionBit::encode(scope->is_wrapped_function());
260 scope_info->set_flags(flags, kRelaxedStore);
261
262 scope_info->set_parameter_count(parameter_count);
263 scope_info->set_context_local_count(context_local_count);
264
265 scope_info->set_position_info_start(scope->start_position());
266 scope_info->set_position_info_end(scope->end_position());
267
268 if (scope->is_module_scope()) {
269 scope_info->set_module_variable_count(module_vars_count);
270 ++index;
271 }
272 if (!has_inlined_local_names) {
273 scope_info->set_context_local_names_hashtable(*local_names_hashtable);
274 }
275
276 // Add context locals' names and info, module variables' names and info.
277 // Context locals are added using their index.
278 int context_local_base = index;
279 int context_local_info_base =
280 context_local_base + local_names_container_size;
281 int module_var_entry = scope_info->ModuleVariablesIndex();
282
283 for (Variable* var : *scope->locals()) {
284 switch (var->location()) {
287 // Due to duplicate parameters, context locals aren't guaranteed to
288 // come in order.
289 int local_index = var->index() - scope->ContextHeaderLength();
290 DCHECK_LE(0, local_index);
291 DCHECK_LT(local_index, context_local_count);
292 uint32_t info =
293 VariableModeBits::encode(var->mode()) |
294 InitFlagBit::encode(var->initialization_flag()) |
295 MaybeAssignedFlagBit::encode(var->maybe_assigned()) |
296 ParameterNumberBits::encode(ParameterNumberBits::kMax) |
297 IsStaticFlagBit::encode(var->is_static_flag());
298 if (has_inlined_local_names) {
299 scope_info->set(context_local_base + local_index, *var->name(),
300 mode);
301 } else {
303 isolate, local_names_hashtable, var->name(), local_index);
304 DCHECK_EQ(*new_table, *local_names_hashtable);
305 USE(new_table);
306 }
307 scope_info->set(context_local_info_base + local_index,
308 Smi::FromInt(info));
309 break;
310 }
312 scope_info->set(
313 module_var_entry +
314 TorqueGeneratedModuleVariableOffsets::kNameOffset /
316 *var->name(), mode);
317 scope_info->set(
318 module_var_entry +
319 TorqueGeneratedModuleVariableOffsets::kIndexOffset /
321 Smi::FromInt(var->index()));
322 uint32_t properties =
323 VariableModeBits::encode(var->mode()) |
324 InitFlagBit::encode(var->initialization_flag()) |
325 MaybeAssignedFlagBit::encode(var->maybe_assigned()) |
326 ParameterNumberBits::encode(ParameterNumberBits::kMax) |
327 IsStaticFlagBit::encode(var->is_static_flag());
328 scope_info->set(
329 module_var_entry +
330 TorqueGeneratedModuleVariableOffsets::kPropertiesOffset /
332 Smi::FromInt(properties));
333 module_var_entry += kModuleVariableEntryLength;
334 break;
335 }
336 default:
337 break;
338 }
339 }
340
341 if (scope->is_declaration_scope()) {
342 // Mark contexts slots with the parameter number they represent. We walk
343 // the list of parameters. That can include duplicate entries if a
344 // parameter name is repeated. By walking upwards, we'll automatically
345 // mark the context slot with the highest parameter number that uses this
346 // variable. That will be the parameter number that is represented by the
347 // context slot. All lower parameters will only be available on the stack
348 // through the arguments object.
349 for (int i = 0; i < parameter_count; i++) {
350 Variable* parameter = scope->AsDeclarationScope()->parameter(i);
351 if (parameter->location() != VariableLocation::CONTEXT) continue;
352 int param_index = parameter->index() - scope->ContextHeaderLength();
353 int info_index = context_local_info_base + param_index;
354 int info = Smi::ToInt(scope_info->get(info_index));
355 info = ParameterNumberBits::update(info, i);
356 scope_info->set(info_index, Smi::FromInt(info));
357 }
358 }
359
360 // Advance past local names and local names info.
361 index += local_names_container_size + context_local_count;
362
363 DCHECK_EQ(index, scope_info->SavedClassVariableInfoIndex());
364 // If the scope is a class scope and has used static private methods, save
365 // the context slot index of the class variable.
366 // Store the class variable index.
367 if (should_save_class_variable_index) {
368 Variable* class_variable = scope->AsClassScope()->class_variable();
369 DCHECK_EQ(class_variable->location(), VariableLocation::CONTEXT);
370 int local_index;
371 if (has_inlined_local_names) {
372 local_index = class_variable->index();
373 } else {
374 DirectHandle<Name> name = class_variable->name();
375 InternalIndex entry = local_names_hashtable->FindEntry(isolate, name);
376 local_index = entry.as_int();
377 }
378 scope_info->set(index++, Smi::FromInt(local_index));
379 }
380
381 // If present, add the function variable name and its index.
382 DCHECK_EQ(index, scope_info->FunctionVariableInfoIndex());
383 if (has_function_name) {
384 Variable* var = scope->AsDeclarationScope()->function_var();
385 int var_index = -1;
386 Tagged<Object> name = Smi::zero();
387 if (var != nullptr) {
388 var_index = var->index();
389 name = *var->name();
390 }
391 scope_info->set(index++, name, mode);
392 scope_info->set(index++, Smi::FromInt(var_index));
393 DCHECK(function_name_info != VariableAllocationInfo::CONTEXT ||
394 var_index == scope_info->ContextLength() - 1);
395 }
396
397 DCHECK_EQ(index, scope_info->InferredFunctionNameIndex());
398 if (has_inferred_function_name) {
399 // The inferred function name is taken from the SFI.
400 index++;
401 }
402
403 // If present, add the outer scope info.
404 DCHECK_EQ(index, scope_info->OuterScopeInfoIndex());
405 if (has_outer_scope_info) {
406 scope_info->set(index++, *outer_scope.ToHandleChecked(), mode);
407 }
408
409 // Module-specific information (only for module scopes).
410 if (scope->is_module_scope()) {
411 DCHECK_EQ(index, scope_info->ModuleInfoIndex());
412 scope_info->set(index++, *module_info);
413 DCHECK_EQ(index, scope_info->ModuleVariablesIndex());
414 // The variable entries themselves have already been written above.
415 index += kModuleVariableEntryLength * module_vars_count;
416 }
417
418 DCHECK_EQ(index, scope_info->DependentCodeIndex());
419 if (has_dependent_code) {
420 ReadOnlyRoots roots(isolate);
421 scope_info->set(index++, DependentCode::empty_dependent_code(roots));
422 }
423 }
424
425 DCHECK_EQ(index, scope_info_handle->length());
426 DCHECK_EQ(length, scope_info_handle->length());
427 DCHECK_EQ(parameter_count, scope_info_handle->ParameterCount());
428 DCHECK_EQ(scope->num_heap_slots(), scope_info_handle->ContextLength());
429
430 return scope_info_handle;
431}
432
435 Isolate* isolate, Zone* zone, Scope* scope,
436 MaybeDirectHandle<ScopeInfo> outer_scope);
439 LocalIsolate* isolate, Zone* zone, Scope* scope,
440 MaybeDirectHandle<ScopeInfo> outer_scope);
441
442// static
444 Isolate* isolate, MaybeDirectHandle<ScopeInfo> outer_scope) {
445 const bool has_outer_scope_info = !outer_scope.is_null();
446 const int length = kVariablePartIndex + (has_outer_scope_info ? 1 : 0);
447
448 Factory* factory = isolate->factory();
449 DirectHandle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
450
451 // Encode the flags.
452 uint32_t flags =
453 ScopeTypeBits::encode(WITH_SCOPE) |
454 SloppyEvalCanExtendVarsBit::encode(false) |
455 LanguageModeBit::encode(LanguageMode::kSloppy) |
456 DeclarationScopeBit::encode(false) |
457 ReceiverVariableBits::encode(VariableAllocationInfo::NONE) |
458 ClassScopeHasPrivateBrandBit::encode(false) |
459 HasSavedClassVariableBit::encode(false) | HasNewTargetBit::encode(false) |
460 FunctionVariableBits::encode(VariableAllocationInfo::NONE) |
461 IsAsmModuleBit::encode(false) | HasSimpleParametersBit::encode(true) |
462 FunctionKindBits::encode(FunctionKind::kNormalFunction) |
463 HasOuterScopeInfoBit::encode(has_outer_scope_info) |
464 IsDebugEvaluateScopeBit::encode(false) |
465 ForceContextAllocationBit::encode(false) |
466 PrivateNameLookupSkipsOuterClassBit::encode(false) |
467 HasContextExtensionSlotBit::encode(true) | IsHiddenBit::encode(false) |
468 IsWrappedFunctionBit::encode(false);
469 scope_info->set_flags(flags, kRelaxedStore);
470
471 scope_info->set_parameter_count(0);
472 scope_info->set_context_local_count(0);
473
474 scope_info->set_position_info_start(0);
475 scope_info->set_position_info_end(0);
476
477 int index = kVariablePartIndex;
478 DCHECK_EQ(index, scope_info->FunctionVariableInfoIndex());
479 DCHECK_EQ(index, scope_info->InferredFunctionNameIndex());
480 DCHECK_EQ(index, scope_info->OuterScopeInfoIndex());
481 if (has_outer_scope_info) {
482 Tagged<ScopeInfo> outer = *outer_scope.ToHandleChecked();
483 scope_info->set(index++, outer);
484 }
485 DCHECK_EQ(index, scope_info->DependentCodeIndex());
486 DCHECK_EQ(index, scope_info->length());
487 DCHECK_EQ(length, scope_info->length());
488 DCHECK_EQ(0, scope_info->ParameterCount());
489 DCHECK_EQ(scope_info->ContextHeaderLength(), scope_info->ContextLength());
490 return scope_info;
491}
492
493// static
497
498// static
502
503// static
507
508// static
513
514// static
516 Isolate* isolate, BootstrappingType type) {
517 const int parameter_count = 0;
518 const bool is_empty_function = type == BootstrappingType::kFunction;
519 const bool is_native_context = (type == BootstrappingType::kNative) ||
521 const bool is_script = type == BootstrappingType::kScript;
522 const bool is_shadow_realm = type == BootstrappingType::kShadowRealm;
523 const bool has_const_tracking_let_side_data = is_script;
524 const int context_local_count =
525 is_empty_function || is_native_context ? 0 : 1;
526 const bool has_inferred_function_name = is_empty_function;
527 // NOTE: Local names are always inlined here, since context_local_count < 2.
528 DCHECK_LT(context_local_count, kScopeInfoMaxInlinedLocalNamesSize);
529 const int length = kVariablePartIndex + 2 * context_local_count +
530 (is_empty_function ? kFunctionNameEntries : 0) +
531 (has_inferred_function_name ? 1 : 0);
532
533 Factory* factory = isolate->factory();
534 DirectHandle<ScopeInfo> scope_info =
535 factory->NewScopeInfo(length, AllocationType::kReadOnly);
537 // Encode the flags.
538 DCHECK_IMPLIES(is_shadow_realm || is_script, !is_empty_function);
539 uint32_t flags =
540 ScopeTypeBits::encode(
541 is_empty_function
543 : (is_shadow_realm ? SHADOW_REALM_SCOPE : SCRIPT_SCOPE)) |
544 SloppyEvalCanExtendVarsBit::encode(false) |
545 LanguageModeBit::encode(LanguageMode::kSloppy) |
546 DeclarationScopeBit::encode(true) |
547 ReceiverVariableBits::encode(is_script ? VariableAllocationInfo::CONTEXT
549 ClassScopeHasPrivateBrandBit::encode(false) |
550 HasSavedClassVariableBit::encode(false) | HasNewTargetBit::encode(false) |
551 FunctionVariableBits::encode(is_empty_function
554 HasInferredFunctionNameBit::encode(has_inferred_function_name) |
555 IsAsmModuleBit::encode(false) | HasSimpleParametersBit::encode(true) |
556 FunctionKindBits::encode(FunctionKind::kNormalFunction) |
557 HasOuterScopeInfoBit::encode(false) |
558 IsDebugEvaluateScopeBit::encode(false) |
559 ForceContextAllocationBit::encode(false) |
560 PrivateNameLookupSkipsOuterClassBit::encode(false) |
561 HasContextExtensionSlotBit::encode(is_native_context ||
562 has_const_tracking_let_side_data) |
563 IsHiddenBit::encode(false) | IsWrappedFunctionBit::encode(false);
564 Tagged<ScopeInfo> raw_scope_info = *scope_info;
565 raw_scope_info->set_flags(flags, kRelaxedStore);
566 raw_scope_info->set_parameter_count(parameter_count);
567 raw_scope_info->set_context_local_count(context_local_count);
568 raw_scope_info->set_position_info_start(0);
569 raw_scope_info->set_position_info_end(0);
570
571 int index = kVariablePartIndex;
572
573 // Here we add info for context-allocated "this".
574 DCHECK_EQ(index, raw_scope_info->ContextLocalNamesIndex());
575 ReadOnlyRoots roots(isolate);
576 if (context_local_count) {
577 raw_scope_info->set(index++, roots.this_string());
578 }
579 DCHECK_EQ(index, raw_scope_info->ContextLocalInfosIndex());
580 if (context_local_count > 0) {
581 const uint32_t value =
582 VariableModeBits::encode(VariableMode::kConst) |
583 InitFlagBit::encode(kCreatedInitialized) |
584 MaybeAssignedFlagBit::encode(kNotAssigned) |
585 ParameterNumberBits::encode(ParameterNumberBits::kMax) |
586 IsStaticFlagBit::encode(IsStaticFlag::kNotStatic);
587 raw_scope_info->set(index++, Smi::FromInt(value));
588 }
589
590 DCHECK_EQ(index, raw_scope_info->FunctionVariableInfoIndex());
591 if (is_empty_function) {
592 raw_scope_info->set(index++, roots.empty_string());
593 raw_scope_info->set(index++, Smi::zero());
594 }
595 DCHECK_EQ(index, raw_scope_info->InferredFunctionNameIndex());
596 if (has_inferred_function_name) {
597 raw_scope_info->set(index++, roots.empty_string());
598 }
599 DCHECK_EQ(index, raw_scope_info->OuterScopeInfoIndex());
600 DCHECK_EQ(index, raw_scope_info->DependentCodeIndex());
601 DCHECK_EQ(index, raw_scope_info->length());
602 DCHECK_EQ(length, raw_scope_info->length());
603 DCHECK_EQ(raw_scope_info->ParameterCount(), parameter_count);
604 if (is_empty_function || is_native_context) {
605 DCHECK_EQ(raw_scope_info->ContextLength(), 0);
606 } else {
607 DCHECK_EQ(raw_scope_info->ContextLength(),
608 raw_scope_info->ContextHeaderLength() + 1);
609 }
610
611 return scope_info;
612}
613
615 PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
616 return get(cage_base, index);
617}
618
619Tagged<Object> ScopeInfo::get(PtrComprCageBase cage_base, int index) const {
620 DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
621 return TaggedField<Object>::Relaxed_Load(cage_base, *this,
622 OffsetOfElementAt(index));
623}
624
625void ScopeInfo::set(int index, Tagged<Smi> value) {
626 DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
627 DCHECK(IsSmi(Tagged<Object>(value)));
628 int offset = OffsetOfElementAt(index);
629 RELAXED_WRITE_FIELD(*this, offset, value);
630}
631
632void ScopeInfo::set(int index, Tagged<Object> value, WriteBarrierMode mode) {
633 DCHECK_LT(static_cast<unsigned>(index), static_cast<unsigned>(length()));
634 int offset = OffsetOfElementAt(index);
635 RELAXED_WRITE_FIELD(*this, offset, value);
636 CONDITIONAL_WRITE_BARRIER(*this, offset, value, mode);
637}
638
639void ScopeInfo::CopyElements(Isolate* isolate, int dst_index,
640 Tagged<ScopeInfo> src, int src_index, int len,
641 WriteBarrierMode mode) {
642 if (len == 0) return;
643 DCHECK_LE(src_index + len, src->length());
645
646 ObjectSlot dst_slot(RawFieldOfElementAt(dst_index));
647 ObjectSlot src_slot(src->RawFieldOfElementAt(src_index));
648 isolate->heap()->CopyRange(*this, dst_slot, src_slot, len, mode);
649}
650
652 return RawField(OffsetOfElementAt(index));
653}
654
655int ScopeInfo::length() const {
656 // AllocatedSize() is generated by Torque and represents the size in bytes of
657 // the object, as computed from flags, context_local_count, and possibly
658 // module_variable_count. Convert that size into a number of slots.
659 return (AllocatedSize() - HeapObject::kHeaderSize) / kTaggedSize;
660}
661
663 return ReadOnlyRoots(isolate).empty_scope_info();
664}
665
666bool ScopeInfo::IsEmpty() const { return IsEmptyBit::decode(Flags()); }
667
669 DCHECK(!this->IsEmpty());
670 return ScopeTypeBits::decode(Flags());
671}
672
674 return !this->IsEmpty() &&
676}
677
679 bool sloppy_eval_can_extend_vars =
680 SloppyEvalCanExtendVarsBit::decode(Flags());
681 DCHECK_IMPLIES(sloppy_eval_can_extend_vars, is_sloppy(language_mode()));
682 DCHECK_IMPLIES(sloppy_eval_can_extend_vars, is_declaration_scope());
683 return sloppy_eval_can_extend_vars;
684}
685
687 return LanguageModeBit::decode(Flags());
688}
689
691 return DeclarationScopeBit::decode(Flags());
692}
693
695 if (this->IsEmpty()) return 0;
696 int context_locals = ContextLocalCount();
697 bool function_name_context_slot = HasContextAllocatedFunctionName();
698 bool force_context = ForceContextAllocationBit::decode(Flags());
699 bool has_context =
700 context_locals > 0 || force_context || function_name_context_slot ||
707
708 if (!has_context) return 0;
709 return ContextHeaderLength() + context_locals +
710 (function_name_context_slot ? 1 : 0);
711}
712
713// Needs to be kept in sync with Scope::UniqueIdInScript and
714// SharedFunctionInfo::UniqueIdInScript.
716 // Script scopes start "before" the script to avoid clashing with a scope that
717 // starts on character 0.
718 if (is_script_scope() || scope_type() == EVAL_SCOPE ||
720 return -2;
721 }
722 // Wrapped functions start before the function body, but after the script
723 // start, to avoid clashing with a scope starting on character 0.
725 return -1;
726 }
727 // Default constructors have the same start position as their parent class
728 // scope. Use the next char position to distinguish this scope.
730}
731
733 return HasContextExtensionSlotBit::decode(Flags());
734}
735
737 return SomeContextHasExtensionBit::decode(Flags());
738}
739
741 set_flags(SomeContextHasExtensionBit::update(Flags(), true), kRelaxedStore);
742}
743
748
750 return VariableAllocationInfo::NONE != ReceiverVariableBits::decode(Flags());
751}
752
754 // The receiver is allocated and needs to be deserialized during reparsing
755 // when:
756 // 1. During the initial parsing, it's been observed that the inner
757 // scopes are accessing this, so the receiver should be allocated
758 // again. This can be inferred when the receiver variable is
759 // recorded as being allocated on the stack or context.
760 // 2. The scope is created as a debug evaluate scope, so this is not
761 // an actual reparse, we are not sure if the inner scope will access
762 // this, but the receiver should be allocated just in case.
763 VariableAllocationInfo allocation = ReceiverVariableBits::decode(Flags());
764 return allocation == VariableAllocationInfo::STACK ||
765 allocation == VariableAllocationInfo::CONTEXT ||
767}
768
770 return ClassScopeHasPrivateBrandBit::decode(Flags());
771}
772
774 return HasSavedClassVariableBit::decode(Flags());
775}
776
778 return HasNewTargetBit::decode(Flags());
779}
780
782 return VariableAllocationInfo::NONE != FunctionVariableBits::decode(Flags());
783}
784
787 FunctionVariableBits::decode(Flags());
788}
789
791 return HasInferredFunctionNameBit::decode(Flags());
792}
793
794bool ScopeInfo::HasPositionInfo() const { return !this->IsEmpty(); }
795
799
802 DCHECK(IsString(name) || name == SharedFunctionInfo::kNoSharedNameSentinel);
803 DCHECK_IMPLIES(HasContextAllocatedFunctionName(), IsInternalizedString(name));
804 set_function_variable_info_name(name);
805}
806
809 set_inferred_function_name(name);
810}
811
813 return HasOuterScopeInfoBit::decode(Flags());
814}
815
817 return IsDebugEvaluateScopeBit::decode(Flags());
818}
819
821 CHECK(!this->IsEmpty());
823 set_flags(Flags() | IsDebugEvaluateScopeBit::encode(true), kRelaxedStore);
824}
825
827 return PrivateNameLookupSkipsOuterClassBit::decode(Flags());
828}
829
831 return scope_type() == REPL_MODE_SCOPE;
832}
833
835 DCHECK_IMPLIES(IsWrappedFunctionBit::decode(Flags()),
837 return IsWrappedFunctionBit::decode(Flags());
838}
839
840bool ScopeInfo::HasContext() const { return ContextLength() > 0; }
841
844 return function_variable_info_name();
845}
846
849 return inferred_function_name();
850}
851
853 if (!HasFunctionName()) return GetReadOnlyRoots().empty_string();
855 if (IsString(name) && Cast<String>(name)->length() > 0) {
856 return Cast<String>(name);
857 }
859 name = InferredFunctionName();
860 if (IsString(name)) return Cast<String>(name);
861 }
862 return GetReadOnlyRoots().empty_string();
863}
864
867 return position_info_start();
868}
869
872 return position_info_end();
873}
874
878 set_position_info_start(start);
879 set_position_info_end(end);
880}
881
884 return Cast<ScopeInfo>(outer_scope_info());
885}
886
891
894 return context_local_names(var);
895}
896
898 int var) const {
900 return context_local_names(cage_base, var);
901}
902
904 int value = context_local_infos(var);
905 return VariableModeBits::decode(value);
906}
907
909 int value = context_local_infos(var);
910 return IsStaticFlagBit::decode(value);
911}
912
914 int value = context_local_infos(var);
915 return InitFlagBit::decode(value);
916}
917
919 int value = context_local_infos(var);
920 return ParameterNumberBits::decode(value) != ParameterNumberBits::kMax;
921}
922
925 int value = context_local_infos(var);
926 return ParameterNumberBits::decode(value);
927}
928
930 int value = context_local_infos(var);
931 return MaybeAssignedFlagBit::decode(value);
932}
933
934// static
936 // There's currently no flag stored on the ScopeInfo to indicate that a
937 // variable is a compiler-introduced temporary. However, to avoid conflict
938 // with user declarations, the current temporaries like .generator_object and
939 // .result start with a dot, so we can use that as a flag. It's a hack!
940 return name->length() == 0 || name->Get(0) == '.' || name->Get(0) == '#' ||
941 name->Equals(GetReadOnlyRoots().this_string());
942}
943
946 return module_variable_count();
947}
948
950 InitializationFlag* init_flag,
951 MaybeAssignedFlag* maybe_assigned_flag) {
953 DCHECK(IsInternalizedString(name));
955 DCHECK_NOT_NULL(mode);
956 DCHECK_NOT_NULL(init_flag);
957 DCHECK_NOT_NULL(maybe_assigned_flag);
958
959 int module_vars_count = module_variable_count();
960 for (int i = 0; i < module_vars_count; ++i) {
961 Tagged<String> var_name = module_variables_name(i);
962 if (name->Equals(var_name)) {
963 int index;
964 ModuleVariable(i, nullptr, &index, mode, init_flag, maybe_assigned_flag);
965 return index;
966 }
967 }
968
969 return 0;
970}
971
974 PtrComprCageBase cage_base = GetPtrComprCageBase(*this);
975 int local_count = context_local_count();
976 for (int i = 0; i < local_count; ++i) {
977 if (name == ContextInlinedLocalName(cage_base, i)) {
978 return i;
979 }
980 }
981 return -1;
982}
983
985 VariableLookupResult* lookup_result) {
987 DCHECK(IsInternalizedString(*name));
988 DCHECK_NOT_NULL(lookup_result);
989
990 if (this->IsEmpty()) return -1;
991
992 int index = HasInlinedLocalNames()
994 : context_local_names_hashtable()->Lookup(name);
995
996 if (index != -1) {
997 lookup_result->mode = ContextLocalMode(index);
998 lookup_result->is_static_flag = ContextLocalIsStaticFlag(index);
999 lookup_result->init_flag = ContextLocalInitFlag(index);
1000 lookup_result->maybe_assigned_flag = ContextLocalMaybeAssignedFlag(index);
1001 lookup_result->is_repl_mode = IsReplModeScope();
1002 int context_slot = ContextHeaderLength() + index;
1003 DCHECK_LT(context_slot, ContextLength());
1004 return context_slot;
1005 }
1006
1007 return -1;
1008}
1009
1011 VariableLookupResult lookup_result;
1012 return ContextSlotIndex(name, &lookup_result);
1013}
1014
1015std::pair<Tagged<String>, int> ScopeInfo::SavedClassVariable() const {
1016 DCHECK(HasSavedClassVariableBit::decode(Flags()));
1017 if (HasInlinedLocalNames()) {
1018 // The saved class variable info corresponds to the context slot index.
1019 int index = saved_class_variable_info() - Context::MIN_CONTEXT_SLOTS;
1020 DCHECK_GE(index, 0);
1021 DCHECK_LT(index, ContextLocalCount());
1023 return std::make_pair(name, index);
1024 } else {
1025 // The saved class variable info corresponds to the offset in the hash
1026 // table storage.
1027 InternalIndex entry(saved_class_variable_info());
1028 Tagged<NameToIndexHashTable> table = context_local_names_hashtable();
1029 Tagged<Object> name = table->KeyAt(entry);
1030 DCHECK(IsString(name));
1031 return std::make_pair(Cast<String>(name), table->IndexAt(entry));
1032 }
1033}
1034
1036 if (ReceiverVariableBits::decode(Flags()) ==
1038 return ContextHeaderLength();
1039 }
1040 return -1;
1041}
1042
1044 if (ReceiverVariableBits::decode(Flags()) ==
1046 return ContextHeaderLength() + 1;
1047 }
1048 return ContextHeaderLength();
1049}
1050
1052 DCHECK(IsInternalizedString(name));
1054 DCHECK_IMPLIES(HasFunctionName(), IsInternalizedString(FunctionName()));
1055 if (FunctionName() == name) {
1056 return function_variable_info_context_or_stack_slot_index();
1057 }
1058 }
1059 return -1;
1060}
1061
1063 return FunctionKindBits::decode(Flags());
1064}
1065
1067 return ConvertOffsetToIndex(ContextLocalNamesOffset());
1068}
1069
1071 return ConvertOffsetToIndex(ContextLocalInfosOffset());
1072}
1073
1075 return ConvertOffsetToIndex(SavedClassVariableInfoOffset());
1076}
1077
1079 return ConvertOffsetToIndex(FunctionVariableInfoOffset());
1080}
1081
1083 return ConvertOffsetToIndex(InferredFunctionNameOffset());
1084}
1085
1087 return ConvertOffsetToIndex(OuterScopeInfoOffset());
1088}
1089
1091 return ConvertOffsetToIndex(ModuleInfoOffset());
1092}
1093
1095 return ConvertOffsetToIndex(kModuleVariableCountOffset);
1096}
1097
1099 return ConvertOffsetToIndex(ModuleVariablesOffset());
1100}
1101
1102void ScopeInfo::ModuleVariable(int i, Tagged<String>* name, int* index,
1103 VariableMode* mode,
1104 InitializationFlag* init_flag,
1105 MaybeAssignedFlag* maybe_assigned_flag) {
1106 int properties = module_variables_properties(i);
1107
1108 if (name != nullptr) {
1109 *name = module_variables_name(i);
1110 }
1111 if (index != nullptr) {
1112 *index = module_variables_index(i);
1113 DCHECK_NE(*index, 0);
1114 }
1115 if (mode != nullptr) {
1116 *mode = VariableModeBits::decode(properties);
1117 }
1118 if (init_flag != nullptr) {
1119 *init_flag = InitFlagBit::decode(properties);
1120 }
1121 if (maybe_assigned_flag != nullptr) {
1122 *maybe_assigned_flag = MaybeAssignedFlagBit::decode(properties);
1123 }
1124}
1125
1127 return ConvertOffsetToIndex(DependentCodeOffset());
1128}
1129
1131 // Hash ScopeInfo based on its start and end position.
1132 // Note: Ideally we'd also have the script ID. But since we only use the
1133 // hash in a debug-evaluate cache, we don't worry too much about collisions.
1134 if (HasPositionInfo()) {
1135 return static_cast<uint32_t>(base::hash_combine(
1137 }
1138
1139 return static_cast<uint32_t>(
1140 base::hash_combine(flags(kRelaxedLoad), context_local_count()));
1141}
1142
1143std::ostream& operator<<(std::ostream& os, VariableAllocationInfo var_info) {
1144 switch (var_info) {
1146 return os << "NONE";
1148 return os << "STACK";
1150 return os << "CONTEXT";
1152 return os << "UNUSED";
1153 }
1154 UNREACHABLE();
1155}
1156
1157template <typename IsolateT>
1159 IsolateT* isolate, DirectHandle<String> specifier, ModuleImportPhase phase,
1160 DirectHandle<FixedArray> import_attributes, int position) {
1162 isolate->factory()->NewStruct(MODULE_REQUEST_TYPE, AllocationType::kOld));
1165 raw->set_specifier(*specifier);
1166 raw->set_import_attributes(*import_attributes);
1167 raw->set_flags(0);
1168
1169 raw->set_phase(phase);
1170 DCHECK_GE(position, 0);
1171 raw->set_position(position);
1172 return result;
1173}
1174
1176 Isolate* isolate, DirectHandle<String> specifier, ModuleImportPhase phase,
1177 DirectHandle<FixedArray> import_attributes, int position);
1179 LocalIsolate* isolate, DirectHandle<String> specifier,
1180 ModuleImportPhase phase, DirectHandle<FixedArray> import_attributes,
1181 int position);
1182
1183template <typename IsolateT>
1185 IsolateT* isolate, DirectHandle<UnionOf<String, Undefined>> export_name,
1187 DirectHandle<UnionOf<String, Undefined>> import_name, int module_request,
1188 int cell_index, int beg_pos, int end_pos) {
1189 auto result = Cast<SourceTextModuleInfoEntry>(isolate->factory()->NewStruct(
1190 SOURCE_TEXT_MODULE_INFO_ENTRY_TYPE, AllocationType::kOld));
1193 raw->set_export_name(*export_name);
1194 raw->set_local_name(*local_name);
1195 raw->set_import_name(*import_name);
1196 raw->set_module_request(module_request);
1197 raw->set_cell_index(cell_index);
1198 raw->set_beg_pos(beg_pos);
1199 raw->set_end_pos(end_pos);
1200 return result;
1201}
1202
1204 Isolate* isolate, DirectHandle<UnionOf<String, Undefined>> export_name,
1206 DirectHandle<UnionOf<String, Undefined>> import_name, int module_request,
1207 int cell_index, int beg_pos, int end_pos);
1211 DirectHandle<UnionOf<String, Undefined>> import_name, int module_request,
1212 int cell_index, int beg_pos, int end_pos);
1213
1214template <typename IsolateT>
1216 IsolateT* isolate, Zone* zone, SourceTextModuleDescriptor* descr) {
1217 // Serialize module requests.
1218 int size = static_cast<int>(descr->module_requests().size());
1220 isolate->factory()->NewFixedArray(size, AllocationType::kOld);
1221 for (const auto& elem : descr->module_requests()) {
1222 DirectHandle<ModuleRequest> serialized_module_request =
1223 elem->Serialize(isolate);
1224 module_requests->set(elem->index(), *serialized_module_request);
1225 }
1226
1227 // Serialize special exports.
1228 DirectHandle<FixedArray> special_exports = isolate->factory()->NewFixedArray(
1229 static_cast<int>(descr->special_exports().size()), AllocationType::kOld);
1230 {
1231 int i = 0;
1232 for (auto entry : descr->special_exports()) {
1234 entry->Serialize(isolate);
1235 special_exports->set(i++, *serialized_entry);
1236 }
1237 }
1238
1239 // Serialize namespace imports.
1241 isolate->factory()->NewFixedArray(
1242 static_cast<int>(descr->namespace_imports().size()),
1244 {
1245 int i = 0;
1246 for (auto entry : descr->namespace_imports()) {
1248 entry->Serialize(isolate);
1249 namespace_imports->set(i++, *serialized_entry);
1250 }
1251 }
1252
1253 // Serialize regular exports.
1255 descr->SerializeRegularExports(isolate, zone);
1256
1257 // Serialize regular imports.
1258 DirectHandle<FixedArray> regular_imports = isolate->factory()->NewFixedArray(
1259 static_cast<int>(descr->regular_imports().size()), AllocationType::kOld);
1260 {
1261 int i = 0;
1262 for (const auto& elem : descr->regular_imports()) {
1264 elem.second->Serialize(isolate);
1265 regular_imports->set(i++, *serialized_entry);
1266 }
1267 }
1268
1270 isolate->factory()->NewSourceTextModuleInfo();
1276 return result;
1277}
1278
1280 Isolate* isolate, Zone* zone, SourceTextModuleDescriptor* descr);
1282 LocalIsolate* isolate, Zone* zone, SourceTextModuleDescriptor* descr);
1283
1288
1293
1298
1303
1304} // namespace internal
1305} // namespace v8
1306
int16_t parameter_count
Definition builtins.cc:67
Builtins::Kind kind
Definition builtins.cc:40
bool should_save_class_variable_index() const
Definition scopes.h:1472
Variable * class_variable()
Definition scopes.h:1453
FunctionKind function_kind() const
Definition scopes.h:863
bool class_scope_has_private_brand() const
Definition scopes.h:1227
Variable * function_var() const
Definition scopes.h:1046
Variable * parameter(int index) const
Definition scopes.h:1058
bool sloppy_eval_can_extend_vars() const
Definition scopes.h:926
bool has_this_declaration() const
Definition scopes.h:1039
bool has_simple_parameters() const
Definition scopes.h:1076
static V8_EXPORT_PRIVATE Tagged< DependentCode > empty_dependent_code(const ReadOnlyRoots &roots)
Handle< ScopeInfo > NewScopeInfo(int length, AllocationType type=AllocationType::kOld)
static constexpr int kHeaderSize
constexpr int as_int() const
V8_INLINE DirectHandle< T > ToHandleChecked() const
V8_INLINE bool is_null() const
static NEVER_READ_ONLY_SPACE Handle< ModuleRequest > New(IsolateT *isolate, DirectHandle< String > specifier, ModuleImportPhase phase, DirectHandle< FixedArray > import_attributes, int position)
ModuleImportPhase phase() const
Definition module-inl.h:50
SourceTextModuleDescriptor * module() const
Definition scopes.h:1379
static Handle< NameToIndexHashTable > Add(IsolateT *isolate, Handle< NameToIndexHashTable > table, DirectHandle< Name > key, int32_t value)
bool HasPositionInfo() const
bool HasContextExtensionSlot() const
uint32_t ContextLocalParameterNumber(int var) const
bool HasContextAllocatedFunctionName() const
V8_EXPORT_PRIVATE uint32_t Hash()
int FunctionContextSlotIndex(Tagged< String > name) const
static DirectHandle< ScopeInfo > CreateForBootstrapping(Isolate *isolate, BootstrappingType type)
void CopyElements(Isolate *isolate, int dst_index, Tagged< ScopeInfo > src, int src_index, int len, WriteBarrierMode mode)
V8_EXPORT_PRIVATE Tagged< Object > get(int index) const
V8_EXPORT_PRIVATE Tagged< Object > InferredFunctionName() const
void mark_some_context_has_extension()
Tagged< SourceTextModuleInfo > ModuleDescriptorInfo() const
int ParametersStartIndex() const
bool HasNewTarget() const
static DirectHandle< ScopeInfo > CreateGlobalThisBinding(Isolate *isolate)
V8_EXPORT_PRIVATE bool HasFunctionName() const
int ContextSlotIndex(DirectHandle< String > name)
Tagged< String > ContextInlinedLocalName(int var) const
void SetFunctionName(Tagged< UnionOf< Smi, String > > name)
void SetInferredFunctionName(Tagged< String > name)
bool ClassScopeHasPrivateBrand() const
bool PrivateNameLookupSkipsOuterClass() const
bool SomeContextHasExtension() const
bool Equals(Tagged< ScopeInfo > other, bool is_live_edit_compare=false, int *out_last_checked_field=nullptr) const
Definition scope-info.cc:25
bool IsReplModeScope() const
uint32_t Flags() const
int ContextLocalInfosIndex() const
bool is_declaration_scope() const
bool HasOuterScopeInfo() const
int ModuleIndex(Tagged< String > name, VariableMode *mode, InitializationFlag *init_flag, MaybeAssignedFlag *maybe_assigned_flag)
static DirectHandle< ScopeInfo > CreateForShadowRealmNativeContext(Isolate *isolate)
void set(int index, Tagged< Smi > value)
FunctionKind function_kind() const
LanguageMode language_mode() const
int ContextLocalNamesIndex() const
int InferredFunctionNameIndex() const
void ModuleVariable(int i, Tagged< String > *name, int *index, VariableMode *mode=nullptr, InitializationFlag *init_flag=nullptr, MaybeAssignedFlag *maybe_assigned_flag=nullptr)
ObjectSlot RawFieldOfElementAt(int index)
ScopeType scope_type() const
int DependentCodeIndex() const
bool HasAllocatedReceiver() const
V8_EXPORT_PRIVATE Tagged< UnionOf< Smi, String > > FunctionName() const
static const int kFunctionNameEntries
Definition scope-info.h:367
int ContextHeaderLength() const
static const int kModuleVariableEntryLength
Definition scope-info.h:369
bool IsWrappedFunctionScope() const
int UniqueIdInScript() const
static constexpr int OffsetOfElementAt(int index)
Definition scope-info.h:342
bool SloppyEvalCanExtendVars() const
bool IsDebugEvaluateScope() const
static V8_EXPORT_PRIVATE DirectHandle< ScopeInfo > CreateForEmptyFunction(Isolate *isolate)
bool HasSavedClassVariable() const
int InlinedLocalNamesLookup(Tagged< String > name)
IsStaticFlag ContextLocalIsStaticFlag(int var) const
std::pair< Tagged< String >, int > SavedClassVariable() const
static V8_EXPORT_PRIVATE DirectHandle< ScopeInfo > CreateForWithScope(Isolate *isolate, MaybeDirectHandle< ScopeInfo > outer_scope)
static DirectHandle< ScopeInfo > CreateForNativeContext(Isolate *isolate)
int ModuleVariablesIndex() const
int FunctionVariableInfoIndex() const
int ModuleVariableCountIndex() const
V8_EXPORT_PRIVATE bool HasInferredFunctionName() const
InitializationFlag ContextLocalInitFlag(int var) const
V8_EXPORT_PRIVATE bool HasSharedFunctionName() const
bool is_script_scope() const
static constexpr int ConvertOffsetToIndex(int offset)
Definition scope-info.h:345
int SavedClassVariableInfoIndex() const
int ReceiverContextSlotIndex() const
void SetPositionInfo(int start, int end)
bool HasInlinedLocalNames() const
int OuterScopeInfoIndex() const
MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var) const
Tagged< String > FunctionDebugName() const
static V8_EXPORT_PRIVATE Tagged< ScopeInfo > Empty(Isolate *isolate)
VariableMode ContextLocalMode(int var) const
V8_EXPORT_PRIVATE int length() const
static Handle< ScopeInfo > Create(IsolateT *isolate, Zone *zone, Scope *scope, MaybeDirectHandle< ScopeInfo > outer_scope)
Definition scope-info.cc:79
bool ContextLocalIsParameter(int var) const
Tagged< ScopeInfo > OuterScopeInfo() const
int ModuleVariableCount() const
static bool VariableIsSynthetic(Tagged< String > name)
int ContextLocalCount() const
Definition scopes.cc:2935
bool HasContextExtensionSlot() const
Definition scopes.h:505
int num_heap_slots() const
Definition scopes.h:503
bool private_name_lookup_skips_outer_class() const
Definition scopes.h:388
DeclarationScope * AsDeclarationScope()
bool IsConstructorScope() const
Definition scopes.cc:1586
ClassScope * AsClassScope()
Definition scopes.cc:566
base::ThreadedList< Variable > * locals()
Definition scopes.h:231
bool is_script_scope() const
Definition scopes.h:364
int ContextHeaderLength() const
Definition scopes.h:522
ModuleScope * AsModuleScope()
Definition scopes.cc:556
bool is_debug_evaluate_scope() const
Definition scopes.h:608
bool is_class_scope() const
Definition scopes.h:373
bool is_eval_scope() const
Definition scopes.h:361
bool is_function_scope() const
Definition scopes.h:362
ScopeType scope_type() const
Definition scopes.h:474
bool is_hidden() const
Definition scopes.h:346
bool is_wrapped_function() const
Definition scopes.h:397
int end_position() const
Definition scopes.h:342
LanguageMode language_mode() const
Definition scopes.h:477
int start_position() const
Definition scopes.h:338
bool is_module_scope() const
Definition scopes.h:363
bool ForceContextForLanguageMode() const
Definition scopes.h:419
bool is_declaration_scope() const
Definition scopes.h:372
static V8_EXPORT_PRIVATE constexpr Tagged< Smi > const kNoSharedNameSentinel
static constexpr int ToInt(const Tagged< Object > object)
Definition smi.h:33
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
static constexpr Tagged< Smi > zero()
Definition smi.h:99
DirectHandle< FixedArray > SerializeRegularExports(IsolateT *isolate, Zone *zone) const
Definition modules.cc:185
const ModuleRequestMap & module_requests() const
Definition modules.h:181
const RegularImportMap & regular_imports() const
Definition modules.h:189
const ZoneVector< const Entry * > & namespace_imports() const
Definition modules.h:184
const ZoneVector< const Entry * > & special_exports() const
Definition modules.h:192
static Handle< SourceTextModuleInfoEntry > New(IsolateT *isolate, DirectHandle< UnionOf< String, Undefined > > export_name, DirectHandle< UnionOf< String, Undefined > > local_name, DirectHandle< UnionOf< String, Undefined > > import_name, int module_request, int cell_index, int beg_pos, int end_pos)
Tagged< FixedArray > regular_imports() const
Definition module-inl.h:76
Tagged< FixedArray > special_exports() const
Definition module-inl.h:68
Tagged< FixedArray > namespace_imports() const
Definition module-inl.h:80
Tagged< String > RegularExportLocalName(int i) const
Tagged< FixedArray > module_requests() const
Definition module-inl.h:64
static DirectHandle< SourceTextModuleInfo > New(IsolateT *isolate, Zone *zone, SourceTextModuleDescriptor *descr)
Tagged< FixedArray > RegularExportExportNames(int i) const
Tagged< FixedArray > regular_exports() const
Definition module-inl.h:72
static PtrType Relaxed_Load(Tagged< HeapObject > host, int offset=0)
bool IsParameter() const
Definition variables.h:127
VariableLocation location() const
Definition variables.h:276
bool IsStackLocal() const
Definition variables.h:128
bool IsContextSlot() const
Definition variables.h:130
Handle< String > name() const
Definition variables.h:64
int start
int end
#define EXPORT_TEMPLATE_DEFINE(export)
int32_t offset
std::map< const std::string, const std::string > map
ZoneVector< RpoNumber > & result
int position
Definition liveedit.cc:290
V8_INLINE size_t hash_combine(size_t seed, size_t hash)
Definition hashing.h:77
@ kCreatedInitialized
Definition globals.h:2225
constexpr int kTaggedSize
Definition globals.h:542
bool is_sloppy(LanguageMode language_mode)
Definition globals.h:773
ReadOnlyRoots GetReadOnlyRoots()
Definition roots-inl.h:86
@ SHADOW_REALM_SCOPE
Definition globals.h:1903
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
Definition objects.h:665
constexpr int kScopeInfoMaxInlinedLocalNamesSize
Definition globals.h:1891
Flag flags[]
Definition flags.cc:3797
std::ostream & operator<<(std::ostream &os, AtomicMemoryOrder order)
V8_INLINE PtrComprCageBase GetPtrComprCageBase()
typename detail::FlattenUnionHelper< Union<>, Ts... >::type UnionOf
Definition union.h:123
refactor address components for immediate indexing make OptimizeMaglevOnNextCall optimize to turbofan instead of maglev filter for tracing turbofan compilation nullptr
Definition flags.cc:1263
bool IsDefaultConstructor(FunctionKind kind)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
static constexpr RelaxedLoadTag kRelaxedLoad
Definition globals.h:2909
static constexpr RelaxedStoreTag kRelaxedStore
Definition globals.h:2911
ModuleImportPhase
#define CONDITIONAL_WRITE_BARRIER(object, offset, value, mode)
#define RELAXED_WRITE_FIELD(p, offset, value)
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define CHECK(condition)
Definition logging.h:124
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define USE(...)
Definition macros.h:293
#define V8_EXPORT_PRIVATE
Definition macros.h:460
MaybeAssignedFlag maybe_assigned_flag
Definition scope-info.h:40