Revision: 10425
Author:   [email protected]
Date:     Tue Jan 17 08:06:03 2012
Log:      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
Review URL: http://codereview.chromium.org/9240006
http://code.google.com/p/v8/source/detail?r=10425

Modified:
 /branches/bleeding_edge/src/ast.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/ast.cc  Tue Jan 17 07:53:58 2012
+++ /branches/bleeding_edge/src/ast.cc  Tue Jan 17 08:06:03 2012
@@ -725,6 +725,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
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Mon Jan 16 03:04:58 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Tue Jan 17 08:06:03 2012
@@ -8910,17 +8910,6 @@
     "}");
   CHECK_EQ(41 * 7, value->Int32Value());
 }
-
-
-static v8::Handle<Value> call_ic_function5;
-static v8::Handle<Value> InterceptorCallICGetter5(Local<String> name,
- const AccessorInfo& info) {
-  ApiTestFuzzer::Fuzz();
-  if (v8_str("x")->Equals(name))
-    return call_ic_function5;
-  else
-    return Local<Value>();
-}


 // This test checks that if interceptor doesn't provide a function,
@@ -8941,6 +8930,17 @@
     "}");
   CHECK_EQ(43, value->Int32Value());
 }
+
+
+static v8::Handle<Value> call_ic_function5;
+static v8::Handle<Value> InterceptorCallICGetter5(Local<String> name,
+ const AccessorInfo& info) {
+  ApiTestFuzzer::Fuzz();
+  if (v8_str("x")->Equals(name))
+    return call_ic_function5;
+  else
+    return Local<Value>();
+}


 // This test checks that if interceptor provides a function,
@@ -8964,6 +8964,48 @@
     "}");
   CHECK_EQ(41, value->Int32Value());
 }
+
+
+static v8::Handle<Value> call_ic_function6;
+static v8::Handle<Value> InterceptorCallICGetter6(Local<String> name,
+ const AccessorInfo& info) {
+  ApiTestFuzzer::Fuzz();
+  if (v8_str("x")->Equals(name))
+    return call_ic_function6;
+  else
+    return Local<Value>();
+}
+
+
+// Same test as above, except the code is wrapped in a function
+// to test the optimized compiler.
+THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
+  i::FLAG_allow_natives_syntax = true;
+  v8::HandleScope scope;
+  v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
+  templ->SetNamedPropertyHandler(InterceptorCallICGetter6);
+  LocalContext context;
+  context->Global()->Set(v8_str("o"), templ->NewInstance());
+  call_ic_function6 =
+      v8_compile("function f(x) { return x - 1; }; f")->Run();
+  v8::Handle<Value> value = CompileRun(
+    "function inc(x) { return x + 1; };"
+    "inc(1);"
+    "o.x = inc;"
+    "function test() {"
+    "  var result = 0;"
+    "  for (var i = 0; i < 1000; i++) {"
+    "    result = o.x(42);"
+    "  }"
+    "  return result;"
+    "};"
+    "test();"
+    "test();"
+    "test();"
+    "%OptimizeFunctionOnNextCall(test);"
+    "test()");
+  CHECK_EQ(41, value->Int32Value());
+}


 // Test the case when we stored constant function into

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

Reply via email to