From 842f936e040373b41a4c1e4c95df9b2f580f46af Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 31 Aug 2021 11:16:45 +0200 Subject: [PATCH] src: use Isolate::TryGetCurrent where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In two places, we call `Isolate::GetCurrent()` even though that is technically invalid usage of the function. Now that V8 exposes `Isolate::TryGetCurrent()`, we can do this in a proper way. PR-URL: https://github.com/nodejs/node/pull/39954 Reviewed-By: Michaël Zasso Reviewed-By: Tobias Nießen Reviewed-By: Darshan Sen Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- src/node.cc | 2 +- src/node_errors.cc | 2 +- src/util.cc | 2 +- src/util.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node.cc b/src/node.cc index 3ee25ebbd67a01..acf4f0fac03c0b 100644 --- a/src/node.cc +++ b/src/node.cc @@ -147,7 +147,7 @@ unsigned int reverted_cve = 0; // util.h // Tells whether the per-process V8::Initialize() is called and -// if it is safe to call v8::Isolate::GetCurrent(). +// if it is safe to call v8::Isolate::TryGetCurrent(). bool v8_initialized = false; // node_internals.h diff --git a/src/node_errors.cc b/src/node_errors.cc index 0e4ba26e1bcb70..3028892b0807e3 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -430,7 +430,7 @@ void OnFatalError(const char* location, const char* message) { FPrintF(stderr, "FATAL ERROR: %s\n", message); } - Isolate* isolate = Isolate::GetCurrent(); + Isolate* isolate = Isolate::TryGetCurrent(); Environment* env = nullptr; if (isolate != nullptr) { env = Environment::GetCurrent(isolate); diff --git a/src/util.cc b/src/util.cc index e181fdf568cd18..bae5a47a06d8de 100644 --- a/src/util.cc +++ b/src/util.cc @@ -128,7 +128,7 @@ BufferValue::BufferValue(Isolate* isolate, Local value) { void LowMemoryNotification() { if (per_process::v8_initialized) { - auto isolate = Isolate::GetCurrent(); + auto isolate = Isolate::TryGetCurrent(); if (isolate != nullptr) { isolate->LowMemoryNotification(); } diff --git a/src/util.h b/src/util.h index 050e4bda35a139..43dac02110adbf 100644 --- a/src/util.h +++ b/src/util.h @@ -91,7 +91,7 @@ inline T MultiplyWithOverflowCheck(T a, T b); namespace per_process { // Tells whether the per-process V8::Initialize() is called and -// if it is safe to call v8::Isolate::GetCurrent(). +// if it is safe to call v8::Isolate::TryGetCurrent(). extern bool v8_initialized; } // namespace per_process