src: avoid Isolate::GetCurrent() for platform implementation

There’s no need to use `Isolate::GetCurrent()`, which is generally
discouraged, as the `Isolate*` pointer can generally be looked up
from the per-Isolate platform data structure.

PR-URL: https://github.com/nodejs/node/pull/32269
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Anna Henningsen authored and Michaël Zasso committed 2020-04-28 16:14:50 +02:00
1 parent df046dec97
commit 8f7f4e5aba
2 files changed
+9 -9

No files matched your search

+7 -8
View File
@@ -222,7 +222,7 @@ int WorkerThreadsTaskRunner::NumberOfWorkerThreads() const {
PerIsolatePlatformData::PerIsolatePlatformData(
Isolate* isolate, uv_loop_t* loop)
: loop_(loop) {
: isolate_(isolate), loop_(loop) {
flush_tasks_ = new uv_async_t();
CHECK_EQ(0, uv_async_init(loop, flush_tasks_, FlushTasks));
flush_tasks_->data = static_cast<void*>(this);
@@ -372,12 +372,11 @@ int NodePlatform::NumberOfWorkerThreads() {
}
void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
Isolate* isolate = Isolate::GetCurrent();
DebugSealHandleScope scope(isolate);
Environment* env = Environment::GetCurrent(isolate);
DebugSealHandleScope scope(isolate_);
Environment* env = Environment::GetCurrent(isolate_);
if (env != nullptr) {
v8::HandleScope scope(isolate);
InternalCallbackScope cb_scope(env, Object::New(isolate), { 0, 0 },
v8::HandleScope scope(isolate_);
InternalCallbackScope cb_scope(env, Object::New(isolate_), { 0, 0 },
InternalCallbackScope::kNoFlags);
task->Run();
} else {
@@ -396,8 +395,8 @@ void PerIsolatePlatformData::DeleteFromScheduledTasks(DelayedTask* task) {
}
void PerIsolatePlatformData::RunForegroundTask(uv_timer_t* handle) {
DelayedTask* delayed = static_cast<DelayedTask*>(handle->data);
RunForegroundTask(std::move(delayed->task));
DelayedTask* delayed = ContainerOf(&DelayedTask::timer, handle);
delayed->platform_data->RunForegroundTask(std::move(delayed->task));
delayed->platform_data->DeleteFromScheduledTasks(delayed);
}
+2 -1
View File
@@ -86,7 +86,7 @@ class PerIsolatePlatformData :
void DecreaseHandleCount();
static void FlushTasks(uv_async_t* handle);
static void RunForegroundTask(std::unique_ptr<v8::Task> task);
void RunForegroundTask(std::unique_ptr<v8::Task> task);
static void RunForegroundTask(uv_timer_t* timer);
struct ShutdownCallback {
@@ -99,6 +99,7 @@ class PerIsolatePlatformData :
std::shared_ptr<PerIsolatePlatformData> self_reference_;
uint32_t uv_handle_count_ = 1; // 1 = flush_tasks_
v8::Isolate* const isolate_;
uv_loop_t* const loop_;
uv_async_t* flush_tasks_ = nullptr;
TaskQueue<v8::Task> foreground_tasks_;