Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd55a9a

Browse filesBrowse files
addaleaxMylesBorins
authored andcommitted
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: #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>
1 parent 11650c6 commit bd55a9a
Copy full SHA for bd55a9a

File tree

Expand file treeCollapse file tree

2 files changed

+9
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-9
lines changed
Open diff view settings
Collapse file

‎src/node_platform.cc‎

Copy file name to clipboardExpand all lines: src/node_platform.cc
+7-8Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ int WorkerThreadsTaskRunner::NumberOfWorkerThreads() const {
222222

223223
PerIsolatePlatformData::PerIsolatePlatformData(
224224
Isolate* isolate, uv_loop_t* loop)
225-
: loop_(loop) {
225+
: isolate_(isolate), loop_(loop) {
226226
flush_tasks_ = new uv_async_t();
227227
CHECK_EQ(0, uv_async_init(loop, flush_tasks_, FlushTasks));
228228
flush_tasks_->data = static_cast<void*>(this);
@@ -372,12 +372,11 @@ int NodePlatform::NumberOfWorkerThreads() {
372372
}
373373

374374
void PerIsolatePlatformData::RunForegroundTask(std::unique_ptr<Task> task) {
375-
Isolate* isolate = Isolate::GetCurrent();
376-
DebugSealHandleScope scope(isolate);
377-
Environment* env = Environment::GetCurrent(isolate);
375+
DebugSealHandleScope scope(isolate_);
376+
Environment* env = Environment::GetCurrent(isolate_);
378377
if (env != nullptr) {
379-
v8::HandleScope scope(isolate);
380-
InternalCallbackScope cb_scope(env, Object::New(isolate), { 0, 0 },
378+
v8::HandleScope scope(isolate_);
379+
InternalCallbackScope cb_scope(env, Object::New(isolate_), { 0, 0 },
381380
InternalCallbackScope::kNoFlags);
382381
task->Run();
383382
} else {
@@ -396,8 +395,8 @@ void PerIsolatePlatformData::DeleteFromScheduledTasks(DelayedTask* task) {
396395
}
397396

398397
void PerIsolatePlatformData::RunForegroundTask(uv_timer_t* handle) {
399-
DelayedTask* delayed = static_cast<DelayedTask*>(handle->data);
400-
RunForegroundTask(std::move(delayed->task));
398+
DelayedTask* delayed = ContainerOf(&DelayedTask::timer, handle);
399+
delayed->platform_data->RunForegroundTask(std::move(delayed->task));
401400
delayed->platform_data->DeleteFromScheduledTasks(delayed);
402401
}
403402

Collapse file

‎src/node_platform.h‎

Copy file name to clipboardExpand all lines: src/node_platform.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class PerIsolatePlatformData :
8686
void DecreaseHandleCount();
8787

8888
static void FlushTasks(uv_async_t* handle);
89-
static void RunForegroundTask(std::unique_ptr<v8::Task> task);
89+
void RunForegroundTask(std::unique_ptr<v8::Task> task);
9090
static void RunForegroundTask(uv_timer_t* timer);
9191

9292
struct ShutdownCallback {
@@ -99,6 +99,7 @@ class PerIsolatePlatformData :
9999
std::shared_ptr<PerIsolatePlatformData> self_reference_;
100100
uint32_t uv_handle_count_ = 1; // 1 = flush_tasks_
101101

102+
v8::Isolate* const isolate_;
102103
uv_loop_t* const loop_;
103104
uv_async_t* flush_tasks_ = nullptr;
104105
TaskQueue<v8::Task> foreground_tasks_;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.