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