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>
This commit is contained in:
Smitty 2024-03-17 05:50:40 -04:00 committed by GitHub
parent f98975bbbe
commit d2dcb20bea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 46 additions and 72 deletions

View file

@ -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}” doesnt exist.")),
)
}
}
}