From 9c277c04ad74c50a338dab1c5e9fc1ca6056804d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 24 Feb 2019 22:04:56 +0100 Subject: [PATCH] src: allow running tasks without `Environment` There is no real reason to assume that V8 tasks would have to run in a Node.js `Context`. PR-URL: https://github.com/nodejs/node/pull/26376 Reviewed-By: Gireesh Punathil Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/node_platform.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/node_platform.cc b/src/node_platform.cc index da28de0a844929..9b1c4b4ca9bebd 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -334,9 +334,13 @@ void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr task) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); Environment* env = Environment::GetCurrent(isolate); - InternalCallbackScope cb_scope(env, Local(), { 0, 0 }, - InternalCallbackScope::kAllowEmptyResource); - task->Run(); + if (env != nullptr) { + InternalCallbackScope cb_scope(env, Local(), { 0, 0 }, + InternalCallbackScope::kAllowEmptyResource); + task->Run(); + } else { + task->Run(); + } } void PerIsolatePlatformData::DeleteFromScheduledTasks(DelayedTask* task) {