From 2d94f77fd36cf478e1117854e95d5a9a96fccf45 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 20 Mar 2018 02:55:19 +0100 Subject: [PATCH] src: ensure that `SetImmediate()`s have `HandleScope`s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that all native `SetImmediate()` functions have `HandleScope`s if they create handles. PR-URL: https://github.com/nodejs/node/pull/19470 Reviewed-By: Colin Ihrig Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- src/env.cc | 3 +++ src/node_file.cc | 1 + src/node_http2.cc | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/env.cc b/src/env.cc index c876103972fe92..16a24260f626d1 100644 --- a/src/env.cc +++ b/src/env.cc @@ -376,6 +376,9 @@ void Environment::RunAndClearNativeImmediates() { auto drain_list = [&]() { v8::TryCatch try_catch(isolate()); for (auto it = list.begin(); it != list.end(); ++it) { +#ifdef DEBUG + v8::SealHandleScope seal_handle_scope(isolate()); +#endif it->cb_(this, it->data_); if (it->refed_) ref_count++; diff --git a/src/node_file.cc b/src/node_file.cc index 510689607e87a7..7b493de131f6b2 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -178,6 +178,7 @@ inline void FileHandle::Close() { // it is being thrown from within the SetImmediate handler and // there is no JS stack to bubble it to. In other words, tearing // down the process is the only reasonable thing we can do here. + HandleScope handle_scope(env->isolate()); env->ThrowUVException(detail->ret, "close", msg); delete detail; }, detail); diff --git a/src/node_http2.cc b/src/node_http2.cc index 52b0f8d66622a5..63ef4df793c0c5 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -520,6 +520,7 @@ void Http2Stream::EmitStatistics() { static_cast(data) }; if (!HasHttp2Observer(env)) return; + HandleScope handle_scope(env->isolate()); AliasedBuffer& buffer = env->http2_state()->stream_stats_buffer; buffer[IDX_STREAM_STATS_ID] = entry->id(); @@ -558,6 +559,7 @@ void Http2Session::EmitStatistics() { static_cast(data) }; if (!HasHttp2Observer(env)) return; + HandleScope handle_scope(env->isolate()); AliasedBuffer& buffer = env->http2_state()->session_stats_buffer; buffer[IDX_SESSION_STATS_TYPE] = entry->type();