diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-09-20 14:43:19 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-05-10 14:15:17 +0200 |
commit | bcb324c3ffd74147041cf892a0b2840aa340c248 (patch) | |
tree | dd5c72e9c70ad18f8853d0f0a0a1781ad8e97e5d /src/async_wrap.cc | |
parent | 61fd027096c0416a6e9bbe3ee7b7edb4c180725a (diff) | |
download | android-node-v8-bcb324c3ffd74147041cf892a0b2840aa340c248.tar.gz android-node-v8-bcb324c3ffd74147041cf892a0b2840aa340c248.tar.bz2 android-node-v8-bcb324c3ffd74147041cf892a0b2840aa340c248.zip |
src: add can_call_into_js flag
This prevents calls back into JS from the shutdown phase.
Many thanks for Stephen Belanger for reviewing the original version of
this commit in the Ayo.js project.
Refs: https://github.com/ayojs/ayo/pull/82
PR-URL: https://github.com/nodejs/node/pull/19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/async_wrap.cc')
-rw-r--r-- | src/async_wrap.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/async_wrap.cc b/src/async_wrap.cc index f7a6d4e68d..b20e2b746f 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -141,6 +141,7 @@ static void DestroyAsyncIdsCallback(Environment* env, void* data) { do { std::vector<double> destroy_async_id_list; destroy_async_id_list.swap(*env->destroy_async_id_list()); + if (!env->can_call_into_js()) return; for (auto async_id : destroy_async_id_list) { // Want each callback to be cleaned up after itself, instead of cleaning // them all up after the while() loop completes. @@ -166,7 +167,7 @@ void Emit(Environment* env, double async_id, AsyncHooks::Fields type, Local<Function> fn) { AsyncHooks* async_hooks = env->async_hooks(); - if (async_hooks->fields()[type] == 0) + if (async_hooks->fields()[type] == 0 || !env->can_call_into_js()) return; v8::HandleScope handle_scope(env->isolate()); @@ -625,8 +626,10 @@ void AsyncWrap::EmitTraceEventDestroy() { } void AsyncWrap::EmitDestroy(Environment* env, double async_id) { - if (env->async_hooks()->fields()[AsyncHooks::kDestroy] == 0) + if (env->async_hooks()->fields()[AsyncHooks::kDestroy] == 0 || + !env->can_call_into_js()) { return; + } if (env->destroy_async_id_list()->empty()) { env->SetUnrefImmediate(DestroyAsyncIdsCallback, nullptr); |