From 4b386e3dbe4563266fd6d9effee52f80f11e1a7f Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 6 Dec 2020 16:35:06 +0100 Subject: [PATCH] src: add missing context scopes Add scopes that ensure that the context associated with the current Environment is always entered when working with it. PR-URL: https://github.com/nodejs/node/pull/36413 Reviewed-By: Colin Ihrig Reviewed-By: Gus Caplan Reviewed-By: Benjamin Gruenbaum Reviewed-By: Gireesh Punathil Reviewed-By: James M Snell Reviewed-By: Rich Trott --- src/env.cc | 2 ++ src/node_file.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/env.cc b/src/env.cc index 1f34a71afb2429..fdc29644bfcb3c 100644 --- a/src/env.cc +++ b/src/env.cc @@ -503,6 +503,8 @@ void Environment::InitializeLibuv() { [](uv_async_t* async) { Environment* env = ContainerOf( &Environment::task_queues_async_, async); + HandleScope handle_scope(env->isolate()); + Context::Scope context_scope(env->context()); env->RunAndClearNativeImmediates(); }); uv_unref(reinterpret_cast(&task_queues_async_)); diff --git a/src/node_file.cc b/src/node_file.cc index 074935b51aa66b..4e975530b2c63c 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -288,6 +288,7 @@ inline void FileHandle::Close() { void FileHandle::CloseReq::Resolve() { Isolate* isolate = env()->isolate(); HandleScope scope(isolate); + Context::Scope context_scope(env()->context()); InternalCallbackScope callback_scope(this); Local promise = promise_.Get(isolate); Local resolver = promise.As(); @@ -297,6 +298,7 @@ void FileHandle::CloseReq::Resolve() { void FileHandle::CloseReq::Reject(Local reason) { Isolate* isolate = env()->isolate(); HandleScope scope(isolate); + Context::Scope context_scope(env()->context()); InternalCallbackScope callback_scope(this); Local promise = promise_.Get(isolate); Local resolver = promise.As();