From c2ac0ca3c2ff140ee22b7722106b7be71ed27000 Mon Sep 17 00:00:00 2001 From: SpiralP Date: Sun, 31 Aug 2025 15:40:19 -0700 Subject: [PATCH] fix(web_stub): initialize `StartTime` state to fix `console.time()` crash --- src/ext/web_stub/mod.rs | 4 ++++ src/ext/web_stub/timers.rs | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ext/web_stub/mod.rs b/src/ext/web_stub/mod.rs index 48e5e45..906dfa0 100644 --- a/src/ext/web_stub/mod.rs +++ b/src/ext/web_stub/mod.rs @@ -8,6 +8,7 @@ use super::ExtensionTrait; mod encoding; mod timers; +use timers::StartTime; extension!( deno_web, @@ -17,6 +18,9 @@ extension!( ], esm_entry_point = "ext:deno_web/init_stub.js", esm = [ dir "src/ext/web_stub", "init_stub.js", "01_dom_exception.js", "02_timers.js", "05_base64.js" ], + state = |state| { + state.put(StartTime::default()); + } ); impl ExtensionTrait<()> for deno_web { fn init((): ()) -> Extension { diff --git a/src/ext/web_stub/timers.rs b/src/ext/web_stub/timers.rs index 340d59e..93a582b 100644 --- a/src/ext/web_stub/timers.rs +++ b/src/ext/web_stub/timers.rs @@ -5,7 +5,21 @@ use std::time::Instant; use deno_core::op2; use deno_core::OpState; -pub type StartTime = Instant; +pub struct StartTime(Instant); + +impl Default for StartTime { + fn default() -> Self { + Self(Instant::now()) + } +} + +impl std::ops::Deref for StartTime { + type Target = Instant; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} // Returns a milliseconds and nanoseconds subsec // since the start time of the deno runtime.