add CanGc as argument to methods in HTMLInputElement, HTMLLinkElement (#36504)

add CanGc as argument to methods in HTMLInputElement, HTMLLinkElement

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 13:42:52 -07:00 committed by GitHub
parent d5284dfad9
commit 5d84acc06e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 26 deletions

View file

@ -1566,7 +1566,7 @@ impl HTMLInputElementMethods<crate::DomTypeHolder> for HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
// Different from make_labels_getter because this one
// conditionally returns null.
fn GetLabels(&self) -> Option<DomRoot<NodeList>> {
fn GetLabels(&self, can_gc: CanGc) -> Option<DomRoot<NodeList>> {
if self.input_type() == InputType::Hidden {
None
} else {
@ -1574,7 +1574,7 @@ impl HTMLInputElementMethods<crate::DomTypeHolder> for HTMLInputElement {
NodeList::new_labels_list(
self.upcast::<Node>().owner_doc().window(),
self.upcast::<HTMLElement>(),
CanGc::note(),
can_gc,
)
}))
}
@ -2378,7 +2378,7 @@ impl VirtualMethods for HTMLInputElement {
el.set_read_write_state(read_write);
}
el.update_sequentially_focusable_status(CanGc::note());
el.update_sequentially_focusable_status(can_gc);
},
local_name!("checked") if !self.checked_changed.get() => {
let checked_state = match mutation {
@ -2416,7 +2416,7 @@ impl VirtualMethods for HTMLInputElement {
if new_type == InputType::File {
let window = self.owner_window();
let filelist = FileList::new(&window, vec![], CanGc::note());
let filelist = FileList::new(&window, vec![], can_gc);
self.filelist.set(Some(&filelist));
}
@ -2425,7 +2425,7 @@ impl VirtualMethods for HTMLInputElement {
// Step 1
(&ValueMode::Value, false, ValueMode::Default) |
(&ValueMode::Value, false, ValueMode::DefaultOn) => {
self.SetValue(old_idl_value, CanGc::note())
self.SetValue(old_idl_value, can_gc)
.expect("Failed to set input value on type change to a default ValueMode.");
},
@ -2437,7 +2437,7 @@ impl VirtualMethods for HTMLInputElement {
.map_or(DOMString::from(""), |a| {
DOMString::from(a.summarize().value)
}),
CanGc::note(),
can_gc,
)
.expect(
"Failed to set input value on type change to ValueMode::Value.",
@ -2449,7 +2449,7 @@ impl VirtualMethods for HTMLInputElement {
(_, _, ValueMode::Filename)
if old_value_mode != ValueMode::Filename =>
{
self.SetValue(DOMString::from(""), CanGc::note())
self.SetValue(DOMString::from(""), can_gc)
.expect("Failed to set input value on type change to ValueMode::Filename.");
},
_ => {},
@ -2642,11 +2642,8 @@ impl VirtualMethods for HTMLInputElement {
// now.
if let Some(point_in_target) = mouse_event.point_in_target() {
let window = self.owner_window();
let index = window.text_index_query(
self.upcast::<Node>(),
point_in_target,
CanGc::note(),
);
let index =
window.text_index_query(self.upcast::<Node>(), point_in_target, can_gc);
// Position the caret at the click position or at the end of the current
// value.
let edit_point_index = match index {
@ -2672,7 +2669,7 @@ impl VirtualMethods for HTMLInputElement {
let action = self.textinput.borrow_mut().handle_keydown(keyevent);
match action {
TriggerDefaultAction => {
self.implicit_submission(CanGc::note());
self.implicit_submission(can_gc);
},
DispatchInput => {
self.value_dirty.set(true);
@ -2725,7 +2722,7 @@ impl VirtualMethods for HTMLInputElement {
}
} else if let Some(clipboard_event) = event.downcast::<ClipboardEvent>() {
if !event.DefaultPrevented() {
handle_text_clipboard_action(self, &self.textinput, clipboard_event, CanGc::note());
handle_text_clipboard_action(self, &self.textinput, clipboard_event, can_gc);
}
}
@ -2988,7 +2985,7 @@ impl Activatable for HTMLInputElement {
form_owner.submit(
SubmittedFrom::NotFromForm,
FormSubmitterElement::Input(self),
CanGc::note(),
can_gc,
)
}
},

View file

@ -179,7 +179,7 @@ impl HTMLLinkElement {
self.stylesheet.borrow().clone()
}
pub(crate) fn get_cssom_stylesheet(&self) -> Option<DomRoot<CSSStyleSheet>> {
pub(crate) fn get_cssom_stylesheet(&self, can_gc: CanGc) -> Option<DomRoot<CSSStyleSheet>> {
self.get_stylesheet().map(|sheet| {
self.cssom_stylesheet.or_init(|| {
CSSStyleSheet::new(
@ -189,7 +189,7 @@ impl HTMLLinkElement {
None, // todo handle location
None, // todo handle title
sheet,
CanGc::note(),
can_gc,
)
})
})
@ -541,7 +541,7 @@ impl StylesheetOwner for HTMLLinkElement {
}
fn referrer_policy(&self) -> ReferrerPolicy {
if self.RelList().Contains("noreferrer".into()) {
if self.RelList(CanGc::note()).Contains("noreferrer".into()) {
return ReferrerPolicy::NoReferrer;
}
@ -549,7 +549,7 @@ impl StylesheetOwner for HTMLLinkElement {
}
fn set_origin_clean(&self, origin_clean: bool) {
if let Some(stylesheet) = self.get_cssom_stylesheet() {
if let Some(stylesheet) = self.get_cssom_stylesheet(CanGc::note()) {
stylesheet.set_origin_clean(origin_clean);
}
}
@ -602,7 +602,7 @@ impl HTMLLinkElementMethods<crate::DomTypeHolder> for HTMLLinkElement {
make_bool_setter!(SetDisabled, "disabled");
// https://html.spec.whatwg.org/multipage/#dom-link-rellist
fn RelList(&self) -> DomRoot<DOMTokenList> {
fn RelList(&self, can_gc: CanGc) -> DomRoot<DOMTokenList> {
self.rel_list.or_init(|| {
DOMTokenList::new(
self.upcast(),
@ -624,7 +624,7 @@ impl HTMLLinkElementMethods<crate::DomTypeHolder> for HTMLLinkElement {
Atom::from("prerender"),
Atom::from("stylesheet"),
]),
CanGc::note(),
can_gc,
)
})
}
@ -666,8 +666,8 @@ impl HTMLLinkElementMethods<crate::DomTypeHolder> for HTMLLinkElement {
make_setter!(SetReferrerPolicy, "referrerpolicy");
// https://drafts.csswg.org/cssom/#dom-linkstyle-sheet
fn GetSheet(&self) -> Option<DomRoot<DOMStyleSheet>> {
self.get_cssom_stylesheet().map(DomRoot::upcast)
fn GetSheet(&self, can_gc: CanGc) -> Option<DomRoot<DOMStyleSheet>> {
self.get_cssom_stylesheet(can_gc).map(DomRoot::upcast)
}
}

View file

@ -1367,7 +1367,7 @@ impl Node {
if let Some(node) = self.downcast::<HTMLStyleElement>() {
node.get_cssom_stylesheet()
} else if let Some(node) = self.downcast::<HTMLLinkElement>() {
node.get_cssom_stylesheet()
node.get_cssom_stylesheet(CanGc::note())
} else {
None
}

View file

@ -375,11 +375,11 @@ DOMInterfaces = {
},
'HTMLInputElement': {
'canGc': ['ReportValidity', 'SetValue', 'SetValueAsNumber', 'SetValueAsDate', 'StepUp', 'StepDown', 'CheckValidity', 'ReportValidity', 'SelectFiles'],
'canGc': ['ReportValidity', 'SetValue', 'SetValueAsNumber', 'SetValueAsDate', 'StepUp', 'StepDown', 'CheckValidity', 'ReportValidity', 'SelectFiles', 'GetLabels'],
},
'HTMLLinkElement': {
'canGc': ['SetRel', 'SetCrossOrigin'],
'canGc': ['GetSheet', 'SetRel', 'SetCrossOrigin', 'RelList'],
},
'HTMLMediaElement': {