From 63b056d8d4f0696254cd5fc40a69aee0157fc410 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 3 Sep 2019 22:44:10 -0700 Subject: [PATCH] src: check microtasks before running them PR-URL: https://github.com/nodejs/node/pull/29434 Reviewed-By: Ben Noordhuis Reviewed-By: David Carlier Reviewed-By: Anna Henningsen Reviewed-By: Gus Caplan Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater Reviewed-By: Minwoo Jung --- src/api/callback.cc | 3 ++- src/node_task_queue.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/callback.cc b/src/api/callback.cc index 52a8da35b671d1..e6098d5921a038 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -12,6 +12,7 @@ using v8::HandleScope; using v8::Isolate; using v8::Local; using v8::MaybeLocal; +using v8::MicrotasksScope; using v8::NewStringType; using v8::Object; using v8::String; @@ -100,7 +101,7 @@ void InternalCallbackScope::Close() { if (!env_->can_call_into_js()) return; if (!tick_info->has_tick_scheduled()) { - env_->isolate()->RunMicrotasks(); + MicrotasksScope::PerformCheckpoint(env_->isolate()); } // Make sure the stack unwound properly. If there are nested MakeCallback's diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index e6b4d0b8e211cd..4ff51bc3b80b56 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -21,6 +21,7 @@ using v8::kPromiseRejectWithNoHandler; using v8::kPromiseResolveAfterResolved; using v8::Local; using v8::Message; +using v8::MicrotasksScope; using v8::Number; using v8::Object; using v8::Promise; @@ -43,7 +44,7 @@ static void EnqueueMicrotask(const FunctionCallbackInfo& args) { bool RunNextTicksNative(Environment* env) { TickInfo* tick_info = env->tick_info(); if (!tick_info->has_tick_scheduled() && !tick_info->has_rejection_to_warn()) - env->isolate()->RunMicrotasks(); + MicrotasksScope::PerformCheckpoint(env->isolate()); if (!tick_info->has_tick_scheduled() && !tick_info->has_rejection_to_warn()) return true;