Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new web lock api interface #3604

Merged
merged 5 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

### Added

* Add bindings for the Web Locks API to `web-sys`.
[#3604](https://github.com/rustwasm/wasm-bindgen/pull/3604)

* Add bindings for `ViewTransition` to `web-sys`.
[#3598](https://github.com/rustwasm/wasm-bindgen/pull/3598)

Expand Down
6 changes: 6 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ ListBoxObject = []
LocalMediaStream = ["EventTarget", "MediaStream"]
LocaleInfo = []
Location = []
Lock = []
LockInfo = []
LockManager = []
LockManagerSnapshot = []
LockMode = []
LockOptions = []
MediaCapabilities = []
MediaCapabilitiesInfo = []
MediaConfiguration = []
Expand Down
42 changes: 42 additions & 0 deletions crates/web-sys/src/features/gen_Lock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = Lock , typescript_type = "Lock")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `Lock` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Lock)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Lock`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type Lock;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "Lock" , js_name = name)]
#[doc = "Getter for the `name` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Lock/name)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Lock`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn name(this: &Lock) -> String;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "LockMode")]
# [wasm_bindgen (structural , method , getter , js_class = "Lock" , js_name = mode)]
#[doc = "Getter for the `mode` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Lock/mode)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `Lock`, `LockMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn mode(this: &Lock) -> LockMode;
}
93 changes: 93 additions & 0 deletions crates/web-sys/src/features/gen_LockInfo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = LockInfo)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `LockInfo` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type LockInfo;
}
#[cfg(web_sys_unstable_apis)]
impl LockInfo {
#[doc = "Construct a new `LockInfo`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `clientId` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn client_id(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("clientId"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "LockMode")]
#[doc = "Change the `mode` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockInfo`, `LockMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn mode(&mut self, val: LockMode) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("mode"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `name` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockInfo`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn name(&mut self, val: &str) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("name"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for LockInfo {
fn default() -> Self {
Self::new()
}
}
62 changes: 62 additions & 0 deletions crates/web-sys/src/features/gen_LockManager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = LockManager , typescript_type = "LockManager")]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `LockManager` class."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManager`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type LockManager;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "LockManager" , js_name = query)]
#[doc = "The `query()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager/query)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManager`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn query(this: &LockManager) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "LockManager" , js_name = request)]
#[doc = "The `request()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManager`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn request_with_callback(
this: &LockManager,
name: &str,
callback: &::js_sys::Function,
) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "LockOptions")]
# [wasm_bindgen (method , structural , js_class = "LockManager" , js_name = request)]
#[doc = "The `request()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManager`, `LockOptions`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn request_with_options_and_callback(
this: &LockManager,
name: &str,
options: &LockOptions,
callback: &::js_sys::Function,
) -> ::js_sys::Promise;
}
75 changes: 75 additions & 0 deletions crates/web-sys/src/features/gen_LockManagerSnapshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = LockManagerSnapshot)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `LockManagerSnapshot` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type LockManagerSnapshot;
}
#[cfg(web_sys_unstable_apis)]
impl LockManagerSnapshot {
#[doc = "Construct a new `LockManagerSnapshot`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `held` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn held(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("held"), &JsValue::from(val));
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `pending` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockManagerSnapshot`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn pending(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
use wasm_bindgen::JsValue;
let r = ::js_sys::Reflect::set(
self.as_ref(),
&JsValue::from("pending"),
&JsValue::from(val),
);
debug_assert!(
r.is_ok(),
"setting properties should never fail on our dictionary objects"
);
let _ = r;
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for LockManagerSnapshot {
fn default() -> Self {
Self::new()
}
}
16 changes: 16 additions & 0 deletions crates/web-sys/src/features/gen_LockMode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
#[doc = "The `LockMode` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `LockMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LockMode {
Shared = "shared",
Exclusive = "exclusive",
}
Loading