From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: VerteDinde <vertedinde@electronjs.org>
Date: Mon, 29 Apr 2024 02:56:27 -0700
Subject: fix: add source location for v8::Task Runner

This patch corresponds with an upstream change which adds
Post*TaskImpl variants of v8::TaskRunner::Post*Task methods,
which take a v8::SourceLocation argument, and makes Post*Task
methods non-virtual. In the original CL, embedders are asked
to override the Post*TaskImpl methods.

This patch can be removed when node's upstream makes a
corresponding change.

CL: https://chromium-review.googlesource.com/c/v8/v8/+/5300826

diff --git a/src/node_platform.cc b/src/node_platform.cc
index 9c4c1e1db5fa7c0ca791e01d9be331e0957e9699..b438b3774d0aa7680fdbc6c6bf39a87893d221b2 100644
--- a/src/node_platform.cc
+++ b/src/node_platform.cc
@@ -307,11 +307,13 @@ void PerIsolatePlatformData::FlushTasks(uv_async_t* handle) {
   platform_data->FlushForegroundTasksInternal();
 }
 
-void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
+void PerIsolatePlatformData::PostIdleTaskImpl(std::unique_ptr<v8::IdleTask> task,
+                                              const v8::SourceLocation& location) {
   UNREACHABLE();
 }
 
-void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
+void PerIsolatePlatformData::PostTaskImpl(std::unique_ptr<Task> task,
+                                          const v8::SourceLocation& location) {
   // The task can be posted from any V8 background worker thread, even when
   // the foreground task runner is being cleaned up by Shutdown(). In that
   // case, make sure we wait until the shutdown is completed (which leads
@@ -330,8 +332,10 @@ void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
   uv_async_send(flush_tasks_);
 }
 
-void PerIsolatePlatformData::PostDelayedTask(
-    std::unique_ptr<Task> task, double delay_in_seconds) {
+void PerIsolatePlatformData::PostDelayedTaskImpl(
+    std::unique_ptr<Task> task,
+    double delay_in_seconds,
+    const v8::SourceLocation& location) {
   if (debug_log_level_ != PlatformDebugLogLevel::kNone) {
     fprintf(stderr,
             "\nPerIsolatePlatformData::PostDelayedTaskImpl %p %f",
@@ -353,13 +357,15 @@ void PerIsolatePlatformData::PostDelayedTask(
   uv_async_send(flush_tasks_);
 }
 
-void PerIsolatePlatformData::PostNonNestableTask(std::unique_ptr<Task> task) {
+void PerIsolatePlatformData::PostNonNestableTaskImpl(std::unique_ptr<Task> task,
+                                                     const v8::SourceLocation& location) {
   PostTask(std::move(task));
 }
 
-void PerIsolatePlatformData::PostNonNestableDelayedTask(
+void PerIsolatePlatformData::PostNonNestableDelayedTaskImpl(
     std::unique_ptr<Task> task,
-    double delay_in_seconds) {
+    double delay_in_seconds,
+    const v8::SourceLocation& location) {
   PostDelayedTask(std::move(task), delay_in_seconds);
 }
 
diff --git a/src/node_platform.h b/src/node_platform.h
index af30ebeb0c8629ab86d1a55fd63610165abfbabf..a0222b4a1b074c6708e390d58d04221717069ac1 100644
--- a/src/node_platform.h
+++ b/src/node_platform.h
@@ -80,18 +80,21 @@ class PerIsolatePlatformData :
   ~PerIsolatePlatformData() override;
 
   std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner() override;
-  void PostTask(std::unique_ptr<v8::Task> task) override;
-  void PostIdleTask(std::unique_ptr<v8::IdleTask> task) override;
-  void PostDelayedTask(std::unique_ptr<v8::Task> task,
-                       double delay_in_seconds) override;
+  void PostTaskImpl(std::unique_ptr<v8::Task> task, const v8::SourceLocation&) override;
+  void PostIdleTaskImpl(std::unique_ptr<v8::IdleTask> task, const v8::SourceLocation&) override;
+  void PostDelayedTaskImpl(std::unique_ptr<v8::Task> task,
+                          double delay_in_seconds,
+                          const v8::SourceLocation&) override;
   bool IdleTasksEnabled() override { return false; }
 
   // Non-nestable tasks are treated like regular tasks.
   bool NonNestableTasksEnabled() const override { return true; }
   bool NonNestableDelayedTasksEnabled() const override { return true; }
-  void PostNonNestableTask(std::unique_ptr<v8::Task> task) override;
-  void PostNonNestableDelayedTask(std::unique_ptr<v8::Task> task,
-                                  double delay_in_seconds) override;
+  void PostNonNestableTaskImpl(std::unique_ptr<v8::Task> task,
+                               const v8::SourceLocation&) override;
+  void PostNonNestableDelayedTaskImpl(std::unique_ptr<v8::Task> task,
+                                      double delay_in_seconds,
+                                      const v8::SourceLocation&) override;
 
   void AddShutdownCallback(void (*callback)(void*), void* data);
   void Shutdown();
