diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs
index f307dc2e733..d14afa7ac28 100644
--- a/components/script/dom/htmlmediaelement.rs
+++ b/components/script/dom/htmlmediaelement.rs
@@ -140,15 +140,11 @@ impl HTMLMediaElement {
// Step 2.3.
let window = window_from_node(self);
+ let target = Trusted::new(self.upcast::());
// FIXME(nox): Why are errors silenced here?
let _ = window.dom_manipulation_task_source().queue(
- box InternalPauseStepsTask(Trusted::new(self.upcast())),
- window.upcast(),
- );
- struct InternalPauseStepsTask(Trusted);
- impl Task for InternalPauseStepsTask {
- fn run(self: Box) {
- let target = self.0.root();
+ box task!(internal_pause_steps: move || {
+ let target = target.root();
// Step 2.3.1.
target.fire_event(atom!("timeupdate"));
@@ -159,8 +155,9 @@ impl HTMLMediaElement {
// Step 2.3.3.
// FIXME(nox): Reject pending play promises with promises
// and an "AbortError" DOMException.
- }
- }
+ }),
+ window.upcast(),
+ );
// Step 2.4.
// FIXME(nox): Set the official playback position to the current
diff --git a/components/script/lib.rs b/components/script/lib.rs
index b015a5407b0..1f8401961fe 100644
--- a/components/script/lib.rs
+++ b/components/script/lib.rs
@@ -106,6 +106,9 @@ extern crate webrender_api;
extern crate webvr_traits;
extern crate xml5ever;
+#[macro_use]
+mod task;
+
mod body;
pub mod clipboard_provider;
mod devtools;
@@ -123,7 +126,6 @@ pub mod script_thread;
mod serviceworker_manager;
mod serviceworkerjob;
mod stylesheet_loader;
-mod task;
mod task_source;
pub mod test;
pub mod textinput;
diff --git a/components/script/task.rs b/components/script/task.rs
index 55c8f37aca4..35f202480ca 100644
--- a/components/script/task.rs
+++ b/components/script/task.rs
@@ -9,6 +9,26 @@ use std::intrinsics;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
+macro_rules! task {
+ ($name:ident: move || $body:tt) => {{
+ #[allow(non_camel_case_types)]
+ struct $name(F);
+ impl ::task::Task for $name
+ where
+ F: ::std::ops::FnOnce(),
+ {
+ fn name(&self) -> &'static str {
+ stringify!($name)
+ }
+
+ fn run(self: Box) {
+ (self.0)();
+ }
+ }
+ $name(move || $body)
+ }};
+}
+
/// A task that can be run. The name method is for profiling purposes.
pub trait Task {
#[allow(unsafe_code)]