diff options
-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 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 2 | ||||
-rw-r--r-- | ports/cef/Cargo.lock | 2 | ||||
-rw-r--r-- | ports/gonk/Cargo.lock | 2 |
7 files changed, 22 insertions, 13 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 330eebafdfe..c26ea4461b9 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -88,6 +88,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}; @@ -456,8 +457,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 _); @@ -531,7 +532,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(), diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 8e69e676201..e0066c43971 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1069,7 +1069,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.3" -source = "git+https://github.com/servo/rust-mozjs#3352139c1dedbdff5fe1078152f46522cd04b2f3" +source = "git+https://github.com/servo/rust-mozjs#fae7efd0adf42c0dde517382b83734525e11c6cc" dependencies = [ "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index a21f7c2de47..a1ff6c43c30 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -981,7 +981,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.3" -source = "git+https://github.com/servo/rust-mozjs#3352139c1dedbdff5fe1078152f46522cd04b2f3" +source = "git+https://github.com/servo/rust-mozjs#fae7efd0adf42c0dde517382b83734525e11c6cc" dependencies = [ "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index 008d8c9cb24..c435b675b99 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -969,7 +969,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.3" -source = "git+https://github.com/servo/rust-mozjs#3352139c1dedbdff5fe1078152f46522cd04b2f3" +source = "git+https://github.com/servo/rust-mozjs#fae7efd0adf42c0dde517382b83734525e11c6cc" dependencies = [ "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", |