From 82d8f8747a19b93af04465c423e745176b74afcf Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Thu, 31 May 2018 12:10:07 +0200 Subject: [PATCH 1/2] timers: check can_call_into_js in Immediates Do not execute native immediates and prevent infinite loop if it's possible to call into JS --- src/env.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/env.cc b/src/env.cc index f6303e6011f54c..619e459eafce7c 100644 --- a/src/env.cc +++ b/src/env.cc @@ -457,7 +457,7 @@ void Environment::RunAndClearNativeImmediates() { void Environment::CheckImmediate(uv_check_t* handle) { Environment* env = Environment::from_immediate_check_handle(handle); - if (env->immediate_info()->count() == 0) + if (env->immediate_info()->count() == 0 || !env->can_call_into_js()) return; HandleScope scope(env->isolate()); @@ -472,7 +472,7 @@ void Environment::CheckImmediate(uv_check_t* handle) { 0, nullptr, {0, 0}).ToLocalChecked(); - } while (env->immediate_info()->has_outstanding()); + } while (env->immediate_info()->has_outstanding() && env->can_call_into_js()); if (env->immediate_info()->ref_count() == 0) env->ToggleImmediateRef(false); From 8e7e42b8e012fac706b133975361278018439ea3 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Thu, 31 May 2018 14:44:29 +0200 Subject: [PATCH 2/2] fixup: addaleax feedback --- src/env.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/env.cc b/src/env.cc index 619e459eafce7c..4aec62a99f2c50 100644 --- a/src/env.cc +++ b/src/env.cc @@ -457,7 +457,7 @@ void Environment::RunAndClearNativeImmediates() { void Environment::CheckImmediate(uv_check_t* handle) { Environment* env = Environment::from_immediate_check_handle(handle); - if (env->immediate_info()->count() == 0 || !env->can_call_into_js()) + if (env->immediate_info()->count() == 0) return; HandleScope scope(env->isolate()); @@ -465,6 +465,9 @@ void Environment::CheckImmediate(uv_check_t* handle) { env->RunAndClearNativeImmediates(); + if (!env->can_call_into_js()) + return; + do { MakeCallback(env->isolate(), env->process_object(),