mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Script: ensure child JS runtimes are dropped before parent (#30896)
* clear js runtime of dedicated worker that immediately exits * dedicated worker: clear js runtime if loading script fails * when the script thread crashes, deallocate worker runtimes before dropping main runtime * clear runtime if service worker script fails to load * ensure worker enter their realm before executing script
This commit is contained in:
parent
2f6f03a3b5
commit
90a9300f69
3 changed files with 13 additions and 4 deletions
|
@ -443,6 +443,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
TaskSourceName::DOMManipulation,
|
TaskSourceName::DOMManipulation,
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
scope.clear_js_runtime(context_for_interrupt);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
Ok((metadata, bytes)) => (metadata, bytes),
|
Ok((metadata, bytes)) => (metadata, bytes),
|
||||||
|
@ -457,11 +458,13 @@ impl DedicatedWorkerGlobalScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
if scope.is_closing() {
|
if scope.is_closing() {
|
||||||
|
scope.clear_js_runtime(context_for_interrupt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let _ar = AutoWorkerReset::new(&global, worker.clone());
|
let _ar = AutoWorkerReset::new(&global, worker.clone());
|
||||||
|
let _ac = enter_realm(&*scope);
|
||||||
scope.execute_script(DOMString::from(source));
|
scope.execute_script(DOMString::from(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -349,6 +349,8 @@ impl ServiceWorkerGlobalScope {
|
||||||
closing,
|
closing,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let scope = global.upcast::<WorkerGlobalScope>();
|
||||||
|
|
||||||
let referrer = referrer_url
|
let referrer = referrer_url
|
||||||
.map(|url| Referrer::ReferrerUrl(url))
|
.map(|url| Referrer::ReferrerUrl(url))
|
||||||
.unwrap_or_else(|| global.upcast::<GlobalScope>().get_referrer());
|
.unwrap_or_else(|| global.upcast::<GlobalScope>().get_referrer());
|
||||||
|
@ -367,6 +369,7 @@ impl ServiceWorkerGlobalScope {
|
||||||
{
|
{
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("error loading script {}", serialized_worker_url);
|
println!("error loading script {}", serialized_worker_url);
|
||||||
|
scope.clear_js_runtime(context_for_interrupt);
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
Ok((metadata, bytes)) => {
|
Ok((metadata, bytes)) => {
|
||||||
|
@ -374,15 +377,16 @@ impl ServiceWorkerGlobalScope {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let scope = global.upcast::<WorkerGlobalScope>();
|
|
||||||
let _ac = enter_realm(&*scope);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// Handle interrupt requests
|
// Handle interrupt requests
|
||||||
JS_AddInterruptCallback(*scope.get_cx(), Some(interrupt_callback));
|
JS_AddInterruptCallback(*scope.get_cx(), Some(interrupt_callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// TODO: use AutoWorkerReset as in dedicated worker?
|
||||||
|
let _ac = enter_realm(&*scope);
|
||||||
scope.execute_script(DOMString::from(source));
|
scope.execute_script(DOMString::from(source));
|
||||||
|
}
|
||||||
|
|
||||||
global.dispatch_activate();
|
global.dispatch_activate();
|
||||||
let reporter_name = format!("service-worker-reporter-{}", random::<u64>());
|
let reporter_name = format!("service-worker-reporter-{}", random::<u64>());
|
||||||
|
|
|
@ -393,6 +393,8 @@ impl Window {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn clear_js_runtime_for_script_deallocation(&self) {
|
pub fn clear_js_runtime_for_script_deallocation(&self) {
|
||||||
|
self.upcast::<GlobalScope>()
|
||||||
|
.remove_web_messaging_and_dedicated_workers_infra();
|
||||||
unsafe {
|
unsafe {
|
||||||
*self.js_runtime.borrow_for_script_deallocation() = None;
|
*self.js_runtime.borrow_for_script_deallocation() = None;
|
||||||
self.window_proxy.set(None);
|
self.window_proxy.set(None);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue