Make the closure in flush_promise_jobs return a Root<GlobalScope>

This commit is contained in:
Anthony Ramine 2016-10-05 10:24:21 +02:00
parent 996fd284e2
commit c66cf46bee
3 changed files with 10 additions and 9 deletions

View file

@ -9,7 +9,6 @@ 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::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;
@ -173,8 +172,9 @@ impl WorkerGlobalScope {
fn do_flush_promise_jobs(&self) { fn do_flush_promise_jobs(&self) {
self.promise_job_queue.flush_promise_jobs(|id| { self.promise_job_queue.flush_promise_jobs(|id| {
assert_eq!(self.upcast::<GlobalScope>().pipeline_id(), id); let global = self.upcast::<GlobalScope>();
Some(GlobalRoot::Worker(Root::from_ref(self))) assert_eq!(global.pipeline_id(), id);
Some(Root::from_ref(global))
}); });
} }
} }

View file

@ -8,8 +8,8 @@
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::{GlobalRoot, global_scope_from_object}; use dom::bindings::global::global_scope_from_object;
use dom::bindings::js::{RootCollection, RootCollectionPtr, trace_roots}; use dom::bindings::js::{Root, 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;
@ -150,7 +150,7 @@ impl PromiseJobQueue {
/// Perform a microtask checkpoint, by invoking all of the pending promise job callbacks in /// Perform a microtask checkpoint, by invoking all of the pending promise job callbacks in
/// FIFO order (#4283). /// FIFO order (#4283).
pub fn flush_promise_jobs<F>(&self, target_provider: F) pub fn flush_promise_jobs<F>(&self, target_provider: F)
where F: Fn(PipelineId) -> Option<GlobalRoot> where F: Fn(PipelineId) -> Option<Root<GlobalScope>>
{ {
self.pending_promise_job_runnable.set(false); self.pending_promise_job_runnable.set(false);
{ {
@ -162,7 +162,7 @@ impl PromiseJobQueue {
// `flushing_queue` is a static snapshot during this checkpoint. // `flushing_queue` is a static snapshot during this checkpoint.
for job in &*self.flushing_job_queue.borrow() { for job in &*self.flushing_job_queue.borrow() {
if let Some(target) = target_provider(job.pipeline) { if let Some(target) = target_provider(job.pipeline) {
let _ = job.callback.Call_(&target.r(), ExceptionHandling::Report); let _ = job.callback.Call_(&*target, ExceptionHandling::Report);
} }
} }
self.flushing_job_queue.borrow_mut().clear(); self.flushing_job_queue.borrow_mut().clear();

View file

@ -27,7 +27,6 @@ use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, Documen
use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods; use dom::bindings::codegen::Bindings::LocationBinding::LocationMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior}; use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, StringificationBehavior};
use dom::bindings::global::GlobalRoot;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root, RootCollection}; use dom::bindings::js::{JS, MutNullableHeap, Root, RootCollection};
use dom::bindings::js::{RootCollectionPtr, RootedReference}; use dom::bindings::js::{RootCollectionPtr, RootedReference};
@ -2190,7 +2189,9 @@ impl ScriptThread {
fn do_flush_promise_jobs(&self) { fn do_flush_promise_jobs(&self) {
self.promise_job_queue.flush_promise_jobs(|id| { self.promise_job_queue.flush_promise_jobs(|id| {
self.find_child_context(id).map(|context| GlobalRoot::Window(context.active_window())) self.find_child_context(id).map(|context| {
Root::upcast(context.active_window())
})
}); });
} }
} }