add CanGc as argument to methods in HTMLCollection, HTMLDataListElement, HTMLDialogElement, HTMLElement, HTMLFieldSetElement, HTMLFormControlsCollection, HTMLFormElement, HTMLIFrameElement (#36495)

add CanGc as argument to methods in HTMLCollection, HTMLDataListElement,
HTMLDialogElement, HTMLElement, HTMLFieldSetElement,
HTMLFormControlsCollection, HTMLFormElement, HTMLIFrameElement

Testing: These changes do not require tests because they are a refactor.
Addresses part of https://github.com/servo/servo/issues/34573.

Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
This commit is contained in:
Yerkebulan Tulibergenov 2025-04-13 00:10:00 -07:00 committed by GitHub
parent 06f86f88a2
commit 3babf74986
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 69 additions and 60 deletions

View file

@ -359,7 +359,7 @@ impl HTMLFormElementMethods<crate::DomTypeHolder> for HTMLFormElement {
}
// https://html.spec.whatwg.org/multipage/#dom-form-elements
fn Elements(&self) -> DomRoot<HTMLFormControlsCollection> {
fn Elements(&self, can_gc: CanGc) -> DomRoot<HTMLFormControlsCollection> {
#[derive(JSTraceable, MallocSizeOf)]
struct ElementsFilter {
form: DomRoot<HTMLFormElement>,
@ -422,35 +422,35 @@ impl HTMLFormElementMethods<crate::DomTypeHolder> for HTMLFormElement {
form: DomRoot::from_ref(self),
});
let window = self.owner_window();
HTMLFormControlsCollection::new(&window, self, filter, CanGc::note())
HTMLFormControlsCollection::new(&window, self, filter, can_gc)
}))
}
// https://html.spec.whatwg.org/multipage/#dom-form-length
fn Length(&self) -> u32 {
self.Elements().Length()
self.Elements(CanGc::note()).Length()
}
// https://html.spec.whatwg.org/multipage/#dom-form-item
fn IndexedGetter(&self, index: u32) -> Option<DomRoot<Element>> {
let elements = self.Elements();
fn IndexedGetter(&self, index: u32, can_gc: CanGc) -> Option<DomRoot<Element>> {
let elements = self.Elements(can_gc);
elements.IndexedGetter(index)
}
// https://html.spec.whatwg.org/multipage/#the-form-element%3Adetermine-the-value-of-a-named-property
fn NamedGetter(&self, name: DOMString) -> Option<RadioNodeListOrElement> {
fn NamedGetter(&self, name: DOMString, can_gc: CanGc) -> Option<RadioNodeListOrElement> {
let window = self.owner_window();
let name = Atom::from(name);
// Step 1
let mut candidates =
RadioNodeList::new_controls_except_image_inputs(&window, self, &name, CanGc::note());
RadioNodeList::new_controls_except_image_inputs(&window, self, &name, can_gc);
let mut candidates_length = candidates.Length();
// Step 2
if candidates_length == 0 {
candidates = RadioNodeList::new_images(&window, self, &name, CanGc::note());
candidates = RadioNodeList::new_images(&window, self, &name, can_gc);
candidates_length = candidates.Length();
}
@ -497,7 +497,7 @@ impl HTMLFormElementMethods<crate::DomTypeHolder> for HTMLFormElement {
}
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
fn RelList(&self) -> DomRoot<DOMTokenList> {
fn RelList(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
self.rel_list.or_init(|| {
DOMTokenList::new(
self.upcast(),
@ -507,7 +507,7 @@ impl HTMLFormElementMethods<crate::DomTypeHolder> for HTMLFormElement {
Atom::from("noreferrer"),
Atom::from("opener"),
]),
CanGc::note(),
can_gc,
)
})
}