mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
implement console.timeLog
(#33377)
* Implement console.timeLog Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> * Adjust WPT expectations Signed-off-by: Simon Wülker <simon.wuelker@arcor.de> --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
8c0a566860
commit
cc3c69b953
6 changed files with 34 additions and 54 deletions
|
@ -271,18 +271,29 @@ impl Console {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/time
|
// https://console.spec.whatwg.org/#time
|
||||||
pub fn Time(global: &GlobalScope, label: DOMString) {
|
pub fn Time(global: &GlobalScope, label: DOMString) {
|
||||||
if let Ok(()) = global.time(label.clone()) {
|
if let Ok(()) = global.time(label.clone()) {
|
||||||
let message = DOMString::from(format!("{}: timer started", label));
|
let message = DOMString::from(format!("{label}: timer started"));
|
||||||
console_message(global, message, LogLevel::Log);
|
console_message(global, message, LogLevel::Log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Console/timeEnd
|
// https://console.spec.whatwg.org/#timelog
|
||||||
|
pub fn TimeLog(_cx: JSContext, global: &GlobalScope, label: DOMString, data: Vec<HandleValue>) {
|
||||||
|
if let Ok(delta) = global.time_log(&label) {
|
||||||
|
let message = DOMString::from(format!(
|
||||||
|
"{label}: {delta}ms {}",
|
||||||
|
stringify_handle_values(data)
|
||||||
|
));
|
||||||
|
console_message(global, message, LogLevel::Log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://console.spec.whatwg.org/#timeend
|
||||||
pub fn TimeEnd(global: &GlobalScope, label: DOMString) {
|
pub fn TimeEnd(global: &GlobalScope, label: DOMString) {
|
||||||
if let Ok(delta) = global.time_end(&label) {
|
if let Ok(delta) = global.time_end(&label) {
|
||||||
let message = DOMString::from(format!("{}: {}ms", label, delta));
|
let message = DOMString::from(format!("{label}: {delta}ms"));
|
||||||
console_message(global, message, LogLevel::Log);
|
console_message(global, message, LogLevel::Log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2285,6 +2285,21 @@ impl GlobalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Computes the delta time since a label has been created
|
||||||
|
///
|
||||||
|
/// Returns an error if the label does not exist.
|
||||||
|
pub fn time_log(&self, label: &str) -> Result<u64, ()> {
|
||||||
|
self.console_timers
|
||||||
|
.borrow()
|
||||||
|
.get(label)
|
||||||
|
.ok_or(())
|
||||||
|
.map(|&start| (Instant::now() - start).as_millis() as u64)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Computes the delta time since a label has been created and stops
|
||||||
|
/// tracking the label.
|
||||||
|
///
|
||||||
|
/// Returns an error if the label does not exist.
|
||||||
pub fn time_end(&self, label: &str) -> Result<u64, ()> {
|
pub fn time_end(&self, label: &str) -> Result<u64, ()> {
|
||||||
self.console_timers
|
self.console_timers
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace console {
|
||||||
undefined groupEnd();
|
undefined groupEnd();
|
||||||
|
|
||||||
// Timing
|
// Timing
|
||||||
undefined time(DOMString message);
|
undefined time(optional DOMString label = "default");
|
||||||
undefined timeEnd(DOMString message);
|
undefined timeLog(optional DOMString label = "default", any... data);
|
||||||
|
undefined timeEnd(optional DOMString label = "default");
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
[console-label-conversion.any.html]
|
|
||||||
[console.timeLog()'s label gets converted to string via label.toString() when label is an object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console.timeLog() throws exceptions generated by erroneous label.toString() conversion]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[console-label-conversion.any.worker.html]
|
|
||||||
[console.timeLog()'s label gets converted to string via label.toString() when label is an object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console.timeLog() throws exceptions generated by erroneous label.toString() conversion]
|
|
||||||
expected: FAIL
|
|
|
@ -1,14 +0,0 @@
|
||||||
[console-label-conversion.any.html]
|
|
||||||
[console.timeLog()'s label gets converted to string via label.toString() when label is an object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console.timeLog() throws exceptions generated by erroneous label.toString() conversion]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[console-label-conversion.any.worker.html]
|
|
||||||
[console.timeLog()'s label gets converted to string via label.toString() when label is an object]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console.timeLog() throws exceptions generated by erroneous label.toString() conversion]
|
|
||||||
expected: FAIL
|
|
19
tests/wpt/meta/console/idlharness.any.js.ini
vendored
19
tests/wpt/meta/console/idlharness.any.js.ini
vendored
|
@ -14,16 +14,6 @@
|
||||||
[console namespace: operation dirxml(any...)]
|
[console namespace: operation dirxml(any...)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[console namespace: operation time(optional DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console namespace: operation timeLog(optional DOMString, any...)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console namespace: operation timeEnd(optional DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[idlharness.any.worker.html]
|
[idlharness.any.worker.html]
|
||||||
[console namespace: operation assert(optional boolean, any...)]
|
[console namespace: operation assert(optional boolean, any...)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
@ -39,12 +29,3 @@
|
||||||
|
|
||||||
[console namespace: operation dirxml(any...)]
|
[console namespace: operation dirxml(any...)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[console namespace: operation time(optional DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console namespace: operation timeLog(optional DOMString, any...)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[console namespace: operation timeEnd(optional DOMString)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue