diff options
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index c591cd955a3..1f6adc177c1 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -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 /// different Receiver interfaces. pub trait ScriptPort { - fn recv(&self) -> CommonScriptMsg; + fn recv(&self) -> Result<CommonScriptMsg, ()>; } impl ScriptPort for Receiver<CommonScriptMsg> { - fn recv(&self) -> CommonScriptMsg { - self.recv().unwrap() + fn recv(&self) -> Result<CommonScriptMsg, ()> { + self.recv().map_err(|_| ()) } } impl ScriptPort for Receiver<MainThreadScriptMsg> { - fn recv(&self) -> CommonScriptMsg { - match self.recv().unwrap() { - MainThreadScriptMsg::Common(script_msg) => script_msg, - _ => panic!("unexpected main thread event message!") + fn recv(&self) -> Result<CommonScriptMsg, ()> { + match self.recv() { + Ok(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg), + Ok(_) => panic!("unexpected main thread event message!"), + _ => Err(()), } } } impl ScriptPort for Receiver<(TrustedWorkerAddress, CommonScriptMsg)> { - fn recv(&self) -> CommonScriptMsg { - self.recv().unwrap().1 + fn recv(&self) -> Result<CommonScriptMsg, ()> { + self.recv().map(|(_, msg)| msg).map_err(|_| ()) } } impl ScriptPort for Receiver<(TrustedWorkerAddress, MainThreadScriptMsg)> { - fn recv(&self) -> CommonScriptMsg { - match self.recv().unwrap().1 { - MainThreadScriptMsg::Common(script_msg) => script_msg, - _ => panic!("unexpected main thread event message!") + fn recv(&self) -> Result<CommonScriptMsg, ()> { + match self.recv().map(|(_, msg)| msg) { + Ok(MainThreadScriptMsg::Common(script_msg)) => Ok(script_msg), + Ok(_) => panic!("unexpected main thread event message!"), + _ => Err(()), } } } |