Introduce a task! macro and use it for internal pause steps

This commit is contained in:
Anthony Ramine 2017-09-17 17:30:21 +02:00
parent 46628fba05
commit 5412767f46
3 changed files with 29 additions and 10 deletions

View file

@ -140,15 +140,11 @@ impl HTMLMediaElement {
// Step 2.3.
let window = window_from_node(self);
let target = Trusted::new(self.upcast::<EventTarget>());
// 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<EventTarget>);
impl Task for InternalPauseStepsTask {
fn run(self: Box<Self>) {
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

View file

@ -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;

View file

@ -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>(F);
impl<F> ::task::Task for $name<F>
where
F: ::std::ops::FnOnce(),
{
fn name(&self) -> &'static str {
stringify!($name)
}
fn run(self: Box<Self>) {
(self.0)();
}
}
$name(move || $body)
}};
}
/// A task that can be run. The name method is for profiling purposes.
pub trait Task {
#[allow(unsafe_code)]