Resolved potential GC borrow hazards in ModuleTree::append_handler, ModuleTree::append_dynamic_module_handler, and ModuleTree::fetch_module_descendants' (#33942)

* GC borrow hazard ModuleTree fix

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* Prevent `stretch` from producing a negative size (#33951)

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* reverted debug_assert back to assert

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* added can_gc arguments to the function calls

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
chickenleaf 2024-10-23 17:21:49 +05:30 committed by GitHub
parent 324f42abd7
commit 076b37e6aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -363,15 +363,14 @@ impl ModuleTree {
let comp = InRealm::Entered(&realm);
let _ais = AutoIncumbentScript::new(&owner.global());
let mut promise = self.promise.borrow_mut();
match promise.as_ref() {
Some(promise) => promise.append_native_handler(&handler, comp, can_gc),
None => {
let new_promise = Promise::new_in_current_realm(comp, can_gc);
new_promise.append_native_handler(&handler, comp, can_gc);
*promise = Some(new_promise);
},
if let Some(promise) = self.promise.borrow().as_ref() {
promise.append_native_handler(&handler, comp, can_gc);
return;
}
let new_promise = Promise::new_in_current_realm(comp, can_gc);
new_promise.append_native_handler(&handler, comp, can_gc);
*self.promise.borrow_mut() = Some(new_promise);
}
fn append_dynamic_module_handler(
@ -400,15 +399,14 @@ impl ModuleTree {
let comp = InRealm::Entered(&realm);
let _ais = AutoIncumbentScript::new(&owner.global());
let mut promise = self.promise.borrow_mut();
match promise.as_ref() {
Some(promise) => promise.append_native_handler(&handler, comp, can_gc),
None => {
let new_promise = Promise::new_in_current_realm(comp, can_gc);
new_promise.append_native_handler(&handler, comp, can_gc);
*promise = Some(new_promise);
},
if let Some(promise) = self.promise.borrow().as_ref() {
promise.append_native_handler(&handler, comp, can_gc);
return;
}
let new_promise = Promise::new_in_current_realm(comp, can_gc);
new_promise.append_native_handler(&handler, comp, can_gc);
*self.promise.borrow_mut() = Some(new_promise);
}
}
@ -745,23 +743,26 @@ impl ModuleTree {
.borrow_mut()
.extend(valid_specifier_urls.clone());
let mut urls = IndexSet::new();
let mut visited_urls = self.visited_urls.borrow_mut();
let urls_to_fetch = {
let mut urls = IndexSet::new();
let mut visited_urls = self.visited_urls.borrow_mut();
for parsed_url in valid_specifier_urls {
// Step 5-3.
if !visited_urls.contains(&parsed_url) {
// Step 5-3-1.
urls.insert(parsed_url.clone());
// Step 5-3-2.
visited_urls.insert(parsed_url.clone());
for parsed_url in &valid_specifier_urls {
// Step 5-3.
if !visited_urls.contains(parsed_url) {
// Step 5-3-1.
urls.insert(parsed_url.clone());
// Step 5-3-2.
visited_urls.insert(parsed_url.clone());
self.insert_incomplete_fetch_url(&parsed_url);
self.insert_incomplete_fetch_url(parsed_url);
}
}
}
urls
};
// Step 3.
if urls.is_empty() {
if urls_to_fetch.is_empty() {
debug!(
"After checking with visited urls, module {} doesn't have dependencies to load.",
&self.url
@ -772,12 +773,13 @@ impl ModuleTree {
// Step 8.
for url in urls {
let visited_urls = self.visited_urls.borrow().clone();
let options = options.descendant_fetch_options();
for url in urls_to_fetch {
// https://html.spec.whatwg.org/multipage/#internal-module-script-graph-fetching-procedure
// Step 1.
assert!(visited_urls.get(&url).is_some());
let options = options.descendant_fetch_options();
assert!(self.visited_urls.borrow().contains(&url));
// Step 2.
fetch_single_module_script(
@ -785,7 +787,7 @@ impl ModuleTree {
url,
visited_urls.clone(),
destination,
options,
options.clone(),
Some(parent_identity.clone()),
false,
None,