Skip to content

Commit 1062e03

Browse files
committed
clean up
1 parent 1b1694c commit 1062e03

File tree

2 files changed

+8
-68
lines changed

2 files changed

+8
-68
lines changed

src/binding.cc

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,8 +3025,6 @@ void v8__Platform__CustomPlatform__BASE__PostNonNestableDelayedTask(
30253025
void* context, void* isolate, double delay_in_seconds);
30263026
void v8__Platform__CustomPlatform__BASE__PostIdleTask(void* context,
30273027
void* isolate);
3028-
void v8__Platform__CustomPlatform__BASE__NotifyIsolateShutdown(void* context,
3029-
void* isolate);
30303028
void 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).
30963099
class 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

32663231
void 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

32793236
void v8__Platform__DELETE(v8::Platform* self) { delete self; }

src/platform.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,6 @@ pub trait PlatformImpl: Send + Sync {
127127
///
128128
/// Same semantics as [`post_task`](Self::post_task).
129129
fn post_idle_task(&self, isolate_ptr: *mut std::ffi::c_void) {}
130-
131-
// ---- Platform virtual methods ----
132-
133-
/// Called when `Platform::NotifyIsolateShutdown` is invoked.
134-
///
135-
/// The default `DefaultPlatform` cleanup runs after this callback
136-
/// returns.
137-
fn notify_isolate_shutdown(&self, isolate_ptr: *mut std::ffi::c_void) {}
138130
}
139131

140132
// FFI callbacks called from C++ CustomPlatform/CustomTaskRunner.
@@ -187,15 +179,6 @@ unsafe extern "C" fn v8__Platform__CustomPlatform__BASE__PostIdleTask(
187179
imp.post_idle_task(isolate);
188180
}
189181

190-
#[unsafe(no_mangle)]
191-
unsafe extern "C" fn v8__Platform__CustomPlatform__BASE__NotifyIsolateShutdown(
192-
context: *mut std::ffi::c_void,
193-
isolate: *mut std::ffi::c_void,
194-
) {
195-
let imp = unsafe { &*(context as *const Box<dyn PlatformImpl>) };
196-
imp.notify_isolate_shutdown(isolate);
197-
}
198-
199182
#[unsafe(no_mangle)]
200183
unsafe extern "C" fn v8__Platform__CustomPlatform__BASE__DROP(
201184
context: *mut std::ffi::c_void,

0 commit comments

Comments
 (0)