mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #12277 - ConnorGBrewster:network_listener_cancellable, r=Manishearth
Make network listener runnable cancellable <!-- Please describe your changes on the following line: --> This keeps scripts from executing after its script thread has been shut down. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [x] These changes fix (maybe) #12048 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12277) <!-- Reviewable:end -->
This commit is contained in:
commit
12260b24d0
11 changed files with 60 additions and 7 deletions
|
@ -226,6 +226,7 @@ impl HTMLLinkElement {
|
||||||
let listener = NetworkListener {
|
let listener = NetworkListener {
|
||||||
context: context,
|
context: context,
|
||||||
script_chan: document.window().networking_task_source(),
|
script_chan: document.window().networking_task_source(),
|
||||||
|
wrapper: Some(document.window().get_runnable_wrapper()),
|
||||||
};
|
};
|
||||||
let response_target = AsyncResponseTarget {
|
let response_target = AsyncResponseTarget {
|
||||||
sender: action_sender,
|
sender: action_sender,
|
||||||
|
|
|
@ -473,10 +473,12 @@ impl HTMLMediaElement {
|
||||||
// 4.2
|
// 4.2
|
||||||
let context = Arc::new(Mutex::new(HTMLMediaElementContext::new(self, url.clone())));
|
let context = Arc::new(Mutex::new(HTMLMediaElementContext::new(self, url.clone())));
|
||||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
let script_chan = window_from_node(self).networking_task_source();
|
let window = window_from_node(self);
|
||||||
|
let script_chan = window.networking_task_source();
|
||||||
let listener = box NetworkListener {
|
let listener = box NetworkListener {
|
||||||
context: context,
|
context: context,
|
||||||
script_chan: script_chan,
|
script_chan: script_chan,
|
||||||
|
wrapper: Some(window.get_runnable_wrapper()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let response_target = AsyncResponseTarget {
|
let response_target = AsyncResponseTarget {
|
||||||
|
|
|
@ -308,6 +308,7 @@ impl HTMLScriptElement {
|
||||||
let listener = NetworkListener {
|
let listener = NetworkListener {
|
||||||
context: context,
|
context: context,
|
||||||
script_chan: doc.window().networking_task_source(),
|
script_chan: doc.window().networking_task_source(),
|
||||||
|
wrapper: Some(doc.window().get_runnable_wrapper()),
|
||||||
};
|
};
|
||||||
let response_target = AsyncResponseTarget {
|
let response_target = AsyncResponseTarget {
|
||||||
sender: action_sender,
|
sender: action_sender,
|
||||||
|
|
|
@ -949,7 +949,7 @@ impl Window {
|
||||||
self.current_state.set(WindowState::Zombie);
|
self.current_state.set(WindowState::Zombie);
|
||||||
*self.js_runtime.borrow_mut() = None;
|
*self.js_runtime.borrow_mut() = None;
|
||||||
self.browsing_context.set(None);
|
self.browsing_context.set(None);
|
||||||
self.ignore_further_async_events.store(true, Ordering::Relaxed);
|
self.ignore_further_async_events.store(true, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/cssom-view/#dom-window-scroll
|
/// https://drafts.csswg.org/cssom-view/#dom-window-scroll
|
||||||
|
|
|
@ -258,6 +258,7 @@ impl XMLHttpRequest {
|
||||||
let listener = NetworkListener {
|
let listener = NetworkListener {
|
||||||
context: context,
|
context: context,
|
||||||
script_chan: script_chan,
|
script_chan: script_chan,
|
||||||
|
wrapper: None,
|
||||||
};
|
};
|
||||||
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
||||||
listener.notify_fetch(message.to().unwrap());
|
listener.notify_fetch(message.to().unwrap());
|
||||||
|
|
|
@ -6,7 +6,7 @@ use net_traits::{Action, AsyncResponseListener, FetchResponseListener};
|
||||||
use net_traits::{FetchResponseMsg, ResponseAction};
|
use net_traits::{FetchResponseMsg, ResponseAction};
|
||||||
use script_runtime::ScriptThreadEventCategory::NetworkEvent;
|
use script_runtime::ScriptThreadEventCategory::NetworkEvent;
|
||||||
use script_runtime::{CommonScriptMsg, ScriptChan};
|
use script_runtime::{CommonScriptMsg, ScriptChan};
|
||||||
use script_thread::Runnable;
|
use script_thread::{Runnable, RunnableWrapper};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
/// An off-thread sink for async network event runnables. All such events are forwarded to
|
/// An off-thread sink for async network event runnables. All such events are forwarded to
|
||||||
|
@ -14,15 +14,25 @@ use std::sync::{Arc, Mutex};
|
||||||
pub struct NetworkListener<Listener: PreInvoke + Send + 'static> {
|
pub struct NetworkListener<Listener: PreInvoke + Send + 'static> {
|
||||||
pub context: Arc<Mutex<Listener>>,
|
pub context: Arc<Mutex<Listener>>,
|
||||||
pub script_chan: Box<ScriptChan + Send>,
|
pub script_chan: Box<ScriptChan + Send>,
|
||||||
|
pub wrapper: Option<RunnableWrapper>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Listener: PreInvoke + Send + 'static> NetworkListener<Listener> {
|
impl<Listener: PreInvoke + Send + 'static> NetworkListener<Listener> {
|
||||||
pub fn notify<A: Action<Listener> + Send + 'static>(&self, action: A) {
|
pub fn notify<A: Action<Listener> + Send + 'static>(&self, action: A) {
|
||||||
if let Err(err) = self.script_chan.send(CommonScriptMsg::RunnableMsg(NetworkEvent, box ListenerRunnable {
|
let runnable = ListenerRunnable {
|
||||||
context: self.context.clone(),
|
context: self.context.clone(),
|
||||||
action: action,
|
action: action,
|
||||||
})) {
|
};
|
||||||
warn!("failed to deliver network data: {:?}", err);
|
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);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Err(err) = self.script_chan.send(
|
||||||
|
CommonScriptMsg::RunnableMsg(NetworkEvent, box runnable)) {
|
||||||
|
warn!("failed to deliver network data: {:?}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ pub struct CancellableRunnable<T: Runnable + Send> {
|
||||||
|
|
||||||
impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
|
impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
|
||||||
fn is_cancelled(&self) -> bool {
|
fn is_cancelled(&self) -> bool {
|
||||||
self.cancelled.load(Ordering::Relaxed)
|
self.cancelled.load(Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handler(self: Box<CancellableRunnable<T>>) {
|
fn handler(self: Box<CancellableRunnable<T>>) {
|
||||||
|
@ -2055,6 +2055,7 @@ impl ScriptThread {
|
||||||
let listener = NetworkListener {
|
let listener = NetworkListener {
|
||||||
context: context,
|
context: context,
|
||||||
script_chan: self.chan.clone(),
|
script_chan: self.chan.clone(),
|
||||||
|
wrapper: None,
|
||||||
};
|
};
|
||||||
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
|
||||||
listener.notify_action(message.to().unwrap());
|
listener.notify_action(message.to().unwrap());
|
||||||
|
|
|
@ -37190,6 +37190,12 @@
|
||||||
"path": "html/semantics/embedded-content/the-img-element/invalid-src.html",
|
"path": "html/semantics/embedded-content/the-img-element/invalid-src.html",
|
||||||
"url": "/html/semantics/embedded-content/the-img-element/invalid-src.html"
|
"url": "/html/semantics/embedded-content/the-img-element/invalid-src.html"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"html/semantics/scripting-1/the-script-element/script-not-executed-after-shutdown.html": [
|
||||||
|
{
|
||||||
|
"path": "html/semantics/scripting-1/the-script-element/script-not-executed-after-shutdown.html",
|
||||||
|
"url": "/html/semantics/scripting-1/the-script-element/script-not-executed-after-shutdown.html"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Script is not executed after script thread is shutdown</title>
|
||||||
|
<script>
|
||||||
|
onload = function() {
|
||||||
|
script_executed = parent.script_executed;
|
||||||
|
s = document.createElement('script');
|
||||||
|
s.type = 'text/javascript';
|
||||||
|
s.src = 'script-not-executed-after-shutdown.js?pipe=trickle(d3)';
|
||||||
|
document.body.appendChild(s);
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -0,0 +1,18 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Script is not executed after script thread is shutdown</title>
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<iframe id="testiframe" src="script-not-executed-after-shutdown-child.html"></iframe>
|
||||||
|
<script>
|
||||||
|
async_test(function(t) {
|
||||||
|
window.script_executed = t.unreached_func("script executed in removed iframe");
|
||||||
|
let iframe = document.getElementById("testiframe");
|
||||||
|
iframe.onload = function() {
|
||||||
|
iframe.parentNode.removeChild(iframe);
|
||||||
|
};
|
||||||
|
setTimeout(function() {
|
||||||
|
t.done();
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -0,0 +1 @@
|
||||||
|
script_executed();
|
Loading…
Add table
Add a link
Reference in a new issue