mirror of
https://github.com/servo/servo.git
synced 2025-07-30 18:50:36 +01:00
Report panics in web worker threads.
This commit is contained in:
parent
aa8c835d3b
commit
1ebe681d8d
7 changed files with 42 additions and 12 deletions
|
@ -18,7 +18,7 @@ use ipc_channel::ipc::IpcSender;
|
|||
use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment};
|
||||
use js::jsapi::{JSContext, JSObject, JS_GetClass, MutableHandleValue};
|
||||
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
||||
use msg::constellation_msg::{ConstellationChan, PipelineId};
|
||||
use msg::constellation_msg::{ConstellationChan, PanicMsg, PipelineId};
|
||||
use net_traits::ResourceThread;
|
||||
use profile_traits::mem;
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
|
||||
|
@ -263,6 +263,14 @@ impl<'a> GlobalRef<'a> {
|
|||
GlobalRef::Worker(ref worker) => worker.reflector(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an `IpcSender` to report panics on.
|
||||
pub fn panic_chan(&self) -> &IpcSender<PanicMsg> {
|
||||
match *self {
|
||||
GlobalRef::Window(ref window) => window.panic_chan(),
|
||||
GlobalRef::Worker(ref worker) => worker.panic_chan(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GlobalRoot {
|
||||
|
|
|
@ -36,8 +36,7 @@ use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
|
|||
use std::sync::{Arc, Mutex};
|
||||
use url::Url;
|
||||
use util::str::DOMString;
|
||||
use util::thread::spawn_named;
|
||||
use util::thread_state;
|
||||
use util::thread::spawn_named_with_send_on_panic;
|
||||
use util::thread_state::{IN_WORKER, SCRIPT};
|
||||
|
||||
/// Messages used to control the worker event loops
|
||||
|
@ -218,9 +217,9 @@ impl DedicatedWorkerGlobalScope {
|
|||
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
||||
receiver: Receiver<(TrustedWorkerAddress, WorkerScriptMsg)>) {
|
||||
let serialized_worker_url = worker_url.to_string();
|
||||
spawn_named(format!("WebWorker for {}", serialized_worker_url), move || {
|
||||
thread_state::initialize(SCRIPT | IN_WORKER);
|
||||
|
||||
let name = format!("WebWorker for {}", serialized_worker_url);
|
||||
let panic_chan = init.panic_chan.clone();
|
||||
spawn_named_with_send_on_panic(name, SCRIPT | IN_WORKER, move || {
|
||||
let roots = RootCollection::new();
|
||||
let _stack_roots_tls = StackRootTLS::new(&roots);
|
||||
|
||||
|
@ -284,7 +283,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
global.handle_event(event);
|
||||
}
|
||||
}, reporter_name, parent_sender, CommonScriptMsg::CollectReports);
|
||||
});
|
||||
}, Some(id.clone()), panic_chan);
|
||||
}
|
||||
|
||||
pub fn script_chan(&self) -> Box<ScriptChan + Send> {
|
||||
|
|
|
@ -42,7 +42,7 @@ use js::rust::Runtime;
|
|||
use layout_interface::{ContentBoxResponse, ContentBoxesResponse, ResolvedStyleResponse, ScriptReflow};
|
||||
use layout_interface::{LayoutChan, LayoutRPC, Msg, Reflow, ReflowQueryType, MarginStyleResponse};
|
||||
use libc;
|
||||
use msg::constellation_msg::{ConstellationChan, LoadData, PipelineId, SubpageId};
|
||||
use msg::constellation_msg::{ConstellationChan, LoadData, PanicMsg, PipelineId, SubpageId};
|
||||
use msg::constellation_msg::{WindowSizeData, WindowSizeType};
|
||||
use msg::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
||||
use net_traits::ResourceThread;
|
||||
|
@ -253,6 +253,9 @@ pub struct Window {
|
|||
ignore_further_async_events: Arc<AtomicBool>,
|
||||
|
||||
error_reporter: CSSErrorReporter,
|
||||
|
||||
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
||||
panic_chan: IpcSender<PanicMsg>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -1275,6 +1278,10 @@ impl Window {
|
|||
&self.scheduler_chan
|
||||
}
|
||||
|
||||
pub fn panic_chan(&self) -> &IpcSender<PanicMsg> {
|
||||
&self.panic_chan
|
||||
}
|
||||
|
||||
pub fn schedule_callback(&self, callback: OneshotTimerCallback, duration: MsDuration) -> OneshotTimerHandle {
|
||||
self.timers.schedule_callback(callback,
|
||||
duration,
|
||||
|
@ -1428,6 +1435,7 @@ impl Window {
|
|||
constellation_chan: ConstellationChan<ConstellationMsg>,
|
||||
control_chan: IpcSender<ConstellationControlMsg>,
|
||||
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
panic_chan: IpcSender<PanicMsg>,
|
||||
timer_event_chan: IpcSender<TimerEvent>,
|
||||
layout_chan: LayoutChan,
|
||||
id: PipelineId,
|
||||
|
@ -1496,7 +1504,8 @@ impl Window {
|
|||
devtools_wants_updates: Cell::new(false),
|
||||
webdriver_script_chan: DOMRefCell::new(None),
|
||||
ignore_further_async_events: Arc::new(AtomicBool::new(false)),
|
||||
error_reporter: error_reporter
|
||||
error_reporter: error_reporter,
|
||||
panic_chan: panic_chan,
|
||||
};
|
||||
|
||||
WindowBinding::Wrap(runtime.cx(), win)
|
||||
|
|
|
@ -106,6 +106,7 @@ impl Worker {
|
|||
from_devtools_sender: optional_sender,
|
||||
constellation_chan: constellation_chan,
|
||||
scheduler_chan: scheduler_chan,
|
||||
panic_chan: global.panic_chan().clone(),
|
||||
worker_id: worker_id,
|
||||
closing: closing,
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ use ipc_channel::ipc::IpcSender;
|
|||
use js::jsapi::{HandleValue, JSContext, JSRuntime, RootedValue};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::Runtime;
|
||||
use msg::constellation_msg::{ConstellationChan, PipelineId};
|
||||
use msg::constellation_msg::{ConstellationChan, PanicMsg, PipelineId};
|
||||
use net_traits::{LoadContext, ResourceThread, load_whole_resource};
|
||||
use profile_traits::mem;
|
||||
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
|
||||
|
@ -49,6 +49,7 @@ pub struct WorkerGlobalScopeInit {
|
|||
pub from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
|
||||
pub constellation_chan: ConstellationChan<ConstellationMsg>,
|
||||
pub scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
pub panic_chan: IpcSender<PanicMsg>,
|
||||
pub worker_id: WorkerId,
|
||||
pub closing: Arc<AtomicBool>,
|
||||
}
|
||||
|
@ -94,6 +95,9 @@ pub struct WorkerGlobalScope {
|
|||
|
||||
#[ignore_heap_size_of = "Defined in std"]
|
||||
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
|
||||
#[ignore_heap_size_of = "Defined in ipc-channel"]
|
||||
panic_chan: IpcSender<PanicMsg>,
|
||||
}
|
||||
|
||||
impl WorkerGlobalScope {
|
||||
|
@ -124,6 +128,7 @@ impl WorkerGlobalScope {
|
|||
devtools_wants_updates: Cell::new(false),
|
||||
constellation_chan: init.constellation_chan,
|
||||
scheduler_chan: init.scheduler_chan,
|
||||
panic_chan: init.panic_chan,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,6 +196,10 @@ impl WorkerGlobalScope {
|
|||
self.next_worker_id.set(WorkerId(id_num + 1));
|
||||
worker_id
|
||||
}
|
||||
|
||||
pub fn panic_chan(&self) -> &IpcSender<PanicMsg> {
|
||||
&self.panic_chan
|
||||
}
|
||||
}
|
||||
|
||||
impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
||||
|
|
|
@ -59,7 +59,7 @@ use js::rust::Runtime;
|
|||
use layout_interface::{ReflowQueryType};
|
||||
use layout_interface::{self, LayoutChan, NewLayoutThreadInfo, ScriptLayoutChan};
|
||||
use mem::heap_size_of_self_and_children;
|
||||
use msg::constellation_msg::{ConstellationChan, LoadData};
|
||||
use msg::constellation_msg::{ConstellationChan, LoadData, PanicMsg};
|
||||
use msg::constellation_msg::{PipelineId, PipelineNamespace};
|
||||
use msg::constellation_msg::{SubpageId, WindowSizeData, WindowSizeType};
|
||||
use msg::webdriver_msg::WebDriverScriptCommand;
|
||||
|
@ -383,6 +383,8 @@ pub struct ScriptThread {
|
|||
timer_event_port: Receiver<TimerEvent>,
|
||||
|
||||
content_process_shutdown_chan: IpcSender<()>,
|
||||
|
||||
panic_chan: IpcSender<PanicMsg>,
|
||||
}
|
||||
|
||||
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
||||
|
@ -575,6 +577,7 @@ impl ScriptThread {
|
|||
compositor: DOMRefCell::new(state.compositor),
|
||||
time_profiler_chan: state.time_profiler_chan,
|
||||
mem_profiler_chan: state.mem_profiler_chan,
|
||||
panic_chan: state.panic_chan.0,
|
||||
|
||||
devtools_chan: state.devtools_chan,
|
||||
devtools_port: devtools_port,
|
||||
|
@ -1450,6 +1453,7 @@ impl ScriptThread {
|
|||
self.constellation_chan.clone(),
|
||||
self.control_chan.clone(),
|
||||
self.scheduler_chan.clone(),
|
||||
self.panic_chan.clone(),
|
||||
ipc_timer_event_chan,
|
||||
incomplete.layout_chan,
|
||||
incomplete.pipeline_id,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
[004.worker]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
expected: CRASH
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue