44
55use devtools;
66use devtools_traits:: DevtoolScriptControlMsg ;
7+ use dom:: abstractworker:: { WorkerScriptLoadOrigin , WorkerScriptMsg , SharedRt , SimpleWorkerErrorHandler } ;
8+ use dom:: abstractworkerglobalscope:: { SendableWorkerScriptChan , WorkerThreadWorkerChan } ;
79use dom:: bindings:: cell:: DOMRefCell ;
810use dom:: bindings:: codegen:: Bindings :: DedicatedWorkerGlobalScopeBinding ;
911use dom:: bindings:: codegen:: Bindings :: DedicatedWorkerGlobalScopeBinding :: DedicatedWorkerGlobalScopeMethods ;
@@ -17,8 +19,7 @@ use dom::bindings::reflector::Reflectable;
1719use dom:: bindings:: str:: DOMString ;
1820use dom:: bindings:: structuredclone:: StructuredCloneData ;
1921use dom:: messageevent:: MessageEvent ;
20- use dom:: worker:: { SimpleWorkerErrorHandler , SharedRt , TrustedWorkerAddress } ;
21- use dom:: worker:: { WorkerScriptLoadOrigin , WorkerMessageHandler } ;
22+ use dom:: worker:: { TrustedWorkerAddress , WorkerMessageHandler } ;
2223use dom:: workerglobalscope:: WorkerGlobalScope ;
2324use dom:: workerglobalscope:: WorkerGlobalScopeInit ;
2425use ipc_channel:: ipc:: { self , IpcReceiver , IpcSender } ;
@@ -40,70 +41,6 @@ use url::Url;
4041use util:: thread:: spawn_named_with_send_on_panic;
4142use util:: thread_state:: { IN_WORKER , SCRIPT } ;
4243
43- /// Messages used to control the worker event loops
44- pub enum WorkerScriptMsg {
45- /// Common variants associated with the script messages
46- Common ( CommonScriptMsg ) ,
47- /// Message sent through Worker.postMessage
48- DOMMessage ( StructuredCloneData ) ,
49- }
50-
51- /// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with
52- /// common event loop messages. While this SendableWorkerScriptChan is alive, the associated
53- /// Worker object will remain alive.
54- #[ derive( JSTraceable , Clone ) ]
55- pub struct SendableWorkerScriptChan {
56- sender : Sender < ( TrustedWorkerAddress , CommonScriptMsg ) > ,
57- worker : TrustedWorkerAddress ,
58- }
59-
60- impl ScriptChan for SendableWorkerScriptChan {
61- fn send ( & self , msg : CommonScriptMsg ) -> Result < ( ) , ( ) > {
62- self . sender . send ( ( self . worker . clone ( ) , msg) ) . map_err ( |_| ( ) )
63- }
64-
65- fn clone ( & self ) -> Box < ScriptChan + Send > {
66- box SendableWorkerScriptChan {
67- sender : self . sender . clone ( ) ,
68- worker : self . worker . clone ( ) ,
69- }
70- }
71- }
72-
73- /// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with
74- /// worker event loop messages. While this SendableWorkerScriptChan is alive, the associated
75- /// Worker object will remain alive.
76- #[ derive( JSTraceable , Clone ) ]
77- pub struct WorkerThreadWorkerChan {
78- sender : Sender < ( TrustedWorkerAddress , WorkerScriptMsg ) > ,
79- worker : TrustedWorkerAddress ,
80- }
81-
82- impl ScriptChan for WorkerThreadWorkerChan {
83- fn send ( & self , msg : CommonScriptMsg ) -> Result < ( ) , ( ) > {
84- self . sender
85- . send ( ( self . worker . clone ( ) , WorkerScriptMsg :: Common ( msg) ) )
86- . map_err ( |_| ( ) )
87- }
88-
89- fn clone ( & self ) -> Box < ScriptChan + Send > {
90- box WorkerThreadWorkerChan {
91- sender : self . sender . clone ( ) ,
92- worker : self . worker . clone ( ) ,
93- }
94- }
95- }
96-
97- impl ScriptPort for Receiver < ( TrustedWorkerAddress , WorkerScriptMsg ) > {
98- fn recv ( & self ) -> Result < CommonScriptMsg , ( ) > {
99- match self . recv ( ) . map ( |( _, msg) | msg) {
100- Ok ( WorkerScriptMsg :: Common ( script_msg) ) => Ok ( script_msg) ,
101- Ok ( WorkerScriptMsg :: DOMMessage ( _) ) => panic ! ( "unexpected worker event message!" ) ,
102- Err ( _) => Err ( ( ) ) ,
103- }
104- }
105- }
106-
10744/// Set the `worker` field of a related DedicatedWorkerGlobalScope object to a particular
10845/// value for the duration of this object's lifetime. This ensures that the related Worker
10946/// object only lives as long as necessary (ie. while events are being executed), while
0 commit comments