Make Promise::reject_error sound

This commit is contained in:
Anthony Ramine 2017-09-21 18:22:20 +02:00
parent 15acd1525e
commit af2e83f378
19 changed files with 110 additions and 94 deletions

View file

@ -89,17 +89,16 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
fn ReadValue(&self) -> Rc<Promise> {
let p = Promise::new(&self.global());
let p_cx = p.global().get_cx();
// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
p.reject_error(p_cx, Security);
p.reject_error(Security);
return p;
}
// Step 2.
if !self.Characteristic().Service().Device().get_gatt().Connected() {
p.reject_error(p_cx, Network);
p.reject_error(Network);
return p;
}
@ -116,23 +115,22 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
let p = Promise::new(&self.global());
let p_cx = p.global().get_cx();
// Step 1.
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {
p.reject_error(p_cx, Security);
p.reject_error(Security);
return p;
}
// Step 2 - 3.
if value.len() > MAXIMUM_ATTRIBUTE_LENGTH {
p.reject_error(p_cx, InvalidModification);
p.reject_error(InvalidModification);
return p;
}
// Step 4.
if !self.Characteristic().Service().Device().get_gatt().Connected() {
p.reject_error(p_cx, Network);
p.reject_error(Network);
return p;
}
@ -147,7 +145,11 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
}
impl AsyncBluetoothListener for BluetoothRemoteGATTDescriptor {
fn handle_response(&self, response: BluetoothResponse, promise_cx: *mut JSContext, promise: &Rc<Promise>) {
fn handle_response(
&self, response: BluetoothResponse,
_promise_cx: *mut JSContext,
promise: &Rc<Promise>,
) {
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
BluetoothResponse::ReadValue(result) => {
@ -173,7 +175,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTDescriptor {
// TODO: Resolve promise with undefined instead of a value.
promise.resolve_native(&());
},
_ => promise.reject_error(promise_cx, Error::Type("Something went wrong...".to_owned())),
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}
}
}