Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Unified Diff: src/isolate.cc

Issue 1731773005: Introduce MicrotasksCompletedCallback. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: DCHECK Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « src/isolate.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698