Commit b8008a3e authored by ishell@chromium.org's avatar ishell@chromium.org

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
parent 134ead10
...@@ -137,7 +137,8 @@ Handle<Object> Context::Lookup(Handle<String> name, ...@@ -137,7 +137,8 @@ Handle<Object> Context::Lookup(Handle<String> name,
} }
VariableMode mode; VariableMode mode;
InitializationFlag init_flag; 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); ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS);
if (slot_index >= 0) { if (slot_index >= 0) {
if (FLAG_trace_contexts) { if (FLAG_trace_contexts) {
......
...@@ -4489,9 +4489,10 @@ class ScopeInfo : public FixedArray { ...@@ -4489,9 +4489,10 @@ class ScopeInfo : public FixedArray {
// returns a value < 0. The name must be an internalized string. // returns a value < 0. The name must be an internalized string.
// If the slot is present and mode != NULL, sets *mode to the corresponding // If the slot is present and mode != NULL, sets *mode to the corresponding
// mode for that variable. // mode for that variable.
int ContextSlotIndex(String* name, static int ContextSlotIndex(Handle<ScopeInfo> scope_info,
VariableMode* mode, Handle<String> name,
InitializationFlag* init_flag); VariableMode* mode,
InitializationFlag* init_flag);
// Lookup support for serialized scope info. Returns the // Lookup support for serialized scope info. Returns the
// parameter index for a given parameter name if the parameter is present; // parameter index for a given parameter name if the parameter is present;
......
...@@ -11277,7 +11277,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) { ...@@ -11277,7 +11277,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
InitializationFlag init_flag; InitializationFlag init_flag;
locals->set(local * 2, *name); locals->set(local * 2, *name);
int context_slot_index = 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); Object* value = context->get(context_slot_index);
locals->set(local * 2 + 1, value); locals->set(local * 2 + 1, value);
local++; local++;
...@@ -11449,10 +11449,10 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) { ...@@ -11449,10 +11449,10 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info, static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info,
int index) { Handle<String> parameter_name) {
VariableMode mode; VariableMode mode;
InitializationFlag flag; 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<JSObject> MaterializeStackLocalsWithFrameInspector( ...@@ -11470,7 +11470,8 @@ static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector(
// First fill all parameters. // First fill all parameters.
for (int i = 0; i < scope_info->ParameterCount(); ++i) { for (int i = 0; i < scope_info->ParameterCount(); ++i) {
// Do not materialize the parameter if it is shadowed by a context local. // Do not materialize the parameter if it is shadowed by a context local.
if (ParameterIsShadowedByContextLocal(scope_info, i)) continue; Handle<String> name(scope_info->ParameterName(i));
if (ParameterIsShadowedByContextLocal(scope_info, name)) continue;
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Object> value(i < frame_inspector->GetParametersCount() Handle<Object> value(i < frame_inspector->GetParametersCount()
...@@ -11478,7 +11479,6 @@ static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( ...@@ -11478,7 +11479,6 @@ static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector(
: isolate->heap()->undefined_value(), : isolate->heap()->undefined_value(),
isolate); isolate);
ASSERT(!value->IsTheHole()); ASSERT(!value->IsTheHole());
Handle<String> name(scope_info->ParameterName(i));
RETURN_ON_EXCEPTION( RETURN_ON_EXCEPTION(
isolate, isolate,
...@@ -11521,11 +11521,11 @@ static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate, ...@@ -11521,11 +11521,11 @@ static void UpdateStackLocalsFromMaterializedObject(Isolate* isolate,
// Parameters. // Parameters.
for (int i = 0; i < scope_info->ParameterCount(); ++i) { for (int i = 0; i < scope_info->ParameterCount(); ++i) {
// Shadowed parameters were not materialized. // Shadowed parameters were not materialized.
if (ParameterIsShadowedByContextLocal(scope_info, i)) continue; Handle<String> name(scope_info->ParameterName(i));
if (ParameterIsShadowedByContextLocal(scope_info, name)) continue;
ASSERT(!frame->GetParameter(i)->IsTheHole()); ASSERT(!frame->GetParameter(i)->IsTheHole());
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<String> name(scope_info->ParameterName(i));
Handle<Object> value = Handle<Object> value =
Object::GetPropertyOrElement(target, name).ToHandleChecked(); Object::GetPropertyOrElement(target, name).ToHandleChecked();
frame->SetParameterValue(i, *value); frame->SetParameterValue(i, *value);
...@@ -11626,7 +11626,7 @@ static bool SetContextLocalValue(Isolate* isolate, ...@@ -11626,7 +11626,7 @@ static bool SetContextLocalValue(Isolate* isolate,
VariableMode mode; VariableMode mode;
InitializationFlag init_flag; InitializationFlag init_flag;
int context_index = 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); context->set(context_index, *new_value);
return true; return true;
} }
......
...@@ -281,35 +281,41 @@ int ScopeInfo::StackSlotIndex(String* name) { ...@@ -281,35 +281,41 @@ int ScopeInfo::StackSlotIndex(String* name) {
} }
int ScopeInfo::ContextSlotIndex(String* name, int ScopeInfo::ContextSlotIndex(Handle<ScopeInfo> scope_info,
Handle<String> name,
VariableMode* mode, VariableMode* mode,
InitializationFlag* init_flag) { InitializationFlag* init_flag) {
ASSERT(name->IsInternalizedString()); ASSERT(name->IsInternalizedString());
ASSERT(mode != NULL); ASSERT(mode != NULL);
ASSERT(init_flag != NULL); ASSERT(init_flag != NULL);
if (length() > 0) { if (scope_info->length() > 0) {
ContextSlotCache* context_slot_cache = GetIsolate()->context_slot_cache(); ContextSlotCache* context_slot_cache =
int result = context_slot_cache->Lookup(this, name, mode, init_flag); scope_info->GetIsolate()->context_slot_cache();
int result =
context_slot_cache->Lookup(*scope_info, *name, mode, init_flag);
if (result != ContextSlotCache::kNotFound) { if (result != ContextSlotCache::kNotFound) {
ASSERT(result < ContextLength()); ASSERT(result < scope_info->ContextLength());
return result; return result;
} }
int start = ContextLocalNameEntriesIndex(); int start = scope_info->ContextLocalNameEntriesIndex();
int end = ContextLocalNameEntriesIndex() + ContextLocalCount(); int end = scope_info->ContextLocalNameEntriesIndex() +
scope_info->ContextLocalCount();
for (int i = start; i < end; ++i) { for (int i = start; i < end; ++i) {
if (name == get(i)) { if (*name == scope_info->get(i)) {
int var = i - start; int var = i - start;
*mode = ContextLocalMode(var); *mode = scope_info->ContextLocalMode(var);
*init_flag = ContextLocalInitFlag(var); *init_flag = scope_info->ContextLocalInitFlag(var);
result = Context::MIN_CONTEXT_SLOTS + var; result = Context::MIN_CONTEXT_SLOTS + var;
context_slot_cache->Update(this, name, *mode, *init_flag, result); context_slot_cache->Update(
ASSERT(result < ContextLength()); *scope_info, *name, *mode, *init_flag, result);
ASSERT(result < scope_info->ContextLength());
return result; return result;
} }
} }
// Cache as not found. Mode and init flag don't matter. // 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; return -1;
} }
......
...@@ -379,7 +379,7 @@ Variable* Scope::LocalLookup(Handle<String> name) { ...@@ -379,7 +379,7 @@ Variable* Scope::LocalLookup(Handle<String> name) {
VariableMode mode; VariableMode mode;
Variable::Location location = Variable::CONTEXT; Variable::Location location = Variable::CONTEXT;
InitializationFlag init_flag; 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) { if (index < 0) {
// Check parameters. // Check parameters.
index = scope_info_->ParameterIndex(*name); index = scope_info_->ParameterIndex(*name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment