From afc0ccb48d03cfacec06b9c6d6be3626b46ff793 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Mon, 11 Jul 2016 22:21:45 -0600 Subject: [PATCH 1/4] Add event runnables Make tasks a wrapper over runnables --- components/script/dom/event.rs | 38 +++++++++++++++- components/script/dom/htmldetailselement.rs | 2 +- components/script/dom/htmlformelement.rs | 2 +- components/script/dom/htmlimageelement.rs | 2 +- components/script/dom/htmlmediaelement.rs | 8 ++-- components/script/dom/storage.rs | 2 +- components/script/script_thread.rs | 4 +- .../script/task_source/dom_manipulation.rs | 45 +++++++------------ .../script/task_source/user_interaction.rs | 37 +++++++-------- 9 files changed, 79 insertions(+), 61 deletions(-) diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index 9174fa2cb3d..da7664e0e19 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -8,9 +8,11 @@ use dom::bindings::codegen::Bindings::EventBinding::{EventConstants, EventMethod use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; +use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::str::DOMString; use dom::eventtarget::EventTarget; +use script_thread::Runnable; use std::cell::Cell; use std::default::Default; use string_cache::Atom; @@ -26,7 +28,7 @@ pub enum EventPhase { Bubbling = EventConstants::BUBBLING_PHASE, } -#[derive(PartialEq, HeapSizeOf)] +#[derive(PartialEq, HeapSizeOf, Copy, Clone)] pub enum EventBubbles { Bubbles, DoesNotBubble @@ -50,7 +52,7 @@ impl From for EventBubbles { } } -#[derive(PartialEq, HeapSizeOf)] +#[derive(PartialEq, HeapSizeOf, Copy, Clone)] pub enum EventCancelable { Cancelable, NotCancelable @@ -297,3 +299,35 @@ impl Event { target.dispatch_event(self) } } + +// https://dom.spec.whatwg.org/#concept-event-fire +pub struct EventRunnable { + pub target: Trusted, + pub name: Atom, + pub bubbles: EventBubbles, + pub cancelable: EventCancelable, +} + +impl Runnable for EventRunnable { + fn name(&self) -> &'static str { "EventRunnable" } + + fn handler(self: Box) { + let target = self.target.root(); + target.fire_event(&*self.name, self.bubbles, self.cancelable); + } +} + +// https://html.spec.whatwg.org/multipage/#fire-a-simple-event +pub struct SimpleEventRunnable { + pub target: Trusted, + pub name: Atom, +} + +impl Runnable for SimpleEventRunnable { + fn name(&self) -> &'static str { "SimpleEventRunnable" } + + fn handler(self: Box) { + let target = self.target.root(); + target.fire_simple_event(&*self.name); + } +} diff --git a/components/script/dom/htmldetailselement.rs b/components/script/dom/htmldetailselement.rs index f8fc6545f8d..4b9d5146b95 100644 --- a/components/script/dom/htmldetailselement.rs +++ b/components/script/dom/htmldetailselement.rs @@ -79,7 +79,7 @@ impl VirtualMethods for HTMLDetailsElement { element: details, toggle_number: counter }; - let _ = task_source.queue(DOMManipulationTask::Runnable(runnable)); + let _ = task_source.queue(DOMManipulationTask(runnable)); } } } diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 18c30a9d86c..4cd367d5032 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -484,7 +484,7 @@ impl HTMLFormElement { }; // Step 3 - window.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(nav)).unwrap(); + window.dom_manipulation_task_source().queue(DOMManipulationTask(nav)).unwrap(); } /// Interactively validate the constraints of form elements diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 8c28b1e8c8d..110138134c5 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -185,7 +185,7 @@ impl HTMLImageElement { src: src.into(), }); let task = window.dom_manipulation_task_source(); - let _ = task.queue(DOMManipulationTask::Runnable(runnable)); + let _ = task.queue(DOMManipulationTask(runnable)); } } } diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index b38f796e57c..3c9a4665303 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -242,7 +242,7 @@ impl HTMLMediaElement { elem: Trusted::new(self), }; let win = window_from_node(self); - let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task)); + let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task)); } // https://html.spec.whatwg.org/multipage/#internal-pause-steps step 2.2 @@ -266,13 +266,13 @@ impl HTMLMediaElement { elem: Trusted::new(self), }; let win = window_from_node(self); - let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task)); + let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task)); } fn queue_fire_simple_event(&self, type_: &'static str) { let win = window_from_node(self); let task = FireSimpleEventTask::new(self, type_); - let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask::Runnable(box task)); + let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task)); } fn fire_simple_event(&self, type_: &str) { @@ -499,7 +499,7 @@ impl HTMLMediaElement { fn queue_dedicated_media_source_failure_steps(&self) { let _ = window_from_node(self).dom_manipulation_task_source().queue( - DOMManipulationTask::Runnable(box DedicatedMediaSourceFailureTask::new(self))); + DOMManipulationTask(box DedicatedMediaSourceFailureTask::new(self))); } // https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index d927c5ba213..d44f9684027 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -161,7 +161,7 @@ impl Storage { let global_ref = global_root.r(); let task_source = global_ref.as_window().dom_manipulation_task_source(); let trusted_storage = Trusted::new(self); - task_source.queue(DOMManipulationTask::Runnable( + task_source.queue(DOMManipulationTask( box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap(); } } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index e116ace1be4..db58cb49586 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -982,7 +982,7 @@ impl ScriptThread { MainThreadScriptMsg::DOMManipulation(task) => task.handle_task(self), MainThreadScriptMsg::UserInteraction(task) => - task.handle_task(), + task.handle_task(self), } } @@ -1221,7 +1221,7 @@ impl ScriptThread { // https://html.spec.whatwg.org/multipage/#the-end step 7 let handler = box DocumentProgressHandler::new(Trusted::new(doc)); - self.dom_manipulation_task_source.queue(DOMManipulationTask::Runnable(handler)).unwrap(); + self.dom_manipulation_task_source.queue(DOMManipulationTask(handler)).unwrap(); self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap(); } diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index a1c06f2c09e..3cb08055446 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::refcounted::Trusted; -use dom::event::{EventBubbles, EventCancelable}; +use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnable}; use dom::eventtarget::EventTarget; use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread}; use std::result::Result; @@ -27,44 +27,31 @@ impl DOMManipulationTaskSource { bubbles: EventBubbles, cancelable: EventCancelable) { let target = Trusted::new(target); - let _ = self.0.send(MainThreadScriptMsg::DOMManipulation(DOMManipulationTask::FireEvent( - target, name, bubbles, cancelable))); + let runnable = box EventRunnable { + target: target, + name: name, + bubbles: bubbles, + cancelable: cancelable, + }; + let _ = self.queue(DOMManipulationTask(runnable)); } pub fn queue_simple_event(&self, target: &EventTarget, name: Atom) { let target = Trusted::new(target); - let _ = self.0.send(MainThreadScriptMsg::DOMManipulation(DOMManipulationTask::FireSimpleEvent( - target, name))); + let runnable = box SimpleEventRunnable { + target: target, + name: name, + }; + let _ = self.queue(DOMManipulationTask(runnable)); } } -pub enum DOMManipulationTask { - // https://dom.spec.whatwg.org/#concept-event-fire - FireEvent(Trusted, Atom, EventBubbles, EventCancelable), - // https://html.spec.whatwg.org/multipage/#fire-a-simple-event - FireSimpleEvent(Trusted, Atom), - - Runnable(Box), -} +pub struct DOMManipulationTask(pub Box); impl DOMManipulationTask { pub fn handle_task(self, script_thread: &ScriptThread) { - use self::DOMManipulationTask::*; - - match self { - FireEvent(element, name, bubbles, cancelable) => { - let target = element.root(); - target.fire_event(&*name, bubbles, cancelable); - } - FireSimpleEvent(element, name) => { - let target = element.root(); - target.fire_simple_event(&*name); - } - Runnable(runnable) => { - if !runnable.is_cancelled() { - runnable.main_thread_handler(script_thread); - } - } + if !self.0.is_cancelled() { + self.0.main_thread_handler(script_thread); } } } diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index 24dd59af222..afdb7a34d29 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -3,9 +3,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::refcounted::Trusted; -use dom::event::{EventBubbles, EventCancelable}; +use dom::event::{EventBubbles, EventCancelable, EventRunnable}; use dom::eventtarget::EventTarget; -use script_thread::MainThreadScriptMsg; +use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread}; use std::result::Result; use std::sync::mpsc::Sender; use string_cache::Atom; @@ -22,30 +22,27 @@ impl TaskSource for UserInteractionTaskSource { impl UserInteractionTaskSource { pub fn queue_event(&self, - target: &EventTarget, - name: Atom, - bubbles: EventBubbles, - cancelable: EventCancelable) { + target: &EventTarget, + name: Atom, + bubbles: EventBubbles, + cancelable: EventCancelable) { let target = Trusted::new(target); - let _ = self.0.send(MainThreadScriptMsg::UserInteraction(UserInteractionTask::FireEvent( - target, name, bubbles, cancelable))); + let runnable = box EventRunnable { + target: target, + name: name, + bubbles: bubbles, + cancelable: cancelable, + }; + let _ = self.queue(UserInteractionTask(runnable)); } } -pub enum UserInteractionTask { - // https://dom.spec.whatwg.org/#concept-event-fire - FireEvent(Trusted, Atom, EventBubbles, EventCancelable), -} +pub struct UserInteractionTask(pub Box); impl UserInteractionTask { - pub fn handle_task(self) { - use self::UserInteractionTask::*; - - match self { - FireEvent(element, name, bubbles, cancelable) => { - let target = element.root(); - target.fire_event(&*name, bubbles, cancelable); - } + pub fn handle_task(self, script_thread: &ScriptThread) { + if !self.0.is_cancelled() { + self.0.main_thread_handler(script_thread); } } } From 5f7324a9a5fbc5ecf8a348a5e9e238aacfd6f3d9 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Mon, 11 Jul 2016 22:59:53 -0600 Subject: [PATCH 2/4] Make all task source runnables cancellable Implement all Runnable methods on CancellableRunnable to redirect to their inner runnable --- components/script/dom/document.rs | 11 ++++++----- components/script/dom/htmldetailselement.rs | 6 ++---- components/script/dom/htmlformelement.rs | 5 ++--- components/script/dom/htmlimageelement.rs | 7 +++---- components/script/dom/htmlinputelement.rs | 6 ++++-- components/script/dom/htmlmediaelement.rs | 11 +++++------ components/script/dom/htmlscriptelement.rs | 5 +++-- components/script/dom/htmltextareaelement.rs | 6 ++++-- components/script/dom/storage.rs | 7 +++---- components/script/network_listener.rs | 15 ++++++--------- components/script/script_thread.rs | 10 ++++++++-- .../script/task_source/dom_manipulation.rs | 19 +++++++++++-------- components/script/task_source/mod.rs | 6 ++++-- .../script/task_source/user_interaction.rs | 13 ++++++++----- 14 files changed, 69 insertions(+), 58 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 68cd619ba43..d5fc2d39606 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1488,11 +1488,12 @@ impl Document { update_with_current_time_ms(&self.dom_content_loaded_event_start); - self.window().dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"), - EventBubbles::Bubbles, EventCancelable::NotCancelable); - self.window().reflow(ReflowGoal::ForDisplay, - ReflowQueryType::NoQuery, - ReflowReason::DOMContentLoaded); + let window = self.window(); + window.dom_manipulation_task_source().queue_event(self.upcast(), atom!("DOMContentLoaded"), + EventBubbles::Bubbles, EventCancelable::NotCancelable, window); + window.reflow(ReflowGoal::ForDisplay, + ReflowQueryType::NoQuery, + ReflowReason::DOMContentLoaded); update_with_current_time_ms(&self.dom_content_loaded_event_end); } diff --git a/components/script/dom/htmldetailselement.rs b/components/script/dom/htmldetailselement.rs index 4b9d5146b95..a116c09a755 100644 --- a/components/script/dom/htmldetailselement.rs +++ b/components/script/dom/htmldetailselement.rs @@ -19,7 +19,6 @@ use script_thread::Runnable; use std::cell::Cell; use string_cache::Atom; use task_source::TaskSource; -use task_source::dom_manipulation::DOMManipulationTask; #[dom_struct] pub struct HTMLDetailsElement { @@ -72,14 +71,13 @@ impl VirtualMethods for HTMLDetailsElement { self.toggle_counter.set(counter); let window = window_from_node(self); - let window = window.r(); let task_source = window.dom_manipulation_task_source(); let details = Trusted::new(self); - let runnable = box DetailsNotificationRunnable { + let runnable = DetailsNotificationRunnable { element: details, toggle_number: counter }; - let _ = task_source.queue(DOMManipulationTask(runnable)); + let _ = task_source.queue(runnable, window.r()); } } } diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 4cd367d5032..eb23c52c775 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -53,7 +53,6 @@ use string_cache::Atom; use style::attr::AttrValue; use style::str::split_html_space_chars; use task_source::TaskSource; -use task_source::dom_manipulation::DOMManipulationTask; use url::form_urlencoded; #[derive(JSTraceable, PartialEq, Clone, Copy, HeapSizeOf)] @@ -475,7 +474,7 @@ impl HTMLFormElement { self.generation_id.set(GenerationId(prev_id + 1)); // Step 2 - let nav = box PlannedNavigation { + let nav = PlannedNavigation { load_data: load_data, pipeline_id: window.pipeline(), script_chan: window.main_thread_script_chan().clone(), @@ -484,7 +483,7 @@ impl HTMLFormElement { }; // Step 3 - window.dom_manipulation_task_source().queue(DOMManipulationTask(nav)).unwrap(); + window.dom_manipulation_task_source().queue(nav, window).unwrap(); } /// Interactively validate the constraints of form elements diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 110138134c5..7a47293eb42 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -32,7 +32,6 @@ use std::sync::Arc; use string_cache::Atom; use style::attr::{AttrValue, LengthOrPercentageOrAuto}; use task_source::TaskSource; -use task_source::dom_manipulation::DOMManipulationTask; use url::Url; #[derive(JSTraceable, HeapSizeOf)] @@ -180,12 +179,12 @@ impl HTMLImageElement { } } - let runnable = Box::new(ImgParseErrorRunnable { + let runnable = ImgParseErrorRunnable { img: Trusted::new(self), src: src.into(), - }); + }; let task = window.dom_manipulation_task_source(); - let _ = task.queue(DOMManipulationTask(runnable)); + let _ = task.queue(runnable, window); } } } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index d8acc2dbe75..3cf8cea392a 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -576,7 +576,8 @@ impl HTMLInputElementMethods for HTMLInputElement { &self.upcast(), atom!("select"), EventBubbles::Bubbles, - EventCancelable::NotCancelable); + EventCancelable::NotCancelable, + window.r()); self.upcast::().dirty(NodeDamage::OtherNodeDamage); } @@ -1061,7 +1062,8 @@ impl VirtualMethods for HTMLInputElement { &self.upcast(), atom!("input"), EventBubbles::Bubbles, - EventCancelable::NotCancelable); + EventCancelable::NotCancelable, + window.r()); } self.upcast::().dirty(NodeDamage::OtherNodeDamage); diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 3c9a4665303..16c41811384 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -33,7 +33,6 @@ use std::cell::Cell; use std::sync::{Arc, Mutex}; use string_cache::Atom; use task_source::TaskSource; -use task_source::dom_manipulation::DOMManipulationTask; use time::{self, Timespec, Duration}; use url::Url; @@ -242,7 +241,7 @@ impl HTMLMediaElement { elem: Trusted::new(self), }; let win = window_from_node(self); - let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task)); + let _ = win.dom_manipulation_task_source().queue(task, win.r()); } // https://html.spec.whatwg.org/multipage/#internal-pause-steps step 2.2 @@ -266,13 +265,13 @@ impl HTMLMediaElement { elem: Trusted::new(self), }; let win = window_from_node(self); - let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task)); + let _ = win.dom_manipulation_task_source().queue(task, win.r()); } fn queue_fire_simple_event(&self, type_: &'static str) { let win = window_from_node(self); let task = FireSimpleEventTask::new(self, type_); - let _ = win.dom_manipulation_task_source().queue(DOMManipulationTask(box task)); + let _ = win.dom_manipulation_task_source().queue(task, win.r()); } fn fire_simple_event(&self, type_: &str) { @@ -498,8 +497,8 @@ impl HTMLMediaElement { } fn queue_dedicated_media_source_failure_steps(&self) { - let _ = window_from_node(self).dom_manipulation_task_source().queue( - DOMManipulationTask(box DedicatedMediaSourceFailureTask::new(self))); + let window = window_from_node(self); + let _ = window.dom_manipulation_task_source().queue(DedicatedMediaSourceFailureTask::new(self), window.r()); } // https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 2d10e5f43d8..5195b0e53a6 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -460,12 +460,13 @@ impl HTMLScriptElement { if external { self.dispatch_load_event(); } else { - window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load")); + window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load"), window.r()); } } pub fn queue_error_event(&self) { - window_from_node(self).dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("error")); + let window = window_from_node(self); + window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("error"), window.r()); } pub fn dispatch_before_script_execute_event(&self) -> bool { diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 69fe9046dad..5fb3a6ea102 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -260,7 +260,8 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement { &self.upcast(), atom!("select"), EventBubbles::Bubbles, - EventCancelable::NotCancelable); + EventCancelable::NotCancelable, + window.r()); self.upcast::().dirty(NodeDamage::OtherNodeDamage); } } @@ -383,7 +384,8 @@ impl VirtualMethods for HTMLTextAreaElement { &self.upcast(), atom!("input"), EventBubbles::Bubbles, - EventCancelable::NotCancelable); + EventCancelable::NotCancelable, + window.r()); } self.upcast::().dirty(NodeDamage::OtherNodeDamage); diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index d44f9684027..20b5d4924a8 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -19,7 +19,6 @@ use net_traits::IpcSend; use net_traits::storage_thread::{StorageThreadMsg, StorageType}; use script_thread::{Runnable, ScriptThread}; use task_source::TaskSource; -use task_source::dom_manipulation::DOMManipulationTask; use url::Url; #[dom_struct] @@ -159,10 +158,10 @@ impl Storage { new_value: Option) { let global_root = self.global(); let global_ref = global_root.r(); - let task_source = global_ref.as_window().dom_manipulation_task_source(); + let window = global_ref.as_window(); + let task_source = window.dom_manipulation_task_source(); let trusted_storage = Trusted::new(self); - task_source.queue(DOMManipulationTask( - box StorageEventRunnable::new(trusted_storage, key, old_value, new_value))).unwrap(); + task_source.queue(StorageEventRunnable::new(trusted_storage, key, old_value, new_value), window).unwrap(); } } diff --git a/components/script/network_listener.rs b/components/script/network_listener.rs index 5d37b025cca..272dfb0a975 100644 --- a/components/script/network_listener.rs +++ b/components/script/network_listener.rs @@ -23,16 +23,13 @@ impl NetworkListener { context: self.context.clone(), action: action, }; - if let Some(ref wrapper) = self.wrapper { - if let Err(err) = self.script_chan.send( - CommonScriptMsg::RunnableMsg(NetworkEvent, wrapper.wrap_runnable(runnable))) { - warn!("failed to deliver network data: {:?}", err); - } + let result = if let Some(ref wrapper) = self.wrapper { + self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, wrapper.wrap_runnable(runnable))) } else { - if let Err(err) = self.script_chan.send( - CommonScriptMsg::RunnableMsg(NetworkEvent, box runnable)) { - warn!("failed to deliver network data: {:?}", err); - } + self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, box runnable)) + }; + if let Err(err) = result { + warn!("failed to deliver network data: {:?}", err); } } } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index db58cb49586..3f79912bea2 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -189,10 +189,16 @@ pub struct CancellableRunnable { } impl Runnable for CancellableRunnable { + fn name(&self) -> &'static str { self.inner.name() } + fn is_cancelled(&self) -> bool { self.cancelled.load(Ordering::SeqCst) } + fn main_thread_handler(self: Box>, script_thread: &ScriptThread) { + self.inner.main_thread_handler(script_thread); + } + fn handler(self: Box>) { self.inner.handler() } @@ -1220,8 +1226,8 @@ impl ScriptThread { doc.mut_loader().inhibit_events(); // https://html.spec.whatwg.org/multipage/#the-end step 7 - let handler = box DocumentProgressHandler::new(Trusted::new(doc)); - self.dom_manipulation_task_source.queue(DOMManipulationTask(handler)).unwrap(); + let handler = DocumentProgressHandler::new(Trusted::new(doc)); + self.dom_manipulation_task_source.queue(handler, doc.window()).unwrap(); self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap(); } diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index 3cb08055446..5deef052c3e 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -5,6 +5,7 @@ use dom::bindings::refcounted::Trusted; use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnable}; use dom::eventtarget::EventTarget; +use dom::window::Window; use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread}; use std::result::Result; use std::sync::mpsc::Sender; @@ -14,8 +15,9 @@ use task_source::TaskSource; #[derive(JSTraceable, Clone)] pub struct DOMManipulationTaskSource(pub Sender); -impl TaskSource for DOMManipulationTaskSource { - fn queue(&self, msg: DOMManipulationTask) -> Result<(), ()> { +impl TaskSource for DOMManipulationTaskSource { + fn queue(&self, msg: T, window: &Window) -> Result<(), ()> { + let msg = DOMManipulationTask(window.get_runnable_wrapper().wrap_runnable(msg)); self.0.send(MainThreadScriptMsg::DOMManipulation(msg)).map_err(|_| ()) } } @@ -25,24 +27,25 @@ impl DOMManipulationTaskSource { target: &EventTarget, name: Atom, bubbles: EventBubbles, - cancelable: EventCancelable) { + cancelable: EventCancelable, + window: &Window) { let target = Trusted::new(target); - let runnable = box EventRunnable { + let runnable = EventRunnable { target: target, name: name, bubbles: bubbles, cancelable: cancelable, }; - let _ = self.queue(DOMManipulationTask(runnable)); + let _ = self.queue(runnable, window); } - pub fn queue_simple_event(&self, target: &EventTarget, name: Atom) { + pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) { let target = Trusted::new(target); - let runnable = box SimpleEventRunnable { + let runnable = SimpleEventRunnable { target: target, name: name, }; - let _ = self.queue(DOMManipulationTask(runnable)); + let _ = self.queue(runnable, window); } } diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index fe2d159b04a..393a358fadb 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -8,8 +8,10 @@ pub mod history_traversal; pub mod networking; pub mod user_interaction; +use dom::window::Window; +use script_thread::Runnable; use std::result::Result; -pub trait TaskSource { - fn queue(&self, msg: T) -> Result<(), ()>; +pub trait TaskSource { + fn queue(&self, msg: T, window: &Window) -> Result<(), ()>; } diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index afdb7a34d29..7bd8f58b006 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -5,6 +5,7 @@ use dom::bindings::refcounted::Trusted; use dom::event::{EventBubbles, EventCancelable, EventRunnable}; use dom::eventtarget::EventTarget; +use dom::window::Window; use script_thread::{MainThreadScriptMsg, Runnable, ScriptThread}; use std::result::Result; use std::sync::mpsc::Sender; @@ -14,8 +15,9 @@ use task_source::TaskSource; #[derive(JSTraceable, Clone)] pub struct UserInteractionTaskSource(pub Sender); -impl TaskSource for UserInteractionTaskSource { - fn queue(&self, msg: UserInteractionTask) -> Result<(), ()> { +impl TaskSource for UserInteractionTaskSource { + fn queue(&self, msg: T, window: &Window) -> Result<(), ()> { + let msg = UserInteractionTask(window.get_runnable_wrapper().wrap_runnable(msg)); self.0.send(MainThreadScriptMsg::UserInteraction(msg)).map_err(|_| ()) } } @@ -25,15 +27,16 @@ impl UserInteractionTaskSource { target: &EventTarget, name: Atom, bubbles: EventBubbles, - cancelable: EventCancelable) { + cancelable: EventCancelable, + window: &Window) { let target = Trusted::new(target); - let runnable = box EventRunnable { + let runnable = EventRunnable { target: target, name: name, bubbles: bubbles, cancelable: cancelable, }; - let _ = self.queue(UserInteractionTask(runnable)); + let _ = self.queue(runnable, window); } } From ad30275d04d9d814da86f985d252f2b78fccfcd0 Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Wed, 13 Jul 2016 11:10:13 -0600 Subject: [PATCH 3/4] Move boxing to runnable initialization --- components/script/dom/htmldetailselement.rs | 2 +- components/script/dom/htmlformelement.rs | 2 +- components/script/dom/htmlimageelement.rs | 4 ++-- components/script/dom/htmlmediaelement.rs | 8 ++++---- components/script/dom/storage.rs | 2 +- components/script/network_listener.rs | 4 ++-- components/script/script_thread.rs | 6 +++--- components/script/task_source/dom_manipulation.rs | 6 +++--- components/script/task_source/mod.rs | 2 +- components/script/task_source/user_interaction.rs | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/components/script/dom/htmldetailselement.rs b/components/script/dom/htmldetailselement.rs index a116c09a755..619c8263e3f 100644 --- a/components/script/dom/htmldetailselement.rs +++ b/components/script/dom/htmldetailselement.rs @@ -73,7 +73,7 @@ impl VirtualMethods for HTMLDetailsElement { let window = window_from_node(self); let task_source = window.dom_manipulation_task_source(); let details = Trusted::new(self); - let runnable = DetailsNotificationRunnable { + let runnable = box DetailsNotificationRunnable { element: details, toggle_number: counter }; diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index eb23c52c775..f2615ff0374 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -474,7 +474,7 @@ impl HTMLFormElement { self.generation_id.set(GenerationId(prev_id + 1)); // Step 2 - let nav = PlannedNavigation { + let nav = box PlannedNavigation { load_data: load_data, pipeline_id: window.pipeline(), script_chan: window.main_thread_script_chan().clone(), diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 7a47293eb42..52d5c9d7222 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -140,7 +140,7 @@ impl HTMLImageElement { // Return the image via a message to the script thread, which marks the element // as dirty and triggers a reflow. let image_response = message.to().unwrap(); - let runnable = ImageResponseHandlerRunnable::new( + let runnable = box ImageResponseHandlerRunnable::new( trusted_node.clone(), image_response); let runnable = wrapper.wrap_runnable(runnable); let _ = script_chan.send(CommonScriptMsg::RunnableMsg( @@ -179,7 +179,7 @@ impl HTMLImageElement { } } - let runnable = ImgParseErrorRunnable { + let runnable = box ImgParseErrorRunnable { img: Trusted::new(self), src: src.into(), }; diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 16c41811384..b95244f02bf 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -237,7 +237,7 @@ impl HTMLMediaElement { } } - let task = Task { + let task = box Task { elem: Trusted::new(self), }; let win = window_from_node(self); @@ -261,7 +261,7 @@ impl HTMLMediaElement { } } - let task = Task { + let task = box Task { elem: Trusted::new(self), }; let win = window_from_node(self); @@ -270,7 +270,7 @@ impl HTMLMediaElement { fn queue_fire_simple_event(&self, type_: &'static str) { let win = window_from_node(self); - let task = FireSimpleEventTask::new(self, type_); + let task = box FireSimpleEventTask::new(self, type_); let _ = win.dom_manipulation_task_source().queue(task, win.r()); } @@ -498,7 +498,7 @@ impl HTMLMediaElement { fn queue_dedicated_media_source_failure_steps(&self) { let window = window_from_node(self); - let _ = window.dom_manipulation_task_source().queue(DedicatedMediaSourceFailureTask::new(self), window.r()); + let _ = window.dom_manipulation_task_source().queue(box DedicatedMediaSourceFailureTask::new(self), window.r()); } // https://html.spec.whatwg.org/multipage/#dedicated-media-source-failure-steps diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index 20b5d4924a8..11dfc3ab5d2 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -161,7 +161,7 @@ impl Storage { let window = global_ref.as_window(); let task_source = window.dom_manipulation_task_source(); let trusted_storage = Trusted::new(self); - task_source.queue(StorageEventRunnable::new(trusted_storage, key, old_value, new_value), window).unwrap(); + task_source.queue(box StorageEventRunnable::new(trusted_storage, key, old_value, new_value), window).unwrap(); } } diff --git a/components/script/network_listener.rs b/components/script/network_listener.rs index 272dfb0a975..1dd0d8f0a34 100644 --- a/components/script/network_listener.rs +++ b/components/script/network_listener.rs @@ -19,14 +19,14 @@ pub struct NetworkListener { impl NetworkListener { pub fn notify + Send + 'static>(&self, action: A) { - let runnable = ListenerRunnable { + let runnable = box ListenerRunnable { context: self.context.clone(), action: action, }; let result = if let Some(ref wrapper) = self.wrapper { self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, wrapper.wrap_runnable(runnable))) } else { - self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, box runnable)) + self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, runnable)) }; if let Err(err) = result { warn!("failed to deliver network data: {:?}", err); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 3f79912bea2..788ec212a72 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -174,10 +174,10 @@ pub struct RunnableWrapper { } impl RunnableWrapper { - pub fn wrap_runnable(&self, runnable: T) -> Box { + pub fn wrap_runnable(&self, runnable: Box) -> Box { box CancellableRunnable { cancelled: self.cancelled.clone(), - inner: box runnable, + inner: runnable, } } } @@ -1226,7 +1226,7 @@ impl ScriptThread { doc.mut_loader().inhibit_events(); // https://html.spec.whatwg.org/multipage/#the-end step 7 - let handler = DocumentProgressHandler::new(Trusted::new(doc)); + let handler = box DocumentProgressHandler::new(Trusted::new(doc)); self.dom_manipulation_task_source.queue(handler, doc.window()).unwrap(); self.constellation_chan.send(ConstellationMsg::LoadComplete(pipeline)).unwrap(); diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index 5deef052c3e..b8bad662353 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -16,7 +16,7 @@ use task_source::TaskSource; pub struct DOMManipulationTaskSource(pub Sender); impl TaskSource for DOMManipulationTaskSource { - fn queue(&self, msg: T, window: &Window) -> Result<(), ()> { + fn queue(&self, msg: Box, window: &Window) -> Result<(), ()> { let msg = DOMManipulationTask(window.get_runnable_wrapper().wrap_runnable(msg)); self.0.send(MainThreadScriptMsg::DOMManipulation(msg)).map_err(|_| ()) } @@ -30,7 +30,7 @@ impl DOMManipulationTaskSource { cancelable: EventCancelable, window: &Window) { let target = Trusted::new(target); - let runnable = EventRunnable { + let runnable = box EventRunnable { target: target, name: name, bubbles: bubbles, @@ -41,7 +41,7 @@ impl DOMManipulationTaskSource { pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) { let target = Trusted::new(target); - let runnable = SimpleEventRunnable { + let runnable = box SimpleEventRunnable { target: target, name: name, }; diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index 393a358fadb..48fc775d959 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -13,5 +13,5 @@ use script_thread::Runnable; use std::result::Result; pub trait TaskSource { - fn queue(&self, msg: T, window: &Window) -> Result<(), ()>; + fn queue(&self, msg: Box, window: &Window) -> Result<(), ()>; } diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index 7bd8f58b006..2f4c0923801 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -16,7 +16,7 @@ use task_source::TaskSource; pub struct UserInteractionTaskSource(pub Sender); impl TaskSource for UserInteractionTaskSource { - fn queue(&self, msg: T, window: &Window) -> Result<(), ()> { + fn queue(&self, msg: Box, window: &Window) -> Result<(), ()> { let msg = UserInteractionTask(window.get_runnable_wrapper().wrap_runnable(msg)); self.0.send(MainThreadScriptMsg::UserInteraction(msg)).map_err(|_| ()) } @@ -30,7 +30,7 @@ impl UserInteractionTaskSource { cancelable: EventCancelable, window: &Window) { let target = Trusted::new(target); - let runnable = EventRunnable { + let runnable = box EventRunnable { target: target, name: name, bubbles: bubbles, From 862dc006818d09acf3af5c340635181f47e6fb2c Mon Sep 17 00:00:00 2001 From: Connor Brewster Date: Tue, 12 Jul 2016 17:21:15 -0600 Subject: [PATCH 4/4] Enable change_parentage test --- .../the-iframe-element/change_parentage.html.ini | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 tests/wpt/metadata/html/semantics/embedded-content/the-iframe-element/change_parentage.html.ini diff --git a/tests/wpt/metadata/html/semantics/embedded-content/the-iframe-element/change_parentage.html.ini b/tests/wpt/metadata/html/semantics/embedded-content/the-iframe-element/change_parentage.html.ini deleted file mode 100644 index 5c3ee2555e4..00000000000 --- a/tests/wpt/metadata/html/semantics/embedded-content/the-iframe-element/change_parentage.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[change_parentage.html] - type: testharness - disabled: https://github.com/servo/servo/issues/11703