diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 92b79e352e2..0cbb3ec302b 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -18,7 +18,7 @@ use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; use js::glue::{IsWrapper, UnwrapObject}; use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment}; use js::jsapi::{JSContext, JSObject, JS_GetClass}; -use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan, ScriptPort}; +use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; use script_thread::ScriptThread; use task_source::file_reading::FileReadingTaskSource; @@ -84,14 +84,6 @@ impl<'a> GlobalRef<'a> { GlobalRef::Worker(ref worker) => worker.process_event(msg), } } - - /// Enqueue a promise callback for subsequent execution. - pub fn enqueue_promise_job(&self, job: EnqueuedPromiseCallback) { - match *self { - GlobalRef::Window(_) => ScriptThread::enqueue_promise_job(job, *self), - GlobalRef::Worker(ref worker) => worker.enqueue_promise_job(job), - } - } } impl<'a> Reflectable for GlobalRef<'a> { diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index f9eaead2189..cd8fca9a0e4 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -26,7 +26,7 @@ use libc; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; use profile_traits::{mem, time}; -use script_runtime::{ScriptChan, maybe_take_panic_result}; +use script_runtime::{EnqueuedPromiseCallback, ScriptChan, maybe_take_panic_result}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent}; use script_traits::{TimerEventId, TimerEventRequest, TimerSource}; @@ -420,6 +420,17 @@ impl GlobalScope { } unreachable!(); } + + /// Enqueue a promise callback for subsequent execution. + pub fn enqueue_promise_job(&self, job: EnqueuedPromiseCallback) { + if self.is::() { + return ScriptThread::enqueue_promise_job(job, self); + } + if let Some(worker) = self.downcast::() { + return worker.enqueue_promise_job(job); + } + unreachable!(); + } } fn timestamp_in_ms(time: Timespec) -> u64 { diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 36ae678ade7..145ef1ef19e 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -8,7 +8,7 @@ use dom::bindings::callback::ExceptionHandling; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; -use dom::bindings::global::{global_root_from_object, GlobalRoot}; +use dom::bindings::global::{GlobalRoot, global_scope_from_object}; use dom::bindings::js::{RootCollection, RootCollectionPtr, trace_roots}; use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; use dom::bindings::trace::trace_traceables; @@ -178,9 +178,9 @@ unsafe extern "C" fn enqueue_job(_cx: *mut JSContext, _allocation_site: HandleObject, _data: *mut c_void) -> bool { let result = panic::catch_unwind(AssertUnwindSafe(|| { - let global = global_root_from_object(job.get()); - let pipeline = global.r().as_global_scope().pipeline_id(); - global.r().enqueue_promise_job(EnqueuedPromiseCallback { + let global = global_scope_from_object(job.get()); + let pipeline = global.pipeline_id(); + global.enqueue_promise_job(EnqueuedPromiseCallback { callback: PromiseJobCallback::new(job.get()), pipeline: pipeline, }); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 467b77d1f76..22ca69c78df 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -27,7 +27,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, Documen use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior}; -use dom::bindings::global::{GlobalRef, GlobalRoot}; +use dom::bindings::global::GlobalRoot; use dom::bindings::inheritance::Castable; use dom::bindings::js::{JS, MutNullableHeap, Root, RootCollection}; use dom::bindings::js::{RootCollectionPtr, RootedReference}; @@ -2173,10 +2173,10 @@ impl ScriptThread { } } - pub fn enqueue_promise_job(job: EnqueuedPromiseCallback, global: GlobalRef) { + pub fn enqueue_promise_job(job: EnqueuedPromiseCallback, global: &GlobalScope) { SCRIPT_THREAD_ROOT.with(|root| { let script_thread = unsafe { &*root.get().unwrap() }; - script_thread.promise_job_queue.enqueue(job, global.as_global_scope()); + script_thread.promise_job_queue.enqueue(job, global); }); }