Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src: use Isolate::TryGetCurrent where appropriate
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.
  • Loading branch information
addaleax committed Aug 31, 2021
commit 52948a0b549f64fa7d129dc50fcbb6b9fbdd9c8f
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;
Copy link
Copy Markdown
Member

@legendecas legendecas Sep 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this as it claiming that it tells "if it is safe to call v8::Isolate::GetCurrent"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah … I don’t know why, but v8::Isolate::TryGetCurrent() is not something you can call without V8 being initialized first.

} // namespace per_process

Expand Down