mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
use ThreadSafeJSContext
instead of ContextForRequestInterrupt
(#33769)
* use `ThreadSafeJSContext` instead of `ContextForRequestInterrupt` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * use servo/mozjs Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
61a930402d
commit
7cd73ef4a7
10 changed files with 53 additions and 89 deletions
|
@ -64,7 +64,7 @@ use crate::dom::bindings::str::{DOMString, USVString};
|
|||
use crate::dom::htmlimageelement::SourceSet;
|
||||
use crate::dom::htmlmediaelement::HTMLMediaElementFetchContext;
|
||||
use crate::dom::windowproxy::WindowProxyHandler;
|
||||
use crate::script_runtime::{ContextForRequestInterrupt, StreamConsumer};
|
||||
use crate::script_runtime::StreamConsumer;
|
||||
use crate::script_thread::IncompleteParserContexts;
|
||||
use crate::task::TaskBox;
|
||||
|
||||
|
@ -359,7 +359,6 @@ where
|
|||
unsafe_no_jsmanaged_fields!(Error);
|
||||
unsafe_no_jsmanaged_fields!(TrustedPromise);
|
||||
|
||||
unsafe_no_jsmanaged_fields!(ContextForRequestInterrupt);
|
||||
unsafe_no_jsmanaged_fields!(WindowProxyHandler);
|
||||
unsafe_no_jsmanaged_fields!(DOMString);
|
||||
unsafe_no_jsmanaged_fields!(USVString);
|
||||
|
|
|
@ -55,8 +55,8 @@ use crate::fetch::load_whole_resource;
|
|||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::ScriptThreadEventCategory::WorkerEvent;
|
||||
use crate::script_runtime::{
|
||||
new_child_runtime, CanGc, CommonScriptMsg, ContextForRequestInterrupt,
|
||||
JSContext as SafeJSContext, Runtime, ScriptChan, ScriptPort,
|
||||
new_child_runtime, CanGc, CommonScriptMsg, JSContext as SafeJSContext, Runtime, ScriptChan,
|
||||
ScriptPort, ThreadSafeJSContext,
|
||||
};
|
||||
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||
use crate::task_source::networking::NetworkingTaskSource;
|
||||
|
@ -332,7 +332,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
browsing_context: Option<BrowsingContextId>,
|
||||
gpu_id_hub: Arc<IdentityHub>,
|
||||
control_receiver: Receiver<DedicatedWorkerControlMsg>,
|
||||
context_sender: Sender<ContextForRequestInterrupt>,
|
||||
context_sender: Sender<ThreadSafeJSContext>,
|
||||
can_gc: CanGc,
|
||||
) -> JoinHandle<()> {
|
||||
let serialized_worker_url = worker_url.to_string();
|
||||
|
@ -384,8 +384,8 @@ impl DedicatedWorkerGlobalScope {
|
|||
new_child_runtime(parent, Some(task_source))
|
||||
};
|
||||
|
||||
let context_for_interrupt = ContextForRequestInterrupt::new(runtime.cx());
|
||||
let _ = context_sender.send(context_for_interrupt.clone());
|
||||
let context_for_interrupt = runtime.thread_safe_js_context();
|
||||
let _ = context_sender.send(context_for_interrupt);
|
||||
|
||||
let (devtools_mpsc_chan, devtools_mpsc_port) = unbounded();
|
||||
ROUTER.route_ipc_receiver_to_crossbeam_sender(
|
||||
|
@ -442,7 +442,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
TaskSourceName::DOMManipulation,
|
||||
))
|
||||
.unwrap();
|
||||
scope.clear_js_runtime(context_for_interrupt);
|
||||
scope.clear_js_runtime();
|
||||
return;
|
||||
},
|
||||
Ok((metadata, bytes)) => (metadata, bytes),
|
||||
|
@ -457,7 +457,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
}
|
||||
|
||||
if scope.is_closing() {
|
||||
scope.clear_js_runtime(context_for_interrupt);
|
||||
scope.clear_js_runtime();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -487,7 +487,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
CommonScriptMsg::CollectReports,
|
||||
);
|
||||
|
||||
scope.clear_js_runtime(context_for_interrupt);
|
||||
scope.clear_js_runtime();
|
||||
})
|
||||
.expect("Thread spawning failed")
|
||||
}
|
||||
|
|
|
@ -120,8 +120,7 @@ use crate::microtask::{Microtask, MicrotaskQueue, UserMicrotask};
|
|||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_module::{DynamicModuleList, ModuleScript, ModuleTree, ScriptFetchOptions};
|
||||
use crate::script_runtime::{
|
||||
CanGc, CommonScriptMsg, ContextForRequestInterrupt, JSContext as SafeJSContext, ScriptChan,
|
||||
ScriptPort,
|
||||
CanGc, CommonScriptMsg, JSContext as SafeJSContext, ScriptChan, ScriptPort, ThreadSafeJSContext,
|
||||
};
|
||||
use crate::script_thread::{MainThreadScriptChan, ScriptThread};
|
||||
use crate::security_manager::CSPViolationReporter;
|
||||
|
@ -151,7 +150,8 @@ pub struct AutoCloseWorker {
|
|||
#[no_trace]
|
||||
control_sender: Sender<DedicatedWorkerControlMsg>,
|
||||
/// The context to request an interrupt on the worker thread.
|
||||
context: ContextForRequestInterrupt,
|
||||
#[no_trace]
|
||||
context: ThreadSafeJSContext,
|
||||
}
|
||||
|
||||
impl Drop for AutoCloseWorker {
|
||||
|
@ -168,7 +168,7 @@ impl Drop for AutoCloseWorker {
|
|||
warn!("Couldn't send an exit message to a dedicated worker.");
|
||||
}
|
||||
|
||||
self.context.request_interrupt();
|
||||
self.context.request_interrupt_callback();
|
||||
|
||||
// TODO: step 2 and 3.
|
||||
// Step 4 is unnecessary since we don't use actual ports for dedicated workers.
|
||||
|
@ -2115,7 +2115,7 @@ impl GlobalScope {
|
|||
closing: Arc<AtomicBool>,
|
||||
join_handle: JoinHandle<()>,
|
||||
control_sender: Sender<DedicatedWorkerControlMsg>,
|
||||
context: ContextForRequestInterrupt,
|
||||
context: ThreadSafeJSContext,
|
||||
) {
|
||||
self.list_auto_close_worker
|
||||
.borrow_mut()
|
||||
|
|
|
@ -45,8 +45,8 @@ use crate::dom::workerglobalscope::WorkerGlobalScope;
|
|||
use crate::fetch::load_whole_resource;
|
||||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::{
|
||||
new_rt_and_cx, CanGc, CommonScriptMsg, ContextForRequestInterrupt, JSContext as SafeJSContext,
|
||||
Runtime, ScriptChan,
|
||||
new_rt_and_cx, CanGc, CommonScriptMsg, JSContext as SafeJSContext, Runtime, ScriptChan,
|
||||
ThreadSafeJSContext,
|
||||
};
|
||||
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||
use crate::task_source::TaskSourceName;
|
||||
|
@ -293,7 +293,7 @@ impl ServiceWorkerGlobalScope {
|
|||
swmanager_sender: IpcSender<ServiceWorkerMsg>,
|
||||
scope_url: ServoUrl,
|
||||
control_receiver: Receiver<ServiceWorkerControlMsg>,
|
||||
context_sender: Sender<ContextForRequestInterrupt>,
|
||||
context_sender: Sender<ThreadSafeJSContext>,
|
||||
closing: Arc<AtomicBool>,
|
||||
can_gc: CanGc,
|
||||
) -> JoinHandle<()> {
|
||||
|
@ -311,8 +311,8 @@ impl ServiceWorkerGlobalScope {
|
|||
.spawn(move || {
|
||||
thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER);
|
||||
let runtime = new_rt_and_cx(None);
|
||||
let context_for_interrupt = ContextForRequestInterrupt::new(runtime.cx());
|
||||
let _ = context_sender.send(context_for_interrupt.clone());
|
||||
let context_for_interrupt = runtime.thread_safe_js_context();
|
||||
let _ = context_sender.send(context_for_interrupt);
|
||||
|
||||
let roots = RootCollection::new();
|
||||
let _stack_roots = ThreadLocalStackRoots::new(&roots);
|
||||
|
@ -366,7 +366,7 @@ impl ServiceWorkerGlobalScope {
|
|||
match load_whole_resource(request, &resource_threads_sender, global.upcast()) {
|
||||
Err(_) => {
|
||||
println!("error loading script {}", serialized_worker_url);
|
||||
scope.clear_js_runtime(context_for_interrupt);
|
||||
scope.clear_js_runtime();
|
||||
return;
|
||||
},
|
||||
Ok((metadata, bytes)) => {
|
||||
|
@ -407,7 +407,7 @@ impl ServiceWorkerGlobalScope {
|
|||
CommonScriptMsg::CollectReports,
|
||||
);
|
||||
|
||||
scope.clear_js_runtime(context_for_interrupt);
|
||||
scope.clear_js_runtime();
|
||||
})
|
||||
.expect("Thread spawning failed")
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ use crate::dom::messageevent::MessageEvent;
|
|||
use crate::dom::window::Window;
|
||||
use crate::dom::workerglobalscope::prepare_workerscope_init;
|
||||
use crate::realms::enter_realm;
|
||||
use crate::script_runtime::{CanGc, ContextForRequestInterrupt, JSContext};
|
||||
use crate::script_runtime::{CanGc, JSContext, ThreadSafeJSContext};
|
||||
use crate::task::TaskOnce;
|
||||
|
||||
pub type TrustedWorkerAddress = Trusted<Worker>;
|
||||
|
@ -55,7 +55,8 @@ pub struct Worker {
|
|||
closing: Arc<AtomicBool>,
|
||||
terminated: Cell<bool>,
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
context_for_interrupt: DomRefCell<Option<ContextForRequestInterrupt>>,
|
||||
#[no_trace]
|
||||
context_for_interrupt: DomRefCell<Option<ThreadSafeJSContext>>,
|
||||
}
|
||||
|
||||
impl Worker {
|
||||
|
@ -88,7 +89,7 @@ impl Worker {
|
|||
self.terminated.get()
|
||||
}
|
||||
|
||||
pub fn set_context_for_interrupt(&self, cx: ContextForRequestInterrupt) {
|
||||
pub fn set_context_for_interrupt(&self, cx: ThreadSafeJSContext) {
|
||||
assert!(
|
||||
self.context_for_interrupt.borrow().is_none(),
|
||||
"Context for interrupt must be set only once"
|
||||
|
@ -272,7 +273,7 @@ impl WorkerMethods for Worker {
|
|||
|
||||
// Step 3
|
||||
if let Some(cx) = self.context_for_interrupt.borrow().as_ref() {
|
||||
cx.request_interrupt()
|
||||
cx.request_interrupt_callback()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,7 @@ use crate::dom::workernavigator::WorkerNavigator;
|
|||
use crate::fetch;
|
||||
use crate::realms::{enter_realm, InRealm};
|
||||
use crate::script_runtime::{
|
||||
get_reports, CommonScriptMsg, ContextForRequestInterrupt, JSContext, Runtime, ScriptChan,
|
||||
ScriptPort,
|
||||
get_reports, CommonScriptMsg, JSContext, Runtime, ScriptChan, ScriptPort,
|
||||
};
|
||||
use crate::task::TaskCanceller;
|
||||
use crate::task_source::dom_manipulation::DOMManipulationTaskSource;
|
||||
|
@ -177,10 +176,7 @@ impl WorkerGlobalScope {
|
|||
}
|
||||
|
||||
/// Clear various items when the worker event-loop shuts-down.
|
||||
pub fn clear_js_runtime(&self, cx_for_interrupt: ContextForRequestInterrupt) {
|
||||
// Ensure parent thread can no longer request interrupt
|
||||
// using our JSContext that will soon be destroyed
|
||||
cx_for_interrupt.revoke();
|
||||
pub fn clear_js_runtime(&self) {
|
||||
self.upcast::<GlobalScope>()
|
||||
.remove_web_messaging_and_dedicated_workers_infra();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue