Skip to content

Commit ceaf996

Browse files
authored
Add support for performance.measureUserAgentSpecificMemory (#3350)
Fixes #3159 This is a Chrome-only API for measuring the memory usage of JS/wasm. So, I've marked it as unstable.
1 parent 5600b15 commit ceaf996

8 files changed

+393
-0
lines changed

crates/web-sys/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,10 @@ MediaTrackConstraintSet = []
803803
MediaTrackConstraints = []
804804
MediaTrackSettings = []
805805
MediaTrackSupportedConstraints = []
806+
MemoryAttribution = []
807+
MemoryAttributionContainer = []
808+
MemoryBreakdownEntry = []
809+
MemoryMeasurement = []
806810
MessageChannel = []
807811
MessageEvent = ["Event"]
808812
MessageEventInit = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = MemoryAttribution)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `MemoryAttribution` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttribution`*"]
12+
#[doc = ""]
13+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
14+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
15+
pub type MemoryAttribution;
16+
}
17+
#[cfg(web_sys_unstable_apis)]
18+
impl MemoryAttribution {
19+
#[doc = "Construct a new `MemoryAttribution`."]
20+
#[doc = ""]
21+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttribution`*"]
22+
#[doc = ""]
23+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
24+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
25+
pub fn new() -> Self {
26+
#[allow(unused_mut)]
27+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
28+
ret
29+
}
30+
#[cfg(web_sys_unstable_apis)]
31+
#[cfg(feature = "MemoryAttributionContainer")]
32+
#[doc = "Change the `container` field of this object."]
33+
#[doc = ""]
34+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttribution`, `MemoryAttributionContainer`*"]
35+
#[doc = ""]
36+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
37+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
38+
pub fn container(&mut self, val: &MemoryAttributionContainer) -> &mut Self {
39+
use wasm_bindgen::JsValue;
40+
let r = ::js_sys::Reflect::set(
41+
self.as_ref(),
42+
&JsValue::from("container"),
43+
&JsValue::from(val),
44+
);
45+
debug_assert!(
46+
r.is_ok(),
47+
"setting properties should never fail on our dictionary objects"
48+
);
49+
let _ = r;
50+
self
51+
}
52+
#[cfg(web_sys_unstable_apis)]
53+
#[doc = "Change the `scope` field of this object."]
54+
#[doc = ""]
55+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttribution`*"]
56+
#[doc = ""]
57+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
58+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
59+
pub fn scope(&mut self, val: &str) -> &mut Self {
60+
use wasm_bindgen::JsValue;
61+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("scope"), &JsValue::from(val));
62+
debug_assert!(
63+
r.is_ok(),
64+
"setting properties should never fail on our dictionary objects"
65+
);
66+
let _ = r;
67+
self
68+
}
69+
#[cfg(web_sys_unstable_apis)]
70+
#[doc = "Change the `url` field of this object."]
71+
#[doc = ""]
72+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttribution`*"]
73+
#[doc = ""]
74+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
75+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
76+
pub fn url(&mut self, val: &str) -> &mut Self {
77+
use wasm_bindgen::JsValue;
78+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("url"), &JsValue::from(val));
79+
debug_assert!(
80+
r.is_ok(),
81+
"setting properties should never fail on our dictionary objects"
82+
);
83+
let _ = r;
84+
self
85+
}
86+
}
87+
#[cfg(web_sys_unstable_apis)]
88+
impl Default for MemoryAttribution {
89+
fn default() -> Self {
90+
Self::new()
91+
}
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = MemoryAttributionContainer)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `MemoryAttributionContainer` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttributionContainer`*"]
12+
#[doc = ""]
13+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
14+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
15+
pub type MemoryAttributionContainer;
16+
}
17+
#[cfg(web_sys_unstable_apis)]
18+
impl MemoryAttributionContainer {
19+
#[doc = "Construct a new `MemoryAttributionContainer`."]
20+
#[doc = ""]
21+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttributionContainer`*"]
22+
#[doc = ""]
23+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
24+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
25+
pub fn new() -> Self {
26+
#[allow(unused_mut)]
27+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
28+
ret
29+
}
30+
#[cfg(web_sys_unstable_apis)]
31+
#[doc = "Change the `id` field of this object."]
32+
#[doc = ""]
33+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttributionContainer`*"]
34+
#[doc = ""]
35+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
36+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
37+
pub fn id(&mut self, val: &str) -> &mut Self {
38+
use wasm_bindgen::JsValue;
39+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("id"), &JsValue::from(val));
40+
debug_assert!(
41+
r.is_ok(),
42+
"setting properties should never fail on our dictionary objects"
43+
);
44+
let _ = r;
45+
self
46+
}
47+
#[cfg(web_sys_unstable_apis)]
48+
#[doc = "Change the `src` field of this object."]
49+
#[doc = ""]
50+
#[doc = "*This API requires the following crate features to be activated: `MemoryAttributionContainer`*"]
51+
#[doc = ""]
52+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
53+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
54+
pub fn src(&mut self, val: &str) -> &mut Self {
55+
use wasm_bindgen::JsValue;
56+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("src"), &JsValue::from(val));
57+
debug_assert!(
58+
r.is_ok(),
59+
"setting properties should never fail on our dictionary objects"
60+
);
61+
let _ = r;
62+
self
63+
}
64+
}
65+
#[cfg(web_sys_unstable_apis)]
66+
impl Default for MemoryAttributionContainer {
67+
fn default() -> Self {
68+
Self::new()
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = MemoryBreakdownEntry)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `MemoryBreakdownEntry` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `MemoryBreakdownEntry`*"]
12+
#[doc = ""]
13+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
14+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
15+
pub type MemoryBreakdownEntry;
16+
}
17+
#[cfg(web_sys_unstable_apis)]
18+
impl MemoryBreakdownEntry {
19+
#[doc = "Construct a new `MemoryBreakdownEntry`."]
20+
#[doc = ""]
21+
#[doc = "*This API requires the following crate features to be activated: `MemoryBreakdownEntry`*"]
22+
#[doc = ""]
23+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
24+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
25+
pub fn new() -> Self {
26+
#[allow(unused_mut)]
27+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
28+
ret
29+
}
30+
#[cfg(web_sys_unstable_apis)]
31+
#[doc = "Change the `attribution` field of this object."]
32+
#[doc = ""]
33+
#[doc = "*This API requires the following crate features to be activated: `MemoryBreakdownEntry`*"]
34+
#[doc = ""]
35+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
36+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
37+
pub fn attribution(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
38+
use wasm_bindgen::JsValue;
39+
let r = ::js_sys::Reflect::set(
40+
self.as_ref(),
41+
&JsValue::from("attribution"),
42+
&JsValue::from(val),
43+
);
44+
debug_assert!(
45+
r.is_ok(),
46+
"setting properties should never fail on our dictionary objects"
47+
);
48+
let _ = r;
49+
self
50+
}
51+
#[cfg(web_sys_unstable_apis)]
52+
#[doc = "Change the `bytes` field of this object."]
53+
#[doc = ""]
54+
#[doc = "*This API requires the following crate features to be activated: `MemoryBreakdownEntry`*"]
55+
#[doc = ""]
56+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
57+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
58+
pub fn bytes(&mut self, val: f64) -> &mut Self {
59+
use wasm_bindgen::JsValue;
60+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("bytes"), &JsValue::from(val));
61+
debug_assert!(
62+
r.is_ok(),
63+
"setting properties should never fail on our dictionary objects"
64+
);
65+
let _ = r;
66+
self
67+
}
68+
#[cfg(web_sys_unstable_apis)]
69+
#[doc = "Change the `types` field of this object."]
70+
#[doc = ""]
71+
#[doc = "*This API requires the following crate features to be activated: `MemoryBreakdownEntry`*"]
72+
#[doc = ""]
73+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
74+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
75+
pub fn types(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
76+
use wasm_bindgen::JsValue;
77+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("types"), &JsValue::from(val));
78+
debug_assert!(
79+
r.is_ok(),
80+
"setting properties should never fail on our dictionary objects"
81+
);
82+
let _ = r;
83+
self
84+
}
85+
}
86+
#[cfg(web_sys_unstable_apis)]
87+
impl Default for MemoryBreakdownEntry {
88+
fn default() -> Self {
89+
Self::new()
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#![allow(unused_imports)]
2+
use super::*;
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = MemoryMeasurement)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `MemoryMeasurement` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `MemoryMeasurement`*"]
12+
#[doc = ""]
13+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
14+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
15+
pub type MemoryMeasurement;
16+
}
17+
#[cfg(web_sys_unstable_apis)]
18+
impl MemoryMeasurement {
19+
#[doc = "Construct a new `MemoryMeasurement`."]
20+
#[doc = ""]
21+
#[doc = "*This API requires the following crate features to be activated: `MemoryMeasurement`*"]
22+
#[doc = ""]
23+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
24+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
25+
pub fn new() -> Self {
26+
#[allow(unused_mut)]
27+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
28+
ret
29+
}
30+
#[cfg(web_sys_unstable_apis)]
31+
#[doc = "Change the `breakdown` field of this object."]
32+
#[doc = ""]
33+
#[doc = "*This API requires the following crate features to be activated: `MemoryMeasurement`*"]
34+
#[doc = ""]
35+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
36+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
37+
pub fn breakdown(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
38+
use wasm_bindgen::JsValue;
39+
let r = ::js_sys::Reflect::set(
40+
self.as_ref(),
41+
&JsValue::from("breakdown"),
42+
&JsValue::from(val),
43+
);
44+
debug_assert!(
45+
r.is_ok(),
46+
"setting properties should never fail on our dictionary objects"
47+
);
48+
let _ = r;
49+
self
50+
}
51+
#[cfg(web_sys_unstable_apis)]
52+
#[doc = "Change the `bytes` field of this object."]
53+
#[doc = ""]
54+
#[doc = "*This API requires the following crate features to be activated: `MemoryMeasurement`*"]
55+
#[doc = ""]
56+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
57+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
58+
pub fn bytes(&mut self, val: f64) -> &mut Self {
59+
use wasm_bindgen::JsValue;
60+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("bytes"), &JsValue::from(val));
61+
debug_assert!(
62+
r.is_ok(),
63+
"setting properties should never fail on our dictionary objects"
64+
);
65+
let _ = r;
66+
self
67+
}
68+
}
69+
#[cfg(web_sys_unstable_apis)]
70+
impl Default for MemoryMeasurement {
71+
fn default() -> Self {
72+
Self::new()
73+
}
74+
}

crates/web-sys/src/features/gen_Performance.rs

+11
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ extern "C" {
152152
start_mark: &str,
153153
end_mark: &str,
154154
) -> Result<(), JsValue>;
155+
#[cfg(web_sys_unstable_apis)]
156+
# [wasm_bindgen (method , structural , js_class = "Performance" , js_name = measureUserAgentSpecificMemory)]
157+
#[doc = "The `measureUserAgentSpecificMemory()` method."]
158+
#[doc = ""]
159+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Performance/measureUserAgentSpecificMemory)"]
160+
#[doc = ""]
161+
#[doc = "*This API requires the following crate features to be activated: `Performance`*"]
162+
#[doc = ""]
163+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
164+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
165+
pub fn measure_user_agent_specific_memory(this: &Performance) -> ::js_sys::Promise;
155166
# [wasm_bindgen (method , structural , js_class = "Performance" , js_name = now)]
156167
#[doc = "The `now()` method."]
157168
#[doc = ""]

crates/web-sys/src/features/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -4636,6 +4636,30 @@ mod gen_MediaTrackSupportedConstraints;
46364636
#[cfg(feature = "MediaTrackSupportedConstraints")]
46374637
pub use gen_MediaTrackSupportedConstraints::*;
46384638

4639+
#[cfg(feature = "MemoryAttribution")]
4640+
#[allow(non_snake_case)]
4641+
mod gen_MemoryAttribution;
4642+
#[cfg(feature = "MemoryAttribution")]
4643+
pub use gen_MemoryAttribution::*;
4644+
4645+
#[cfg(feature = "MemoryAttributionContainer")]
4646+
#[allow(non_snake_case)]
4647+
mod gen_MemoryAttributionContainer;
4648+
#[cfg(feature = "MemoryAttributionContainer")]
4649+
pub use gen_MemoryAttributionContainer::*;
4650+
4651+
#[cfg(feature = "MemoryBreakdownEntry")]
4652+
#[allow(non_snake_case)]
4653+
mod gen_MemoryBreakdownEntry;
4654+
#[cfg(feature = "MemoryBreakdownEntry")]
4655+
pub use gen_MemoryBreakdownEntry::*;
4656+
4657+
#[cfg(feature = "MemoryMeasurement")]
4658+
#[allow(non_snake_case)]
4659+
mod gen_MemoryMeasurement;
4660+
#[cfg(feature = "MemoryMeasurement")]
4661+
pub use gen_MemoryMeasurement::*;
4662+
46394663
#[cfg(feature = "MessageChannel")]
46404664
#[allow(non_snake_case)]
46414665
mod gen_MessageChannel;

0 commit comments

Comments
 (0)