cron: remove all unsafe from Bun.cron
Merged
JA
3mo ago+489+489+012345678901234567890123456789-441-441-012345678901234567890123456789
What
Stacked on #40055 (uses its bun_ptr / host-export generator additions). Takes src/runtime/api/cron.rs from 34 unsafe sites to zero by fixing the layers below rather than annotating call sites:
CronRegisterJob/CronRemoveJobown themselves through aRefPtrreleased infinish(washeap::into_raw+heap::take);finishis one sharedCronJobBasemethod.- The spawned
crontab/launchctl/schtaskschild is abun_spawn::ProcessHandle(owning ref;Drop= detach + deref; typedset_exit_handler<T: ProcessExitOwner>), and argv/env are&[&CStr]end to end via a new safebun_spawn::spawn_process_cstr(options, argv, SpawnEnv)— no raw*const c_chararrays orCStr::from_ptrin the caller. - The promise reactions are
HOST_EXPORTs using a new generator shape: an impl of the formfn(this: ThisPtr<T>, &JSGlobalObject, &CallFrame) -> JsResult<JSValue>gets a thunk that hands back thectxregistered withJSValue::thenas a typedThisPtr(replaces the hand-writtenjsc_host_abi!shims andas_promise_ptr+ThisPtr::newat each reaction; reusable for the other ~20as_promise_ptrsites). - The per-VM job list moves from an erased
Vec<*mut c_void>inbun_jsc::RareDatatoRuntimeState::cron_jobs: Vec<RefPtr<CronJob>>; the pending-promise ref isJsCell<Option<RefPtr<Self>>>instead of a bool + manualref_()/deref();stop()reaches theThisPtrpaths through aself_refback-reference set at allocation; FakeTimers handsstop_dropped_from_fake_heapaThisPtr.
Testing
Debug+ASAN, cronie installed: cron.test.ts 82 pass / 35 skip (Windows-only), in-process-cron.test.ts 27 pass, cron-local-time.test.ts 30 pass; cron-parse.test.ts unchanged (its <50ms case fails on every debug build). By hand: PATH=/nonexistent register/remove reject; register → crontab -l → remove round-trip; stop-inside-callback and pending-promise re-arm under fake timers; worker terminate with a pending cron promise; --hot reload ×3. rust-check-all for x86_64-pc-windows-msvc and aarch64-apple-darwin passes.