@@ -3025,8 +3025,6 @@ void v8__Platform__CustomPlatform__BASE__PostNonNestableDelayedTask(
30253025 void * context, void * isolate, double delay_in_seconds);
30263026void v8__Platform__CustomPlatform__BASE__PostIdleTask (void * context,
30273027 void * isolate);
3028- void v8__Platform__CustomPlatform__BASE__NotifyIsolateShutdown (void * context,
3029- void * isolate);
30303028void v8__Platform__CustomPlatform__BASE__DROP (void * context);
30313029}
30323030
@@ -3091,35 +3089,22 @@ class CustomTaskRunner final : public v8::TaskRunner {
30913089};
30923090
30933091// Platform subclass that overrides GetForegroundTaskRunner to wrap each
3094- // isolate's runner with a CustomTaskRunner, and intercepts
3095- // NotifyIsolateShutdown. Follows the inspector API pattern.
3092+ // Platform subclass that wraps each isolate's TaskRunner to notify Rust
3093+ // when foreground tasks are posted. Follows the inspector API pattern.
3094+ //
3095+ // NotifyIsolateShutdown is NOT intercepted here because it is not virtual
3096+ // on DefaultPlatform — V8's free function does static_cast<DefaultPlatform*>
3097+ // and calls it directly, bypassing any override. Isolate cleanup must be
3098+ // handled on the Rust side (e.g. in the isolate's Drop impl).
30963099class CustomPlatform : public v8 ::platform::DefaultPlatform {
30973100 using IdleTaskSupport = v8::platform::IdleTaskSupport;
30983101
3099- // Magic value used to identify CustomPlatform instances at runtime.
3100- // v8::platform::NotifyIsolateShutdown does static_cast<DefaultPlatform*>
3101- // which bypasses our non-virtual NotifyIsolateShutdown, so the FFI
3102- // wrapper needs to detect CustomPlatform and dispatch correctly.
3103- static constexpr uint64_t kMagic = 0x4375'7374'506C'6174 ; // "CustPlat"
3104-
31053102 public:
31063103 CustomPlatform (int thread_pool_size, IdleTaskSupport idle_task_support,
31073104 void * context)
31083105 : DefaultPlatform(thread_pool_size, idle_task_support),
3109- magic_ (kMagic ),
31103106 context_ (context) {}
31113107
3112- static bool IsCustomPlatform (v8::Platform* platform) {
3113- auto * dp = static_cast <DefaultPlatform*>(platform);
3114- auto * maybe_custom = static_cast <CustomPlatform*>(dp);
3115- return maybe_custom->magic_ == kMagic ;
3116- }
3117-
3118- static CustomPlatform* Cast (v8::Platform* platform) {
3119- return static_cast <CustomPlatform*>(
3120- static_cast <DefaultPlatform*>(platform));
3121- }
3122-
31233108 // SAFETY: The platform is single-owner (via unique_ptr). The destructor
31243109 // runs after all isolates have been disposed and no more task runner
31253110 // callbacks can fire, so DROP does not race with other callbacks.
@@ -3143,25 +3128,6 @@ class CustomPlatform : public v8::platform::DefaultPlatform {
31433128 return custom;
31443129 }
31453130
3146- // NotifyIsolateShutdown is not virtual on DefaultPlatform, so this
3147- // hides the base method. This works because callers always go through
3148- // the CustomPlatform* type (via the platform shared_ptr).
3149- void NotifyIsolateShutdown (v8::Isolate* isolate) {
3150- {
3151- std::lock_guard<std::mutex> lock (mutex_);
3152- for (auto it = runners_.begin (); it != runners_.end ();) {
3153- if (it->first .first == isolate) {
3154- it = runners_.erase (it);
3155- } else {
3156- ++it;
3157- }
3158- }
3159- }
3160- v8__Platform__CustomPlatform__BASE__NotifyIsolateShutdown (
3161- context_, static_cast <void *>(isolate));
3162- DefaultPlatform::NotifyIsolateShutdown (isolate);
3163- }
3164-
31653131 // Disable thread-isolated allocations (same as UnprotectedDefaultPlatform).
31663132 // Required when isolates may be created on threads other than the one that
31673133 // called v8::V8::Initialize (e.g. worker threads in Deno).
@@ -3170,7 +3136,6 @@ class CustomPlatform : public v8::platform::DefaultPlatform {
31703136 }
31713137
31723138 private:
3173- uint64_t magic_;
31743139 void * context_;
31753140 std::mutex mutex_;
31763141 // weak_ptr so runners are kept alive only while V8 holds a reference.
@@ -3265,15 +3230,7 @@ void v8__Platform__RunIdleTasks(v8::Platform* platform, v8::Isolate* isolate,
32653230
32663231void v8__Platform__NotifyIsolateShutdown (v8::Platform* platform,
32673232 v8::Isolate* isolate) {
3268- // v8::platform::NotifyIsolateShutdown does static_cast<DefaultPlatform*>
3269- // and calls the non-virtual NotifyIsolateShutdown, which would bypass
3270- // CustomPlatform's override. Dispatch to CustomPlatform directly when
3271- // applicable so the Rust callback fires.
3272- if (CustomPlatform::IsCustomPlatform (platform)) {
3273- CustomPlatform::Cast (platform)->NotifyIsolateShutdown (isolate);
3274- } else {
3275- v8::platform::NotifyIsolateShutdown (platform, isolate);
3276- }
3233+ v8::platform::NotifyIsolateShutdown (platform, isolate);
32773234}
32783235
32793236void v8__Platform__DELETE (v8::Platform* self) { delete self; }
0 commit comments