Reviewers: Michael Starzinger, dcarney, yhirano,

Description:
Don't lookup the cache for the result of Function::New

Since isFunctionCached condition is wrong, we lookup the cache even if
doNotCache is true. As a result, Function::New always returns null
except for the first time.

BUG=272579

Please review this at https://chromiumcodereview.appspot.com/23513048/

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

Affected files (+12, -3 lines):
  M src/apinatives.js
  M test/cctest/test-api.cc


Index: src/apinatives.js
diff --git a/src/apinatives.js b/src/apinatives.js
index 5fb36c09e7242b6289bb9d5f35551893b6e85ed8..c87d45c83fadcac9bbe8edbdfc3f3b19768f547c 100644
--- a/src/apinatives.js
+++ b/src/apinatives.js
@@ -66,16 +66,16 @@ function InstantiateFunction(data, name) {
   // We need a reference to kApiFunctionCache in the stack frame
   // if we need to bail out from a stack overflow.
   var cache = kApiFunctionCache;
+  var flags = %GetTemplateField(data, kApiFlagOffset);
+  var doNotCache = flags & (1 << kDoNotCacheBit);
   var serialNumber = %GetTemplateField(data, kApiSerialNumberOffset);
   var isFunctionCached =
-   (serialNumber in cache) && (cache[serialNumber] != kUninitialized);
+ !doNotCache && (serialNumber in cache) && (cache[serialNumber] != kUninitialized);
   if (!isFunctionCached) {
     try {
       cache[serialNumber] = null;
       var fun = %CreateApiFunction(data);
       if (name) %FunctionSetName(fun, name);
-      var flags = %GetTemplateField(data, kApiFlagOffset);
-      var doNotCache = flags & (1 << kDoNotCacheBit);
       if (!doNotCache) cache[serialNumber] = fun;
       if (flags & (1 << kRemovePrototypeBit)) {
         %FunctionRemovePrototype(fun);
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index f4e40cdd3844b35b03541eaa95abb91441546848..db861a55239de4d5cdd74d383599bb2584f26d9d 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -20585,5 +20585,14 @@ THREADED_TEST(FunctionNew) {
   i::Object* elm = i_isolate->native_context()->function_cache()
       ->GetElementNoExceptionThrown(i_isolate, serial_number);
   CHECK(elm->IsNull());
+  // Verify that each Function::New creates a new function instance
+  Local<Object> data2 = v8::Object::New();
+  function_new_expected_env = data2;
+ Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
+  CHECK(!func2->IsNull());
+  CHECK_NE(func, func2);
+  env->Global()->Set(v8_str("func2"), func2);
+  Local<Value> result2 = CompileRun("func2();");
+  CHECK_EQ(v8::Integer::New(17, isolate), result2);
 }



--
--
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/groups/opt_out.

Reply via email to