mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Introduce GlobalScope::enqueue_promise_job
This commit is contained in:
parent
2ee073053a
commit
4d9347d5b3
4 changed files with 20 additions and 17 deletions
|
@ -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> {
|
||||
|
|
|
@ -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::<Window>() {
|
||||
return ScriptThread::enqueue_promise_job(job, self);
|
||||
}
|
||||
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
|
||||
return worker.enqueue_promise_job(job);
|
||||
}
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
|
||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue