From 50a82085752e9d12899f11908c68ce5c980e9be8 Mon Sep 17 00:00:00 2001 From: Paul Wagener Date: Tue, 5 Dec 2023 00:14:13 +0100 Subject: [PATCH] Implement User Timing Level 3 --- crates/web-sys/Cargo.toml | 2 + .../web-sys/src/features/gen_Performance.rs | 65 +++++++++++--- .../src/features/gen_PerformanceMark.rs | 25 ++++++ .../features/gen_PerformanceMarkOptions.rs | 59 +++++++++++++ .../src/features/gen_PerformanceMeasure.rs | 7 ++ .../features/gen_PerformanceMeasureOptions.rs | 85 +++++++++++++++++++ crates/web-sys/src/features/mod.rs | 12 +++ .../webidls/enabled/Performance.webidl | 8 +- .../webidls/enabled/PerformanceMark.webidl | 5 +- .../enabled/PerformanceMarkOptions.webidl | 14 +++ .../webidls/enabled/PerformanceMeasure.webidl | 4 +- .../enabled/PerformanceMeasureOptions.webidl | 16 ++++ 12 files changed, 282 insertions(+), 20 deletions(-) create mode 100644 crates/web-sys/src/features/gen_PerformanceMarkOptions.rs create mode 100644 crates/web-sys/src/features/gen_PerformanceMeasureOptions.rs create mode 100644 crates/web-sys/webidls/enabled/PerformanceMarkOptions.webidl create mode 100644 crates/web-sys/webidls/enabled/PerformanceMeasureOptions.webidl diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index baa3d3529c6..60dac9750a3 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -928,7 +928,9 @@ PerformanceEntry = [] PerformanceEntryEventInit = [] PerformanceEntryFilterOptions = [] PerformanceMark = ["PerformanceEntry"] +PerformanceMarkOptions = [] PerformanceMeasure = ["PerformanceEntry"] +PerformanceMeasureOptions = [] PerformanceNavigation = [] PerformanceNavigationTiming = ["PerformanceEntry", "PerformanceResourceTiming"] PerformanceObserver = [] diff --git a/crates/web-sys/src/features/gen_Performance.rs b/crates/web-sys/src/features/gen_Performance.rs index 1ef04f761d9..998c94fd763 100644 --- a/crates/web-sys/src/features/gen_Performance.rs +++ b/crates/web-sys/src/features/gen_Performance.rs @@ -116,43 +116,84 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `Performance`*"] pub fn get_entries_by_type(this: &Performance, entry_type: &str) -> ::js_sys::Array; + #[cfg(feature = "PerformanceMark")] # [wasm_bindgen (catch , method , structural , js_class = "Performance" , js_name = mark)] #[doc = "The `mark()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark)"] #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `Performance`*"] - pub fn mark(this: &Performance, mark_name: &str) -> Result<(), JsValue>; + #[doc = "*This API requires the following crate features to be activated: `Performance`, `PerformanceMark`*"] + pub fn mark(this: &Performance, mark_name: &str) -> Result; + #[cfg(all(feature = "PerformanceMark", feature = "PerformanceMarkOptions",))] + # [wasm_bindgen (catch , method , structural , js_class = "Performance" , js_name = mark)] + #[doc = "The `mark()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Performance`, `PerformanceMark`, `PerformanceMarkOptions`*"] + pub fn mark_with_mark_options( + this: &Performance, + mark_name: &str, + mark_options: &PerformanceMarkOptions, + ) -> Result; + #[cfg(feature = "PerformanceMeasure")] # [wasm_bindgen (catch , method , structural , js_class = "Performance" , js_name = measure)] #[doc = "The `measure()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure)"] #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `Performance`*"] - pub fn measure(this: &Performance, measure_name: &str) -> Result<(), JsValue>; + #[doc = "*This API requires the following crate features to be activated: `Performance`, `PerformanceMeasure`*"] + pub fn measure(this: &Performance, measure_name: &str) -> Result; + #[cfg(feature = "PerformanceMeasure")] # [wasm_bindgen (catch , method , structural , js_class = "Performance" , js_name = measure)] #[doc = "The `measure()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure)"] #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `Performance`*"] - pub fn measure_with_start_mark( + #[doc = "*This API requires the following crate features to be activated: `Performance`, `PerformanceMeasure`*"] + pub fn measure_with_str( this: &Performance, measure_name: &str, - start_mark: &str, - ) -> Result<(), JsValue>; + start_or_measure_options: &str, + ) -> Result; + #[cfg(all(feature = "PerformanceMeasure", feature = "PerformanceMeasureOptions",))] # [wasm_bindgen (catch , method , structural , js_class = "Performance" , js_name = measure)] #[doc = "The `measure()` method."] #[doc = ""] #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure)"] #[doc = ""] - #[doc = "*This API requires the following crate features to be activated: `Performance`*"] - pub fn measure_with_start_mark_and_end_mark( + #[doc = "*This API requires the following crate features to be activated: `Performance`, `PerformanceMeasure`, `PerformanceMeasureOptions`*"] + pub fn measure_with_performance_measure_options( + this: &Performance, + measure_name: &str, + start_or_measure_options: &PerformanceMeasureOptions, + ) -> Result; + #[cfg(feature = "PerformanceMeasure")] + # [wasm_bindgen (catch , method , structural , js_class = "Performance" , js_name = measure)] + #[doc = "The `measure()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Performance`, `PerformanceMeasure`*"] + pub fn measure_with_str_and_end_mark( + this: &Performance, + measure_name: &str, + start_or_measure_options: &str, + end_mark: &str, + ) -> Result; + #[cfg(all(feature = "PerformanceMeasure", feature = "PerformanceMeasureOptions",))] + # [wasm_bindgen (catch , method , structural , js_class = "Performance" , js_name = measure)] + #[doc = "The `measure()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `Performance`, `PerformanceMeasure`, `PerformanceMeasureOptions`*"] + pub fn measure_with_performance_measure_options_and_end_mark( this: &Performance, measure_name: &str, - start_mark: &str, + start_or_measure_options: &PerformanceMeasureOptions, end_mark: &str, - ) -> Result<(), JsValue>; + ) -> Result; #[cfg(web_sys_unstable_apis)] # [wasm_bindgen (method , structural , js_class = "Performance" , js_name = measureUserAgentSpecificMemory)] #[doc = "The `measureUserAgentSpecificMemory()` method."] diff --git a/crates/web-sys/src/features/gen_PerformanceMark.rs b/crates/web-sys/src/features/gen_PerformanceMark.rs index 80029413f93..caab0c259c7 100644 --- a/crates/web-sys/src/features/gen_PerformanceMark.rs +++ b/crates/web-sys/src/features/gen_PerformanceMark.rs @@ -12,4 +12,29 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `PerformanceMark`*"] pub type PerformanceMark; + # [wasm_bindgen (structural , method , getter , js_class = "PerformanceMark" , js_name = detail)] + #[doc = "Getter for the `detail` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMark/detail)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMark`*"] + pub fn detail(this: &PerformanceMark) -> ::wasm_bindgen::JsValue; + #[wasm_bindgen(catch, constructor, js_class = "PerformanceMark")] + #[doc = "The `new PerformanceMark(..)` constructor, creating a new instance of `PerformanceMark`."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMark/PerformanceMark)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMark`*"] + pub fn new(mark_name: &str) -> Result; + #[cfg(feature = "PerformanceMarkOptions")] + #[wasm_bindgen(catch, constructor, js_class = "PerformanceMark")] + #[doc = "The `new PerformanceMark(..)` constructor, creating a new instance of `PerformanceMark`."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMark/PerformanceMark)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMark`, `PerformanceMarkOptions`*"] + pub fn new_with_mark_options( + mark_name: &str, + mark_options: &PerformanceMarkOptions, + ) -> Result; } diff --git a/crates/web-sys/src/features/gen_PerformanceMarkOptions.rs b/crates/web-sys/src/features/gen_PerformanceMarkOptions.rs new file mode 100644 index 00000000000..02ad12cd515 --- /dev/null +++ b/crates/web-sys/src/features/gen_PerformanceMarkOptions.rs @@ -0,0 +1,59 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = PerformanceMarkOptions)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `PerformanceMarkOptions` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMarkOptions`*"] + pub type PerformanceMarkOptions; +} +impl PerformanceMarkOptions { + #[doc = "Construct a new `PerformanceMarkOptions`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMarkOptions`*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[doc = "Change the `detail` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMarkOptions`*"] + pub fn detail(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = + ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("detail"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `startTime` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMarkOptions`*"] + pub fn start_time(&mut self, val: f64) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("startTime"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} +impl Default for PerformanceMarkOptions { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/web-sys/src/features/gen_PerformanceMeasure.rs b/crates/web-sys/src/features/gen_PerformanceMeasure.rs index 88c59b62670..1ee25f9fd92 100644 --- a/crates/web-sys/src/features/gen_PerformanceMeasure.rs +++ b/crates/web-sys/src/features/gen_PerformanceMeasure.rs @@ -12,4 +12,11 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasure`*"] pub type PerformanceMeasure; + # [wasm_bindgen (structural , method , getter , js_class = "PerformanceMeasure" , js_name = detail)] + #[doc = "Getter for the `detail` field of this object."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMeasure/detail)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasure`*"] + pub fn detail(this: &PerformanceMeasure) -> ::wasm_bindgen::JsValue; } diff --git a/crates/web-sys/src/features/gen_PerformanceMeasureOptions.rs b/crates/web-sys/src/features/gen_PerformanceMeasureOptions.rs new file mode 100644 index 00000000000..fdd969f443b --- /dev/null +++ b/crates/web-sys/src/features/gen_PerformanceMeasureOptions.rs @@ -0,0 +1,85 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = PerformanceMeasureOptions)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `PerformanceMeasureOptions` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasureOptions`*"] + pub type PerformanceMeasureOptions; +} +impl PerformanceMeasureOptions { + #[doc = "Construct a new `PerformanceMeasureOptions`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasureOptions`*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[doc = "Change the `detail` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasureOptions`*"] + pub fn detail(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = + ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("detail"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `duration` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasureOptions`*"] + pub fn duration(&mut self, val: f64) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set( + self.as_ref(), + &JsValue::from("duration"), + &JsValue::from(val), + ); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `end` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasureOptions`*"] + pub fn end(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("end"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } + #[doc = "Change the `start` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `PerformanceMeasureOptions`*"] + pub fn start(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self { + use wasm_bindgen::JsValue; + let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("start"), &JsValue::from(val)); + debug_assert!( + r.is_ok(), + "setting properties should never fail on our dictionary objects" + ); + let _ = r; + self + } +} +impl Default for PerformanceMeasureOptions { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 8333053be51..3108a9a437b 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -5380,12 +5380,24 @@ mod gen_PerformanceMark; #[cfg(feature = "PerformanceMark")] pub use gen_PerformanceMark::*; +#[cfg(feature = "PerformanceMarkOptions")] +#[allow(non_snake_case)] +mod gen_PerformanceMarkOptions; +#[cfg(feature = "PerformanceMarkOptions")] +pub use gen_PerformanceMarkOptions::*; + #[cfg(feature = "PerformanceMeasure")] #[allow(non_snake_case)] mod gen_PerformanceMeasure; #[cfg(feature = "PerformanceMeasure")] pub use gen_PerformanceMeasure::*; +#[cfg(feature = "PerformanceMeasureOptions")] +#[allow(non_snake_case)] +mod gen_PerformanceMeasureOptions; +#[cfg(feature = "PerformanceMeasureOptions")] +pub use gen_PerformanceMeasureOptions::*; + #[cfg(feature = "PerformanceNavigation")] #[allow(non_snake_case)] mod gen_PerformanceNavigation; diff --git a/crates/web-sys/webidls/enabled/Performance.webidl b/crates/web-sys/webidls/enabled/Performance.webidl index 5dec7a6af92..553aa41c9fa 100644 --- a/crates/web-sys/webidls/enabled/Performance.webidl +++ b/crates/web-sys/webidls/enabled/Performance.webidl @@ -48,13 +48,13 @@ partial interface Performance { attribute EventHandler onresourcetimingbufferfull; }; -// http://www.w3.org/TR/user-timing/ +// https://www.w3.org/TR/user-timing/#extensions-performance-interface [Exposed=(Window,Worker)] partial interface Performance { [Throws] - undefined mark(DOMString markName); + PerformanceMark mark(DOMString markName, optional PerformanceMarkOptions markOptions = {}); undefined clearMarks(optional DOMString markName); [Throws] - undefined measure(DOMString measureName, optional DOMString startMark, optional DOMString endMark); + PerformanceMeasure measure(DOMString measureName, optional (DOMString or PerformanceMeasureOptions) startOrMeasureOptions = {}, optional DOMString endMark); undefined clearMeasures(optional DOMString measureName); -}; +}; \ No newline at end of file diff --git a/crates/web-sys/webidls/enabled/PerformanceMark.webidl b/crates/web-sys/webidls/enabled/PerformanceMark.webidl index 20e9e92c022..f56216db8c9 100644 --- a/crates/web-sys/webidls/enabled/PerformanceMark.webidl +++ b/crates/web-sys/webidls/enabled/PerformanceMark.webidl @@ -8,6 +8,7 @@ */ [Exposed=(Window,Worker)] -interface PerformanceMark : PerformanceEntry -{ +interface PerformanceMark : PerformanceEntry { + constructor(DOMString markName, optional PerformanceMarkOptions markOptions = {}); + readonly attribute any detail; }; diff --git a/crates/web-sys/webidls/enabled/PerformanceMarkOptions.webidl b/crates/web-sys/webidls/enabled/PerformanceMarkOptions.webidl new file mode 100644 index 00000000000..937e49e024a --- /dev/null +++ b/crates/web-sys/webidls/enabled/PerformanceMarkOptions.webidl @@ -0,0 +1,14 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://www.w3.org/TR/user-timing/#extensions-performance-interface + */ + +[Exposed=(Window,Worker)] +dictionary PerformanceMarkOptions { + any detail; + DOMHighResTimeStamp startTime; +}; diff --git a/crates/web-sys/webidls/enabled/PerformanceMeasure.webidl b/crates/web-sys/webidls/enabled/PerformanceMeasure.webidl index aa4e8cd256b..b21f6538f9d 100644 --- a/crates/web-sys/webidls/enabled/PerformanceMeasure.webidl +++ b/crates/web-sys/webidls/enabled/PerformanceMeasure.webidl @@ -8,6 +8,6 @@ */ [Exposed=(Window,Worker)] -interface PerformanceMeasure : PerformanceEntry -{ +interface PerformanceMeasure : PerformanceEntry { + readonly attribute any detail; }; diff --git a/crates/web-sys/webidls/enabled/PerformanceMeasureOptions.webidl b/crates/web-sys/webidls/enabled/PerformanceMeasureOptions.webidl new file mode 100644 index 00000000000..859c0e6c77c --- /dev/null +++ b/crates/web-sys/webidls/enabled/PerformanceMeasureOptions.webidl @@ -0,0 +1,16 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://www.w3.org/TR/user-timing/#extensions-performance-interface + */ + +[Exposed=(Window,Worker)] +dictionary PerformanceMeasureOptions { + any detail; + (DOMString or DOMHighResTimeStamp) start; + DOMHighResTimeStamp duration; + (DOMString or DOMHighResTimeStamp) end; +};