diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/dedicatedworkerglobalscope.rs | 7 | ||||
-rw-r--r-- | components/script/dom/worker.rs | 11 | ||||
-rw-r--r-- | components/script/script_runtime.rs | 4 | ||||
-rw-r--r-- | components/script/script_thread.rs | 7 |
4 files changed, 19 insertions, 10 deletions
diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 8373855ac14..d02c57845ea 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -213,7 +213,8 @@ impl DedicatedWorkerGlobalScope { worker_url: Url, id: PipelineId, from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>, - main_thread_rt: Arc<Mutex<Option<SharedRt>>>, + parent_rt: SharedRt, + worker_rt_for_mainthread: Arc<Mutex<Option<SharedRt>>>, worker: TrustedWorkerAddress, parent_sender: Box<ScriptChan + Send>, own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>, @@ -240,8 +241,8 @@ impl DedicatedWorkerGlobalScope { } }; - let runtime = unsafe { new_rt_and_cx() }; - *main_thread_rt.lock().unwrap() = Some(SharedRt::new(&runtime)); + let runtime = unsafe { new_rt_and_cx(parent_rt.rt()) }; + *worker_rt_for_mainthread.lock().unwrap() = Some(SharedRt::new(&runtime)); let (devtools_mpsc_chan, devtools_mpsc_port) = channel(); ROUTER.route_ipc_receiver_to_mpsc_sender(from_devtools_receiver, devtools_mpsc_chan); diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index e969328a210..0a18125f1bc 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -22,7 +22,7 @@ use dom::messageevent::MessageEvent; use dom::workerglobalscope::WorkerGlobalScopeInit; use ipc_channel::ipc; use js::jsapi::{HandleValue, JSContext, JSRuntime, RootedValue}; -use js::jsapi::{JSAutoCompartment, JS_RequestInterruptCallback}; +use js::jsapi::{JSAutoCompartment, JS_GetRuntime, JS_RequestInterruptCallback}; use js::jsval::UndefinedValue; use js::rust::Runtime; use msg::constellation_msg::{PipelineId, ReferrerPolicy}; @@ -91,6 +91,7 @@ impl Worker { } // https://html.spec.whatwg.org/multipage/#dom-worker + #[allow(unsafe_code)] pub fn Constructor(global: GlobalRef, script_url: DOMString) -> Fallible<Root<Worker>> { // Step 2-4. let worker_url = match global.api_base_url().join(&script_url) { @@ -145,8 +146,10 @@ impl Worker { closing: closing, }; + let shared_rt = SharedRt { rt: unsafe { JS_GetRuntime(global.get_cx()) } }; + DedicatedWorkerGlobalScope::run_worker_scope( - init, worker_url, global.pipeline(), devtools_receiver, worker.runtime.clone(), worker_ref, + init, worker_url, global.pipeline(), devtools_receiver, shared_rt, worker.runtime.clone(), worker_ref, global.script_chan(), sender, receiver, worker_load_origin); Ok(worker) @@ -309,6 +312,10 @@ impl SharedRt { JS_RequestInterruptCallback(self.rt); } } + + pub fn rt(&self) -> *mut JSRuntime { + self.rt + } } #[allow(unsafe_code)] diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 543574ccc62..2b2e2437e16 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -95,9 +95,9 @@ impl<'a> Drop for StackRootTLS<'a> { } #[allow(unsafe_code)] -pub unsafe fn new_rt_and_cx() -> Runtime { +pub unsafe fn new_rt_and_cx(parent_rt: *mut JSRuntime) -> Runtime { LiveDOMReferences::initialize(); - let runtime = Runtime::new(); + let runtime = Runtime::new(parent_rt); JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_rust_roots), ptr::null_mut()); JS_AddExtraGCRootsTracer(runtime.rt(), Some(trace_refcounted_objects), ptr::null_mut()); diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 24172ab900f..8b87dcb2169 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -87,6 +87,7 @@ use std::borrow::ToOwned; use std::cell::{Cell, RefCell}; use std::collections::HashSet; use std::option::Option; +use std::ptr; use std::rc::Rc; use std::result::Result; use std::sync::atomic::{Ordering, AtomicBool}; @@ -443,8 +444,8 @@ impl ScriptThreadFactory for ScriptThread { let mem_profiler_chan = state.mem_profiler_chan.clone(); let window_size = state.window_size; let script_thread = ScriptThread::new(state, - script_port, - script_chan.clone()); + script_port, + script_chan.clone()); SCRIPT_THREAD_ROOT.with(|root| { *root.borrow_mut() = Some(&script_thread as *const _); @@ -519,7 +520,7 @@ impl ScriptThread { port: Receiver<MainThreadScriptMsg>, chan: Sender<MainThreadScriptMsg>) -> ScriptThread { - let runtime = unsafe { new_rt_and_cx() }; + let runtime = unsafe { new_rt_and_cx(ptr::null_mut()) }; unsafe { JS_SetWrapObjectCallbacks(runtime.rt(), |