aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/globalscope.rs
diff options
context:
space:
mode:
authorSimon Wülker <simon.wuelker@arcor.de>2024-09-09 18:48:49 +0200
committerGitHub <noreply@github.com>2024-09-09 16:48:49 +0000
commitcc3c69b95364268610858f4a149d84c4cfee1a5f (patch)
tree28901322258aa2b6611839d3c464950d3b77f16e /components/script/dom/globalscope.rs
parent8c0a566860cf0f43662dc9d6c3474ae194c1a9fc (diff)
downloadservo-cc3c69b95364268610858f4a149d84c4cfee1a5f.tar.gz
servo-cc3c69b95364268610858f4a149d84c4cfee1a5f.zip
implement `console.timeLog` (#33377)
* Implement console.timeLog Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Adjust WPT expectations Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r--components/script/dom/globalscope.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index 2caf00da4cf..a14a750015c 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -2285,6 +2285,21 @@ impl GlobalScope {
}
}
+ /// Computes the delta time since a label has been created
+ ///
+ /// Returns an error if the label does not exist.
+ pub fn time_log(&self, label: &str) -> Result<u64, ()> {
+ self.console_timers
+ .borrow()
+ .get(label)
+ .ok_or(())
+ .map(|&start| (Instant::now() - start).as_millis() as u64)
+ }
+
+ /// Computes the delta time since a label has been created and stops
+ /// tracking the label.
+ ///
+ /// Returns an error if the label does not exist.
pub fn time_end(&self, label: &str) -> Result<u64, ()> {
self.console_timers
.borrow_mut()