Skip to content

Commit

Permalink
src: use Isolate::TryGetCurrent where appropriate
Browse files Browse the repository at this point in the history
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: #39954
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
addaleax authored and BethGriggs committed Sep 21, 2021
1 parent 98f56d1 commit 842f936
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ BufferValue::BufferValue(Isolate* isolate, Local<Value> value) {

void LowMemoryNotification() {
if (per_process::v8_initialized) {
auto isolate = Isolate::GetCurrent();
auto isolate = Isolate::TryGetCurrent();
if (isolate != nullptr) {
isolate->LowMemoryNotification();
}
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 842f936

Please sign in to comment.