Skip to content

Commit bca5dc8

Browse files
authored
Merge pull request #393 from SpiralP/rustyscript-console-time-bug
fix(web_stub): initialize `StartTime` state to fix `console.time()` crash
2 parents 8ef98fb + c2ac0ca commit bca5dc8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ext/web_stub/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::ExtensionTrait;
88

99
mod encoding;
1010
mod timers;
11+
use timers::StartTime;
1112

1213
extension!(
1314
deno_web,
@@ -17,6 +18,9 @@ extension!(
1718
],
1819
esm_entry_point = "ext:deno_web/init_stub.js",
1920
esm = [ dir "src/ext/web_stub", "init_stub.js", "01_dom_exception.js", "02_timers.js", "05_base64.js" ],
21+
state = |state| {
22+
state.put(StartTime::default());
23+
}
2024
);
2125
impl ExtensionTrait<()> for deno_web {
2226
fn init((): ()) -> Extension {

src/ext/web_stub/timers.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@ use std::time::Instant;
55
use deno_core::op2;
66
use deno_core::OpState;
77

8-
pub type StartTime = Instant;
8+
pub struct StartTime(Instant);
9+
10+
impl Default for StartTime {
11+
fn default() -> Self {
12+
Self(Instant::now())
13+
}
14+
}
15+
16+
impl std::ops::Deref for StartTime {
17+
type Target = Instant;
18+
19+
fn deref(&self) -> &Self::Target {
20+
&self.0
21+
}
22+
}
923

1024
// Returns a milliseconds and nanoseconds subsec
1125
// since the start time of the deno runtime.

0 commit comments

Comments
 (0)