From b8008a3e39817d28f9fcd74d41333984808a94f4 Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Wed, 30 Apr 2014 15:13:38 +0000 Subject: [PATCH] ScopeInfo::ContextSlotIndex() handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/253263003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21096 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/contexts.cc | 3 ++- src/objects.h | 7 ++++--- src/runtime.cc | 16 ++++++++-------- src/scopeinfo.cc | 32 +++++++++++++++++++------------- src/scopes.cc | 2 +- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/contexts.cc b/src/contexts.cc index d1151f7..58ae49a 100644 --- a/src/contexts.cc +++ b/src/contexts.cc @@ -137,7 +137,8 @@ Handle Context::Lookup(Handle name, } VariableMode mode; InitializationFlag init_flag; - int slot_index = scope_info->ContextSlotIndex(*name, &mode, &init_flag); + int slot_index = + ScopeInfo::ContextSlotIndex(scope_info, name, &mode, &init_flag); ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); if (slot_index >= 0) { if (FLAG_trace_contexts) { diff --git a/src/objects.h b/src/objects.h index 4f91688..f5167b0 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4489,9 +4489,10 @@ class ScopeInfo : public FixedArray { // returns a value < 0. The name must be an internalized string. // If the slot is present and mode != NULL, sets *mode to the corresponding // mode for that variable. - int ContextSlotIndex(String* name, - VariableMode* mode, - InitializationFlag* init_flag); + static int ContextSlotIndex(Handle scope_info, + Handle name, + VariableMode* mode, + InitializationFlag* init_flag); // Lookup support for serialized scope info. Returns the // parameter index for a given parameter name if the parameter is present; diff --git a/src/runtime.cc b/src/runtime.cc index 4a5638c..9b866d1 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -11277,7 +11277,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) { InitializationFlag init_flag; locals->set(local * 2, *name); int context_slot_index = - scope_info->ContextSlotIndex(*name, &mode, &init_flag); + ScopeInfo::ContextSlotIndex(scope_info, name, &mode, &init_flag); Object* value = context->get(context_slot_index); locals->set(local * 2 + 1, value); local++; @@ -11449,10 +11449,10 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) { static bool ParameterIsShadowedByContextLocal(Handle info, - int index) { + Handle parameter_name) { VariableMode mode; InitializationFlag flag; - return info->ContextSlotIndex(info->ParameterName(index), &mode, &flag) != -1; + return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &flag) != -1; } @@ -11470,7 +11470,8 @@ static MaybeHandle MaterializeStackLocalsWithFrameInspector( // First fill all parameters. for (int i = 0; i < scope_info->ParameterCount(); ++i) { // Do not materialize the parameter if it is shadowed by a context local. - if (ParameterIsShadowedByContextLocal(scope_info, i)) continue; + Handle name(scope_info->ParameterName(i)); + if (ParameterIsShadowedByContextLocal(scope_info, name)) continue; HandleScope scope(isolate); Handle value(i < frame_inspector->GetParametersCount() @@ -11478,7 +11479,6 @@ static MaybeHandle MaterializeStackLocalsWithFrameInspector( : isolate->heap()->undefined_value(), isolate); ASSERT(!value->IsTheHole()); - Handle name(scope_info->ParameterName(i)); RETURN_ON_EXCEPTION( isolate, @@ -11521,11 +11521,11 @@ static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, // Parameters. for (int i = 0; i < scope_info->ParameterCount(); ++i) { // Shadowed parameters were not materialized. - if (ParameterIsShadowedByContextLocal(scope_info, i)) continue; + Handle name(scope_info->ParameterName(i)); + if (ParameterIsShadowedByContextLocal(scope_info, name)) continue; ASSERT(!frame->GetParameter(i)->IsTheHole()); HandleScope scope(isolate); - Handle name(scope_info->ParameterName(i)); Handle value = Object::GetPropertyOrElement(target, name).ToHandleChecked(); frame->SetParameterValue(i, *value); @@ -11626,7 +11626,7 @@ static bool SetContextLocalValue(Isolate* isolate, VariableMode mode; InitializationFlag init_flag; int context_index = - scope_info->ContextSlotIndex(*next_name, &mode, &init_flag); + ScopeInfo::ContextSlotIndex(scope_info, next_name, &mode, &init_flag); context->set(context_index, *new_value); return true; } diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc index 7f85492..a44ac61 100644 --- a/src/scopeinfo.cc +++ b/src/scopeinfo.cc @@ -281,35 +281,41 @@ int ScopeInfo::StackSlotIndex(String* name) { } -int ScopeInfo::ContextSlotIndex(String* name, +int ScopeInfo::ContextSlotIndex(Handle scope_info, + Handle name, VariableMode* mode, InitializationFlag* init_flag) { ASSERT(name->IsInternalizedString()); ASSERT(mode != NULL); ASSERT(init_flag != NULL); - if (length() > 0) { - ContextSlotCache* context_slot_cache = GetIsolate()->context_slot_cache(); - int result = context_slot_cache->Lookup(this, name, mode, init_flag); + if (scope_info->length() > 0) { + ContextSlotCache* context_slot_cache = + scope_info->GetIsolate()->context_slot_cache(); + int result = + context_slot_cache->Lookup(*scope_info, *name, mode, init_flag); if (result != ContextSlotCache::kNotFound) { - ASSERT(result < ContextLength()); + ASSERT(result < scope_info->ContextLength()); return result; } - int start = ContextLocalNameEntriesIndex(); - int end = ContextLocalNameEntriesIndex() + ContextLocalCount(); + int start = scope_info->ContextLocalNameEntriesIndex(); + int end = scope_info->ContextLocalNameEntriesIndex() + + scope_info->ContextLocalCount(); for (int i = start; i < end; ++i) { - if (name == get(i)) { + if (*name == scope_info->get(i)) { int var = i - start; - *mode = ContextLocalMode(var); - *init_flag = ContextLocalInitFlag(var); + *mode = scope_info->ContextLocalMode(var); + *init_flag = scope_info->ContextLocalInitFlag(var); result = Context::MIN_CONTEXT_SLOTS + var; - context_slot_cache->Update(this, name, *mode, *init_flag, result); - ASSERT(result < ContextLength()); + context_slot_cache->Update( + *scope_info, *name, *mode, *init_flag, result); + ASSERT(result < scope_info->ContextLength()); return result; } } // Cache as not found. Mode and init flag don't matter. - context_slot_cache->Update(this, name, INTERNAL, kNeedsInitialization, -1); + context_slot_cache->Update( + *scope_info, *name, INTERNAL, kNeedsInitialization, -1); } return -1; } diff --git a/src/scopes.cc b/src/scopes.cc index ffdc1eb..1818909 100644 --- a/src/scopes.cc +++ b/src/scopes.cc @@ -379,7 +379,7 @@ Variable* Scope::LocalLookup(Handle name) { VariableMode mode; Variable::Location location = Variable::CONTEXT; InitializationFlag init_flag; - int index = scope_info_->ContextSlotIndex(*name, &mode, &init_flag); + int index = ScopeInfo::ContextSlotIndex(scope_info_, name, &mode, &init_flag); if (index < 0) { // Check parameters. index = scope_info_->ParameterIndex(*name); -- 2.7.4