Skip to content

Commit 7702823

Browse files
authored
Adjust Bluetooth IDL for Rust (#2385)
* navigator.bluetooth is optional -- it may be manatory by the WebBluetooth spec, but the Rust code should still be able to handle the errors resulting from a browser not implementing the spec at all without panicking. * requestDevice: While it's marked optional upstream, practically it's mandatory (the default value, an empty dictionary, is not accepted). Contributes-To: #2381
1 parent a125903 commit 7702823

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,6 @@ extern "C" {
204204
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
205205
pub fn get_devices(this: &Bluetooth) -> ::js_sys::Promise;
206206
#[cfg(web_sys_unstable_apis)]
207-
# [wasm_bindgen (method , structural , js_class = "Bluetooth" , js_name = requestDevice)]
208-
#[doc = "The `requestDevice()` method."]
209-
#[doc = ""]
210-
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice)"]
211-
#[doc = ""]
212-
#[doc = "*This API requires the following crate features to be activated: `Bluetooth`*"]
213-
#[doc = ""]
214-
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
215-
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
216-
pub fn request_device(this: &Bluetooth) -> ::js_sys::Promise;
217-
#[cfg(web_sys_unstable_apis)]
218207
#[cfg(feature = "RequestDeviceOptions")]
219208
# [wasm_bindgen (method , structural , js_class = "Bluetooth" , js_name = requestDevice)]
220209
#[doc = "The `requestDevice()` method."]
@@ -225,8 +214,5 @@ extern "C" {
225214
#[doc = ""]
226215
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
227216
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
228-
pub fn request_device_with_options(
229-
this: &Bluetooth,
230-
options: &RequestDeviceOptions,
231-
) -> ::js_sys::Promise;
217+
pub fn request_device(this: &Bluetooth, options: &RequestDeviceOptions) -> ::js_sys::Promise;
232218
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ extern "C" {
115115
#[doc = ""]
116116
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
117117
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
118-
pub fn bluetooth(this: &Navigator) -> Bluetooth;
118+
pub fn bluetooth(this: &Navigator) -> Option<Bluetooth>;
119119
#[cfg(web_sys_unstable_apis)]
120120
#[cfg(feature = "Clipboard")]
121121
# [wasm_bindgen (structural , method , getter , js_class = "Navigator" , js_name = clipboard)]

crates/web-sys/webidls/unstable/Bluetooth.webidl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface Bluetooth : EventTarget {
2626
[SameObject]
2727
readonly attribute BluetoothDevice? referringDevice;
2828
Promise<sequence<BluetoothDevice>> getDevices();
29-
Promise<BluetoothDevice> requestDevice(optional RequestDeviceOptions options = {});
29+
Promise<BluetoothDevice> requestDevice(RequestDeviceOptions options);
3030
};
3131

3232
Bluetooth includes BluetoothDeviceEventHandlers;
@@ -232,5 +232,5 @@ typedef (DOMString or unsigned long) BluetoothDescriptorUUID;
232232
[SecureContext]
233233
partial interface Navigator {
234234
[SameObject]
235-
readonly attribute Bluetooth bluetooth;
236-
};
235+
readonly attribute Bluetooth? bluetooth;
236+
};

0 commit comments

Comments
 (0)