mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
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:
parent
f98975bbbe
commit
d2dcb20bea
7 changed files with 46 additions and 72 deletions
|
@ -329,6 +329,11 @@ pub struct GlobalScope {
|
|||
/// The stack of active group labels for the Console APIs.
|
||||
console_group_stack: DomRefCell<Vec<DOMString>>,
|
||||
|
||||
/// The count map for the Console APIs.
|
||||
///
|
||||
/// <https://console.spec.whatwg.org/#count>
|
||||
console_count_map: DomRefCell<HashMap<DOMString, usize>>,
|
||||
|
||||
/// List of ongoing dynamic module imports.
|
||||
dynamic_modules: DomRefCell<DynamicModuleList>,
|
||||
|
||||
|
@ -790,6 +795,7 @@ impl GlobalScope {
|
|||
frozen_supported_performance_entry_types: DomRefCell::new(Default::default()),
|
||||
https_state: Cell::new(HttpsState::None),
|
||||
console_group_stack: DomRefCell::new(Vec::new()),
|
||||
console_count_map: Default::default(),
|
||||
dynamic_modules: DomRefCell::new(DynamicModuleList::new()),
|
||||
inherited_secure_context,
|
||||
}
|
||||
|
@ -3255,6 +3261,25 @@ impl GlobalScope {
|
|||
let _ = self.console_group_stack.borrow_mut().pop();
|
||||
}
|
||||
|
||||
pub(crate) fn increment_console_count(&self, label: &DOMString) -> usize {
|
||||
*self
|
||||
.console_count_map
|
||||
.borrow_mut()
|
||||
.entry(label.clone())
|
||||
.and_modify(|e| *e += 1)
|
||||
.or_insert(1)
|
||||
}
|
||||
|
||||
pub(crate) fn reset_console_count(&self, label: &DOMString) -> Result<(), ()> {
|
||||
match self.console_count_map.borrow_mut().get_mut(label) {
|
||||
Some(value) => {
|
||||
*value = 0;
|
||||
Ok(())
|
||||
},
|
||||
None => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dynamic_module_list(&self) -> RefMut<DynamicModuleList> {
|
||||
self.dynamic_modules.borrow_mut()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue