Skip to content

Commit e617fca

Browse files
authored
feat: add new web lock api interface (#3604)
1 parent 373b7a5 commit e617fca

12 files changed

+514
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
### Added
77

8+
* Add bindings for the Web Locks API to `web-sys`.
9+
[#3604](https://github.com/rustwasm/wasm-bindgen/pull/3604)
10+
811
* Add bindings for `ViewTransition` to `web-sys`.
912
[#3598](https://github.com/rustwasm/wasm-bindgen/pull/3598)
1013

crates/web-sys/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,12 @@ ListBoxObject = []
757757
LocalMediaStream = ["EventTarget", "MediaStream"]
758758
LocaleInfo = []
759759
Location = []
760+
Lock = []
761+
LockInfo = []
762+
LockManager = []
763+
LockManagerSnapshot = []
764+
LockMode = []
765+
LockOptions = []
760766
MediaCapabilities = []
761767
MediaCapabilitiesInfo = []
762768
MediaConfiguration = []
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[cfg(web_sys_unstable_apis)]
6+
#[wasm_bindgen]
7+
extern "C" {
8+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = Lock , typescript_type = "Lock")]
9+
#[derive(Debug, Clone, PartialEq, Eq)]
10+
#[doc = "The `Lock` class."]
11+
#[doc = ""]
12+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Lock)"]
13+
#[doc = ""]
14+
#[doc = "*This API requires the following crate features to be activated: `Lock`*"]
15+
#[doc = ""]
16+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
17+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
18+
pub type Lock;
19+
#[cfg(web_sys_unstable_apis)]
20+
# [wasm_bindgen (structural , method , getter , js_class = "Lock" , js_name = name)]
21+
#[doc = "Getter for the `name` field of this object."]
22+
#[doc = ""]
23+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Lock/name)"]
24+
#[doc = ""]
25+
#[doc = "*This API requires the following crate features to be activated: `Lock`*"]
26+
#[doc = ""]
27+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
28+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
29+
pub fn name(this: &Lock) -> String;
30+
#[cfg(web_sys_unstable_apis)]
31+
#[cfg(feature = "LockMode")]
32+
# [wasm_bindgen (structural , method , getter , js_class = "Lock" , js_name = mode)]
33+
#[doc = "Getter for the `mode` field of this object."]
34+
#[doc = ""]
35+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Lock/mode)"]
36+
#[doc = ""]
37+
#[doc = "*This API requires the following crate features to be activated: `Lock`, `LockMode`*"]
38+
#[doc = ""]
39+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
40+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
41+
pub fn mode(this: &Lock) -> LockMode;
42+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[cfg(web_sys_unstable_apis)]
6+
#[wasm_bindgen]
7+
extern "C" {
8+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = LockInfo)]
9+
#[derive(Debug, Clone, PartialEq, Eq)]
10+
#[doc = "The `LockInfo` dictionary."]
11+
#[doc = ""]
12+
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
13+
#[doc = ""]
14+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
15+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
16+
pub type LockInfo;
17+
}
18+
#[cfg(web_sys_unstable_apis)]
19+
impl LockInfo {
20+
#[doc = "Construct a new `LockInfo`."]
21+
#[doc = ""]
22+
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
23+
#[doc = ""]
24+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
25+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
26+
pub fn new() -> Self {
27+
#[allow(unused_mut)]
28+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
29+
ret
30+
}
31+
#[cfg(web_sys_unstable_apis)]
32+
#[doc = "Change the `clientId` field of this object."]
33+
#[doc = ""]
34+
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
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 client_id(&mut self, val: &str) -> &mut Self {
39+
use wasm_bindgen::JsValue;
40+
let r = ::js_sys::Reflect::set(
41+
self.as_ref(),
42+
&JsValue::from("clientId"),
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+
#[cfg(feature = "LockMode")]
54+
#[doc = "Change the `mode` field of this object."]
55+
#[doc = ""]
56+
#[doc = "*This API requires the following crate features to be activated: `LockInfo`, `LockMode`*"]
57+
#[doc = ""]
58+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
59+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
60+
pub fn mode(&mut self, val: LockMode) -> &mut Self {
61+
use wasm_bindgen::JsValue;
62+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("mode"), &JsValue::from(val));
63+
debug_assert!(
64+
r.is_ok(),
65+
"setting properties should never fail on our dictionary objects"
66+
);
67+
let _ = r;
68+
self
69+
}
70+
#[cfg(web_sys_unstable_apis)]
71+
#[doc = "Change the `name` field of this object."]
72+
#[doc = ""]
73+
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
74+
#[doc = ""]
75+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
76+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
77+
pub fn name(&mut self, val: &str) -> &mut Self {
78+
use wasm_bindgen::JsValue;
79+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("name"), &JsValue::from(val));
80+
debug_assert!(
81+
r.is_ok(),
82+
"setting properties should never fail on our dictionary objects"
83+
);
84+
let _ = r;
85+
self
86+
}
87+
}
88+
#[cfg(web_sys_unstable_apis)]
89+
impl Default for LockInfo {
90+
fn default() -> Self {
91+
Self::new()
92+
}
93+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[cfg(web_sys_unstable_apis)]
6+
#[wasm_bindgen]
7+
extern "C" {
8+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = LockManager , typescript_type = "LockManager")]
9+
#[derive(Debug, Clone, PartialEq, Eq)]
10+
#[doc = "The `LockManager` class."]
11+
#[doc = ""]
12+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager)"]
13+
#[doc = ""]
14+
#[doc = "*This API requires the following crate features to be activated: `LockManager`*"]
15+
#[doc = ""]
16+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
17+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
18+
pub type LockManager;
19+
#[cfg(web_sys_unstable_apis)]
20+
# [wasm_bindgen (method , structural , js_class = "LockManager" , js_name = query)]
21+
#[doc = "The `query()` method."]
22+
#[doc = ""]
23+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager/query)"]
24+
#[doc = ""]
25+
#[doc = "*This API requires the following crate features to be activated: `LockManager`*"]
26+
#[doc = ""]
27+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
28+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
29+
pub fn query(this: &LockManager) -> ::js_sys::Promise;
30+
#[cfg(web_sys_unstable_apis)]
31+
# [wasm_bindgen (method , structural , js_class = "LockManager" , js_name = request)]
32+
#[doc = "The `request()` method."]
33+
#[doc = ""]
34+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request)"]
35+
#[doc = ""]
36+
#[doc = "*This API requires the following crate features to be activated: `LockManager`*"]
37+
#[doc = ""]
38+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
39+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
40+
pub fn request_with_callback(
41+
this: &LockManager,
42+
name: &str,
43+
callback: &::js_sys::Function,
44+
) -> ::js_sys::Promise;
45+
#[cfg(web_sys_unstable_apis)]
46+
#[cfg(feature = "LockOptions")]
47+
# [wasm_bindgen (method , structural , js_class = "LockManager" , js_name = request)]
48+
#[doc = "The `request()` method."]
49+
#[doc = ""]
50+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request)"]
51+
#[doc = ""]
52+
#[doc = "*This API requires the following crate features to be activated: `LockManager`, `LockOptions`*"]
53+
#[doc = ""]
54+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
55+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
56+
pub fn request_with_options_and_callback(
57+
this: &LockManager,
58+
name: &str,
59+
options: &LockOptions,
60+
callback: &::js_sys::Function,
61+
) -> ::js_sys::Promise;
62+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[cfg(web_sys_unstable_apis)]
6+
#[wasm_bindgen]
7+
extern "C" {
8+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = LockManagerSnapshot)]
9+
#[derive(Debug, Clone, PartialEq, Eq)]
10+
#[doc = "The `LockManagerSnapshot` dictionary."]
11+
#[doc = ""]
12+
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
13+
#[doc = ""]
14+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
15+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
16+
pub type LockManagerSnapshot;
17+
}
18+
#[cfg(web_sys_unstable_apis)]
19+
impl LockManagerSnapshot {
20+
#[doc = "Construct a new `LockManagerSnapshot`."]
21+
#[doc = ""]
22+
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
23+
#[doc = ""]
24+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
25+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
26+
pub fn new() -> Self {
27+
#[allow(unused_mut)]
28+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
29+
ret
30+
}
31+
#[cfg(web_sys_unstable_apis)]
32+
#[doc = "Change the `held` field of this object."]
33+
#[doc = ""]
34+
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
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 held(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
39+
use wasm_bindgen::JsValue;
40+
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("held"), &JsValue::from(val));
41+
debug_assert!(
42+
r.is_ok(),
43+
"setting properties should never fail on our dictionary objects"
44+
);
45+
let _ = r;
46+
self
47+
}
48+
#[cfg(web_sys_unstable_apis)]
49+
#[doc = "Change the `pending` field of this object."]
50+
#[doc = ""]
51+
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
52+
#[doc = ""]
53+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
54+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
55+
pub fn pending(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
56+
use wasm_bindgen::JsValue;
57+
let r = ::js_sys::Reflect::set(
58+
self.as_ref(),
59+
&JsValue::from("pending"),
60+
&JsValue::from(val),
61+
);
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+
}
70+
#[cfg(web_sys_unstable_apis)]
71+
impl Default for LockManagerSnapshot {
72+
fn default() -> Self {
73+
Self::new()
74+
}
75+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use wasm_bindgen::prelude::*;
4+
#[cfg(web_sys_unstable_apis)]
5+
#[wasm_bindgen]
6+
#[doc = "The `LockMode` enum."]
7+
#[doc = ""]
8+
#[doc = "*This API requires the following crate features to be activated: `LockMode`*"]
9+
#[doc = ""]
10+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
11+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
12+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13+
pub enum LockMode {
14+
Shared = "shared",
15+
Exclusive = "exclusive",
16+
}

0 commit comments

Comments
 (0)