Index: src/isolate.cc |
diff --git a/src/isolate.cc b/src/isolate.cc |
index 3d87e55e33c23a220fb671d39db96cafc6517b64..09113c366d329bb28f92b62fc981193b2735cebb 100644 |
--- a/src/isolate.cc |
+++ b/src/isolate.cc |
@@ -2766,7 +2766,12 @@ void Isolate::RunMicrotasks() { |
// Increase call depth to prevent recursive callbacks. |
v8::Isolate::SuppressMicrotaskExecutionScope suppress( |
reinterpret_cast<v8::Isolate*>(this)); |
+ RunMicrotasksInternal(); |
+ FireMicrotasksCompletedCallback(); |
+} |
+ |
+void Isolate::RunMicrotasksInternal() { |
while (pending_microtask_count() > 0) { |
HandleScope scope(this); |
int num_tasks = pending_microtask_count(); |
@@ -2808,6 +2813,32 @@ void Isolate::RunMicrotasks() { |
} |
+void Isolate::AddMicrotasksCompletedCallback( |
+ MicrotasksCompletedCallback callback) { |
+ for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { |
+ if (callback == microtasks_completed_callbacks_.at(i)) return; |
+ } |
+ microtasks_completed_callbacks_.Add(callback); |
+} |
+ |
+ |
+void Isolate::RemoveMicrotasksCompletedCallback( |
+ MicrotasksCompletedCallback callback) { |
+ for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { |
+ if (callback == microtasks_completed_callbacks_.at(i)) { |
+ microtasks_completed_callbacks_.Remove(i); |
+ } |
+ } |
+} |
+ |
+ |
+void Isolate::FireMicrotasksCompletedCallback() { |
+ for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { |
+ microtasks_completed_callbacks_.at(i)(reinterpret_cast<v8::Isolate*>(this)); |
+ } |
+} |
+ |
+ |
void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) { |
DCHECK(!use_counter_callback_); |
use_counter_callback_ = callback; |