Make RunnableWrapper store an Option<Arc<AtomicBool>>

This makes WorkerGlobalScope::get_runnable_wrapper not panic anymore
when the worker is a ServiceWorkerGlobalScope.
This commit is contained in:
Anthony Ramine 2016-10-04 15:27:13 +02:00
parent 991801488c
commit ca8c6fb072
3 changed files with 7 additions and 5 deletions

View file

@ -868,7 +868,7 @@ impl WindowMethods for Window {
impl Window { impl Window {
pub fn get_runnable_wrapper(&self) -> RunnableWrapper { pub fn get_runnable_wrapper(&self) -> RunnableWrapper {
RunnableWrapper { RunnableWrapper {
cancelled: self.ignore_further_async_events.clone() cancelled: Some(self.ignore_further_async_events.clone()),
} }
} }

View file

@ -155,7 +155,7 @@ impl WorkerGlobalScope {
pub fn get_runnable_wrapper(&self) -> RunnableWrapper { pub fn get_runnable_wrapper(&self) -> RunnableWrapper {
RunnableWrapper { RunnableWrapper {
cancelled: self.closing.clone().unwrap(), cancelled: self.closing.clone(),
} }
} }

View file

@ -170,7 +170,7 @@ impl InProgressLoad {
/// Encapsulated state required to create cancellable runnables from non-script threads. /// Encapsulated state required to create cancellable runnables from non-script threads.
pub struct RunnableWrapper { pub struct RunnableWrapper {
pub cancelled: Arc<AtomicBool>, pub cancelled: Option<Arc<AtomicBool>>,
} }
impl RunnableWrapper { impl RunnableWrapper {
@ -184,7 +184,7 @@ impl RunnableWrapper {
/// A runnable that can be discarded by toggling a shared flag. /// A runnable that can be discarded by toggling a shared flag.
pub struct CancellableRunnable<T: Runnable + Send> { pub struct CancellableRunnable<T: Runnable + Send> {
cancelled: Arc<AtomicBool>, cancelled: Option<Arc<AtomicBool>>,
inner: Box<T>, inner: Box<T>,
} }
@ -192,7 +192,9 @@ impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
fn name(&self) -> &'static str { self.inner.name() } fn name(&self) -> &'static str { self.inner.name() }
fn is_cancelled(&self) -> bool { fn is_cancelled(&self) -> bool {
self.cancelled.load(Ordering::SeqCst) self.cancelled.as_ref()
.map(|cancelled| cancelled.load(Ordering::SeqCst))
.unwrap_or(false)
} }
fn main_thread_handler(self: Box<CancellableRunnable<T>>, script_thread: &ScriptThread) { fn main_thread_handler(self: Box<CancellableRunnable<T>>, script_thread: &ScriptThread) {