Auto merge of #27088 - jdm:group, r=ferjm

Implement Console grouping APIs.

These are used by Hubs and other sites we want to run.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #9274
- [x] These changes do not require tests because we can't test stdout content or devtools messages.
This commit is contained in:
bors-servo 2020-07-07 01:24:03 -04:00 committed by GitHub
commit cbbbe16936
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 59 deletions

View file

@ -295,6 +295,9 @@ pub struct GlobalScope {
/// currect https state (from previous request)
https_state: Cell<HttpsState>,
/// The stack of active group labels for the Console APIs.
console_group_stack: DomRefCell<Vec<DOMString>>,
}
/// A wrapper for glue-code between the ipc router and the event-loop.
@ -744,6 +747,7 @@ impl GlobalScope {
gpu_id_hub,
frozen_supported_performance_entry_types: DomRefCell::new(Default::default()),
https_state: Cell::new(HttpsState::None),
console_group_stack: DomRefCell::new(Vec::new()),
}
}
@ -2934,6 +2938,21 @@ impl GlobalScope {
pub fn wgpu_id_hub(&self) -> Arc<Mutex<Identities>> {
self.gpu_id_hub.clone()
}
pub(crate) fn current_group_label(&self) -> Option<DOMString> {
self.console_group_stack
.borrow()
.last()
.map(|label| DOMString::from(format!("[{}]", label)))
}
pub(crate) fn push_console_group(&self, group: DOMString) {
self.console_group_stack.borrow_mut().push(group);
}
pub(crate) fn pop_console_group(&self) {
let _ = self.console_group_stack.borrow_mut().pop();
}
}
fn timestamp_in_ms(time: Timespec) -> u64 {