Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/node_platform.cc
Expand Up @@ -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);
Expand Down Expand Up @@ -391,12 +391,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 {
Expand All @@ -415,8 +414,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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/node_platform.h
Expand Up @@ -88,7 +88,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);
gireeshpunathil marked this conversation as resolved.
Show resolved Hide resolved
static void RunForegroundTask(uv_timer_t* timer);

struct ShutdownCallback {
Expand All @@ -101,6 +101,7 @@ class PerIsolatePlatformData :
std::shared_ptr<PerIsolatePlatformData> self_reference_;
uint32_t uv_handle_count_ = 1; // 1 = flush_tasks_

v8::Isolate* const isolate_;
gireeshpunathil marked this conversation as resolved.
Show resolved Hide resolved
uv_loop_t* const loop_;
uv_async_t* flush_tasks_ = nullptr;
TaskQueue<v8::Task> foreground_tasks_;
Expand Down