mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-31 21:21:08 +00:00
servo: Merge #18573 - Introduce TaskOnce (from servo:TASKS); r=SimonSapin
Source-Repo: https://github.com/servo/servo Source-Revision: 44c6bd9fa9594e7fd2a6576a4eab501a5838d113 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 8814df2f1a210ddeba69a81774f35853fcc018fd
This commit is contained in:
parent
b078909af6
commit
3875b3dac8
@ -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::TaskOnce;
|
||||
|
||||
|
||||
#[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 Send + Task {
|
||||
pub fn reject_task(self, error: Error) -> impl TaskOnce {
|
||||
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<T>(self, value: T) -> impl Send + Task
|
||||
pub fn resolve_task<T>(self, value: T) -> impl TaskOnce
|
||||
where
|
||||
T: ToJSValConvertible + Send,
|
||||
{
|
||||
|
@ -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::TaskOnce;
|
||||
|
||||
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,18 +229,17 @@ pub fn response_async<T: AsyncBluetoothListener + DomObject + 'static>(
|
||||
action: BluetoothResponseResult,
|
||||
}
|
||||
|
||||
impl<T> Task for ListenerTask<T>
|
||||
impl<T> TaskOnce for ListenerTask<T>
|
||||
where
|
||||
T: AsyncBluetoothListener + DomObject,
|
||||
{
|
||||
fn run(self: Box<Self>) {
|
||||
let this = *self;
|
||||
let mut context = this.context.lock().unwrap();
|
||||
context.response(this.action);
|
||||
fn run_once(self) {
|
||||
let mut context = self.context.lock().unwrap();
|
||||
context.response(self.action);
|
||||
}
|
||||
}
|
||||
|
||||
let task = box ListenerTask {
|
||||
let task = ListenerTask {
|
||||
context: context.clone(),
|
||||
action: message.to().unwrap(),
|
||||
};
|
||||
|
@ -1716,7 +1716,7 @@ impl Document {
|
||||
debug!("Document loads are complete.");
|
||||
let document = Trusted::new(self);
|
||||
self.window.dom_manipulation_task_source().queue(
|
||||
box task!(fire_load_event: move || {
|
||||
task!(fire_load_event: move || {
|
||||
let document = document.root();
|
||||
let window = document.window();
|
||||
if !window.is_alive() {
|
||||
|
@ -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::TaskOnce;
|
||||
|
||||
// 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 TaskOnce for ElementPerformFullscreenEnter {
|
||||
#[allow(unrooted_must_root)]
|
||||
fn run(self: Box<Self>) {
|
||||
fn run_once(self) {
|
||||
let element = self.element.root();
|
||||
let document = document_from_node(element.r());
|
||||
|
||||
@ -3100,9 +3100,9 @@ impl ElementPerformFullscreenExit {
|
||||
}
|
||||
}
|
||||
|
||||
impl Task for ElementPerformFullscreenExit {
|
||||
impl TaskOnce for ElementPerformFullscreenExit {
|
||||
#[allow(unrooted_must_root)]
|
||||
fn run(self: Box<Self>) {
|
||||
fn run_once(self) {
|
||||
let element = self.element.root();
|
||||
let document = document_from_node(element.r());
|
||||
// TODO Step 9.1-5
|
||||
|
@ -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::TaskOnce;
|
||||
use time;
|
||||
|
||||
#[dom_struct]
|
||||
@ -388,8 +388,8 @@ pub struct EventTask {
|
||||
pub cancelable: EventCancelable,
|
||||
}
|
||||
|
||||
impl Task for EventTask {
|
||||
fn run(self: Box<Self>) {
|
||||
impl TaskOnce for EventTask {
|
||||
fn run_once(self) {
|
||||
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<Self>) {
|
||||
impl TaskOnce for SimpleEventTask {
|
||||
fn run_once(self) {
|
||||
let target = self.target.root();
|
||||
target.fire_event(self.name);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ impl EventSourceContext {
|
||||
let event_source = self.event_source.clone();
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = global.networking_task_source().queue(
|
||||
box task!(announce_the_event_source_connection: move || {
|
||||
task!(announce_the_event_source_connection: move || {
|
||||
let event_source = event_source.root();
|
||||
if event_source.ready_state.get() != ReadyState::Closed {
|
||||
event_source.ready_state.set(ReadyState::Open);
|
||||
@ -121,7 +121,7 @@ impl EventSourceContext {
|
||||
let event_source = self.event_source.clone();
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = global.networking_task_source().queue(
|
||||
box task!(fail_the_event_source_connection: move || {
|
||||
task!(fail_the_event_source_connection: move || {
|
||||
let event_source = event_source.root();
|
||||
if event_source.ready_state.get() != ReadyState::Closed {
|
||||
event_source.ready_state.set(ReadyState::Closed);
|
||||
@ -145,7 +145,7 @@ impl EventSourceContext {
|
||||
let global = event_source.global();
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = global.networking_task_source().queue(
|
||||
box task!(reestablish_the_event_source_onnection: move || {
|
||||
task!(reestablish_the_event_source_onnection: move || {
|
||||
let event_source = trusted_event_source.root();
|
||||
|
||||
// Step 1.1.
|
||||
@ -242,7 +242,7 @@ impl EventSourceContext {
|
||||
let event = Trusted::new(&*event);
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = global.networking_task_source().queue(
|
||||
box task!(dispatch_the_event_source_event: move || {
|
||||
task!(dispatch_the_event_source_event: move || {
|
||||
let event_source = event_source.root();
|
||||
if event_source.ready_state.get() != ReadyState::Closed {
|
||||
event.root().upcast::<Event>().fire(&event_source.upcast());
|
||||
|
@ -416,11 +416,11 @@ fn perform_annotated_read_operation(
|
||||
) {
|
||||
// Step 4
|
||||
let task = FileReadingTask::ProcessRead(filereader.clone(), gen_id);
|
||||
task_source.queue_with_canceller(box task, &canceller).unwrap();
|
||||
task_source.queue_with_canceller(task, &canceller).unwrap();
|
||||
|
||||
let task = FileReadingTask::ProcessReadData(filereader.clone(), gen_id);
|
||||
task_source.queue_with_canceller(box task, &canceller).unwrap();
|
||||
task_source.queue_with_canceller(task, &canceller).unwrap();
|
||||
|
||||
let task = FileReadingTask::ProcessReadEOF(filereader, gen_id, data, blob_contents);
|
||||
task_source.queue_with_canceller(box task, &canceller).unwrap();
|
||||
task_source.queue_with_canceller(task, &canceller).unwrap();
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ impl VirtualMethods for HTMLDetailsElement {
|
||||
let this = Trusted::new(self);
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = window.dom_manipulation_task_source().queue(
|
||||
box task!(details_notification_task_steps: move || {
|
||||
task!(details_notification_task_steps: move || {
|
||||
let this = this.root();
|
||||
if counter == this.toggle_counter.get() {
|
||||
this.upcast::<EventTarget>().fire_event(atom!("toggle"));
|
||||
|
@ -440,7 +440,7 @@ impl HTMLFormElement {
|
||||
let pipeline_id = window.upcast::<GlobalScope>().pipeline_id();
|
||||
let script_chan = window.main_thread_script_chan().clone();
|
||||
let this = Trusted::new(self);
|
||||
let task = box task!(navigate_to_form_planned_navigation: move || {
|
||||
let task = task!(navigate_to_form_planned_navigation: move || {
|
||||
if generation_id != this.root().generation_id.get() {
|
||||
return;
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ impl HTMLIFrameElement {
|
||||
let pipeline_id = self.pipeline_id().unwrap();
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = window.dom_manipulation_task_source().queue(
|
||||
box task!(iframe_load_event_steps: move || {
|
||||
task!(iframe_load_event_steps: move || {
|
||||
this.root().iframe_load_event_steps(pipeline_id);
|
||||
}),
|
||||
window.upcast(),
|
||||
|
@ -174,7 +174,7 @@ impl HTMLImageElement {
|
||||
let image = message.to().unwrap();
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = task_source.queue_with_canceller(
|
||||
box task!(process_image_response: move || {
|
||||
task!(process_image_response: move || {
|
||||
let element = element.root();
|
||||
// Ignore any image response for a previous request that has been discarded.
|
||||
if generation == element.generation.get() {
|
||||
@ -425,7 +425,7 @@ impl HTMLImageElement {
|
||||
// Step 9.
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = task_source.queue(
|
||||
box task!(image_null_source_error: move || {
|
||||
task!(image_null_source_error: move || {
|
||||
let this = this.root();
|
||||
{
|
||||
let mut current_request =
|
||||
@ -451,7 +451,7 @@ impl HTMLImageElement {
|
||||
let target = Trusted::new(self.upcast::<EventTarget>());
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = task_source.queue(
|
||||
box task!(fire_progress_event: move || {
|
||||
task!(fire_progress_event: move || {
|
||||
let target = target.root();
|
||||
|
||||
let event = ProgressEvent::new(
|
||||
@ -480,7 +480,7 @@ impl HTMLImageElement {
|
||||
let src = String::from(src);
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = task_source.queue(
|
||||
box task!(image_selected_source_error: move || {
|
||||
task!(image_selected_source_error: move || {
|
||||
let this = this.root();
|
||||
{
|
||||
let mut current_request =
|
||||
@ -549,7 +549,7 @@ impl HTMLImageElement {
|
||||
let this = Trusted::new(self);
|
||||
let src = String::from(src);
|
||||
let _ = window.dom_manipulation_task_source().queue(
|
||||
box task!(image_load_event: move || {
|
||||
task!(image_load_event: move || {
|
||||
let this = this.root();
|
||||
{
|
||||
let mut current_request =
|
||||
|
@ -154,7 +154,7 @@ impl HTMLMediaElement {
|
||||
let target = Trusted::new(self.upcast::<EventTarget>());
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = window.dom_manipulation_task_source().queue(
|
||||
box task!(internal_pause_steps: move || {
|
||||
task!(internal_pause_steps: move || {
|
||||
let target = target.root();
|
||||
|
||||
// Step 2.3.1.
|
||||
@ -186,7 +186,7 @@ impl HTMLMediaElement {
|
||||
let window = window_from_node(self);
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = window.dom_manipulation_task_source().queue(
|
||||
box task!(notify_about_playing: move || {
|
||||
task!(notify_about_playing: move || {
|
||||
let target = target.root();
|
||||
|
||||
// Step 2.1.
|
||||
@ -495,7 +495,7 @@ impl HTMLMediaElement {
|
||||
let window = window_from_node(self);
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = window.dom_manipulation_task_source().queue(
|
||||
box task!(dedicated_media_source_failure_steps: move || {
|
||||
task!(dedicated_media_source_failure_steps: move || {
|
||||
let this = this.root();
|
||||
|
||||
// Step 1.
|
||||
|
@ -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::TaskOnce;
|
||||
|
||||
pub type TrustedServiceWorkerAddress = Trusted<ServiceWorker>;
|
||||
|
||||
@ -104,10 +104,9 @@ impl ServiceWorkerMethods for ServiceWorker {
|
||||
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
|
||||
}
|
||||
|
||||
impl Task for SimpleWorkerErrorHandler<ServiceWorker> {
|
||||
impl TaskOnce for SimpleWorkerErrorHandler<ServiceWorker> {
|
||||
#[allow(unrooted_must_root)]
|
||||
fn run(self: Box<Self>) {
|
||||
let this = *self;
|
||||
ServiceWorker::dispatch_simple_error(this.addr);
|
||||
fn run_once(self) {
|
||||
ServiceWorker::dispatch_simple_error(self.addr);
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ impl Storage {
|
||||
let global = self.global();
|
||||
let this = Trusted::new(self);
|
||||
global.as_window().dom_manipulation_task_source().queue(
|
||||
box task!(send_storage_notification: move || {
|
||||
task!(send_storage_notification: move || {
|
||||
let this = this.root();
|
||||
let global = this.global();
|
||||
let event = StorageEvent::new(
|
||||
|
@ -37,7 +37,7 @@ use std::borrow::ToOwned;
|
||||
use std::cell::Cell;
|
||||
use std::ptr;
|
||||
use std::thread;
|
||||
use task::{Task, TaskCanceller};
|
||||
use task::{TaskOnce, TaskCanceller};
|
||||
use task_source::TaskSource;
|
||||
use task_source::networking::NetworkingTaskSource;
|
||||
|
||||
@ -74,7 +74,7 @@ pub fn close_the_websocket_connection(
|
||||
code: Option<u16>,
|
||||
reason: String,
|
||||
) {
|
||||
let close_task = box CloseTask {
|
||||
let close_task = CloseTask {
|
||||
address: address,
|
||||
failed: false,
|
||||
code: code,
|
||||
@ -88,7 +88,7 @@ pub fn fail_the_websocket_connection(
|
||||
task_source: &NetworkingTaskSource,
|
||||
canceller: &TaskCanceller,
|
||||
) {
|
||||
let close_task = box CloseTask {
|
||||
let close_task = CloseTask {
|
||||
address: address,
|
||||
failed: true,
|
||||
code: Some(close_code::ABNORMAL),
|
||||
@ -206,14 +206,14 @@ impl WebSocket {
|
||||
while let Ok(event) = dom_event_receiver.recv() {
|
||||
match event {
|
||||
WebSocketNetworkEvent::ConnectionEstablished { protocol_in_use } => {
|
||||
let open_thread = box ConnectionEstablishedTask {
|
||||
let open_thread = ConnectionEstablishedTask {
|
||||
address: address.clone(),
|
||||
protocol_in_use,
|
||||
};
|
||||
task_source.queue_with_canceller(open_thread, &canceller).unwrap();
|
||||
},
|
||||
WebSocketNetworkEvent::MessageReceived(message) => {
|
||||
let message_thread = box MessageReceivedTask {
|
||||
let message_thread = MessageReceivedTask {
|
||||
address: address.clone(),
|
||||
message: message,
|
||||
};
|
||||
@ -397,9 +397,9 @@ struct ConnectionEstablishedTask {
|
||||
protocol_in_use: Option<String>,
|
||||
}
|
||||
|
||||
impl Task for ConnectionEstablishedTask {
|
||||
impl TaskOnce for ConnectionEstablishedTask {
|
||||
/// https://html.spec.whatwg.org/multipage/#feedback-from-the-protocol:concept-websocket-established
|
||||
fn run(self: Box<Self>) {
|
||||
fn run_once(self) {
|
||||
let ws = self.address.root();
|
||||
|
||||
// Step 1.
|
||||
@ -422,13 +422,13 @@ struct BufferedAmountTask {
|
||||
address: Trusted<WebSocket>,
|
||||
}
|
||||
|
||||
impl Task for BufferedAmountTask {
|
||||
impl TaskOnce 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<Self>) {
|
||||
fn run_once(self) {
|
||||
let ws = self.address.root();
|
||||
|
||||
ws.buffered_amount.set(0);
|
||||
@ -443,8 +443,8 @@ struct CloseTask {
|
||||
reason: Option<String>,
|
||||
}
|
||||
|
||||
impl Task for CloseTask {
|
||||
fn run(self: Box<Self>) {
|
||||
impl TaskOnce for CloseTask {
|
||||
fn run_once(self) {
|
||||
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 TaskOnce for MessageReceivedTask {
|
||||
#[allow(unsafe_code)]
|
||||
fn run(self: Box<Self>) {
|
||||
fn run_once(self) {
|
||||
let ws = self.address.root();
|
||||
debug!("MessageReceivedTask::handler({:p}): readyState={:?}", &*ws,
|
||||
ws.ready_state.get());
|
||||
|
@ -1977,7 +1977,7 @@ impl Window {
|
||||
serialize_with_transfer_result: StructuredCloneData,
|
||||
) {
|
||||
let this = Trusted::new(self);
|
||||
let task = box task!(post_serialised_message: move || {
|
||||
let task = task!(post_serialised_message: move || {
|
||||
let this = this.root();
|
||||
|
||||
// Step 7.1.
|
||||
@ -2012,7 +2012,7 @@ impl Window {
|
||||
// TODO(#12718): Use the "posted message task source".
|
||||
let _ = self.script_chan.send(CommonScriptMsg::Task(
|
||||
ScriptThreadEventCategory::DomEvent,
|
||||
self.task_canceller().wrap_task(task),
|
||||
box self.task_canceller().wrap_task(task),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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::TaskOnce;
|
||||
|
||||
pub type TrustedWorkerAddress = Trusted<Worker>;
|
||||
|
||||
@ -175,10 +175,9 @@ impl WorkerMethods for Worker {
|
||||
event_handler!(error, GetOnerror, SetOnerror);
|
||||
}
|
||||
|
||||
impl Task for SimpleWorkerErrorHandler<Worker> {
|
||||
impl TaskOnce for SimpleWorkerErrorHandler<Worker> {
|
||||
#[allow(unrooted_must_root)]
|
||||
fn run(self: Box<Self>) {
|
||||
let this = *self;
|
||||
Worker::dispatch_simple_error(this.addr);
|
||||
fn run_once(self) {
|
||||
Worker::dispatch_simple_error(self.addr);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
@ -645,8 +645,9 @@ impl WorkletThread {
|
||||
}
|
||||
|
||||
/// Run a task in the main script thread.
|
||||
fn run_in_script_thread<T>(&self, task: T) where
|
||||
T: 'static + Send + Task,
|
||||
fn run_in_script_thread<T>(&self, task: T)
|
||||
where
|
||||
T: TaskBox + 'static,
|
||||
{
|
||||
let msg = CommonScriptMsg::Task(ScriptThreadEventCategory::WorkletEvent, box task);
|
||||
let msg = MainThreadScriptMsg::Common(msg);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use net_traits::{Action, FetchResponseListener, FetchResponseMsg};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use task::{Task, TaskCanceller};
|
||||
use task::{TaskCanceller, TaskOnce};
|
||||
use task_source::TaskSource;
|
||||
use task_source::networking::NetworkingTaskSource;
|
||||
|
||||
@ -18,7 +18,7 @@ pub struct NetworkListener<Listener: PreInvoke + Send + 'static> {
|
||||
|
||||
impl<Listener: PreInvoke + Send + 'static> NetworkListener<Listener> {
|
||||
pub fn notify<A: Action<Listener> + Send + 'static>(&self, action: A) {
|
||||
let task = box ListenerTask {
|
||||
let task = ListenerTask {
|
||||
context: self.context.clone(),
|
||||
action: action,
|
||||
};
|
||||
@ -55,16 +55,15 @@ struct ListenerTask<A: Action<Listener> + Send + 'static, Listener: PreInvoke +
|
||||
action: A,
|
||||
}
|
||||
|
||||
impl<A, Listener> Task for ListenerTask<A, Listener>
|
||||
impl<A, Listener> TaskOnce for ListenerTask<A, Listener>
|
||||
where
|
||||
A: Action<Listener> + Send + 'static,
|
||||
Listener: PreInvoke + Send,
|
||||
{
|
||||
fn run(self: Box<Self>) {
|
||||
let this = *self;
|
||||
let mut context = this.context.lock().unwrap();
|
||||
fn run_once(self) {
|
||||
let mut context = self.context.lock().unwrap();
|
||||
if context.should_invoke() {
|
||||
this.action.process(&mut *context);
|
||||
self.action.process(&mut *context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 + Send>),
|
||||
Task(ScriptThreadEventCategory, Box<TaskBox>),
|
||||
}
|
||||
|
||||
impl fmt::Debug for CommonScriptMsg {
|
||||
|
@ -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)
|
||||
|
@ -275,7 +275,7 @@ fn queue_settle_promise_for_job(job: &Job, settle: SettleType, task_source: &DOM
|
||||
let promise = TrustedPromise::new(job.promise.clone());
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = task_source.queue(
|
||||
box task!(settle_promise_for_job: move || {
|
||||
task!(settle_promise_for_job: move || {
|
||||
let promise = promise.root();
|
||||
settle_job_promise(&promise.global(), &promise, settle)
|
||||
}),
|
||||
|
@ -13,15 +13,15 @@ macro_rules! task {
|
||||
($name:ident: move || $body:tt) => {{
|
||||
#[allow(non_camel_case_types)]
|
||||
struct $name<F>(F);
|
||||
impl<F> ::task::Task for $name<F>
|
||||
impl<F> ::task::TaskOnce for $name<F>
|
||||
where
|
||||
F: ::std::ops::FnOnce(),
|
||||
F: ::std::ops::FnOnce() + Send,
|
||||
{
|
||||
fn name(&self) -> &'static str {
|
||||
stringify!($name)
|
||||
}
|
||||
|
||||
fn run(self: Box<Self>) {
|
||||
fn run_once(self) {
|
||||
(self.0)();
|
||||
}
|
||||
}
|
||||
@ -30,13 +30,36 @@ macro_rules! task {
|
||||
}
|
||||
|
||||
/// A task that can be run. The name method is for profiling purposes.
|
||||
pub trait Task {
|
||||
pub trait TaskOnce: Send {
|
||||
#[allow(unsafe_code)]
|
||||
fn name(&self) -> &'static str { unsafe { intrinsics::type_name::<Self>() } }
|
||||
fn run(self: Box<Self>);
|
||||
fn name(&self) -> &'static str {
|
||||
unsafe { intrinsics::type_name::<Self>() }
|
||||
}
|
||||
|
||||
fn run_once(self);
|
||||
}
|
||||
|
||||
impl fmt::Debug for Task + Send {
|
||||
/// A boxed version of `TaskOnce`.
|
||||
pub trait TaskBox: Send {
|
||||
fn name(&self) -> &'static str;
|
||||
|
||||
fn run_box(self: Box<Self>);
|
||||
}
|
||||
|
||||
impl<T> TaskBox for T
|
||||
where
|
||||
T: TaskOnce,
|
||||
{
|
||||
fn name(&self) -> &'static str {
|
||||
TaskOnce::name(self)
|
||||
}
|
||||
|
||||
fn run_box(self: Box<Self>) {
|
||||
self.run_once()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TaskBox {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_tuple(self.name()).field(&format_args!("...")).finish()
|
||||
}
|
||||
@ -50,11 +73,11 @@ pub struct TaskCanceller {
|
||||
impl TaskCanceller {
|
||||
/// Returns a wrapped `task` that will be cancelled if the `TaskCanceller`
|
||||
/// says so.
|
||||
pub fn wrap_task<T>(&self, task: Box<T>) -> Box<Task + Send>
|
||||
pub fn wrap_task<T>(&self, task: T) -> impl TaskOnce
|
||||
where
|
||||
T: Send + Task + 'static,
|
||||
T: TaskOnce,
|
||||
{
|
||||
box CancellableTask {
|
||||
CancellableTask {
|
||||
cancelled: self.cancelled.clone(),
|
||||
inner: task,
|
||||
}
|
||||
@ -62,14 +85,14 @@ impl TaskCanceller {
|
||||
}
|
||||
|
||||
/// A task that can be cancelled by toggling a shared flag.
|
||||
pub struct CancellableTask<T: Send + Task> {
|
||||
pub struct CancellableTask<T: TaskOnce> {
|
||||
cancelled: Option<Arc<AtomicBool>>,
|
||||
inner: Box<T>,
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> CancellableTask<T>
|
||||
where
|
||||
T: Send + Task,
|
||||
T: TaskOnce,
|
||||
{
|
||||
fn is_cancelled(&self) -> bool {
|
||||
self.cancelled.as_ref().map_or(false, |cancelled| {
|
||||
@ -78,17 +101,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Task for CancellableTask<T>
|
||||
impl<T> TaskOnce for CancellableTask<T>
|
||||
where
|
||||
T: Send + Task,
|
||||
T: TaskOnce,
|
||||
{
|
||||
fn name(&self) -> &'static str {
|
||||
self.inner.name()
|
||||
}
|
||||
|
||||
fn run(self: Box<Self>) {
|
||||
fn run_once(self) {
|
||||
if !self.is_cancelled() {
|
||||
self.inner.run()
|
||||
self.inner.run_once()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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::{TaskCanceller, TaskOnce};
|
||||
use task_source::TaskSource;
|
||||
|
||||
#[derive(Clone, JSTraceable)]
|
||||
@ -28,15 +28,15 @@ impl fmt::Debug for DOMManipulationTaskSource {
|
||||
impl TaskSource for DOMManipulationTaskSource {
|
||||
fn queue_with_canceller<T>(
|
||||
&self,
|
||||
msg: Box<T>,
|
||||
task: T,
|
||||
canceller: &TaskCanceller,
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
T: Task + Send + 'static,
|
||||
T: TaskOnce + 'static,
|
||||
{
|
||||
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
||||
ScriptThreadEventCategory::ScriptEvent,
|
||||
canceller.wrap_task(msg),
|
||||
box canceller.wrap_task(task),
|
||||
));
|
||||
self.0.send(msg).map_err(|_| ())
|
||||
}
|
||||
@ -50,7 +50,7 @@ impl DOMManipulationTaskSource {
|
||||
cancelable: EventCancelable,
|
||||
window: &Window) {
|
||||
let target = Trusted::new(target);
|
||||
let task = box EventTask {
|
||||
let task = EventTask {
|
||||
target: target,
|
||||
name: name,
|
||||
bubbles: bubbles,
|
||||
@ -61,6 +61,6 @@ impl DOMManipulationTaskSource {
|
||||
|
||||
pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) {
|
||||
let target = Trusted::new(target);
|
||||
let _ = self.queue(box SimpleEventTask { target, name }, window.upcast());
|
||||
let _ = self.queue(SimpleEventTask { target, name }, window.upcast());
|
||||
}
|
||||
}
|
||||
|
@ -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::{TaskCanceller, TaskOnce};
|
||||
use task_source::TaskSource;
|
||||
|
||||
#[derive(JSTraceable)]
|
||||
@ -21,21 +21,21 @@ impl Clone for FileReadingTaskSource {
|
||||
impl TaskSource for FileReadingTaskSource {
|
||||
fn queue_with_canceller<T>(
|
||||
&self,
|
||||
msg: Box<T>,
|
||||
task: T,
|
||||
canceller: &TaskCanceller,
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
T: Send + Task + 'static,
|
||||
T: TaskOnce + 'static,
|
||||
{
|
||||
self.0.send(CommonScriptMsg::Task(
|
||||
ScriptThreadEventCategory::FileRead,
|
||||
canceller.wrap_task(msg),
|
||||
box canceller.wrap_task(task),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Task for FileReadingTask {
|
||||
fn run(self: Box<Self>) {
|
||||
impl TaskOnce for FileReadingTask {
|
||||
fn run_once(self) {
|
||||
self.handle_task();
|
||||
}
|
||||
}
|
||||
|
@ -11,18 +11,21 @@ pub mod user_interaction;
|
||||
|
||||
use dom::globalscope::GlobalScope;
|
||||
use std::result::Result;
|
||||
use task::{Task, TaskCanceller};
|
||||
use task::{TaskCanceller, TaskOnce};
|
||||
|
||||
pub trait TaskSource {
|
||||
fn queue_with_canceller<T>(
|
||||
&self,
|
||||
msg: Box<T>,
|
||||
task: T,
|
||||
canceller: &TaskCanceller,
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
T: Send + Task + 'static;
|
||||
T: TaskOnce + 'static;
|
||||
|
||||
fn queue<T: Task + Send + 'static>(&self, msg: Box<T>, global: &GlobalScope) -> Result<(), ()> {
|
||||
self.queue_with_canceller(msg, &global.task_canceller())
|
||||
fn queue<T>(&self, task: T, global: &GlobalScope) -> Result<(), ()>
|
||||
where
|
||||
T: TaskOnce + 'static,
|
||||
{
|
||||
self.queue_with_canceller(task, &global.task_canceller())
|
||||
}
|
||||
}
|
||||
|
@ -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::{TaskCanceller, TaskOnce};
|
||||
use task_source::TaskSource;
|
||||
|
||||
#[derive(JSTraceable)]
|
||||
@ -18,15 +18,15 @@ impl Clone for NetworkingTaskSource {
|
||||
impl TaskSource for NetworkingTaskSource {
|
||||
fn queue_with_canceller<T>(
|
||||
&self,
|
||||
msg: Box<T>,
|
||||
task: T,
|
||||
canceller: &TaskCanceller,
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
T: Send + Task + 'static,
|
||||
T: TaskOnce + 'static,
|
||||
{
|
||||
self.0.send(CommonScriptMsg::Task(
|
||||
ScriptThreadEventCategory::NetworkEvent,
|
||||
canceller.wrap_task(msg),
|
||||
box canceller.wrap_task(task),
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -34,10 +34,13 @@ impl TaskSource for NetworkingTaskSource {
|
||||
impl NetworkingTaskSource {
|
||||
/// This queues a task that will not be cancelled when its associated
|
||||
/// global scope gets destroyed.
|
||||
pub fn queue_unconditionally<T>(&self, msg: Box<T>) -> Result<(), ()>
|
||||
pub fn queue_unconditionally<T>(&self, task: T) -> Result<(), ()>
|
||||
where
|
||||
T: Task + Send + 'static,
|
||||
T: TaskOnce + 'static,
|
||||
{
|
||||
self.0.send(CommonScriptMsg::Task(ScriptThreadEventCategory::NetworkEvent, msg))
|
||||
self.0.send(CommonScriptMsg::Task(
|
||||
ScriptThreadEventCategory::NetworkEvent,
|
||||
box task,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -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::{TaskCanceller, TaskOnce};
|
||||
use task_source::TaskSource;
|
||||
|
||||
#[derive(JSTraceable)]
|
||||
@ -32,15 +32,15 @@ impl fmt::Debug for PerformanceTimelineTaskSource {
|
||||
impl TaskSource for PerformanceTimelineTaskSource {
|
||||
fn queue_with_canceller<T>(
|
||||
&self,
|
||||
msg: Box<T>,
|
||||
task: T,
|
||||
canceller: &TaskCanceller,
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
T: Send + Task + 'static,
|
||||
T: TaskOnce + 'static,
|
||||
{
|
||||
let msg = CommonScriptMsg::Task(
|
||||
ScriptThreadEventCategory::PerformanceTimelineTask,
|
||||
canceller.wrap_task(msg)
|
||||
box canceller.wrap_task(task)
|
||||
);
|
||||
self.0.send(msg).map_err(|_| ())
|
||||
}
|
||||
@ -51,7 +51,7 @@ impl PerformanceTimelineTaskSource {
|
||||
let owner = Trusted::new(&*global.performance());
|
||||
// FIXME(nox): Why are errors silenced here?
|
||||
let _ = self.queue(
|
||||
box task!(notify_performance_observers: move || {
|
||||
task!(notify_performance_observers: move || {
|
||||
owner.root().notify_observers();
|
||||
}),
|
||||
global,
|
||||
|
@ -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::{TaskCanceller, TaskOnce};
|
||||
use task_source::TaskSource;
|
||||
|
||||
#[derive(Clone, JSTraceable)]
|
||||
@ -28,15 +28,15 @@ impl fmt::Debug for UserInteractionTaskSource {
|
||||
impl TaskSource for UserInteractionTaskSource {
|
||||
fn queue_with_canceller<T>(
|
||||
&self,
|
||||
msg: Box<T>,
|
||||
task: T,
|
||||
canceller: &TaskCanceller,
|
||||
) -> Result<(), ()>
|
||||
where
|
||||
T: Task + Send + 'static,
|
||||
T: TaskOnce + 'static,
|
||||
{
|
||||
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
|
||||
ScriptThreadEventCategory::InputEvent,
|
||||
canceller.wrap_task(msg),
|
||||
box canceller.wrap_task(task),
|
||||
));
|
||||
self.0.send(msg).map_err(|_| ())
|
||||
}
|
||||
@ -50,7 +50,7 @@ impl UserInteractionTaskSource {
|
||||
cancelable: EventCancelable,
|
||||
window: &Window) {
|
||||
let target = Trusted::new(target);
|
||||
let task = box EventTask { target, name, bubbles, cancelable };
|
||||
let task = EventTask { target, name, bubbles, cancelable };
|
||||
let _ = self.queue(task, window.upcast());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user