Make PromiseJobQueue::enqueue take a &GlobalScope

This commit is contained in:
Anthony Ramine 2016-10-04 16:08:12 +02:00
parent 6e3be6d894
commit 2ee073053a
3 changed files with 7 additions and 6 deletions

View file

@ -9,7 +9,7 @@ use dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods; use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
use dom::bindings::codegen::UnionTypes::RequestOrUSVString; use dom::bindings::codegen::UnionTypes::RequestOrUSVString;
use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception}; use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception};
use dom::bindings::global::{GlobalRef, GlobalRoot}; use dom::bindings::global::GlobalRoot;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{JS, MutNullableHeap, Root};
use dom::bindings::refcounted::Trusted; use dom::bindings::refcounted::Trusted;
@ -160,7 +160,7 @@ impl WorkerGlobalScope {
} }
pub fn enqueue_promise_job(&self, job: EnqueuedPromiseCallback) { pub fn enqueue_promise_job(&self, job: EnqueuedPromiseCallback) {
self.promise_job_queue.enqueue(job, GlobalRef::Worker(self)); self.promise_job_queue.enqueue(job, self.upcast());
} }
pub fn flush_promise_jobs(&self) { pub fn flush_promise_jobs(&self) {

View file

@ -8,11 +8,12 @@
use dom::bindings::callback::ExceptionHandling; use dom::bindings::callback::ExceptionHandling;
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback; use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback;
use dom::bindings::global::{global_root_from_object, GlobalRoot, GlobalRef}; use dom::bindings::global::{global_root_from_object, GlobalRoot};
use dom::bindings::js::{RootCollection, RootCollectionPtr, trace_roots}; use dom::bindings::js::{RootCollection, RootCollectionPtr, trace_roots};
use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects}; use dom::bindings::refcounted::{LiveDOMReferences, trace_refcounted_objects};
use dom::bindings::trace::trace_traceables; use dom::bindings::trace::trace_traceables;
use dom::bindings::utils::DOM_CALLBACKS; use dom::bindings::utils::DOM_CALLBACKS;
use dom::globalscope::GlobalScope;
use js::glue::CollectServoSizes; use js::glue::CollectServoSizes;
use js::jsapi::{DisableIncrementalGC, GCDescription, GCProgress, HandleObject}; use js::jsapi::{DisableIncrementalGC, GCDescription, GCProgress, HandleObject};
use js::jsapi::{JSContext, JS_GetRuntime, JSRuntime, JSTracer, SetDOMCallbacks, SetGCSliceCallback}; use js::jsapi::{JSContext, JS_GetRuntime, JSRuntime, JSTracer, SetDOMCallbacks, SetGCSliceCallback};
@ -138,11 +139,11 @@ impl PromiseJobQueue {
/// Add a new promise job callback to this queue. It will be invoked as part of the next /// Add a new promise job callback to this queue. It will be invoked as part of the next
/// microtask checkpoint. /// microtask checkpoint.
pub fn enqueue(&self, job: EnqueuedPromiseCallback, global: GlobalRef) { pub fn enqueue(&self, job: EnqueuedPromiseCallback, global: &GlobalScope) {
self.promise_job_queue.borrow_mut().push(job); self.promise_job_queue.borrow_mut().push(job);
if !self.pending_promise_job_runnable.get() { if !self.pending_promise_job_runnable.get() {
self.pending_promise_job_runnable.set(true); self.pending_promise_job_runnable.set(true);
global.as_global_scope().flush_promise_jobs(); global.flush_promise_jobs();
} }
} }

View file

@ -2176,7 +2176,7 @@ impl ScriptThread {
pub fn enqueue_promise_job(job: EnqueuedPromiseCallback, global: GlobalRef) { pub fn enqueue_promise_job(job: EnqueuedPromiseCallback, global: GlobalRef) {
SCRIPT_THREAD_ROOT.with(|root| { SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() }; let script_thread = unsafe { &*root.get().unwrap() };
script_thread.promise_job_queue.enqueue(job, global); script_thread.promise_job_queue.enqueue(job, global.as_global_scope());
}); });
} }