From d2dcb20beac29eabce02ea59b4944585d5b48a7c Mon Sep 17 00:00:00 2001 From: Smitty Date: Sun, 17 Mar 2024 05:50:40 -0400 Subject: Implement console.count/countReset (#31635) * Implement console.count/countReset * Address review comment Signed-off-by: syvb --------- Signed-off-by: syvb --- components/script/dom/console.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'components/script/dom/console.rs') diff --git a/components/script/dom/console.rs b/components/script/dom/console.rs index f8547c449ff..737bb35b926 100644 --- a/components/script/dom/console.rs +++ b/components/script/dom/console.rs @@ -296,4 +296,21 @@ impl Console { pub fn GroupEnd(global: &GlobalScope) { global.pop_console_group(); } + + /// + pub fn Count(global: &GlobalScope, label: DOMString) { + let count = global.increment_console_count(&label); + let message = DOMString::from(format!("{label}: {count}")); + console_message(global, message, LogLevel::Log); + } + + /// + pub fn CountReset(global: &GlobalScope, label: DOMString) { + if global.reset_console_count(&label).is_err() { + Self::internal_warn( + global, + DOMString::from(format!("Counter “{label}” doesn’t exist.")), + ) + } + } } -- cgit v1.2.3