From 1f8bb3a89f50f4edf5d37f6d7c4c9d1480876753 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 5 Oct 2016 01:48:25 +0200 Subject: [PATCH] Make Fetch take a &GlobalScope --- components/script/dom/window.rs | 2 +- components/script/dom/workerglobalscope.rs | 2 +- components/script/fetch.rs | 17 ++++++++--------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 38b08e0ba25..e1f47cc8163 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -861,7 +861,7 @@ impl WindowMethods for Window { #[allow(unrooted_must_root)] // https://fetch.spec.whatwg.org/#fetch-method fn Fetch(&self, input: RequestOrUSVString, init: &RequestInit) -> Rc { - fetch::Fetch(self.global().r(), input, init) + fetch::Fetch(&self.upcast(), input, init) } } diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 93370debc9f..042f2b3d1e3 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -319,7 +319,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope { #[allow(unrooted_must_root)] // https://fetch.spec.whatwg.org/#fetch-method fn Fetch(&self, input: RequestOrUSVString, init: &RequestInit) -> Rc { - fetch::Fetch(self.global().r(), input, init) + fetch::Fetch(self.upcast(), input, init) } } diff --git a/components/script/fetch.rs b/components/script/fetch.rs index f7398ca1d30..1b2d5e77be9 100644 --- a/components/script/fetch.rs +++ b/components/script/fetch.rs @@ -7,10 +7,10 @@ use dom::bindings::codegen::Bindings::ResponseBinding::ResponseBinding::Response use dom::bindings::codegen::Bindings::ResponseBinding::ResponseType as DOMResponseType; use dom::bindings::codegen::UnionTypes::RequestOrUSVString; use dom::bindings::error::Error; -use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::reflector::Reflectable; +use dom::globalscope::GlobalScope; use dom::headers::Guard; use dom::promise::Promise; use dom::request::Request; @@ -66,18 +66,17 @@ fn request_init_from_request(request: NetTraitsRequest) -> NetTraitsRequestInit // https://fetch.spec.whatwg.org/#fetch-method #[allow(unrooted_must_root)] -pub fn Fetch(global: GlobalRef, input: RequestOrUSVString, init: &RequestInit) -> Rc { - let global_scope = global.as_global_scope(); - let core_resource_thread = global_scope.core_resource_thread(); +pub fn Fetch(global: &GlobalScope, input: RequestOrUSVString, init: &RequestInit) -> Rc { + let core_resource_thread = global.core_resource_thread(); // Step 1 - let promise = Promise::new(global_scope); - let response = Response::new(global_scope); + let promise = Promise::new(global); + let response = Response::new(global); // Step 2 - let request = match Request::Constructor(global_scope, input, init) { + let request = match Request::Constructor(global, input, init) { Err(e) => { - promise.reject_error(promise.global().r().get_cx(), e); + promise.reject_error(promise.global_scope().get_cx(), e); return promise; }, Ok(r) => r.get_request(), @@ -96,7 +95,7 @@ pub fn Fetch(global: GlobalRef, input: RequestOrUSVString, init: &RequestInit) - })); let listener = NetworkListener { context: fetch_context, - script_chan: global_scope.networking_task_source(), + script_chan: global.networking_task_source(), wrapper: None, };