Skip to content

Commit 28d4575

Browse files
authored
Add dataview attribute output to WebIDL Codegen (#2316)
* Add Dataview as a valid attribute type for WebIDL Codegen Some WebIDL specs (WebBluetooth, WebUSB, etc) use DataView as an attribute type. These attributes should map to a js_sys::DataView type. Fixes #2312 * Generate missing DataView attrs for WebBluetooth WebBluetooth has a couple DataView attrs that are required for certain core functionality. These were not being generated when the original patch was landed, but after the DataView fix, they now show up.
1 parent 4da073c commit 28d4575

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

crates/web-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ CustomEventInit = []
247247
DataTransfer = []
248248
DataTransferItem = []
249249
DataTransferItemList = []
250+
DataView = []
250251
DateTimeValue = []
251252
DecoderDoctorNotification = []
252253
DecoderDoctorNotificationType = []

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ extern "C" {
5353
this: &BluetoothRemoteGattCharacteristic,
5454
) -> BluetoothCharacteristicProperties;
5555
#[cfg(web_sys_unstable_apis)]
56+
#[cfg(feature = "DataView")]
57+
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = value)]
58+
#[doc = "Getter for the `value` field of this object."]
59+
#[doc = ""]
60+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/value)"]
61+
#[doc = ""]
62+
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattCharacteristic`, `DataView`*"]
63+
#[doc = ""]
64+
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
65+
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
66+
pub fn value(this: &BluetoothRemoteGattCharacteristic) -> Option<::js_sys::DataView>;
67+
#[cfg(web_sys_unstable_apis)]
5668
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = oncharacteristicvaluechanged)]
5769
#[doc = "Getter for the `oncharacteristicvaluechanged` field of this object."]
5870
#[doc = ""]

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ extern "C" {
4141
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
4242
pub fn uuid(this: &BluetoothRemoteGattDescriptor) -> String;
4343
#[cfg(web_sys_unstable_apis)]
44+
#[cfg(feature = "DataView")]
45+
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTDescriptor" , js_name = value)]
46+
#[doc = "Getter for the `value` field of this object."]
47+
#[doc = ""]
48+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTDescriptor/value)"]
49+
#[doc = ""]
50+
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattDescriptor`, `DataView`*"]
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 value(this: &BluetoothRemoteGattDescriptor) -> Option<::js_sys::DataView>;
55+
#[cfg(web_sys_unstable_apis)]
4456
# [wasm_bindgen (method , structural , js_class = "BluetoothRemoteGATTDescriptor" , js_name = readValue)]
4557
#[doc = "The `readValue()` method."]
4658
#[doc = ""]

crates/webidl/src/idl_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'a> IdlType<'a> {
547547
IdlType::Error => Err(TypeError::CannotConvert),
548548

549549
IdlType::ArrayBuffer => Ok(js_sys("ArrayBuffer")),
550-
IdlType::DataView => Err(TypeError::CannotConvert),
550+
IdlType::DataView => Ok(js_sys("DataView")),
551551
IdlType::Int8Array { immutable } => Ok(Some(array("i8", pos, *immutable))),
552552
IdlType::Uint8Array { immutable } => Ok(Some(array("u8", pos, *immutable))),
553553
IdlType::Uint8ClampedArray { immutable } => {

0 commit comments

Comments
 (0)