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

@ -42,7 +42,7 @@ pub enum FetchedData {
// https://fetch.spec.whatwg.org/#concept-body-consume-body
#[allow(unrooted_must_root)]
pub fn consume_body<T: BodyOperations + Reflectable>(object: &T, body_type: BodyType) -> Rc<Promise> {
let promise = Promise::new(object.global().r());
let promise = Promise::new(&object.global_scope());
// Step 1
if object.get_body_used() || object.is_locked() {

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) {

View file

@ -70,8 +70,9 @@ pub fn Fetch(global: GlobalRef, input: RequestOrUSVString, init: &RequestInit) -
let core_resource_thread = global.core_resource_thread();
// Step 1
let promise = Promise::new(global);
let response = Response::new(global.as_global_scope());
let global_scope = global.as_global_scope();
let promise = Promise::new(global_scope);
let response = Response::new(global_scope);
// Step 2
let request = match Request::Constructor(global, input, init) {