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.
This commit is contained in:
Till Schneidereit 2016-05-24 15:28:25 +02:00
parent 2ce9eba3dc
commit 7536afff2a
7 changed files with 22 additions and 13 deletions

View file

@ -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)]