diff options
6 files changed, 17 insertions, 12 deletions
diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 20037c9920c..a8dc2d39a5a 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -12,6 +12,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTCharacteristicBinding:: BluetoothRemoteGATTCharacteristicMethods; use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods; use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods; +use dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer; use dom::bindings::error::Error::{self, InvalidModification, Network, NotSupported, Security}; use dom::bindings::inheritance::Castable; use dom::bindings::reflector::{DomObject, reflect_dom_object}; @@ -155,7 +156,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris #[allow(unrooted_must_root)] // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue - fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> { + fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc<Promise> { let p = Promise::new(&self.global()); // Step 1. @@ -165,7 +166,12 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } // Step 2 - 3. - if value.len() > MAXIMUM_ATTRIBUTE_LENGTH { + let vec = match value { + ArrayBufferViewOrArrayBuffer::ArrayBufferView(mut avb) => avb.to_vec(), + ArrayBufferViewOrArrayBuffer::ArrayBuffer(mut ab) => ab.to_vec(), + }; + + if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH { p.reject_error(InvalidModification); return p; } @@ -190,7 +196,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris // in writeValue function and in handle_response function. let sender = response_async(&p, self); self.get_bluetooth_thread().send( - BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap(); + BluetoothRequest::WriteValue(self.get_instance_id(), vec, sender)).unwrap(); return p; } diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs index 54a6b1142b3..e120648d661 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetoothremotegattdescriptor.rs @@ -125,11 +125,11 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { } // Step 2 - 3. - let v = match value { + let vec = match value { ArrayBufferViewOrArrayBuffer::ArrayBufferView(mut avb) => avb.to_vec(), ArrayBufferViewOrArrayBuffer::ArrayBuffer(mut ab) => ab.to_vec(), }; - if v.len() > MAXIMUM_ATTRIBUTE_LENGTH { + if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH { p.reject_error(InvalidModification); return p; } @@ -145,7 +145,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { // in writeValue function and in handle_response function. let sender = response_async(&p, self); self.get_bluetooth_thread().send( - BluetoothRequest::WriteValue(self.get_instance_id(), v, sender)).unwrap(); + BluetoothRequest::WriteValue(self.get_instance_id(), vec, sender)).unwrap(); return p; } } diff --git a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl index 3e086fc21ca..07cedd97421 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTCharacteristic.webidl @@ -16,8 +16,7 @@ interface BluetoothRemoteGATTCharacteristic : EventTarget { getDescriptors(optional BluetoothDescriptorUUID descriptor); Promise<ByteString> readValue(); //Promise<DataView> readValue(); - Promise<void> writeValue(sequence<octet> value); - //Promise<void> writeValue(BufferSource value); + Promise<void> writeValue(BufferSource value); Promise<BluetoothRemoteGATTCharacteristic> startNotifications(); Promise<BluetoothRemoteGATTCharacteristic> stopNotifications(); }; diff --git a/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl b/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl index 82aa80cc580..243b86fe155 100644 --- a/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl +++ b/components/script/dom/webidls/BluetoothRemoteGATTDescriptor.webidl @@ -11,6 +11,6 @@ interface BluetoothRemoteGATTDescriptor { readonly attribute DOMString uuid; readonly attribute ByteString? value; Promise<ByteString> readValue(); - // Promise<DataView> readValue(); + //Promise<DataView> readValue(); Promise<void> writeValue(BufferSource value); }; diff --git a/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html b/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html index a504a49f2d8..23851862a23 100644 --- a/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html +++ b/tests/wpt/mozilla/tests/bluetooth/writeValue/characteristic/write-updates-value.html @@ -15,8 +15,8 @@ promise_test(() => { .then(service => service.getCharacteristic(device_name.name)) .then(characteristic => { assert_equals(characteristic.value, null); - return characteristic.writeValue(asciiToDecimal('foo')) - .then(() => assert_equals(characteristic.value, 'foo')); + return characteristic.writeValue(Uint8Array.of(1, 2)) + .then(() => assert_equals(characteristic.value, '\x01\x02')); }); }, 'A regular write request to a writable characteristic should update value.'); </script> diff --git a/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html b/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html index 26ad0c4403d..14dc5b027e4 100644 --- a/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html +++ b/tests/wpt/mozilla/tests/bluetooth/writeValue/descriptor/write-updates-value.html @@ -17,7 +17,7 @@ promise_test(() => { .then(descriptor => { assert_equals(descriptor.value, null); return descriptor.writeValue(Uint8Array.of(1, 2)) - .then(() => assert_equals(descriptor.value, "\x01\x02")); + .then(() => assert_equals(descriptor.value, '\x01\x02')); }); }, 'A regular write request to a writable descriptor should update value.'); </script> |