Reviewers: Erik Corry,

Description:
Fix handling of named interceptors in optimized code.

When calling a constant function property from optimized code,
we need to check that there is no interceptor on the receiver map.

TEST=cctest/InterceptorCallICConstantFunctionNotNeededWrapped

Please review this at http://codereview.chromium.org/9240006/

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

Affected files:
  M     src/ast.cc
  M     test/cctest/test-api.cc


Index: src/ast.cc
===================================================================
--- src/ast.cc  (revision 10417)
+++ src/ast.cc  (working copy)
@@ -735,6 +735,10 @@


 bool Call::ComputeTarget(Handle<Map> type, Handle<String> name) {
+  // If there is an interceptor, we can't compute the target for
+  // a direct call.
+  if (type->has_named_interceptor()) return false;
+
   if (check_type_ == RECEIVER_MAP_CHECK) {
     // For primitive checks the holder is set up to point to the
     // corresponding prototype object, i.e. one step of the algorithm
Index: test/cctest/test-api.cc
===================================================================
--- test/cctest/test-api.cc     (revision 10417)
+++ test/cctest/test-api.cc     (working copy)
@@ -8966,6 +8966,31 @@
 }


+// Same test as above, except the code is wrapped in a function
+// to test the optimized compiler.
+THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
+  v8::HandleScope scope;
+  v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
+  templ->SetNamedPropertyHandler(InterceptorCallICGetter5);
+  LocalContext context;
+  context->Global()->Set(v8_str("o"), templ->NewInstance());
+  call_ic_function5 =
+      v8_compile("function f(x) { return x - 1; }; f")->Run();
+  v8::Handle<Value> value = CompileRun(
+    "(function() {"
+    "  function inc(x) { return x + 1; };"
+    "  inc(1);"
+    "  o.x = inc;"
+    "  var result = 0;"
+    "  for (var i = 0; i < 1000; i++) {"
+    "    result = o.x(42);"
+    "  }"
+    "  return result;"
+    "})();");
+  CHECK_EQ(41, value->Int32Value());
+}
+
+
 // Test the case when we stored constant function into
 // a stub, but it got invalidated later on
 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) {


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to