aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2018-12-02 14:58:15 -0500
committerJosh Matthews <josh@joshmatthews.net>2019-01-15 14:00:13 -0500
commit367014a4ea5b3fff5e4f33df199db0fdb7a95925 (patch)
treeda0e8b17e5064337c11877b1ef724e92a14f690a
parent644101e1e42a98996ff98c4cb8fb3cb6dd18be94 (diff)
downloadservo-367014a4ea5b3fff5e4f33df199db0fdb7a95925.tar.gz
servo-367014a4ea5b3fff5e4f33df199db0fdb7a95925.zip
Reintroduce parent runtimes for worker threads.
-rw-r--r--components/script/dom/dedicatedworkerglobalscope.rs12
-rw-r--r--components/script/dom/globalscope.rs12
-rw-r--r--components/script/dom/serviceworkerglobalscope.rs2
-rw-r--r--components/script/dom/workerglobalscope.rs6
-rw-r--r--components/script/dom/worklet.rs2
-rw-r--r--components/script/script_runtime.rs19
-rw-r--r--components/script/script_thread.rs10
7 files changed, 49 insertions, 14 deletions
diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs
index 92e26bad353..00fcd388bf3 100644
--- a/components/script/dom/dedicatedworkerglobalscope.rs
+++ b/components/script/dom/dedicatedworkerglobalscope.rs
@@ -23,7 +23,7 @@ use crate::dom::messageevent::MessageEvent;
use crate::dom::worker::{TrustedWorkerAddress, Worker};
use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::script_runtime::ScriptThreadEventCategory::WorkerEvent;
-use crate::script_runtime::{new_rt_and_cx, CommonScriptMsg, Runtime, ScriptChan, ScriptPort};
+use crate::script_runtime::{new_child_runtime, CommonScriptMsg, Runtime, ScriptChan, ScriptPort};
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
use crate::task_source::TaskSourceName;
use crossbeam_channel::{unbounded, Receiver, Sender};
@@ -272,11 +272,9 @@ impl DedicatedWorkerGlobalScope {
let serialized_worker_url = worker_url.to_string();
let name = format!("WebWorker for {}", serialized_worker_url);
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed();
- let origin = GlobalScope::current()
- .expect("No current global object")
- .origin()
- .immutable()
- .clone();
+ let current_global = GlobalScope::current().expect("No current global object");
+ let origin = current_global.origin().immutable().clone();
+ let parent = current_global.runtime_handle();
thread::Builder::new()
.name(name)
@@ -327,7 +325,7 @@ impl DedicatedWorkerGlobalScope {
let url = metadata.final_url;
let source = String::from_utf8_lossy(&bytes);
- let runtime = unsafe { new_rt_and_cx() };
+ let runtime = unsafe { new_child_runtime(parent) };
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();
ROUTER.route_ipc_receiver_to_crossbeam_sender(
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index 4aa3a29cea6..91112299034 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -47,7 +47,7 @@ use js::jsapi::{HandleObject, Heap};
use js::jsapi::{JSAutoCompartment, JSContext};
use js::panic::maybe_resume_unwind;
use js::rust::wrappers::Evaluate2;
-use js::rust::{get_object_class, CompileOptionsWrapper, Runtime};
+use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
use js::rust::{HandleValue, MutableHandleValue};
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
use msg::constellation_msg::PipelineId;
@@ -711,6 +711,16 @@ impl GlobalScope {
unreachable!();
}
+ pub fn runtime_handle(&self) -> ParentRuntime {
+ if self.is::<Window>() {
+ ScriptThread::runtime_handle()
+ } else if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
+ worker.runtime_handle()
+ } else {
+ unreachable!()
+ }
+ }
+
/// Returns the ["current"] global object.
///
/// ["current"]: https://html.spec.whatwg.org/multipage/#current
diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs
index 23fd1895ea4..116ffffdac5 100644
--- a/components/script/dom/serviceworkerglobalscope.rs
+++ b/components/script/dom/serviceworkerglobalscope.rs
@@ -292,7 +292,7 @@ impl ServiceWorkerGlobalScope {
},
};
- let runtime = unsafe { new_rt_and_cx() };
+ let runtime = new_rt_and_cx();
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();
ROUTER
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index 99cee52eaa1..75987e2aa17 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -39,7 +39,7 @@ use ipc_channel::ipc::IpcSender;
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind;
-use js::rust::HandleValue;
+use js::rust::{HandleValue, ParentRuntime};
use msg::constellation_msg::PipelineId;
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit};
use net_traits::{load_whole_resource, IpcSend};
@@ -135,6 +135,10 @@ impl WorkerGlobalScope {
}
}
+ pub fn runtime_handle(&self) -> ParentRuntime {
+ self.runtime.prepare_for_new_child()
+ }
+
pub fn from_devtools_sender(&self) -> Option<IpcSender<DevtoolScriptControlMsg>> {
self.from_devtools_sender.clone()
}
diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs
index ac17d99d3aa..16d7ccb5f6b 100644
--- a/components/script/dom/worklet.rs
+++ b/components/script/dom/worklet.rs
@@ -470,7 +470,7 @@ impl WorkletThread {
global_init: init.global_init,
global_scopes: HashMap::new(),
control_buffer: None,
- runtime: unsafe { new_rt_and_cx() },
+ runtime: new_rt_and_cx(),
should_gc: false,
gc_threshold: MIN_GC_THRESHOLD,
});
diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs
index 29be8114e35..2ee27ab38bb 100644
--- a/components/script/script_runtime.rs
+++ b/components/script/script_runtime.rs
@@ -43,6 +43,7 @@ use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult};
use js::rust::Handle;
use js::rust::IntoHandle;
use js::rust::JSEngine;
+use js::rust::ParentRuntime;
use js::rust::Runtime as RustRuntime;
use malloc_size_of::MallocSizeOfOps;
use msg::constellation_msg::PipelineId;
@@ -329,9 +330,23 @@ lazy_static! {
}
#[allow(unsafe_code)]
-pub unsafe fn new_rt_and_cx() -> Runtime {
+pub unsafe fn new_child_runtime(parent: ParentRuntime) -> Runtime {
+ new_rt_and_cx_with_parent(Some(parent))
+}
+
+#[allow(unsafe_code)]
+pub fn new_rt_and_cx() -> Runtime {
+ unsafe { new_rt_and_cx_with_parent(None) }
+}
+
+#[allow(unsafe_code)]
+unsafe fn new_rt_and_cx_with_parent(parent: Option<ParentRuntime>) -> Runtime {
LiveDOMReferences::initialize();
- let runtime = RustRuntime::new(JS_ENGINE.clone());
+ let runtime = if let Some(parent) = parent {
+ RustRuntime::create_with_parent(parent)
+ } else {
+ RustRuntime::new(JS_ENGINE.clone())
+ };
let cx = runtime.cx();
JS_AddExtraGCRootsTracer(cx, Some(trace_rust_roots), ptr::null_mut());
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs
index 9247ca6afba..2053b10fa88 100644
--- a/components/script/script_thread.rs
+++ b/components/script/script_thread.rs
@@ -100,6 +100,7 @@ use js::glue::GetWindowProxyClass;
use js::jsapi::{JSAutoCompartment, JSContext, JS_SetWrapObjectCallbacks};
use js::jsapi::{JSTracer, SetWindowProxyClass};
use js::jsval::UndefinedValue;
+use js::rust::ParentRuntime;
use metrics::{PaintTimeMetrics, MAX_TASK_NS};
use mime::{self, Mime};
use msg::constellation_msg::{
@@ -725,6 +726,13 @@ impl ScriptThreadFactory for ScriptThread {
}
impl ScriptThread {
+ pub fn runtime_handle() -> ParentRuntime {
+ SCRIPT_THREAD_ROOT.with(|root| {
+ let script_thread = unsafe { &*root.get().unwrap() };
+ script_thread.js_runtime.prepare_for_new_child()
+ })
+ }
+
pub unsafe fn note_newly_transitioning_nodes(nodes: Vec<UntrustedNodeAddress>) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = &*root.get().unwrap();
@@ -1009,7 +1017,7 @@ impl ScriptThread {
port: Receiver<MainThreadScriptMsg>,
chan: Sender<MainThreadScriptMsg>,
) -> ScriptThread {
- let runtime = unsafe { new_rt_and_cx() };
+ let runtime = new_rt_and_cx();
let cx = runtime.cx();
unsafe {