Reviewers: Yang,

Message:
PTAL #9

Description:
ScopeInfo::ContextSlotIndex() handlified.

Please review this at https://codereview.chromium.org/253263003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+34, -26 lines):
  M src/contexts.cc
  M src/objects.h
  M src/runtime.cc
  M src/scopeinfo.cc
  M src/scopes.cc


Index: src/contexts.cc
diff --git a/src/contexts.cc b/src/contexts.cc
index d1151f7a811cedc8f6abfc08ca6aa5e396683da9..58ae49a9cc853a93c9aafef08b10cf5a50f3fc83 100644
--- a/src/contexts.cc
+++ b/src/contexts.cc
@@ -137,7 +137,8 @@ Handle<Object> Context::Lookup(Handle<String> 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) {
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 6402f86d341919e6f16fb3ba33db96d819ae5458..b63be56dca8f51598712e7a19b9f22af56063bb7 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -4579,9 +4579,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<ScopeInfo> scope_info,
+                              Handle<String> 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;
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 61d363ac20f7cd78aa62db070e372a64be10d2f6..7cacc9bbf3336cbad63c0a0c3d30e2a577314044 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -11251,7 +11251,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++;
@@ -11423,10 +11423,10 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {


 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info,
-                                              int index) {
+ Handle<String> parameter_name) {
   VariableMode mode;
   InitializationFlag flag;
- return info->ContextSlotIndex(info->ParameterName(index), &mode, &flag) != -1; + return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &flag) != -1;
 }


@@ -11444,7 +11444,8 @@ static MaybeHandle<JSObject> 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<String> name(scope_info->ParameterName(i));
+    if (ParameterIsShadowedByContextLocal(scope_info, name)) continue;

     HandleScope scope(isolate);
     Handle<Object> value(i < frame_inspector->GetParametersCount()
@@ -11452,7 +11453,6 @@ static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector(
                              : isolate->heap()->undefined_value(),
                          isolate);
     ASSERT(!value->IsTheHole());
-    Handle<String> name(scope_info->ParameterName(i));

     RETURN_ON_EXCEPTION(
         isolate,
@@ -11495,11 +11495,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<String> name(scope_info->ParameterName(i));
+    if (ParameterIsShadowedByContextLocal(scope_info, name)) continue;

     ASSERT(!frame->GetParameter(i)->IsTheHole());
     HandleScope scope(isolate);
-    Handle<String> name(scope_info->ParameterName(i));
     Handle<Object> value =
         Object::GetPropertyOrElement(target, name).ToHandleChecked();
     frame->SetParameterValue(i, *value);
@@ -11600,7 +11600,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;
     }
Index: src/scopeinfo.cc
diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc
index 7f8549214e214129b900a7798376c423d02fe853..a44ac613aa5a83da88ffdb8837c5a26394bfd3a8 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<ScopeInfo> scope_info,
+                                Handle<String> 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;
 }
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index ffdc1eb910256f03dd034a7107050d10ec241ac8..1818909afc51a74f85a306b39671fc6c4557c0f0 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -379,7 +379,7 @@ Variable* Scope::LocalLookup(Handle<String> 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);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to