Skip to content

Commit

Permalink
Add dataview attribute output to WebIDL Codegen (#2316)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
qdot authored Sep 22, 2020
1 parent 4da073c commit 28d4575
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ CustomEventInit = []
DataTransfer = []
DataTransferItem = []
DataTransferItemList = []
DataView = []
DateTimeValue = []
DecoderDoctorNotification = []
DecoderDoctorNotificationType = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ extern "C" {
this: &BluetoothRemoteGattCharacteristic,
) -> BluetoothCharacteristicProperties;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "DataView")]
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = value)]
#[doc = "Getter for the `value` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/value)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattCharacteristic`, `DataView`*"]
#[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 value(this: &BluetoothRemoteGattCharacteristic) -> Option<::js_sys::DataView>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = oncharacteristicvaluechanged)]
#[doc = "Getter for the `oncharacteristicvaluechanged` field of this object."]
#[doc = ""]
Expand Down
12 changes: 12 additions & 0 deletions crates/web-sys/src/features/gen_BluetoothRemoteGattDescriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn uuid(this: &BluetoothRemoteGattDescriptor) -> String;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "DataView")]
# [wasm_bindgen (structural , method , getter , js_class = "BluetoothRemoteGATTDescriptor" , js_name = value)]
#[doc = "Getter for the `value` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTDescriptor/value)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `BluetoothRemoteGattDescriptor`, `DataView`*"]
#[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 value(this: &BluetoothRemoteGattDescriptor) -> Option<::js_sys::DataView>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "BluetoothRemoteGATTDescriptor" , js_name = readValue)]
#[doc = "The `readValue()` method."]
#[doc = ""]
Expand Down
2 changes: 1 addition & 1 deletion crates/webidl/src/idl_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<'a> IdlType<'a> {
IdlType::Error => Err(TypeError::CannotConvert),

IdlType::ArrayBuffer => Ok(js_sys("ArrayBuffer")),
IdlType::DataView => Err(TypeError::CannotConvert),
IdlType::DataView => Ok(js_sys("DataView")),
IdlType::Int8Array { immutable } => Ok(Some(array("i8", pos, *immutable))),
IdlType::Uint8Array { immutable } => Ok(Some(array("u8", pos, *immutable))),
IdlType::Uint8ClampedArray { immutable } => {
Expand Down

0 comments on commit 28d4575

Please sign in to comment.