mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Switches WriteValue to use BufferSource
This commit is contained in:
parent
b8279b376b
commit
40235da2d3
3 changed files with 12 additions and 8 deletions
|
@ -11,6 +11,7 @@ use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding::BluetoothRemoteGATTDescriptorMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTDescriptorBinding::BluetoothRemoteGATTDescriptorMethods;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServerBinding::BluetoothRemoteGATTServerMethods;
|
||||||
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
use dom::bindings::codegen::Bindings::BluetoothRemoteGATTServiceBinding::BluetoothRemoteGATTServiceMethods;
|
||||||
|
use dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer;
|
||||||
use dom::bindings::error::Error::{self, InvalidModification, Network, Security};
|
use dom::bindings::error::Error::{self, InvalidModification, Network, Security};
|
||||||
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||||
use dom::bindings::root::{Dom, DomRoot};
|
use dom::bindings::root::{Dom, DomRoot};
|
||||||
|
@ -114,7 +115,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
|
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
|
||||||
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
|
fn WriteValue(&self, value: ArrayBufferViewOrArrayBuffer) -> Rc<Promise> {
|
||||||
let p = Promise::new(&self.global());
|
let p = Promise::new(&self.global());
|
||||||
|
|
||||||
// Step 1.
|
// Step 1.
|
||||||
|
@ -124,7 +125,11 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2 - 3.
|
// Step 2 - 3.
|
||||||
if value.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
let v = match value {
|
||||||
|
ArrayBufferViewOrArrayBuffer::ArrayBufferView(mut avb) => avb.to_vec(),
|
||||||
|
ArrayBufferViewOrArrayBuffer::ArrayBuffer(mut ab) => ab.to_vec(),
|
||||||
|
};
|
||||||
|
if v.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||||
p.reject_error(InvalidModification);
|
p.reject_error(InvalidModification);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +145,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
|
||||||
// in writeValue function and in handle_response function.
|
// in writeValue function and in handle_response function.
|
||||||
let sender = response_async(&p, self);
|
let sender = response_async(&p, self);
|
||||||
self.get_bluetooth_thread().send(
|
self.get_bluetooth_thread().send(
|
||||||
BluetoothRequest::WriteValue(self.get_instance_id(), value, sender)).unwrap();
|
BluetoothRequest::WriteValue(self.get_instance_id(), v, sender)).unwrap();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ interface BluetoothRemoteGATTDescriptor {
|
||||||
readonly attribute DOMString uuid;
|
readonly attribute DOMString uuid;
|
||||||
readonly attribute ByteString? value;
|
readonly attribute ByteString? value;
|
||||||
Promise<ByteString> readValue();
|
Promise<ByteString> readValue();
|
||||||
//Promise<DataView> readValue();
|
// Promise<DataView> readValue();
|
||||||
Promise<void> writeValue(sequence<octet> value);
|
Promise<void> writeValue(BufferSource value);
|
||||||
//Promise<void> writeValue(BufferSource value);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,8 +16,8 @@ promise_test(() => {
|
||||||
.then(characteristic => characteristic.getDescriptor(number_of_digitals.name))
|
.then(characteristic => characteristic.getDescriptor(number_of_digitals.name))
|
||||||
.then(descriptor => {
|
.then(descriptor => {
|
||||||
assert_equals(descriptor.value, null);
|
assert_equals(descriptor.value, null);
|
||||||
return descriptor.writeValue(asciiToDecimal('foo'))
|
return descriptor.writeValue(Uint8Array.of(1, 2))
|
||||||
.then(() => assert_equals(descriptor.value, 'foo'));
|
.then(() => assert_equals(descriptor.value, "\x01\x02"));
|
||||||
});
|
});
|
||||||
}, 'A regular write request to a writable descriptor should update value.');
|
}, 'A regular write request to a writable descriptor should update value.');
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue