Make bluetooth::result_to_promise take a &GlobalScope

This commit is contained in:
Anthony Ramine 2016-10-02 17:11:29 +02:00
parent 9183525192
commit d4fccbace4
5 changed files with 16 additions and 17 deletions

View file

@ -8,7 +8,6 @@ use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothMethods,
use dom::bindings::codegen::Bindings::BluetoothBinding::RequestDeviceOptions; use dom::bindings::codegen::Bindings::BluetoothBinding::RequestDeviceOptions;
use dom::bindings::error::Error::{self, Security, Type}; use dom::bindings::error::Error::{self, Security, Type};
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root; use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
@ -271,10 +270,10 @@ fn canonicalize_filter(filter: &BluetoothRequestDeviceFilter) -> Fallible<Blueto
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn result_to_promise<T: ToJSValConvertible>(global_ref: GlobalRef, pub fn result_to_promise<T: ToJSValConvertible>(global: &GlobalScope,
bluetooth_result: Fallible<T>) bluetooth_result: Fallible<T>)
-> Rc<Promise> { -> Rc<Promise> {
let p = Promise::new(global_ref.as_global_scope()); let p = Promise::new(global);
match bluetooth_result { match bluetooth_result {
Ok(v) => p.resolve_native(p.global().r().get_cx(), &v), Ok(v) => p.resolve_native(p.global().r().get_cx(), &v),
Err(e) => p.reject_error(p.global().r().get_cx(), e), Err(e) => p.reject_error(p.global().r().get_cx(), e),
@ -298,6 +297,6 @@ impl BluetoothMethods for Bluetooth {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
fn RequestDevice(&self, option: &RequestDeviceOptions) -> Rc<Promise> { fn RequestDevice(&self, option: &RequestDeviceOptions) -> Rc<Promise> {
result_to_promise(self.global().r(), self.request_device(option)) result_to_promise(&self.global_scope(), self.request_device(option))
} }
} }

View file

@ -212,7 +212,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-getdescriptor
fn GetDescriptor(&self, descriptor: BluetoothDescriptorUUID) -> Rc<Promise> { fn GetDescriptor(&self, descriptor: BluetoothDescriptorUUID) -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_descriptor(descriptor)) result_to_promise(&self.global_scope(), self.get_descriptor(descriptor))
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
@ -220,7 +220,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
fn GetDescriptors(&self, fn GetDescriptors(&self,
descriptor: Option<BluetoothDescriptorUUID>) descriptor: Option<BluetoothDescriptorUUID>)
-> Rc<Promise> { -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_descriptors(descriptor)) result_to_promise(&self.global_scope(), self.get_descriptors(descriptor))
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-value // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-value
@ -231,12 +231,12 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue
fn ReadValue(&self) -> Rc<Promise> { fn ReadValue(&self) -> Rc<Promise> {
result_to_promise(self.global().r(), self.read_value()) result_to_promise(&self.global_scope(), self.read_value())
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> { fn WriteValue(&self, value: Vec<u8>) -> Rc<Promise> {
result_to_promise(self.global().r(), self.write_value(value)) result_to_promise(&self.global_scope(), self.write_value(value))
} }
} }

View file

@ -135,12 +135,12 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
fn ReadValue(&self) -> Rc<Promise> { fn ReadValue(&self) -> Rc<Promise> {
result_to_promise(self.global().r(), self.read_value()) result_to_promise(&self.global_scope(), self.read_value())
} }
#[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: Vec<u8>) -> Rc<Promise> {
result_to_promise(self.global().r(), self.write_value(value)) result_to_promise(&self.global_scope(), self.write_value(value))
} }
} }

View file

@ -138,7 +138,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
fn Connect(&self) -> Rc<Promise> { fn Connect(&self) -> Rc<Promise> {
result_to_promise(self.global().r(), self.connect()) result_to_promise(&self.global_scope(), self.connect())
} }
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-disconnect
@ -161,7 +161,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-getprimaryservice
fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Rc<Promise> { fn GetPrimaryService(&self, service: BluetoothServiceUUID) -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_primary_service(service)) result_to_promise(&self.global_scope(), self.get_primary_service(service))
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
@ -169,6 +169,6 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer {
fn GetPrimaryServices(&self, fn GetPrimaryServices(&self,
service: Option<BluetoothServiceUUID>) service: Option<BluetoothServiceUUID>)
-> Rc<Promise> { -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_primary_services(service)) result_to_promise(&self.global_scope(), self.get_primary_services(service))
} }
} }

View file

@ -236,7 +236,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
fn GetCharacteristic(&self, fn GetCharacteristic(&self,
characteristic: BluetoothCharacteristicUUID) characteristic: BluetoothCharacteristicUUID)
-> Rc<Promise> { -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_characteristic(characteristic)) result_to_promise(&self.global_scope(), self.get_characteristic(characteristic))
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
@ -244,7 +244,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
fn GetCharacteristics(&self, fn GetCharacteristics(&self,
characteristic: Option<BluetoothCharacteristicUUID>) characteristic: Option<BluetoothCharacteristicUUID>)
-> Rc<Promise> { -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_characteristics(characteristic)) result_to_promise(&self.global_scope(), self.get_characteristics(characteristic))
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
@ -252,7 +252,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
fn GetIncludedService(&self, fn GetIncludedService(&self,
service: BluetoothServiceUUID) service: BluetoothServiceUUID)
-> Rc<Promise> { -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_included_service(service)) result_to_promise(&self.global_scope(), self.get_included_service(service))
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
@ -260,6 +260,6 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService {
fn GetIncludedServices(&self, fn GetIncludedServices(&self,
service: Option<BluetoothServiceUUID>) service: Option<BluetoothServiceUUID>)
-> Rc<Promise> { -> Rc<Promise> {
result_to_promise(self.global().r(), self.get_included_services(service)) result_to_promise(&self.global_scope(), self.get_included_services(service))
} }
} }