@@ -3012,20 +3012,21 @@ v8::StartupData v8__SnapshotCreator__CreateBlob(
30123012 return self->CreateBlob (function_code_handling);
30133013}
30143014
3015- // Rust-side callbacks for the trait-based NotifyingPlatform.
3016- // `context` is a pointer to a Rust Box<dyn ForegroundTaskCallback>.
3017- extern " C" {
3018- void v8__Platform__NotifyingPlatform__onForegroundTaskPosted (
3019- void * context, void * isolate, double delay_in_seconds);
3020- void v8__Platform__NotifyingPlatform__dropContext (void * context);
3021- }
3022-
3023- // TaskRunner wrapper that intercepts all PostTask* calls and notifies
3024- // the embedder (via a Rust trait) before delegating to the real runner.
3025- class NotifyingTaskRunner final : public v8::TaskRunner {
3015+ // Rust-side callbacks for trait-based CustomPlatform (PlatformImpl trait).
3016+ // `this` is a pointer to the CustomPlatform instance, used by Rust to
3017+ // recover the Box<dyn PlatformImpl> stored at the same offset.
3018+ void v8__Platform__CustomPlatform__BASE__onForegroundTaskPosted (
3019+ void * this_, void * isolate, double delay_in_seconds);
3020+ void v8__Platform__CustomPlatform__BASE__onIsolateShutdown (void * this_,
3021+ void * isolate);
3022+ void v8__Platform__CustomPlatform__BASE__DROP (void * this_);
3023+
3024+ // TaskRunner wrapper that intercepts all PostTask* calls and dispatches
3025+ // to the Rust PlatformImpl trait via the CustomPlatform context.
3026+ class CustomTaskRunner final : public v8::TaskRunner {
30263027 public:
3027- NotifyingTaskRunner (std::shared_ptr<v8::TaskRunner> wrapped, void * context,
3028- v8::Isolate* isolate)
3028+ CustomTaskRunner (std::shared_ptr<v8::TaskRunner> wrapped, void * context,
3029+ v8::Isolate* isolate)
30293030 : wrapped_(std::move(wrapped)), context_(context), isolate_(isolate) {}
30303031
30313032 bool IdleTasksEnabled () override { return wrapped_->IdleTasksEnabled (); }
@@ -3040,20 +3041,20 @@ class NotifyingTaskRunner final : public v8::TaskRunner {
30403041 void PostTaskImpl (std::unique_ptr<v8::Task> task,
30413042 const v8::SourceLocation& location) override {
30423043 wrapped_->PostTask (std::move (task), location);
3043- v8__Platform__NotifyingPlatform__onForegroundTaskPosted (
3044+ v8__Platform__CustomPlatform__BASE__onForegroundTaskPosted (
30443045 context_, static_cast <void *>(isolate_), 0.0 );
30453046 }
30463047 void PostNonNestableTaskImpl (std::unique_ptr<v8::Task> task,
30473048 const v8::SourceLocation& location) override {
30483049 wrapped_->PostNonNestableTask (std::move (task), location);
3049- v8__Platform__NotifyingPlatform__onForegroundTaskPosted (
3050+ v8__Platform__CustomPlatform__BASE__onForegroundTaskPosted (
30503051 context_, static_cast <void *>(isolate_), 0.0 );
30513052 }
30523053 void PostDelayedTaskImpl (std::unique_ptr<v8::Task> task,
30533054 double delay_in_seconds,
30543055 const v8::SourceLocation& location) override {
30553056 wrapped_->PostDelayedTask (std::move (task), delay_in_seconds, location);
3056- v8__Platform__NotifyingPlatform__onForegroundTaskPosted (
3057+ v8__Platform__CustomPlatform__BASE__onForegroundTaskPosted (
30573058 context_, static_cast <void *>(isolate_),
30583059 delay_in_seconds > 0 ? delay_in_seconds : 0.0 );
30593060 }
@@ -3062,14 +3063,14 @@ class NotifyingTaskRunner final : public v8::TaskRunner {
30623063 const v8::SourceLocation& location) override {
30633064 wrapped_->PostNonNestableDelayedTask (std::move (task), delay_in_seconds,
30643065 location);
3065- v8__Platform__NotifyingPlatform__onForegroundTaskPosted (
3066+ v8__Platform__CustomPlatform__BASE__onForegroundTaskPosted (
30663067 context_, static_cast <void *>(isolate_),
30673068 delay_in_seconds > 0 ? delay_in_seconds : 0.0 );
30683069 }
30693070 void PostIdleTaskImpl (std::unique_ptr<v8::IdleTask> task,
30703071 const v8::SourceLocation& location) override {
30713072 wrapped_->PostIdleTask (std::move (task), location);
3072- v8__Platform__NotifyingPlatform__onForegroundTaskPosted (
3073+ v8__Platform__CustomPlatform__BASE__onForegroundTaskPosted (
30733074 context_, static_cast <void *>(isolate_), 0.0 );
30743075 }
30753076
@@ -3079,19 +3080,19 @@ class NotifyingTaskRunner final : public v8::TaskRunner {
30793080 v8::Isolate* isolate_;
30803081};
30813082
3082- // Platform wrapper that intercepts GetForegroundTaskRunner to return
3083- // NotifyingTaskRunner instances, dispatching to a Rust trait object .
3084- class NotifyingPlatform : public v8 ::platform::DefaultPlatform {
3083+ // Generic Platform subclass that delegates virtual method overrides to a
3084+ // Rust PlatformImpl trait object, following the inspector API pattern .
3085+ class CustomPlatform : public v8 ::platform::DefaultPlatform {
30853086 using IdleTaskSupport = v8::platform::IdleTaskSupport;
30863087
30873088 public:
3088- NotifyingPlatform (int thread_pool_size, IdleTaskSupport idle_task_support,
3089- void * context)
3089+ CustomPlatform (int thread_pool_size, IdleTaskSupport idle_task_support,
3090+ void * context)
30903091 : DefaultPlatform(thread_pool_size, idle_task_support),
30913092 context_ (context) {}
30923093
3093- ~NotifyingPlatform () override {
3094- v8__Platform__NotifyingPlatform__dropContext (context_);
3094+ ~CustomPlatform () override {
3095+ v8__Platform__CustomPlatform__BASE__DROP (context_);
30953096 }
30963097
30973098 std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner (
@@ -3104,10 +3105,10 @@ class NotifyingPlatform : public v8::platform::DefaultPlatform {
31043105 auto runner = it->second .lock ();
31053106 if (runner) return runner;
31063107 }
3107- auto notifying =
3108- std::make_shared<NotifyingTaskRunner >(original, context_, isolate);
3109- runners_[key] = notifying ;
3110- return notifying ;
3108+ auto custom =
3109+ std::make_shared<CustomTaskRunner >(original, context_, isolate);
3110+ runners_[key] = custom ;
3111+ return custom ;
31113112 }
31123113
31133114 void NotifyIsolateShutdown (v8::Isolate* isolate) {
@@ -3121,6 +3122,8 @@ class NotifyingPlatform : public v8::platform::DefaultPlatform {
31213122 }
31223123 }
31233124 }
3125+ v8__Platform__CustomPlatform__BASE__onIsolateShutdown (
3126+ context_, static_cast <void *>(isolate));
31243127 DefaultPlatform::NotifyIsolateShutdown (isolate);
31253128 }
31263129
@@ -3132,7 +3135,7 @@ class NotifyingPlatform : public v8::platform::DefaultPlatform {
31323135 void * context_;
31333136 std::mutex mutex_;
31343137 std::map<std::pair<v8::Isolate*, v8::TaskPriority>,
3135- std::weak_ptr<NotifyingTaskRunner >>
3138+ std::weak_ptr<CustomTaskRunner >>
31363139 runners_;
31373140};
31383141
@@ -3189,14 +3192,14 @@ v8::Platform* v8__Platform__NewSingleThreadedDefaultPlatform(
31893192 .release ();
31903193}
31913194
3192- v8::Platform* v8__Platform__NewNotifyingPlatform (int thread_pool_size,
3193- bool idle_task_support,
3194- void * context) {
3195+ v8::Platform* v8__Platform__NewCustomPlatform (int thread_pool_size,
3196+ bool idle_task_support,
3197+ void * context) {
31953198 if (thread_pool_size < 1 ) {
31963199 thread_pool_size = std::thread::hardware_concurrency ();
31973200 }
31983201 thread_pool_size = std::max (std::min (thread_pool_size, 16 ), 1 );
3199- return std::make_unique<NotifyingPlatform >(
3202+ return std::make_unique<CustomPlatform >(
32003203 thread_pool_size,
32013204 idle_task_support ? v8::platform::IdleTaskSupport::kEnabled
32023205 : v8::platform::IdleTaskSupport::kDisabled ,
0 commit comments