mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Reintroduce parent runtimes for worker threads.
This commit is contained in:
parent
644101e1e4
commit
367014a4ea
7 changed files with 49 additions and 14 deletions
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue