Revision: 21111
Author:   [email protected]
Date:     Fri May  2 08:00:47 2014 UTC
Log: Fix |RunMicrotasks()| leaking reference to the last context being run on.

RunMicrotasks() executes pending tasks and swaps the old array with a new array. However, the new array contains the reference to the current context as its creation context. This prevents the context from gc-ed until RunMicrotasks() is executed in the different context.

BUG=crbug.com/367016
LOG=y
[email protected], [email protected]

Review URL: https://codereview.chromium.org/250883002
http://code.google.com/p/v8/source/detail?r=21111

Modified:
 /branches/bleeding_edge/src/bootstrapper.cc
 /branches/bleeding_edge/src/contexts.h
 /branches/bleeding_edge/src/execution.cc
 /branches/bleeding_edge/src/object-observe.js
 /branches/bleeding_edge/src/promise.js
 /branches/bleeding_edge/src/v8natives.js

=======================================
--- /branches/bleeding_edge/src/bootstrapper.cc Wed Apr 30 09:50:58 2014 UTC
+++ /branches/bleeding_edge/src/bootstrapper.cc Fri May  2 08:00:47 2014 UTC
@@ -1561,8 +1561,7 @@

 void Genesis::InstallExperimentalNativeFunctions() {
   INSTALL_NATIVE(JSFunction, "RunMicrotasks", run_microtasks);
-  INSTALL_NATIVE(JSFunction, "EnqueueExternalMicrotask",
-                 enqueue_external_microtask);
+  INSTALL_NATIVE(JSFunction, "EnqueueMicrotask", enqueue_microtask);

   if (FLAG_harmony_promises) {
     INSTALL_NATIVE(JSFunction, "IsPromise", is_promise);
=======================================
--- /branches/bleeding_edge/src/contexts.h      Tue Apr 29 06:42:26 2014 UTC
+++ /branches/bleeding_edge/src/contexts.h      Fri May  2 08:00:47 2014 UTC
@@ -155,7 +155,7 @@
   V(ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX, Object, \
     error_message_for_code_gen_from_strings) \
   V(RUN_MICROTASKS_INDEX, JSFunction, run_microtasks) \
- V(ENQUEUE_EXTERNAL_MICROTASK_INDEX, JSFunction, enqueue_external_microtask) \
+  V(ENQUEUE_MICROTASK_INDEX, JSFunction, enqueue_microtask) \
   V(IS_PROMISE_INDEX, JSFunction, is_promise) \
   V(PROMISE_CREATE_INDEX, JSFunction, promise_create) \
   V(PROMISE_RESOLVE_INDEX, JSFunction, promise_resolve) \
@@ -326,7 +326,7 @@
     ALLOW_CODE_GEN_FROM_STRINGS_INDEX,
     ERROR_MESSAGE_FOR_CODE_GEN_FROM_STRINGS_INDEX,
     RUN_MICROTASKS_INDEX,
-    ENQUEUE_EXTERNAL_MICROTASK_INDEX,
+    ENQUEUE_MICROTASK_INDEX,
     IS_PROMISE_INDEX,
     PROMISE_CREATE_INDEX,
     PROMISE_RESOLVE_INDEX,
=======================================
--- /branches/bleeding_edge/src/execution.cc    Wed Apr 30 12:25:18 2014 UTC
+++ /branches/bleeding_edge/src/execution.cc    Fri May  2 08:00:47 2014 UTC
@@ -322,7 +322,7 @@
   Handle<Object> args[] = { microtask };
   Execution::Call(
       isolate,
-      isolate->enqueue_external_microtask(),
+      isolate->enqueue_microtask(),
       isolate->factory()->undefined_value(),
       1,
       args).Check();
=======================================
--- /branches/bleeding_edge/src/object-observe.js Tue Apr 29 15:11:57 2014 UTC +++ /branches/bleeding_edge/src/object-observe.js Fri May 2 08:00:47 2014 UTC
@@ -411,8 +411,7 @@
   var callbackInfo = CallbackInfoNormalize(callback);
   if (IS_NULL(GetPendingObservers())) {
     SetPendingObservers(nullProtoObject())
-    GetMicrotaskQueue().push(ObserveMicrotaskRunner);
-    %SetMicrotaskPending(true);
+    EnqueueMicrotask(ObserveMicrotaskRunner);
   }
   GetPendingObservers()[callbackInfo.priority] = callback;
   callbackInfo.push(changeRecord);
=======================================
--- /branches/bleeding_edge/src/promise.js      Wed Apr 30 15:17:51 2014 UTC
+++ /branches/bleeding_edge/src/promise.js      Fri May  2 08:00:47 2014 UTC
@@ -153,13 +153,11 @@
 }

 function PromiseEnqueue(value, tasks) {
-  GetMicrotaskQueue().push(function() {
+  EnqueueMicrotask(function() {
     for (var i = 0; i < tasks.length; i += 2) {
       PromiseHandle(value, tasks[i], tasks[i + 1])
     }
   });
-
-  %SetMicrotaskPending(true);
 }

 function PromiseHandle(value, handler, deferred) {
=======================================
--- /branches/bleeding_edge/src/v8natives.js    Tue Apr 29 06:42:26 2014 UTC
+++ /branches/bleeding_edge/src/v8natives.js    Fri May  2 08:00:47 2014 UTC
@@ -1870,14 +1870,6 @@
 // Eventually, we should move to a real event queue that allows to maintain
 // relative ordering of different kinds of tasks.

-function GetMicrotaskQueue() {
-  var microtaskState = %GetMicrotaskState();
-  if (IS_UNDEFINED(microtaskState.queue)) {
-    microtaskState.queue = new InternalArray;
-  }
-  return microtaskState.queue;
-}
-
 function RunMicrotasks() {
   while (%SetMicrotaskPending(false)) {
     var microtaskState = %GetMicrotaskState();
@@ -1885,7 +1877,7 @@
       return;

     var microtasks = microtaskState.queue;
-    microtaskState.queue = new InternalArray;
+    microtaskState.queue = null;

     for (var i = 0; i < microtasks.length; i++) {
       microtasks[i]();
@@ -1893,7 +1885,11 @@
   }
 }

-function EnqueueExternalMicrotask(fn) {
-  GetMicrotaskQueue().push(fn);
+function EnqueueMicrotask(fn) {
+  var microtaskState = %GetMicrotaskState();
+ if (IS_UNDEFINED(microtaskState.queue) || IS_NULL(microtaskState.queue)) {
+    microtaskState.queue = new InternalArray;
+  }
+  microtaskState.queue.push(fn);
   %SetMicrotaskPending(true);
 }

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