aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/worker.rs
diff options
context:
space:
mode:
authorTill Schneidereit <till@tillschneidereit.net>2016-05-24 15:28:25 +0200
committerTill Schneidereit <till@tillschneidereit.net>2016-05-24 17:43:49 +0200
commit7536afff2a8cd77fd5d0ae6b3324a430eae8ae67 (patch)
tree793132136678cdcd3403317d19e9ed71a5886969 /components/script/dom/worker.rs
parent2ce9eba3dc87348c5de235883295f0f6ead4317e (diff)
downloadservo-7536afff2a8cd77fd5d0ae6b3324a430eae8ae67.tar.gz
servo-7536afff2a8cd77fd5d0ae6b3324a430eae8ae67.zip
Pass a parent JS runtime when creating DOM Worker runtimes
This enables sharing data with the parent runtime, decreasing memory usage and startup time. Also contains an update to current rust-mozjs, because that's required for this to work.
Diffstat (limited to 'components/script/dom/worker.rs')
-rw-r--r--components/script/dom/worker.rs11
1 files changed, 9 insertions, 2 deletions
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)]