GC hazard fix in customelementregistry.rs (#34019)

* GC hazard fix in customelement.registry.rs

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

* removed redundant borrow

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

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-26 21:48:00 +05:30 committed by GitHub
parent 82c9d41330
commit 53911f4e5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -598,13 +598,11 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
}
}
// Step 3
let mut map = self.when_defined.borrow_mut();
// Steps 4, 5
let promise = map.get(&name).cloned().unwrap_or_else(|| {
// Steps 3, 4, 5
let existing_promise = self.when_defined.borrow().get(&name).cloned();
let promise = existing_promise.unwrap_or_else(|| {
let promise = Promise::new_in_current_realm(comp, can_gc);
map.insert(name, promise.clone());
self.when_defined.borrow_mut().insert(name, promise.clone());
promise
});