Remove JSContext argument from AsyncBluetoothListener::handle_response

This commit is contained in:
Anthony Ramine 2017-09-22 13:56:29 +02:00
parent 2400731bfc
commit d246c5cf20
7 changed files with 14 additions and 47 deletions

View file

@ -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<T: AsyncBluetoothListener + DomObject> {
}
pub trait AsyncBluetoothListener {
fn handle_response(&self, result: BluetoothResponse, cx: *mut JSContext, promise: &Rc<Promise>);
fn handle_response(&self, result: BluetoothResponse, promise: &Rc<Promise>);
}
impl<T: AsyncBluetoothListener + DomObject> BluetoothContext<T> {
impl<T> BluetoothContext<T>
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<Promise>,
) {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) {
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices
// Step 11, 13 - 14.

View file

@ -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<Promise>,
) {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) {
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-unwatchadvertisements
BluetoothResponse::WatchAdvertisements(_result) => {

View file

@ -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<Promise>,
) {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) {
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices
// Step 3, 11, 13 - 14.

View file

@ -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<Promise>,
) {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) {
let device = self.Service().Device();
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren

View file

@ -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<Promise>,
) {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) {
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-readvalue
BluetoothResponse::ReadValue(result) => {

View file

@ -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<Promise>,
) {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) {
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
BluetoothResponse::GATTServerConnect(connected) => {

View file

@ -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<Promise>) {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>) {
let device = self.Device();
match response {
// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren