From d246c5cf2069aaac77054d1d8b43d96847bfb483 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 22 Sep 2017 13:56:29 +0200 Subject: [PATCH] Remove JSContext argument from AsyncBluetoothListener::handle_response --- components/script/dom/bluetooth.rs | 19 ++++++++----------- components/script/dom/bluetoothdevice.rs | 8 +------- .../script/dom/bluetoothpermissionresult.rs | 8 +------- .../dom/bluetoothremotegattcharacteristic.rs | 8 +------- .../dom/bluetoothremotegattdescriptor.rs | 7 +------ .../script/dom/bluetoothremotegattserver.rs | 8 +------- .../script/dom/bluetoothremotegattservice.rs | 3 +-- 7 files changed, 14 insertions(+), 47 deletions(-) diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 5ea1e06f215..12d363731ca 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -33,7 +33,7 @@ use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; use js::conversions::ConversionResult; -use js::jsapi::{JSAutoCompartment, JSContext, JSObject}; +use js::jsapi::{JSContext, JSObject}; use js::jsval::{ObjectValue, UndefinedValue}; use std::cell::Ref; use std::collections::HashMap; @@ -94,20 +94,21 @@ struct BluetoothContext { } pub trait AsyncBluetoothListener { - fn handle_response(&self, result: BluetoothResponse, cx: *mut JSContext, promise: &Rc); + fn handle_response(&self, result: BluetoothResponse, promise: &Rc); } -impl BluetoothContext { +impl BluetoothContext +where + T: AsyncBluetoothListener + DomObject, +{ #[allow(unrooted_must_root)] fn response(&mut self, response: BluetoothResponseResult) { let promise = self.promise.take().expect("bt promise is missing").root(); - let promise_cx = promise.global().get_cx(); // JSAutoCompartment needs to be manually made. // Otherwise, Servo will crash. - let _ac = JSAutoCompartment::new(promise_cx, promise.reflector().get_jsobject().get()); match response { - Ok(response) => self.receiver.root().handle_response(response, promise_cx, &promise), + Ok(response) => self.receiver.root().handle_response(response, &promise), // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice // Step 3 - 4. Err(error) => promise.reject_error(Error::from(error)), @@ -506,11 +507,7 @@ impl BluetoothMethods for Bluetooth { } impl AsyncBluetoothListener for Bluetooth { - fn handle_response( - &self, response: BluetoothResponse, - _promise_cx: *mut JSContext, - promise: &Rc, - ) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc) { match response { // https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices // Step 11, 13 - 14. diff --git a/components/script/dom/bluetoothdevice.rs b/components/script/dom/bluetoothdevice.rs index 074b1da7d17..2e8e07503da 100644 --- a/components/script/dom/bluetoothdevice.rs +++ b/components/script/dom/bluetoothdevice.rs @@ -25,7 +25,6 @@ use dom::globalscope::GlobalScope; use dom::promise::Promise; use dom_struct::dom_struct; use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::JSContext; use std::cell::Cell; use std::collections::HashMap; use std::rc::Rc; @@ -266,12 +265,7 @@ impl BluetoothDeviceMethods for BluetoothDevice { } impl AsyncBluetoothListener for BluetoothDevice { - fn handle_response( - &self, - response: BluetoothResponse, - _promise_cx: *mut JSContext, - promise: &Rc, - ) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc) { match response { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-unwatchadvertisements BluetoothResponse::WatchAdvertisements(_result) => { diff --git a/components/script/dom/bluetoothpermissionresult.rs b/components/script/dom/bluetoothpermissionresult.rs index 661ebd9a30c..cc766b85477 100644 --- a/components/script/dom/bluetoothpermissionresult.rs +++ b/components/script/dom/bluetoothpermissionresult.rs @@ -20,7 +20,6 @@ use dom::permissionstatus::PermissionStatus; use dom::promise::Promise; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; -use js::jsapi::JSContext; use std::rc::Rc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothpermissionresult @@ -83,12 +82,7 @@ impl BluetoothPermissionResultMethods for BluetoothPermissionResult { } impl AsyncBluetoothListener for BluetoothPermissionResult { - fn handle_response( - &self, - response: BluetoothResponse, - _promise_cx: *mut JSContext, - promise: &Rc, - ) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc) { match response { // https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices // Step 3, 11, 13 - 14. diff --git a/components/script/dom/bluetoothremotegattcharacteristic.rs b/components/script/dom/bluetoothremotegattcharacteristic.rs index 42c0a634190..f54776d37a9 100644 --- a/components/script/dom/bluetoothremotegattcharacteristic.rs +++ b/components/script/dom/bluetoothremotegattcharacteristic.rs @@ -26,7 +26,6 @@ use dom::globalscope::GlobalScope; use dom::promise::Promise; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; -use js::jsapi::JSContext; use std::rc::Rc; // Maximum length of an attribute value. @@ -252,12 +251,7 @@ impl BluetoothRemoteGATTCharacteristicMethods for BluetoothRemoteGATTCharacteris } impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic { - fn handle_response( - &self, - response: BluetoothResponse, - _promise_cx: *mut JSContext, - promise: &Rc, - ) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc) { let device = self.Service().Device(); match response { // https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren diff --git a/components/script/dom/bluetoothremotegattdescriptor.rs b/components/script/dom/bluetoothremotegattdescriptor.rs index 1ab100fb522..d05194af1d2 100644 --- a/components/script/dom/bluetoothremotegattdescriptor.rs +++ b/components/script/dom/bluetoothremotegattdescriptor.rs @@ -21,7 +21,6 @@ use dom::globalscope::GlobalScope; use dom::promise::Promise; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; -use js::jsapi::JSContext; use std::rc::Rc; // http://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattdescriptor @@ -145,11 +144,7 @@ impl BluetoothRemoteGATTDescriptorMethods for BluetoothRemoteGATTDescriptor { } impl AsyncBluetoothListener for BluetoothRemoteGATTDescriptor { - fn handle_response( - &self, response: BluetoothResponse, - _promise_cx: *mut JSContext, - promise: &Rc, - ) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc) { match response { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue BluetoothResponse::ReadValue(result) => { diff --git a/components/script/dom/bluetoothremotegattserver.rs b/components/script/dom/bluetoothremotegattserver.rs index 7e7f8e64e9e..65e66edecd3 100644 --- a/components/script/dom/bluetoothremotegattserver.rs +++ b/components/script/dom/bluetoothremotegattserver.rs @@ -17,7 +17,6 @@ use dom::globalscope::GlobalScope; use dom::promise::Promise; use dom_struct::dom_struct; use ipc_channel::ipc::IpcSender; -use js::jsapi::JSContext; use std::cell::Cell; use std::rc::Rc; @@ -120,12 +119,7 @@ impl BluetoothRemoteGATTServerMethods for BluetoothRemoteGATTServer { } impl AsyncBluetoothListener for BluetoothRemoteGATTServer { - fn handle_response( - &self, - response: BluetoothResponse, - _promise_cx: *mut JSContext, - promise: &Rc, - ) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc) { match response { // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect BluetoothResponse::GATTServerConnect(connected) => { diff --git a/components/script/dom/bluetoothremotegattservice.rs b/components/script/dom/bluetoothremotegattservice.rs index 0a8509603c1..6140d83c9f5 100644 --- a/components/script/dom/bluetoothremotegattservice.rs +++ b/components/script/dom/bluetoothremotegattservice.rs @@ -17,7 +17,6 @@ use dom::eventtarget::EventTarget; use dom::globalscope::GlobalScope; use dom::promise::Promise; use dom_struct::dom_struct; -use js::jsapi::JSContext; use std::rc::Rc; // https://webbluetoothcg.github.io/web-bluetooth/#bluetoothremotegattservice @@ -128,7 +127,7 @@ impl BluetoothRemoteGATTServiceMethods for BluetoothRemoteGATTService { } impl AsyncBluetoothListener for BluetoothRemoteGATTService { - fn handle_response(&self, response: BluetoothResponse, _promise_cx: *mut JSContext, promise: &Rc) { + fn handle_response(&self, response: BluetoothResponse, promise: &Rc) { let device = self.Device(); match response { // https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren