Index: src/global-handles.cc |
diff --git a/src/global-handles.cc b/src/global-handles.cc |
index aa6542baee922f8f4e517cd6764f8b8ed71290ee..004e55b5bfcd8162fa4bb44d18d8111b35daa13a 100644 |
--- a/src/global-handles.cc |
+++ b/src/global-handles.cc |
@@ -495,6 +495,35 @@ class GlobalHandles::NodeIterator { |
DISALLOW_COPY_AND_ASSIGN(NodeIterator); |
}; |
+class GlobalHandles::PendingPhantomCallbacksSecondPassTask : public v8::Task { |
+ public: |
+ // Takes ownership of the contents of pending_phantom_callbacks, leaving it in |
+ // the same state it would be after a call to Clear(). |
+ PendingPhantomCallbacksSecondPassTask( |
+ List<PendingPhantomCallback>* pending_phantom_callbacks, Isolate* isolate) |
+ : isolate_(isolate) { |
+ pending_phantom_callbacks_.Swap(pending_phantom_callbacks); |
+ } |
+ |
+ ~PendingPhantomCallbacksSecondPassTask() override {} |
+ |
+ void Run() override { |
+ while (pending_phantom_callbacks_.length() != 0) { |
+ auto callback = pending_phantom_callbacks_.RemoveLast(); |
+ DCHECK(callback.node() == nullptr); |
+ // No second pass callback required. |
+ if (callback.callback() == nullptr) continue; |
+ // Fire second pass callback |
+ callback.Invoke(isolate_); |
+ } |
+ pending_phantom_callbacks_.Clear(); |
+ } |
+ |
+ private: |
+ List<PendingPhantomCallback> pending_phantom_callbacks_; |
+ Isolate* isolate_; |
+}; |
jochen (gone - plz use gerrit)
2015/07/03 12:42:27
nit. DISALLOW_COPY_AND_ASSIGN(PendingPhantomCallba
epertoso
2015/07/03 14:38:00
Done.
|
+ |
GlobalHandles::GlobalHandles(Isolate* isolate) |
: isolate_(isolate), |
@@ -804,14 +833,11 @@ int GlobalHandles::DispatchPendingPhantomCallbacks() { |
freed_nodes++; |
} |
} |
- // The second pass empties the list. |
- while (pending_phantom_callbacks_.length() != 0) { |
- auto callback = pending_phantom_callbacks_.RemoveLast(); |
- DCHECK(callback.node() == nullptr); |
- // No second pass callback required. |
- if (callback.callback() == nullptr) continue; |
- // Fire second pass callback. |
- callback.Invoke(isolate()); |
+ if (pending_phantom_callbacks_.length() > 0) { |
+ auto* task = new PendingPhantomCallbacksSecondPassTask( |
+ &pending_phantom_callbacks_, isolate()); |
+ V8::GetCurrentPlatform()->CallOnForegroundThread( |
+ reinterpret_cast<v8::Isolate*>(isolate()), task); |
} |
pending_phantom_callbacks_.Clear(); |
return freed_nodes; |