From 52527d6f9dfaae13458059243d975f5336bdead4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 20 Sep 2017 09:59:52 +0200 Subject: [PATCH] Rename Task to TaskBox --- components/script/dom/bindings/refcounted.rs | 6 ++-- components/script/dom/bluetooth.rs | 6 ++-- components/script/dom/element.rs | 10 +++---- components/script/dom/event.rs | 10 +++---- components/script/dom/serviceworker.rs | 6 ++-- components/script/dom/websocket.rs | 18 ++++++------ components/script/dom/worker.rs | 6 ++-- components/script/dom/workerglobalscope.rs | 2 +- components/script/dom/worklet.rs | 4 +-- components/script/network_listener.rs | 6 ++-- components/script/script_runtime.rs | 4 +-- components/script/script_thread.rs | 2 +- components/script/task.rs | 28 ++++++++++--------- .../script/task_source/dom_manipulation.rs | 4 +-- components/script/task_source/file_reading.rs | 8 +++--- components/script/task_source/mod.rs | 6 ++-- components/script/task_source/networking.rs | 6 ++-- .../task_source/performance_timeline.rs | 4 +-- .../script/task_source/user_interaction.rs | 4 +-- 19 files changed, 71 insertions(+), 69 deletions(-) diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index b449a984356..1f1f9c52722 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -40,7 +40,7 @@ use std::marker::PhantomData; use std::os; use std::rc::Rc; use std::sync::{Arc, Weak}; -use task::Task; +use task::TaskBox; #[allow(missing_docs)] // FIXME @@ -122,7 +122,7 @@ impl TrustedPromise { /// A task which will reject the promise. #[allow(unrooted_must_root)] - pub fn reject_task(self, error: Error) -> impl Task { + pub fn reject_task(self, error: Error) -> impl TaskBox { let this = self; task!(reject_promise: move || { debug!("Rejecting promise."); @@ -135,7 +135,7 @@ impl TrustedPromise { /// A task which will resolve the promise. #[allow(unrooted_must_root)] - pub fn resolve_task(self, value: T) -> impl Task + pub fn resolve_task(self, value: T) -> impl TaskBox where T: ToJSValConvertible + Send, { diff --git a/components/script/dom/bluetooth.rs b/components/script/dom/bluetooth.rs index 2cd557d52b8..27a588a1a63 100644 --- a/components/script/dom/bluetooth.rs +++ b/components/script/dom/bluetooth.rs @@ -40,7 +40,7 @@ use std::collections::HashMap; use std::rc::Rc; use std::str::FromStr; use std::sync::{Arc, Mutex}; -use task::Task; +use task::TaskBox; const KEY_CONVERSION_ERROR: &'static str = "This `manufacturerData` key can not be parsed as unsigned short:"; const FILTER_EMPTY_ERROR: &'static str = "'filters' member, if present, must be nonempty to find any devices."; @@ -229,11 +229,11 @@ pub fn response_async( action: BluetoothResponseResult, } - impl Task for ListenerTask + impl TaskBox for ListenerTask where T: AsyncBluetoothListener + DomObject, { - fn run(self: Box) { + fn run_box(self: Box) { let this = *self; let mut context = this.context.lock().unwrap(); context.response(this.action); diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index c0524cf308c..b96d2bf56aa 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -119,7 +119,7 @@ use style::thread_state; use style::values::{CSSFloat, Either}; use style::values::{specified, computed}; use stylesheet_loader::StylesheetOwner; -use task::Task; +use task::TaskBox; // TODO: Update focus state when the top-level browsing context gains or loses system focus, // and when the element enters or leaves a browsing context container. @@ -3047,9 +3047,9 @@ impl ElementPerformFullscreenEnter { } } -impl Task for ElementPerformFullscreenEnter { +impl TaskBox for ElementPerformFullscreenEnter { #[allow(unrooted_must_root)] - fn run(self: Box) { + fn run_box(self: Box) { let element = self.element.root(); let document = document_from_node(element.r()); @@ -3100,9 +3100,9 @@ impl ElementPerformFullscreenExit { } } -impl Task for ElementPerformFullscreenExit { +impl TaskBox for ElementPerformFullscreenExit { #[allow(unrooted_must_root)] - fn run(self: Box) { + fn run_box(self: Box) { let element = self.element.root(); let document = document_from_node(element.r()); // TODO Step 9.1-5 diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index f5143ec72c4..5121768cd51 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -23,7 +23,7 @@ use dom_struct::dom_struct; use servo_atoms::Atom; use std::cell::Cell; use std::default::Default; -use task::Task; +use task::TaskBox; use time; #[dom_struct] @@ -388,8 +388,8 @@ pub struct EventTask { pub cancelable: EventCancelable, } -impl Task for EventTask { - fn run(self: Box) { +impl TaskBox for EventTask { + fn run_box(self: Box) { let target = self.target.root(); let bubbles = self.bubbles; let cancelable = self.cancelable; @@ -403,8 +403,8 @@ pub struct SimpleEventTask { pub name: Atom, } -impl Task for SimpleEventTask { - fn run(self: Box) { +impl TaskBox for SimpleEventTask { + fn run_box(self: Box) { let target = self.target.root(); target.fire_event(self.name); } diff --git a/components/script/dom/serviceworker.rs b/components/script/dom/serviceworker.rs index 74169428453..9a4d85caa69 100644 --- a/components/script/dom/serviceworker.rs +++ b/components/script/dom/serviceworker.rs @@ -19,7 +19,7 @@ use js::jsapi::{HandleValue, JSContext}; use script_traits::{ScriptMsg, DOMMessage}; use servo_url::ServoUrl; use std::cell::Cell; -use task::Task; +use task::TaskBox; pub type TrustedServiceWorkerAddress = Trusted; @@ -104,9 +104,9 @@ impl ServiceWorkerMethods for ServiceWorker { event_handler!(statechange, GetOnstatechange, SetOnstatechange); } -impl Task for SimpleWorkerErrorHandler { +impl TaskBox for SimpleWorkerErrorHandler { #[allow(unrooted_must_root)] - fn run(self: Box) { + fn run_box(self: Box) { let this = *self; ServiceWorker::dispatch_simple_error(this.addr); } diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 52b2dcc85d6..bb48cec942e 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -37,7 +37,7 @@ use std::borrow::ToOwned; use std::cell::Cell; use std::ptr; use std::thread; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; use task_source::TaskSource; use task_source::networking::NetworkingTaskSource; @@ -397,9 +397,9 @@ struct ConnectionEstablishedTask { protocol_in_use: Option, } -impl Task for ConnectionEstablishedTask { +impl TaskBox for ConnectionEstablishedTask { /// https://html.spec.whatwg.org/multipage/#feedback-from-the-protocol:concept-websocket-established - fn run(self: Box) { + fn run_box(self: Box) { let ws = self.address.root(); // Step 1. @@ -422,13 +422,13 @@ struct BufferedAmountTask { address: Trusted, } -impl Task for BufferedAmountTask { +impl TaskBox for BufferedAmountTask { // See https://html.spec.whatwg.org/multipage/#dom-websocket-bufferedamount // // To be compliant with standards, we need to reset bufferedAmount only when the event loop // reaches step 1. In our implementation, the bytes will already have been sent on a background // thread. - fn run(self: Box) { + fn run_box(self: Box) { let ws = self.address.root(); ws.buffered_amount.set(0); @@ -443,8 +443,8 @@ struct CloseTask { reason: Option, } -impl Task for CloseTask { - fn run(self: Box) { +impl TaskBox for CloseTask { + fn run_box(self: Box) { let ws = self.address.root(); if ws.ready_state.get() == WebSocketRequestState::Closed { @@ -483,9 +483,9 @@ struct MessageReceivedTask { message: MessageData, } -impl Task for MessageReceivedTask { +impl TaskBox for MessageReceivedTask { #[allow(unsafe_code)] - fn run(self: Box) { + fn run_box(self: Box) { let ws = self.address.root(); debug!("MessageReceivedTask::handler({:p}): readyState={:?}", &*ws, ws.ready_state.get()); diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index d250633a49e..cf62e46e456 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -28,7 +28,7 @@ use std::cell::Cell; use std::sync::{Arc, Mutex}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{Sender, channel}; -use task::Task; +use task::TaskBox; pub type TrustedWorkerAddress = Trusted; @@ -175,9 +175,9 @@ impl WorkerMethods for Worker { event_handler!(error, GetOnerror, SetOnerror); } -impl Task for SimpleWorkerErrorHandler { +impl TaskBox for SimpleWorkerErrorHandler { #[allow(unrooted_must_root)] - fn run(self: Box) { + fn run_box(self: Box) { let this = *self; Worker::dispatch_simple_error(this.addr); } diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 57017f5cd55..8ea1a49ccbe 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -388,7 +388,7 @@ impl WorkerGlobalScope { pub fn process_event(&self, msg: CommonScriptMsg) { match msg { CommonScriptMsg::Task(_, task) => { - task.run() + task.run_box() }, CommonScriptMsg::CollectReports(reports_chan) => { let cx = self.get_cx(); diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs index e6d47d42f48..4028670b393 100644 --- a/components/script/dom/worklet.rs +++ b/components/script/dom/worklet.rs @@ -69,7 +69,7 @@ use std::thread; use style::thread_state; use swapper::Swapper; use swapper::swapper; -use task::Task; +use task::TaskBox; use uuid::Uuid; // Magic numbers @@ -647,7 +647,7 @@ impl WorkletThread { /// Run a task in the main script thread. fn run_in_script_thread(&self, task: T) where - T: Task + 'static, + T: TaskBox + 'static, { let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, box task); let msg = MainThreadScriptMsg::Common(msg); diff --git a/components/script/network_listener.rs b/components/script/network_listener.rs index 8b291128065..10bce087064 100644 --- a/components/script/network_listener.rs +++ b/components/script/network_listener.rs @@ -4,7 +4,7 @@ use net_traits::{Action, FetchResponseListener, FetchResponseMsg}; use std::sync::{Arc, Mutex}; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; use task_source::TaskSource; use task_source::networking::NetworkingTaskSource; @@ -55,12 +55,12 @@ struct ListenerTask + Send + 'static, Listener: PreInvoke + action: A, } -impl Task for ListenerTask +impl TaskBox for ListenerTask where A: Action + Send + 'static, Listener: PreInvoke + Send, { - fn run(self: Box) { + fn run_box(self: Box) { let this = *self; let mut context = this.context.lock().unwrap(); if context.should_invoke() { diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 45f3d6a7ea3..be5acd33a6a 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -35,7 +35,7 @@ use std::os::raw::c_void; use std::panic::AssertUnwindSafe; use std::ptr; use style::thread_state; -use task::Task; +use task::TaskBox; use time::{Tm, now}; /// Common messages used to control the event loops in both the script and the worker @@ -44,7 +44,7 @@ pub enum CommonScriptMsg { /// supplied channel. CollectReports(ReportsChan), /// Generic message that encapsulates event handling. - Task(ScriptThreadEventCategory, Box), + Task(ScriptThreadEventCategory, Box), } impl fmt::Debug for CommonScriptMsg { diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 56f47cfdbef..2fa0071ed65 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1258,7 +1258,7 @@ impl ScriptThread { self.handle_exit_window_msg(id) }, MainThreadScriptMsg::Common(CommonScriptMsg::Task(_, task)) => { - task.run() + task.run_box() } MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(chan)) => { self.collect_reports(chan) diff --git a/components/script/task.rs b/components/script/task.rs index dcefd31a162..83ed7737190 100644 --- a/components/script/task.rs +++ b/components/script/task.rs @@ -13,7 +13,7 @@ macro_rules! task { ($name:ident: move || $body:tt) => {{ #[allow(non_camel_case_types)] struct $name(F); - impl ::task::Task for $name + impl ::task::TaskBox for $name where F: ::std::ops::FnOnce() + Send, { @@ -21,7 +21,7 @@ macro_rules! task { stringify!($name) } - fn run(self: Box) { + fn run_box(self: Box) { (self.0)(); } } @@ -30,13 +30,15 @@ macro_rules! task { } /// A task that can be run. The name method is for profiling purposes. -pub trait Task: Send { +/// +/// All tasks must be boxed to be run. +pub trait TaskBox: Send { #[allow(unsafe_code)] fn name(&self) -> &'static str { unsafe { intrinsics::type_name::() } } - fn run(self: Box); + fn run_box(self: Box); } -impl fmt::Debug for Task { +impl fmt::Debug for TaskBox { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_tuple(self.name()).field(&format_args!("...")).finish() } @@ -50,9 +52,9 @@ pub struct TaskCanceller { impl TaskCanceller { /// Returns a wrapped `task` that will be cancelled if the `TaskCanceller` /// says so. - pub fn wrap_task(&self, task: Box) -> Box + pub fn wrap_task(&self, task: Box) -> Box where - T: Task + 'static, + T: TaskBox + 'static, { box CancellableTask { cancelled: self.cancelled.clone(), @@ -62,14 +64,14 @@ impl TaskCanceller { } /// A task that can be cancelled by toggling a shared flag. -pub struct CancellableTask { +pub struct CancellableTask { cancelled: Option>, inner: Box, } impl CancellableTask where - T: Task, + T: TaskBox, { fn is_cancelled(&self) -> bool { self.cancelled.as_ref().map_or(false, |cancelled| { @@ -78,17 +80,17 @@ where } } -impl Task for CancellableTask +impl TaskBox for CancellableTask where - T: Task, + T: TaskBox, { fn name(&self) -> &'static str { self.inner.name() } - fn run(self: Box) { + fn run_box(self: Box) { if !self.is_cancelled() { - self.inner.run() + self.inner.run_box() } } } diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index 4062b5b1495..f5f38e68044 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -13,7 +13,7 @@ use servo_atoms::Atom; use std::fmt; use std::result::Result; use std::sync::mpsc::Sender; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; use task_source::TaskSource; #[derive(Clone, JSTraceable)] @@ -32,7 +32,7 @@ impl TaskSource for DOMManipulationTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + 'static, + T: TaskBox + 'static, { let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( ScriptThreadEventCategory::ScriptEvent, diff --git a/components/script/task_source/file_reading.rs b/components/script/task_source/file_reading.rs index 111f07ddba1..2ed44165b92 100644 --- a/components/script/task_source/file_reading.rs +++ b/components/script/task_source/file_reading.rs @@ -6,7 +6,7 @@ use dom::domexception::DOMErrorName; use dom::filereader::{FileReader, TrustedFileReader, GenerationId, ReadMetaData}; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory, ScriptChan}; use std::sync::Arc; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; use task_source::TaskSource; #[derive(JSTraceable)] @@ -25,7 +25,7 @@ impl TaskSource for FileReadingTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + 'static, + T: TaskBox + 'static, { self.0.send(CommonScriptMsg::Task( ScriptThreadEventCategory::FileRead, @@ -34,8 +34,8 @@ impl TaskSource for FileReadingTaskSource { } } -impl Task for FileReadingTask { - fn run(self: Box) { +impl TaskBox for FileReadingTask { + fn run_box(self: Box) { self.handle_task(); } } diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index 3c6139b6df3..e361ccf2d99 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -11,7 +11,7 @@ pub mod user_interaction; use dom::globalscope::GlobalScope; use std::result::Result; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; pub trait TaskSource { fn queue_with_canceller( @@ -20,11 +20,11 @@ pub trait TaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + 'static; + T: TaskBox + 'static; fn queue(&self, msg: Box, global: &GlobalScope) -> Result<(), ()> where - T: Task + 'static, + T: TaskBox + 'static, { self.queue_with_canceller(msg, &global.task_canceller()) } diff --git a/components/script/task_source/networking.rs b/components/script/task_source/networking.rs index 57dabbbfd39..80acc324f52 100644 --- a/components/script/task_source/networking.rs +++ b/components/script/task_source/networking.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; use task_source::TaskSource; #[derive(JSTraceable)] @@ -22,7 +22,7 @@ impl TaskSource for NetworkingTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + 'static, + T: TaskBox + 'static, { self.0.send(CommonScriptMsg::Task( ScriptThreadEventCategory::NetworkEvent, @@ -36,7 +36,7 @@ impl NetworkingTaskSource { /// global scope gets destroyed. pub fn queue_unconditionally(&self, msg: Box) -> Result<(), ()> where - T: Task + 'static, + T: TaskBox + 'static, { self.0.send(CommonScriptMsg::Task(ScriptThreadEventCategory::NetworkEvent, msg)) } diff --git a/components/script/task_source/performance_timeline.rs b/components/script/task_source/performance_timeline.rs index 0bac66270f6..3c77c1527fd 100644 --- a/components/script/task_source/performance_timeline.rs +++ b/components/script/task_source/performance_timeline.rs @@ -11,7 +11,7 @@ use dom::globalscope::GlobalScope; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use std::fmt; use std::result::Result; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; use task_source::TaskSource; #[derive(JSTraceable)] @@ -36,7 +36,7 @@ impl TaskSource for PerformanceTimelineTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + 'static, + T: TaskBox + 'static, { let msg = CommonScriptMsg::Task( ScriptThreadEventCategory::PerformanceTimelineTask, diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index 76321e0fa10..0ca5687fe46 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -13,7 +13,7 @@ use servo_atoms::Atom; use std::fmt; use std::result::Result; use std::sync::mpsc::Sender; -use task::{Task, TaskCanceller}; +use task::{TaskBox, TaskCanceller}; use task_source::TaskSource; #[derive(Clone, JSTraceable)] @@ -32,7 +32,7 @@ impl TaskSource for UserInteractionTaskSource { canceller: &TaskCanceller, ) -> Result<(), ()> where - T: Task + 'static, + T: TaskBox + 'static, { let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task( ScriptThreadEventCategory::InputEvent,