mirror of
https://github.com/servo/servo.git
synced 2025-07-29 18:20:24 +01:00
Auto merge of #10312 - servo:ScriptPort, r=Ms2ger
Report errors from ScriptPort trait methods. <!-- 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/10312) <!-- Reviewable:end -->
This commit is contained in:
commit
6056b16a77
3 changed files with 21 additions and 18 deletions
|
@ -94,10 +94,11 @@ impl ScriptChan for WorkerThreadWorkerChan {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptPort for Receiver<(TrustedWorkerAddress, WorkerScriptMsg)> {
|
impl ScriptPort for Receiver<(TrustedWorkerAddress, WorkerScriptMsg)> {
|
||||||
fn recv(&self) -> CommonScriptMsg {
|
fn recv(&self) -> Result<CommonScriptMsg, ()> {
|
||||||
match self.recv().unwrap().1 {
|
match self.recv().map(|(_, msg)| msg) {
|
||||||
WorkerScriptMsg::Common(script_msg) => script_msg,
|
Ok(WorkerScriptMsg::Common(script_msg)) => Ok(script_msg),
|
||||||
WorkerScriptMsg::DOMMessage(_) => panic!("unexpected worker event message!"),
|
Ok(WorkerScriptMsg::DOMMessage(_)) => panic!("unexpected worker event message!"),
|
||||||
|
Err(_) => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1337,7 +1337,7 @@ impl XMLHttpRequest {
|
||||||
|
|
||||||
if let Some(script_port) = script_port {
|
if let Some(script_port) = script_port {
|
||||||
loop {
|
loop {
|
||||||
global.process_event(script_port.recv());
|
global.process_event(script_port.recv().unwrap());
|
||||||
let context = context.lock().unwrap();
|
let context = context.lock().unwrap();
|
||||||
let sync_status = context.sync_status.borrow();
|
let sync_status = context.sync_status.borrow();
|
||||||
if let Some(ref status) = *sync_status {
|
if let Some(ref status) = *sync_status {
|
||||||
|
|
|
@ -282,35 +282,37 @@ impl OpaqueSender<CommonScriptMsg> for Box<ScriptChan + Send> {
|
||||||
/// APIs that need to abstract over multiple kinds of event loops (worker/main thread) with
|
/// APIs that need to abstract over multiple kinds of event loops (worker/main thread) with
|
||||||
/// different Receiver interfaces.
|
/// different Receiver interfaces.
|
||||||
pub trait ScriptPort {
|
pub trait ScriptPort {
|
||||||
fn recv(&self) -> CommonScriptMsg;
|
fn recv(&self) -> Result<CommonScriptMsg, ()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptPort for Receiver<CommonScriptMsg> {
|
impl ScriptPort for Receiver<CommonScriptMsg> {
|
||||||
fn recv(&self) -> CommonScriptMsg {
|
fn recv(&self) -> Result<CommonScriptMsg, ()> {
|
||||||
self.recv().unwrap()
|
self.recv().map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptPort for Receiver<MainThreadScriptMsg> {
|
impl ScriptPort for Receiver<MainThreadScriptMsg> {
|
||||||
fn recv(&self) -> CommonScriptMsg {
|
fn recv(&self) -> Result<CommonScriptMsg, ()> {
|
||||||
match self.recv().unwrap() {
|
match self.recv() {
|
||||||
MainThreadScriptMsg::Common(script_msg) => script_msg,
|
Ok(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg),
|
||||||
_ => panic!("unexpected main thread event message!")
|
Ok(_) => panic!("unexpected main thread event message!"),
|
||||||
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptPort for Receiver<(TrustedWorkerAddress, CommonScriptMsg)> {
|
impl ScriptPort for Receiver<(TrustedWorkerAddress, CommonScriptMsg)> {
|
||||||
fn recv(&self) -> CommonScriptMsg {
|
fn recv(&self) -> Result<CommonScriptMsg, ()> {
|
||||||
self.recv().unwrap().1
|
self.recv().map(|(_, msg)| msg).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ScriptPort for Receiver<(TrustedWorkerAddress, MainThreadScriptMsg)> {
|
impl ScriptPort for Receiver<(TrustedWorkerAddress, MainThreadScriptMsg)> {
|
||||||
fn recv(&self) -> CommonScriptMsg {
|
fn recv(&self) -> Result<CommonScriptMsg, ()> {
|
||||||
match self.recv().unwrap().1 {
|
match self.recv().map(|(_, msg)| msg) {
|
||||||
MainThreadScriptMsg::Common(script_msg) => script_msg,
|
Ok(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg),
|
||||||
_ => panic!("unexpected main thread event message!")
|
Ok(_) => panic!("unexpected main thread event message!"),
|
||||||
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue