Make Promise::new take a &GlobalScope

This commit is contained in:
Anthony Ramine 2016-10-01 21:00:17 +02:00
parent a8c05c6962
commit ac5a4adf5f
5 changed files with 11 additions and 9 deletions

View file

@ -276,7 +276,7 @@ fn canonicalize_filter(filter: &BluetoothRequestDeviceFilter) -> Fallible<Blueto
pub fn result_to_promise<T: ToJSValConvertible>(global_ref: GlobalRef,
bluetooth_result: Fallible<T>)
-> Rc<Promise> {
let p = Promise::new(global_ref);
let p = Promise::new(global_ref.as_global_scope());
match bluetooth_result {
Ok(v) => p.resolve_native(p.global().r().get_cx(), &v),
Err(e) => p.reject_error(p.global().r().get_cx(), e),

View file

@ -18,6 +18,7 @@ use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::MutHeapJSVal;
use dom::bindings::reflector::{Reflectable, MutReflectable, Reflector};
use dom::globalscope::GlobalScope;
use dom::promisenativehandler::PromiseNativeHandler;
use js::conversions::ToJSValConvertible;
use js::jsapi::{CallOriginalPromiseResolve, CallOriginalPromiseReject, CallOriginalPromiseThen};
@ -70,7 +71,7 @@ impl Drop for Promise {
impl Promise {
#[allow(unsafe_code)]
pub fn new(global: GlobalRef) -> Rc<Promise> {
pub fn new(global: &GlobalScope) -> Rc<Promise> {
let cx = global.get_cx();
rooted!(in(cx) let mut obj = ptr::null_mut());
unsafe {

View file

@ -691,11 +691,11 @@ impl TestBindingMethods for TestBinding {
fn PromiseNativeHandler(&self,
resolve: Option<Rc<SimpleCallback>>,
reject: Option<Rc<SimpleCallback>>) -> Rc<Promise> {
let global = self.global();
let handler = PromiseNativeHandler::new(global.r().as_global_scope(),
let global = self.global_scope();
let handler = PromiseNativeHandler::new(&global,
resolve.map(SimpleHandler::new),
reject.map(SimpleHandler::new));
let p = Promise::new(global.r());
let p = Promise::new(&global);
p.append_native_handler(&handler);
return p;
@ -720,7 +720,7 @@ impl TestBindingMethods for TestBinding {
#[allow(unrooted_must_root)]
fn PromiseAttribute(&self) -> Rc<Promise> {
Promise::new(self.global().r())
Promise::new(&self.global_scope())
}
fn AcceptPromise(&self, _promise: &Promise) {