summaryrefslogtreecommitdiff
path: root/deps/v8/src/objects/scope-info.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/objects/scope-info.cc')
-rw-r--r--deps/v8/src/objects/scope-info.cc89
1 files changed, 76 insertions, 13 deletions
diff --git a/deps/v8/src/objects/scope-info.cc b/deps/v8/src/objects/scope-info.cc
index c390298b5d..65a26e5d98 100644
--- a/deps/v8/src/objects/scope-info.cc
+++ b/deps/v8/src/objects/scope-info.cc
@@ -138,6 +138,10 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
const bool has_brand = scope->is_class_scope()
? scope->AsClassScope()->brand() != nullptr
: false;
+ const bool should_save_class_variable_index =
+ scope->is_class_scope()
+ ? scope->AsClassScope()->should_save_class_variable_index()
+ : false;
const bool has_function_name = function_name_info != NONE;
const bool has_position_info = NeedsPositionInfo(scope->scope_type());
const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT;
@@ -146,7 +150,9 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
? scope->AsDeclarationScope()->num_parameters()
: 0;
const bool has_outer_scope_info = !outer_scope.is_null();
+
const int length = kVariablePartIndex + 2 * context_local_count +
+ (should_save_class_variable_index ? 1 : 0) +
(has_receiver ? 1 : 0) +
(has_function_name ? kFunctionNameEntries : 0) +
(has_inferred_function_name ? 1 : 0) +
@@ -187,6 +193,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
DeclarationScopeField::encode(scope->is_declaration_scope()) |
ReceiverVariableField::encode(receiver_info) |
HasClassBrandField::encode(has_brand) |
+ HasSavedClassVariableIndexField::encode(
+ should_save_class_variable_index) |
HasNewTargetField::encode(has_new_target) |
FunctionVariableField::encode(function_name_info) |
HasInferredFunctionNameField::encode(has_inferred_function_name) |
@@ -196,7 +204,9 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
HasOuterScopeInfoField::encode(has_outer_scope_info) |
IsDebugEvaluateScopeField::encode(scope->is_debug_evaluate_scope()) |
ForceContextAllocationField::encode(
- scope->ForceContextForLanguageMode());
+ scope->ForceContextForLanguageMode()) |
+ PrivateNameLookupSkipsOuterClassField::encode(
+ scope->private_name_lookup_skips_outer_class());
scope_info.SetFlags(flags);
scope_info.SetParameterCount(parameter_count);
@@ -220,7 +230,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
VariableModeField::encode(var->mode()) |
InitFlagField::encode(var->initialization_flag()) |
MaybeAssignedFlagField::encode(var->maybe_assigned()) |
- ParameterNumberField::encode(ParameterNumberField::kMax);
+ ParameterNumberField::encode(ParameterNumberField::kMax) |
+ IsStaticFlagField::encode(var->is_static_flag());
scope_info.set(context_local_base + local_index, *var->name(), mode);
scope_info.set(context_local_info_base + local_index,
Smi::FromInt(info));
@@ -235,7 +246,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
VariableModeField::encode(var->mode()) |
InitFlagField::encode(var->initialization_flag()) |
MaybeAssignedFlagField::encode(var->maybe_assigned()) |
- ParameterNumberField::encode(ParameterNumberField::kMax);
+ ParameterNumberField::encode(ParameterNumberField::kMax) |
+ IsStaticFlagField::encode(var->is_static_flag());
scope_info.set(module_var_entry + kModuleVariablePropertiesOffset,
Smi::FromInt(properties));
module_var_entry += kModuleVariableEntryLength;
@@ -273,7 +285,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
VariableModeField::encode(var->mode()) |
InitFlagField::encode(var->initialization_flag()) |
MaybeAssignedFlagField::encode(var->maybe_assigned()) |
- ParameterNumberField::encode(ParameterNumberField::kMax);
+ ParameterNumberField::encode(ParameterNumberField::kMax) |
+ IsStaticFlagField::encode(var->is_static_flag());
scope_info.set(context_local_base + local_index, *var->name(), mode);
scope_info.set(context_local_info_base + local_index,
Smi::FromInt(info));
@@ -283,6 +296,16 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
index += 2 * context_local_count;
+ DCHECK_EQ(index, scope_info.SavedClassVariableInfoIndex());
+ // If the scope is a class scope and has used static private methods, save
+ // the context slot index of the class variable.
+ // Store the class variable index.
+ if (should_save_class_variable_index) {
+ Variable* class_variable = scope->AsClassScope()->class_variable();
+ DCHECK_EQ(class_variable->location(), VariableLocation::CONTEXT);
+ scope_info.set(index++, Smi::FromInt(class_variable->index()));
+ }
+
// If the receiver is allocated, add its index.
DCHECK_EQ(index, scope_info.ReceiverInfoIndex());
if (has_receiver) {
@@ -362,11 +385,14 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
LanguageModeField::encode(LanguageMode::kSloppy) |
DeclarationScopeField::encode(false) |
ReceiverVariableField::encode(NONE) | HasClassBrandField::encode(false) |
+ HasSavedClassVariableIndexField::encode(false) |
HasNewTargetField::encode(false) | FunctionVariableField::encode(NONE) |
IsAsmModuleField::encode(false) | HasSimpleParametersField::encode(true) |
FunctionKindField::encode(kNormalFunction) |
HasOuterScopeInfoField::encode(has_outer_scope_info) |
- IsDebugEvaluateScopeField::encode(false);
+ IsDebugEvaluateScopeField::encode(false) |
+ ForceContextAllocationField::encode(false) |
+ PrivateNameLookupSkipsOuterClassField::encode(false);
scope_info->SetFlags(flags);
scope_info->SetParameterCount(0);
@@ -425,13 +451,17 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
LanguageModeField::encode(LanguageMode::kSloppy) |
DeclarationScopeField::encode(true) |
ReceiverVariableField::encode(is_empty_function ? UNUSED : CONTEXT) |
- HasClassBrandField::encode(false) | HasNewTargetField::encode(false) |
+ HasClassBrandField::encode(false) |
+ HasSavedClassVariableIndexField::encode(false) |
+ HasNewTargetField::encode(false) |
FunctionVariableField::encode(is_empty_function ? UNUSED : NONE) |
HasInferredFunctionNameField::encode(has_inferred_function_name) |
IsAsmModuleField::encode(false) | HasSimpleParametersField::encode(true) |
FunctionKindField::encode(FunctionKind::kNormalFunction) |
HasOuterScopeInfoField::encode(false) |
- IsDebugEvaluateScopeField::encode(false);
+ IsDebugEvaluateScopeField::encode(false) |
+ ForceContextAllocationField::encode(false) |
+ PrivateNameLookupSkipsOuterClassField::encode(false);
scope_info->SetFlags(flags);
scope_info->SetParameterCount(parameter_count);
scope_info->SetContextLocalCount(context_local_count);
@@ -449,7 +479,8 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
VariableModeField::encode(VariableMode::kConst) |
InitFlagField::encode(kCreatedInitialized) |
MaybeAssignedFlagField::encode(kNotAssigned) |
- ParameterNumberField::encode(ParameterNumberField::kMax);
+ ParameterNumberField::encode(ParameterNumberField::kMax) |
+ IsStaticFlagField::encode(IsStaticFlag::kNotStatic);
scope_info->set(index++, Smi::FromInt(value));
}
@@ -549,6 +580,10 @@ bool ScopeInfo::HasClassBrand() const {
return HasClassBrandField::decode(Flags());
}
+bool ScopeInfo::HasSavedClassVariableIndex() const {
+ return HasSavedClassVariableIndexField::decode(Flags());
+}
+
bool ScopeInfo::HasNewTarget() const {
return HasNewTargetField::decode(Flags());
}
@@ -608,6 +643,11 @@ void ScopeInfo::SetIsDebugEvaluateScope() {
}
}
+bool ScopeInfo::PrivateNameLookupSkipsOuterClass() const {
+ if (length() == 0) return false;
+ return PrivateNameLookupSkipsOuterClassField::decode(Flags());
+}
+
bool ScopeInfo::HasContext() const { return ContextLength() > 0; }
Object ScopeInfo::FunctionName() const {
@@ -674,6 +714,14 @@ VariableMode ScopeInfo::ContextLocalMode(int var) const {
return VariableModeField::decode(value);
}
+IsStaticFlag ScopeInfo::ContextLocalIsStaticFlag(int var) const {
+ DCHECK_LE(0, var);
+ DCHECK_LT(var, ContextLocalCount());
+ int info_index = ContextLocalInfosIndex() + var;
+ int value = Smi::ToInt(get(info_index));
+ return IsStaticFlagField::decode(value);
+}
+
InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) const {
DCHECK_LE(0, var);
DCHECK_LT(var, ContextLocalCount());
@@ -744,7 +792,8 @@ int ScopeInfo::ModuleIndex(String name, VariableMode* mode,
int ScopeInfo::ContextSlotIndex(ScopeInfo scope_info, String name,
VariableMode* mode,
InitializationFlag* init_flag,
- MaybeAssignedFlag* maybe_assigned_flag) {
+ MaybeAssignedFlag* maybe_assigned_flag,
+ IsStaticFlag* is_static_flag) {
DisallowHeapAllocation no_gc;
DCHECK(name.IsInternalizedString());
DCHECK_NOT_NULL(mode);
@@ -759,6 +808,7 @@ int ScopeInfo::ContextSlotIndex(ScopeInfo scope_info, String name,
if (name != scope_info.get(i)) continue;
int var = i - start;
*mode = scope_info.ContextLocalMode(var);
+ *is_static_flag = scope_info.ContextLocalIsStaticFlag(var);
*init_flag = scope_info.ContextLocalInitFlag(var);
*maybe_assigned_flag = scope_info.ContextLocalMaybeAssignedFlag(var);
int result = Context::MIN_CONTEXT_SLOTS + var;
@@ -770,6 +820,14 @@ int ScopeInfo::ContextSlotIndex(ScopeInfo scope_info, String name,
return -1;
}
+int ScopeInfo::SavedClassVariableContextLocalIndex() const {
+ if (length() > 0 && HasSavedClassVariableIndexField::decode(Flags())) {
+ int index = Smi::ToInt(get(SavedClassVariableInfoIndex()));
+ return index - Context::MIN_CONTEXT_SLOTS;
+ }
+ return -1;
+}
+
int ScopeInfo::ReceiverContextSlotIndex() const {
if (length() > 0 && ReceiverVariableField::decode(Flags()) == CONTEXT) {
return Smi::ToInt(get(ReceiverInfoIndex()));
@@ -801,10 +859,14 @@ int ScopeInfo::ContextLocalInfosIndex() const {
return ContextLocalNamesIndex() + ContextLocalCount();
}
-int ScopeInfo::ReceiverInfoIndex() const {
+int ScopeInfo::SavedClassVariableInfoIndex() const {
return ContextLocalInfosIndex() + ContextLocalCount();
}
+int ScopeInfo::ReceiverInfoIndex() const {
+ return SavedClassVariableInfoIndex() + (HasSavedClassVariableIndex() ? 1 : 0);
+}
+
int ScopeInfo::FunctionNameInfoIndex() const {
return ReceiverInfoIndex() + (HasAllocatedReceiver() ? 1 : 0);
}
@@ -879,9 +941,10 @@ std::ostream& operator<<(std::ostream& os,
}
Handle<SourceTextModuleInfoEntry> SourceTextModuleInfoEntry::New(
- Isolate* isolate, Handle<HeapObject> export_name,
- Handle<HeapObject> local_name, Handle<HeapObject> import_name,
- int module_request, int cell_index, int beg_pos, int end_pos) {
+ Isolate* isolate, Handle<PrimitiveHeapObject> export_name,
+ Handle<PrimitiveHeapObject> local_name,
+ Handle<PrimitiveHeapObject> import_name, int module_request, int cell_index,
+ int beg_pos, int end_pos) {
Handle<SourceTextModuleInfoEntry> result =
Handle<SourceTextModuleInfoEntry>::cast(isolate->factory()->NewStruct(
SOURCE_TEXT_MODULE_INFO_ENTRY_TYPE, AllocationType::kOld));