mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
use microtasks to await a stable state
This commit is contained in:
parent
5da0aa9f11
commit
a8390aea24
12 changed files with 47 additions and 97 deletions
|
@ -31,6 +31,7 @@ use dom_struct::dom_struct;
|
||||||
use html5ever::{LocalName, Prefix};
|
use html5ever::{LocalName, Prefix};
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
use ipc_channel::router::ROUTER;
|
use ipc_channel::router::ROUTER;
|
||||||
|
use microtask::{Microtask, MicrotaskRunnable};
|
||||||
use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError};
|
use net_traits::{FetchResponseListener, FetchMetadata, Metadata, NetworkError};
|
||||||
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
|
use net_traits::request::{CredentialsMode, Destination, RequestInit, Type as RequestType};
|
||||||
use network_listener::{NetworkListener, PreInvoke};
|
use network_listener::{NetworkListener, PreInvoke};
|
||||||
|
@ -429,7 +430,11 @@ impl HTMLMediaElement {
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
ScriptThread::await_stable_state(ResourceSelectionTask::new(self, doc.base_url()));
|
let task = MediaElementMicrotask::ResourceSelectionTask {
|
||||||
|
elem: Root::from_ref(self),
|
||||||
|
base_url: doc.base_url()
|
||||||
|
};
|
||||||
|
ScriptThread::await_stable_state(Microtask::MediaElement(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm
|
// https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm
|
||||||
|
@ -781,7 +786,36 @@ impl VirtualMethods for HTMLMediaElement {
|
||||||
self.super_type().unwrap().unbind_from_tree(context);
|
self.super_type().unwrap().unbind_from_tree(context);
|
||||||
|
|
||||||
if context.tree_in_doc {
|
if context.tree_in_doc {
|
||||||
ScriptThread::await_stable_state(PauseIfNotInDocumentTask::new(self));
|
let task = MediaElementMicrotask::PauseIfNotInDocumentTask {
|
||||||
|
elem: Root::from_ref(self)
|
||||||
|
};
|
||||||
|
ScriptThread::await_stable_state(Microtask::MediaElement(task));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(JSTraceable, HeapSizeOf)]
|
||||||
|
pub enum MediaElementMicrotask {
|
||||||
|
ResourceSelectionTask {
|
||||||
|
elem: Root<HTMLMediaElement>,
|
||||||
|
base_url: ServoUrl
|
||||||
|
},
|
||||||
|
PauseIfNotInDocumentTask {
|
||||||
|
elem: Root<HTMLMediaElement>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MicrotaskRunnable for MediaElementMicrotask {
|
||||||
|
fn handler(&self) {
|
||||||
|
match self {
|
||||||
|
&MediaElementMicrotask::ResourceSelectionTask { ref elem, ref base_url } => {
|
||||||
|
elem.resource_selection_algorithm_sync(base_url.clone());
|
||||||
|
},
|
||||||
|
&MediaElementMicrotask::PauseIfNotInDocumentTask { ref elem } => {
|
||||||
|
if !elem.upcast::<Node>().is_in_doc() {
|
||||||
|
elem.internal_pause_steps();
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -809,28 +843,6 @@ impl Runnable for FireSimpleEventTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ResourceSelectionTask {
|
|
||||||
elem: Trusted<HTMLMediaElement>,
|
|
||||||
base_url: ServoUrl,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ResourceSelectionTask {
|
|
||||||
fn new(elem: &HTMLMediaElement, url: ServoUrl) -> ResourceSelectionTask {
|
|
||||||
ResourceSelectionTask {
|
|
||||||
elem: Trusted::new(elem),
|
|
||||||
base_url: url,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Runnable for ResourceSelectionTask {
|
|
||||||
fn name(&self) -> &'static str { "ResourceSelectionTask" }
|
|
||||||
|
|
||||||
fn handler(self: Box<ResourceSelectionTask>) {
|
|
||||||
self.elem.root().resource_selection_algorithm_sync(self.base_url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DedicatedMediaSourceFailureTask {
|
struct DedicatedMediaSourceFailureTask {
|
||||||
elem: Trusted<HTMLMediaElement>,
|
elem: Trusted<HTMLMediaElement>,
|
||||||
}
|
}
|
||||||
|
@ -851,29 +863,6 @@ impl Runnable for DedicatedMediaSourceFailureTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PauseIfNotInDocumentTask {
|
|
||||||
elem: Trusted<HTMLMediaElement>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PauseIfNotInDocumentTask {
|
|
||||||
fn new(elem: &HTMLMediaElement) -> PauseIfNotInDocumentTask {
|
|
||||||
PauseIfNotInDocumentTask {
|
|
||||||
elem: Trusted::new(elem),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Runnable for PauseIfNotInDocumentTask {
|
|
||||||
fn name(&self) -> &'static str { "PauseIfNotInDocumentTask" }
|
|
||||||
|
|
||||||
fn handler(self: Box<PauseIfNotInDocumentTask>) {
|
|
||||||
let elem = self.elem.root();
|
|
||||||
if !elem.upcast::<Node>().is_in_doc() {
|
|
||||||
elem.internal_pause_steps();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum ResourceSelectionMode {
|
enum ResourceSelectionMode {
|
||||||
Object,
|
Object,
|
||||||
Attribute(String),
|
Attribute(String),
|
||||||
|
|
|
@ -11,6 +11,7 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback;
|
use dom::bindings::codegen::Bindings::PromiseBinding::PromiseJobCallback;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
|
use dom::htmlmediaelement::MediaElementMicrotask;
|
||||||
use dom::mutationobserver::MutationObserver;
|
use dom::mutationobserver::MutationObserver;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -29,9 +30,14 @@ pub struct MicrotaskQueue {
|
||||||
#[derive(JSTraceable, HeapSizeOf)]
|
#[derive(JSTraceable, HeapSizeOf)]
|
||||||
pub enum Microtask {
|
pub enum Microtask {
|
||||||
Promise(EnqueuedPromiseCallback),
|
Promise(EnqueuedPromiseCallback),
|
||||||
|
MediaElement(MediaElementMicrotask),
|
||||||
NotifyMutationObservers,
|
NotifyMutationObservers,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait MicrotaskRunnable {
|
||||||
|
fn handler(&self) {}
|
||||||
|
}
|
||||||
|
|
||||||
/// A promise callback scheduled to run during the next microtask checkpoint (#4283).
|
/// A promise callback scheduled to run during the next microtask checkpoint (#4283).
|
||||||
#[derive(JSTraceable, HeapSizeOf)]
|
#[derive(JSTraceable, HeapSizeOf)]
|
||||||
pub struct EnqueuedPromiseCallback {
|
pub struct EnqueuedPromiseCallback {
|
||||||
|
@ -72,6 +78,9 @@ impl MicrotaskQueue {
|
||||||
if let Some(target) = target_provider(job.pipeline) {
|
if let Some(target) = target_provider(job.pipeline) {
|
||||||
let _ = job.callback.Call_(&*target, ExceptionHandling::Report);
|
let _ = job.callback.Call_(&*target, ExceptionHandling::Report);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Microtask::MediaElement(ref task) => {
|
||||||
|
task.handler();
|
||||||
}
|
}
|
||||||
Microtask::NotifyMutationObservers => {
|
Microtask::NotifyMutationObservers => {
|
||||||
MutationObserver::notify_mutation_observers();
|
MutationObserver::notify_mutation_observers();
|
||||||
|
|
|
@ -665,14 +665,11 @@ impl ScriptThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#await-a-stable-state
|
// https://html.spec.whatwg.org/multipage/#await-a-stable-state
|
||||||
pub fn await_stable_state<T: Runnable + Send + 'static>(task: T) {
|
pub fn await_stable_state(task: Microtask) {
|
||||||
//TODO use microtasks when they exist
|
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
if let Some(script_thread) = root.get() {
|
if let Some(script_thread) = root.get() {
|
||||||
let script_thread = unsafe { &*script_thread };
|
let script_thread = unsafe { &*script_thread };
|
||||||
let _ = script_thread.chan.send(CommonScriptMsg::RunnableMsg(
|
script_thread.microtask_queue.enqueue(task);
|
||||||
ScriptThreadEventCategory::DomEvent,
|
|
||||||
box task));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-in-sync-event.html]
|
|
||||||
type: testharness
|
|
||||||
[await a stable state and sync event handlers]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-load.html]
|
|
||||||
type: testharness
|
|
||||||
[invoking resource selection with load()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-pause-networkState.html]
|
|
||||||
type: testharness
|
|
||||||
[NOT invoking resource selection with pause() when networkState is not NETWORK_EMPTY]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-pause.html]
|
|
||||||
type: testharness
|
|
||||||
[invoking resource selection with pause()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-play.html]
|
|
||||||
type: testharness
|
|
||||||
[invoking resource selection with play()]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-remove-from-document-networkState.html]
|
|
||||||
type: testharness
|
|
||||||
[NOT invoking resource selection with implicit pause() when networkState is not NETWORK_EMPTY]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-set-src-not-in-document.html]
|
|
||||||
type: testharness
|
|
||||||
[invoking load by setting src on video not in a document]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-invoke-set-src.html]
|
|
||||||
type: testharness
|
|
||||||
[invoking load by setting src]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[resource-selection-remove-src.html]
|
|
||||||
type: testharness
|
|
||||||
[invoking resource selection by setting src; await stable state]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue