Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ext/web_stub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::ExtensionTrait;

mod encoding;
mod timers;
use timers::StartTime;

extension!(
deno_web,
Expand All @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion src/ext/web_stub/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down