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

Unified Diff: src/ast/scopeinfo.cc

Issue 2271993002: Chain ScopeInfos together (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: try to please gcmole Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/ast/scopes.h » ('j') | src/ast/scopes.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/scopeinfo.cc
diff --git a/src/ast/scopeinfo.cc b/src/ast/scopeinfo.cc
index a9e824f415bae54881eb5dc84c3787905418756c..f4d6079c0ab9c0531f2485be7503c0d1c38850d1 100644
--- a/src/ast/scopeinfo.cc
+++ b/src/ast/scopeinfo.cc
@@ -71,10 +71,13 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
const bool has_function_name = function_name_info != NONE;
const bool has_receiver = receiver_info == STACK || receiver_info == CONTEXT;
const int parameter_count = scope->num_parameters();
+ const bool has_outer_scope_info =
+ scope->GetOuterScopeWithContext() != nullptr;
const int length = kVariablePartIndex + parameter_count +
(1 + stack_local_count) + 2 * context_local_count +
- 2 * context_global_count +
- (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0);
+ 2 * context_global_count + (has_receiver ? 1 : 0) +
+ (has_function_name ? 2 : 0) +
+ (has_outer_scope_info ? 1 : 0);
Factory* factory = isolate->factory();
Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
@@ -103,7 +106,8 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
AsmModuleField::encode(asm_module) |
AsmFunctionField::encode(asm_function) |
HasSimpleParametersField::encode(has_simple_parameters) |
- FunctionKindField::encode(function_kind);
+ FunctionKindField::encode(function_kind) |
+ HasOuterScopeInfoField::encode(has_outer_scope_info);
scope_info->SetFlags(flags);
scope_info->SetParameterCount(parameter_count);
scope_info->SetStackLocalCount(stack_local_count);
@@ -191,6 +195,14 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone,
var_index == scope_info->ContextLength() - 1);
}
+ // If present, add the outer scope info.
+ DCHECK(index == scope_info->OuterScopeInfoEntryIndex());
+ if (has_outer_scope_info) {
+ Handle<ScopeInfo> outer_scope_info =
+ scope->GetOuterScopeWithContext()->GetScopeInfo(isolate);
+ scope_info->set(index++, *outer_scope_info);
+ }
+
DCHECK(index == scope_info->length());
DCHECK(scope->num_parameters() == scope_info->ParameterCount());
DCHECK(scope->num_heap_slots() == scope_info->ContextLength() ||
@@ -212,26 +224,28 @@ Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) {
const VariableMode function_variable_mode = VAR;
const bool has_function_name = false;
const bool has_receiver = true;
+ const bool has_outer_scope_info = false;
const int parameter_count = 0;
const int length = kVariablePartIndex + parameter_count +
(1 + stack_local_count) + 2 * context_local_count +
- 2 * context_global_count +
- (has_receiver ? 1 : 0) + (has_function_name ? 2 : 0);
+ 2 * context_global_count + (has_receiver ? 1 : 0) +
+ (has_function_name ? 2 : 0) +
+ (has_outer_scope_info ? 1 : 0);
Factory* factory = isolate->factory();
Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
// Encode the flags.
- int flags = ScopeTypeField::encode(SCRIPT_SCOPE) |
- CallsEvalField::encode(false) |
- LanguageModeField::encode(SLOPPY) |
- DeclarationScopeField::encode(true) |
- ReceiverVariableField::encode(receiver_info) |
- FunctionVariableField::encode(function_name_info) |
- FunctionVariableMode::encode(function_variable_mode) |
- AsmModuleField::encode(false) | AsmFunctionField::encode(false) |
- HasSimpleParametersField::encode(has_simple_parameters) |
- FunctionKindField::encode(FunctionKind::kNormalFunction);
+ int flags =
+ ScopeTypeField::encode(SCRIPT_SCOPE) | CallsEvalField::encode(false) |
+ LanguageModeField::encode(SLOPPY) | DeclarationScopeField::encode(true) |
+ ReceiverVariableField::encode(receiver_info) |
+ FunctionVariableField::encode(function_name_info) |
+ FunctionVariableMode::encode(function_variable_mode) |
+ AsmModuleField::encode(false) | AsmFunctionField::encode(false) |
+ HasSimpleParametersField::encode(has_simple_parameters) |
+ FunctionKindField::encode(FunctionKind::kNormalFunction) |
+ HasOuterScopeInfoField::encode(has_outer_scope_info);
scope_info->SetFlags(flags);
scope_info->SetParameterCount(parameter_count);
scope_info->SetStackLocalCount(stack_local_count);
@@ -259,6 +273,7 @@ Handle<ScopeInfo> ScopeInfo::CreateGlobalThisBinding(Isolate* isolate) {
scope_info->set(index++, Smi::FromInt(receiver_index));
DCHECK(index == scope_info->FunctionNameEntryIndex());
+ DCHECK(index == scope_info->OuterScopeInfoEntryIndex());
DCHECK_EQ(index, scope_info->length());
DCHECK_EQ(scope_info->ParameterCount(), 0);
@@ -362,6 +377,13 @@ bool ScopeInfo::HasFunctionName() {
}
}
+bool ScopeInfo::HasOuterScopeInfo() {
+ if (length() > 0) {
+ return HasOuterScopeInfoField::decode(Flags());
+ } else {
+ return false;
+ }
+}
bool ScopeInfo::HasHeapAllocatedLocals() {
if (length() > 0) {
@@ -382,6 +404,10 @@ String* ScopeInfo::FunctionName() {
return String::cast(get(FunctionNameEntryIndex()));
}
+ScopeInfo* ScopeInfo::OuterScopeInfo() {
+ DCHECK(HasOuterScopeInfo());
+ return ScopeInfo::cast(get(OuterScopeInfoEntryIndex()));
+}
String* ScopeInfo::ParameterName(int var) {
DCHECK(0 <= var && var < ParameterCount());
@@ -643,6 +669,10 @@ int ScopeInfo::FunctionNameEntryIndex() {
return ReceiverEntryIndex() + (HasAllocatedReceiver() ? 1 : 0);
}
+int ScopeInfo::OuterScopeInfoEntryIndex() {
+ return FunctionNameEntryIndex() + (HasFunctionName() ? 2 : 0);
+}
+
#ifdef DEBUG
static void PrintList(const char* list_name,
« no previous file with comments | « no previous file | src/ast/scopes.h » ('j') | src/ast/scopes.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698