Reviewers: Toon Verwaest,

Message:
ptal

i'll add some explicit tests if you're good with this

Description:
follow up named interceptor miss with api callback getter

BUG=

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+46, -13 lines):
  M src/ic/call-optimization.h
  M src/ic/call-optimization.cc
  M src/ic/handler-compiler.cc


Index: src/ic/call-optimization.cc
diff --git a/src/ic/call-optimization.cc b/src/ic/call-optimization.cc
index 5377988d1166fc10ba62f6a8485f809291bf116f..df64f08e7fca64b686b6905e8f5ed191107cc2d9 100644
--- a/src/ic/call-optimization.cc
+++ b/src/ic/call-optimization.cc
@@ -49,8 +49,15 @@ Handle<JSObject> CallOptimization::LookupHolderOfExpectedType(
 bool CallOptimization::IsCompatibleReceiver(Handle<Object> receiver,
Handle<JSObject> holder) const {
   DCHECK(is_simple_api_call());
-  if (!receiver->IsJSObject()) return false;
-  Handle<Map> map(JSObject::cast(*receiver)->map());
+  if (!receiver->IsHeapObject()) return false;
+  Handle<Map> map(HeapObject::cast(*receiver)->map());
+  return IsCompatibleReceiverType(map, holder);
+}
+
+
+bool CallOptimization::IsCompatibleReceiverType(Handle<Map> map,
+ Handle<JSObject> holder) const {
+  if (!map->IsJSObjectMap()) return false;
   HolderLookup holder_lookup;
Handle<JSObject> api_holder = LookupHolderOfExpectedType(map, &holder_lookup);
   switch (holder_lookup) {
Index: src/ic/call-optimization.h
diff --git a/src/ic/call-optimization.h b/src/ic/call-optimization.h
index b6435d25a3e30aa2f440e8775e69710a963a7a0a..990a7550c941d3d377b61346eec9f77068816b9c 100644
--- a/src/ic/call-optimization.h
+++ b/src/ic/call-optimization.h
@@ -45,6 +45,10 @@ class CallOptimization BASE_EMBEDDED {
   bool IsCompatibleReceiver(Handle<Object> receiver,
                             Handle<JSObject> holder) const;

+  // Check if the api holder is between the receiver and the holder.
+  bool IsCompatibleReceiverType(Handle<Map> receiver_map,
+                                Handle<JSObject> holder) const;
+
  private:
   void Initialize(Handle<JSFunction> function);

Index: src/ic/handler-compiler.cc
diff --git a/src/ic/handler-compiler.cc b/src/ic/handler-compiler.cc
index 3af36fac203974c572d55d2a317b8168892037b3..00df7be065371c46a40f732385eeae0b12a55840 100644
--- a/src/ic/handler-compiler.cc
+++ b/src/ic/handler-compiler.cc
@@ -289,13 +289,25 @@ Handle<Code> NamedLoadHandlerCompiler::CompileLoadInterceptor(
       break;
     case LookupIterator::ACCESSOR: {
       Handle<Object> accessors = it->GetAccessors();
-      inline_followup = accessors->IsExecutableAccessorInfo();
-      if (!inline_followup) break;
-      Handle<ExecutableAccessorInfo> info =
-          Handle<ExecutableAccessorInfo>::cast(accessors);
-      inline_followup = info->getter() != NULL &&
-                        ExecutableAccessorInfo::IsCompatibleReceiverType(
-                            isolate(), info, type());
+      if (accessors->IsExecutableAccessorInfo()) {
+        Handle<ExecutableAccessorInfo> info =
+            Handle<ExecutableAccessorInfo>::cast(accessors);
+        inline_followup = info->getter() != NULL &&
+                          ExecutableAccessorInfo::IsCompatibleReceiverType(
+                              isolate(), info, type());
+      } else if (accessors->IsAccessorPair()) {
+        Handle<JSObject> property_holder(it->GetHolder<JSObject>());
+ Handle<Object> getter(Handle<AccessorPair>::cast(accessors)->getter(),
+                              isolate());
+        if (!getter->IsJSFunction()) break;
+        if (!property_holder->HasFastProperties()) break;
+        auto function = Handle<JSFunction>::cast(getter);
+        CallOptimization call_optimization(function);
+        Handle<Map> receiver_map = IC::TypeToMap(*type(), isolate());
+        inline_followup = call_optimization.is_simple_api_call() &&
+                          call_optimization.IsCompatibleReceiverType(
+                              receiver_map, property_holder);
+      }
     }
   }

@@ -345,10 +357,20 @@ void NamedLoadHandlerCompiler::GenerateLoadPostInterceptor(
       break;
     }
     case LookupIterator::ACCESSOR:
-      Handle<ExecutableAccessorInfo> info =
-          Handle<ExecutableAccessorInfo>::cast(it->GetAccessors());
-      DCHECK_NOT_NULL(info->getter());
-      GenerateLoadCallback(reg, info);
+      if (it->GetAccessors()->IsExecutableAccessorInfo()) {
+        Handle<ExecutableAccessorInfo> info =
+            Handle<ExecutableAccessorInfo>::cast(it->GetAccessors());
+        DCHECK_NOT_NULL(info->getter());
+        GenerateLoadCallback(reg, info);
+      } else {
+        auto function = handle(JSFunction::cast(
+            AccessorPair::cast(*it->GetAccessors())->getter()));
+        CallOptimization call_optimization(function);
+        Handle<Map> receiver_map = IC::TypeToMap(*type(), isolate());
+        GenerateApiAccessorCall(masm(), call_optimization, receiver_map,
+                                receiver(), scratch2(), false, no_reg, reg,
+                                it->GetAccessorIndex());
+      }
   }
 }



--
--
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