diff options
author | Smitty <me@iter.ca> | 2024-03-17 05:50:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-17 09:50:40 +0000 |
commit | d2dcb20beac29eabce02ea59b4944585d5b48a7c (patch) | |
tree | 82f2c9a162f6dfc03b511af834e3d897c1821735 /components/script/dom/console.rs | |
parent | f98975bbbe7cd8cf55f172dae96f8cbc79c0e479 (diff) | |
download | servo-d2dcb20beac29eabce02ea59b4944585d5b48a7c.tar.gz servo-d2dcb20beac29eabce02ea59b4944585d5b48a7c.zip |
Implement console.count/countReset (#31635)
* Implement console.count/countReset
* Address review comment
Signed-off-by: syvb <me@iter.ca>
---------
Signed-off-by: syvb <me@iter.ca>
Diffstat (limited to 'components/script/dom/console.rs')
-rw-r--r-- | components/script/dom/console.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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(); } + + /// <https://console.spec.whatwg.org/#count> + 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); + } + + /// <https://console.spec.whatwg.org/#countreset> + 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.")), + ) + } + } } |