diff --git a/components/script/dom/bluetoothadvertisingdata.rs b/components/script/dom/bluetoothadvertisingdata.rs index 71c1346fa3d..f6a7805acbf 100644 --- a/components/script/dom/bluetoothadvertisingdata.rs +++ b/components/script/dom/bluetoothadvertisingdata.rs @@ -12,13 +12,16 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object}; #[dom_struct] pub struct BluetoothAdvertisingData { reflector_: Reflector, - appearance: u16, - txPower: i8, - rssi: i8, + appearance: Option, + txPower: Option, + rssi: Option, } impl BluetoothAdvertisingData { - pub fn new_inherited(appearance: u16, txPower: i8, rssi: i8) -> BluetoothAdvertisingData { + pub fn new_inherited(appearance: Option, + txPower: Option, + rssi: Option) + -> BluetoothAdvertisingData { BluetoothAdvertisingData { reflector_: Reflector::new(), appearance: appearance, @@ -27,7 +30,11 @@ impl BluetoothAdvertisingData { } } - pub fn new(global: GlobalRef, appearance: u16, txPower: i8, rssi: i8) -> Root { + pub fn new(global: GlobalRef, + appearance: Option, + txPower: Option, + rssi: Option) + -> Root { reflect_dom_object(box BluetoothAdvertisingData::new_inherited(appearance, txPower, rssi), @@ -39,16 +46,16 @@ impl BluetoothAdvertisingData { impl BluetoothAdvertisingDataMethods for BluetoothAdvertisingData { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-appearance fn GetAppearance(&self) -> Option { - Some(self.appearance) + self.appearance } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-txpower fn GetTxPower(&self) -> Option { - Some(self.txPower) + self.txPower } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothadvertisingdata-rssi fn GetRssi(&self) -> Option { - Some(self.rssi) + self.rssi } } diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetoothdevice.rs index a941f89fa7e..8330ca4604a 100644 --- a/components/script/dom/bluetoothdevice.rs +++ b/components/script/dom/bluetoothdevice.rs @@ -5,8 +5,8 @@ use dom::bindings::codegen::Bindings::BluetoothDeviceBinding; use dom::bindings::codegen::Bindings::BluetoothDeviceBinding::{BluetoothDeviceMethods, VendorIDSource}; use dom::bindings::global::GlobalRef; -use dom::bindings::js::{JS, Root, MutHeap}; -use dom::bindings::reflector::{Reflector, reflect_dom_object}; +use dom::bindings::js::{JS, Root, MutHeap, MutNullableHeap}; +use dom::bindings::reflector::{Reflectable, Reflector, reflect_dom_object}; use dom::bluetoothadvertisingdata::BluetoothAdvertisingData; use dom::bluetoothremotegattserver::BluetoothRemoteGATTServer; use util::str::DOMString; @@ -16,26 +16,25 @@ use util::str::DOMString; pub struct BluetoothDevice { reflector_: Reflector, id: DOMString, - name: DOMString, + name: Option, adData: MutHeap>, - deviceClass: u32, - vendorIDSource: VendorIDSource, - vendorID: u32, - productID: u32, - productVersion: u32, - gatt: MutHeap>, + deviceClass: Option, + vendorIDSource: Option, + vendorID: Option, + productID: Option, + productVersion: Option, + gatt: MutNullableHeap>, } impl BluetoothDevice { pub fn new_inherited(id: DOMString, - name: DOMString, + name: Option, adData: &BluetoothAdvertisingData, - deviceClass: u32, - vendorIDSource: VendorIDSource, - vendorID: u32, - productID: u32, - productVersion: u32, - gatt: &BluetoothRemoteGATTServer) + deviceClass: Option, + vendorIDSource: Option, + vendorID: Option, + productID: Option, + productVersion: Option) -> BluetoothDevice { BluetoothDevice { reflector_: Reflector::new(), @@ -47,21 +46,20 @@ impl BluetoothDevice { vendorID: vendorID, productID: productID, productVersion: productVersion, - gatt: MutHeap::new(gatt), + gatt: Default::default(), } } pub fn new(global: GlobalRef, - id: DOMString, - name: DOMString, - adData: &BluetoothAdvertisingData, - deviceClass: u32, - vendorIDSource: VendorIDSource, - vendorID: u32, - productID: u32, - productVersion: u32, - gatt: &BluetoothRemoteGATTServer) - -> Root { + id: DOMString, + name: Option, + adData: &BluetoothAdvertisingData, + deviceClass: Option, + vendorIDSource: Option, + vendorID: Option, + productID: Option, + productVersion: Option) + -> Root { reflect_dom_object(box BluetoothDevice::new_inherited(id, name, adData, @@ -69,8 +67,7 @@ impl BluetoothDevice { vendorIDSource, vendorID, productID, - productVersion, - gatt), + productVersion), global, BluetoothDeviceBinding::Wrap) } @@ -85,7 +82,7 @@ impl BluetoothDeviceMethods for BluetoothDevice { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-name fn GetName(&self) -> Option { - Some(self.name.clone()) + self.name.clone() } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-addata @@ -95,31 +92,31 @@ impl BluetoothDeviceMethods for BluetoothDevice { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-deviceclass fn GetDeviceClass(&self) -> Option { - Some(self.deviceClass) + self.deviceClass } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendoridsource fn GetVendorIDSource(&self) -> Option { - Some(self.vendorIDSource) + self.vendorIDSource } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-vendorid fn GetVendorID(&self) -> Option { - Some(self.vendorID) + self.vendorID } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productid fn GetProductID(&self) -> Option { - Some(self.productID) + self.productID } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-productversion fn GetProductVersion(&self) -> Option { - Some(self.productVersion) + self.productVersion } // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-gatt fn Gatt(&self) -> Root { - self.gatt.get() + self.gatt.or_init(|| BluetoothRemoteGATTServer::new(self.global().r(), self)) } }