Skip to content

Commit

Permalink
Account for [AllowShared] when using Rust slices
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Oct 9, 2024
1 parent 0d5b3d9 commit c366fc3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ extern "C" {
value: &::js_sys::Object,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValue)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValue)]
#[doc = "The `writeValue()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/writeValue)"]
Expand All @@ -218,7 +218,7 @@ extern "C" {
pub fn write_value_with_u8_slice(
this: &BluetoothRemoteGattCharacteristic,
value: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValue)]
#[doc = "The `writeValue()` method."]
Expand Down Expand Up @@ -248,7 +248,7 @@ extern "C" {
value: &::js_sys::Object,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValueWithResponse)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValueWithResponse)]
#[doc = "The `writeValueWithResponse()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/writeValueWithResponse)"]
Expand All @@ -260,7 +260,7 @@ extern "C" {
pub fn write_value_with_response_with_u8_slice(
this: &BluetoothRemoteGattCharacteristic,
value: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValueWithResponse)]
#[doc = "The `writeValueWithResponse()` method."]
Expand Down Expand Up @@ -290,7 +290,7 @@ extern "C" {
value: &::js_sys::Object,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValueWithoutResponse)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValueWithoutResponse)]
#[doc = "The `writeValueWithoutResponse()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/writeValueWithoutResponse)"]
Expand All @@ -302,7 +302,7 @@ extern "C" {
pub fn write_value_without_response_with_u8_slice(
this: &BluetoothRemoteGattCharacteristic,
value: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTCharacteristic" , js_name = writeValueWithoutResponse)]
#[doc = "The `writeValueWithoutResponse()` method."]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extern "C" {
value: &::js_sys::Object,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "BluetoothRemoteGATTDescriptor" , js_name = writeValue)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTDescriptor" , js_name = writeValue)]
#[doc = "The `writeValue()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTDescriptor/writeValue)"]
Expand All @@ -90,7 +90,7 @@ extern "C" {
pub fn write_value_with_u8_slice(
this: &BluetoothRemoteGattDescriptor,
value: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "BluetoothRemoteGATTDescriptor" , js_name = writeValue)]
#[doc = "The `writeValue()` method."]
Expand Down
8 changes: 4 additions & 4 deletions crates/web-sys/src/features/gen_HidDevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ extern "C" {
data: &::js_sys::Object,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "HIDDevice" , js_name = sendFeatureReport)]
# [wasm_bindgen (catch , method , structural , js_class = "HIDDevice" , js_name = sendFeatureReport)]
#[doc = "The `sendFeatureReport()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice/sendFeatureReport)"]
Expand All @@ -155,7 +155,7 @@ extern "C" {
this: &HidDevice,
report_id: u8,
data: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "HIDDevice" , js_name = sendFeatureReport)]
#[doc = "The `sendFeatureReport()` method."]
Expand Down Expand Up @@ -187,7 +187,7 @@ extern "C" {
data: &::js_sys::Object,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "HIDDevice" , js_name = sendReport)]
# [wasm_bindgen (catch , method , structural , js_class = "HIDDevice" , js_name = sendReport)]
#[doc = "The `sendReport()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice/sendReport)"]
Expand All @@ -200,7 +200,7 @@ extern "C" {
this: &HidDevice,
report_id: u8,
data: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "HIDDevice" , js_name = sendReport)]
#[doc = "The `sendReport()` method."]
Expand Down
12 changes: 6 additions & 6 deletions crates/web-sys/src/features/gen_UsbDevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ extern "C" {
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "UsbControlTransferParameters")]
# [wasm_bindgen (method , structural , js_class = "USBDevice" , js_name = controlTransferOut)]
# [wasm_bindgen (catch , method , structural , js_class = "USBDevice" , js_name = controlTransferOut)]
#[doc = "The `controlTransferOut()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/USBDevice/controlTransferOut)"]
Expand All @@ -304,7 +304,7 @@ extern "C" {
this: &UsbDevice,
setup: &UsbControlTransferParameters,
data: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "UsbControlTransferParameters")]
# [wasm_bindgen (catch , method , structural , js_class = "USBDevice" , js_name = controlTransferOut)]
Expand Down Expand Up @@ -364,7 +364,7 @@ extern "C" {
packet_lengths: &::wasm_bindgen::JsValue,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "USBDevice" , js_name = isochronousTransferOut)]
# [wasm_bindgen (catch , method , structural , js_class = "USBDevice" , js_name = isochronousTransferOut)]
#[doc = "The `isochronousTransferOut()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/USBDevice/isochronousTransferOut)"]
Expand All @@ -378,7 +378,7 @@ extern "C" {
endpoint_number: u8,
data: &mut [u8],
packet_lengths: &::wasm_bindgen::JsValue,
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "USBDevice" , js_name = isochronousTransferOut)]
#[doc = "The `isochronousTransferOut()` method."]
Expand Down Expand Up @@ -481,7 +481,7 @@ extern "C" {
data: &::js_sys::Object,
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "USBDevice" , js_name = transferOut)]
# [wasm_bindgen (catch , method , structural , js_class = "USBDevice" , js_name = transferOut)]
#[doc = "The `transferOut()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/USBDevice/transferOut)"]
Expand All @@ -494,7 +494,7 @@ extern "C" {
this: &UsbDevice,
endpoint_number: u8,
data: &mut [u8],
) -> ::js_sys::Promise;
) -> Result<::js_sys::Promise, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "USBDevice" , js_name = transferOut)]
#[doc = "The `transferOut()` method."]
Expand Down
8 changes: 4 additions & 4 deletions crates/web-sys/src/features/gen_XrFrame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn predicted_display_time(this: &XrFrame) -> f64;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "XRFrame" , js_name = fillJointRadii)]
# [wasm_bindgen (catch , method , structural , js_class = "XRFrame" , js_name = fillJointRadii)]
#[doc = "The `fillJointRadii()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/fillJointRadii)"]
Expand All @@ -53,7 +53,7 @@ extern "C" {
this: &XrFrame,
joint_spaces: &::wasm_bindgen::JsValue,
radii: &mut [f32],
) -> bool;
) -> Result<bool, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (catch , method , structural , js_class = "XRFrame" , js_name = fillJointRadii)]
#[doc = "The `fillJointRadii()` method."]
Expand All @@ -71,7 +71,7 @@ extern "C" {
) -> Result<bool, JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "XrSpace")]
# [wasm_bindgen (method , structural , js_class = "XRFrame" , js_name = fillPoses)]
# [wasm_bindgen (catch , method , structural , js_class = "XRFrame" , js_name = fillPoses)]
#[doc = "The `fillPoses()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/XRFrame/fillPoses)"]
Expand All @@ -85,7 +85,7 @@ extern "C" {
spaces: &::wasm_bindgen::JsValue,
base_space: &XrSpace,
transforms: &mut [f32],
) -> bool;
) -> Result<bool, JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "XrSpace")]
# [wasm_bindgen (catch , method , structural , js_class = "XRFrame" , js_name = fillPoses)]
Expand Down
2 changes: 1 addition & 1 deletion crates/webidl-tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn take_and_return_a_bunch_of_slices() {
assert_eq!(f.i32_with_i32_slice(&mut [1, 2]), [3, 4, 5]);
assert_eq!(f.u8_with_u8_slice(&mut [1, 2]), [3, 4, 5]);
assert_eq!(f.u16_with_u16_slice(&mut [1, 2]), [3, 4, 5]);
assert_eq!(f.u32_with_u32_slice(&mut [1, 2]), [3, 4, 5]);
assert_eq!(f.u32_with_u32_slice(&mut [1, 2]), Ok(vec![3, 4, 5]));
assert_eq!(
f.u8_clamped_with_u8_clamped_slice(Clamped(&mut [1, 2])).0,
[3, 4, 5]
Expand Down
16 changes: 8 additions & 8 deletions crates/webidl-tests/webidls/enabled/array.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ interface TestArrays {
ByteString byteStrings(ByteString arg1);
USVString usvStrings(USVString arg1);

Float32Array f32(Float32Array a);
Float64Array f64(Float64Array a);
Int8Array i8(Int8Array a);
Int16Array i16(Int16Array a);
Int32Array i32(Int32Array a);
Uint8Array u8(Uint8Array a);
Uint8ClampedArray u8Clamped(Uint8ClampedArray a);
Uint16Array u16(Uint16Array a);
Float32Array f32([AllowShared] Float32Array a);
Float64Array f64([AllowShared] Float64Array a);
Int8Array i8([AllowShared] Int8Array a);
Int16Array i16([AllowShared] Int16Array a);
Int32Array i32([AllowShared] Int32Array a);
Uint8Array u8([AllowShared] Uint8Array a);
Uint8ClampedArray u8Clamped([AllowShared] Uint8ClampedArray a);
Uint16Array u16([AllowShared] Uint16Array a);
Uint32Array u32(Uint32Array a);

readonly attribute FrozenArray<octet> octetArray;
Expand Down
15 changes: 14 additions & 1 deletion crates/webidl/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,20 @@ fn arg_throws(ty: &IdlType<'_>) -> bool {
| IdlType::Float32Array { allow_shared, .. }
| IdlType::Float64Array { allow_shared, .. }
| IdlType::ArrayBufferView { allow_shared, .. }
| IdlType::BufferSource { allow_shared, .. } => !allow_shared,
| IdlType::BufferSource { allow_shared, .. }
| IdlType::Identifier {
ty:
IdentifierType::Int8Slice { allow_shared, .. }
| IdentifierType::Uint8Slice { allow_shared, .. }
| IdentifierType::Uint8ClampedSlice { allow_shared, .. }
| IdentifierType::Int16Slice { allow_shared, .. }
| IdentifierType::Uint16Slice { allow_shared, .. }
| IdentifierType::Int32Slice { allow_shared, .. }
| IdentifierType::Uint32Slice { allow_shared, .. }
| IdentifierType::Float32Slice { allow_shared, .. }
| IdentifierType::Float64Slice { allow_shared, .. },
..
} => !allow_shared,
IdlType::Nullable(item) => arg_throws(item),
IdlType::Union(list) => list.iter().any(arg_throws),
// catch-all for everything else like Object
Expand Down

0 comments on commit c366fc3

Please sign in to comment.