CanGc fixes in components/script/dom (#33880)

Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
tanishka 2024-10-17 18:19:00 +05:30 committed by GitHub
parent 72ff89620b
commit cd7b66be58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 59 additions and 33 deletions

View file

@ -878,7 +878,7 @@ fn run_form_data_algorithm(
// ... is not fully determined yet. // ... is not fully determined yet.
if mime.type_() == mime::APPLICATION && mime.subtype() == mime::WWW_FORM_URLENCODED { if mime.type_() == mime::APPLICATION && mime.subtype() == mime::WWW_FORM_URLENCODED {
let entries = form_urlencoded::parse(&bytes); let entries = form_urlencoded::parse(&bytes);
let formdata = FormData::new(None, root); let formdata = FormData::new(None, root, CanGc::note());
for (k, e) in entries { for (k, e) in entries {
formdata.Append(USVString(k.into_owned()), USVString(e.into_owned())); formdata.Append(USVString(k.into_owned()), USVString(e.into_owned()));
} }

View file

@ -132,6 +132,10 @@ DOMInterfaces = {
'inRealms': ['PlayEffect', 'Reset'] 'inRealms': ['PlayEffect', 'Reset']
}, },
'HTMLFormElement': {
'canGc': ['RequestSubmit'],
},
'HTMLMediaElement': { 'HTMLMediaElement': {
'canGc': ['Load', 'Pause', 'Play', 'SetSrcObject'], 'canGc': ['Load', 'Pause', 'Play', 'SetSrcObject'],
'inRealms': ['Play'], 'inRealms': ['Play'],

View file

@ -40,8 +40,9 @@ impl ExtendableEvent {
type_: Atom, type_: Atom,
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
can_gc: CanGc,
) -> DomRoot<ExtendableEvent> { ) -> DomRoot<ExtendableEvent> {
Self::new_with_proto(worker, None, type_, bubbles, cancelable, CanGc::note()) Self::new_with_proto(worker, None, type_, bubbles, cancelable, can_gc)
} }
fn new_with_proto( fn new_with_proto(

View file

@ -45,8 +45,12 @@ impl FormData {
} }
} }
pub fn new(form_datums: Option<Vec<FormDatum>>, global: &GlobalScope) -> DomRoot<FormData> { pub fn new(
Self::new_with_proto(form_datums, global, None, CanGc::note()) form_datums: Option<Vec<FormDatum>>,
global: &GlobalScope,
can_gc: CanGc,
) -> DomRoot<FormData> {
Self::new_with_proto(form_datums, global, None, can_gc)
} }
fn new_with_proto( fn new_with_proto(
@ -73,7 +77,7 @@ impl FormDataMethods for FormData {
form: Option<&HTMLFormElement>, form: Option<&HTMLFormElement>,
) -> Fallible<DomRoot<FormData>> { ) -> Fallible<DomRoot<FormData>> {
if let Some(opt_form) = form { if let Some(opt_form) = form {
return match opt_form.get_form_dataset(None, None) { return match opt_form.get_form_dataset(None, None, can_gc) {
Some(form_datums) => Ok(FormData::new_with_proto( Some(form_datums) => Ok(FormData::new_with_proto(
Some(form_datums), Some(form_datums),
global, global,

View file

@ -31,6 +31,7 @@ use crate::dom::nodelist::NodeList;
use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable}; use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable};
use crate::dom::validitystate::{ValidationFlags, ValidityState}; use crate::dom::validitystate::{ValidationFlags, ValidityState};
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use crate::script_runtime::CanGc;
#[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)]
enum ButtonType { enum ButtonType {
@ -352,6 +353,7 @@ impl Activatable for HTMLButtonElement {
owner.submit( owner.submit(
SubmittedFrom::NotFromForm, SubmittedFrom::NotFromForm,
FormSubmitterElement::Button(self), FormSubmitterElement::Button(self),
CanGc::note(),
); );
} }
}, },

View file

@ -82,6 +82,7 @@ use crate::dom::submitevent::SubmitEvent;
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::links::{get_element_target, LinkRelations}; use crate::links::{get_element_target, LinkRelations};
use crate::script_runtime::CanGc;
use crate::script_thread::ScriptThread; use crate::script_thread::ScriptThread;
use crate::task_source::TaskSource; use crate::task_source::TaskSource;
@ -269,11 +270,15 @@ impl HTMLFormElementMethods for HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#the-form-element:concept-form-submit // https://html.spec.whatwg.org/multipage/#the-form-element:concept-form-submit
fn Submit(&self) { fn Submit(&self) {
self.submit(SubmittedFrom::FromForm, FormSubmitterElement::Form(self)); self.submit(
SubmittedFrom::FromForm,
FormSubmitterElement::Form(self),
CanGc::note(),
);
} }
// https://html.spec.whatwg.org/multipage/#dom-form-requestsubmit // https://html.spec.whatwg.org/multipage/#dom-form-requestsubmit
fn RequestSubmit(&self, submitter: Option<&HTMLElement>) -> Fallible<()> { fn RequestSubmit(&self, submitter: Option<&HTMLElement>, can_gc: CanGc) -> Fallible<()> {
let submitter: FormSubmitterElement = match submitter { let submitter: FormSubmitterElement = match submitter {
Some(submitter_element) => { Some(submitter_element) => {
// Step 1.1 // Step 1.1
@ -329,7 +334,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
}, },
}; };
// Step 3 // Step 3
self.submit(SubmittedFrom::NotFromForm, submitter); self.submit(SubmittedFrom::NotFromForm, submitter, can_gc);
Ok(()) Ok(())
} }
@ -700,7 +705,12 @@ impl HTMLFormElement {
} }
/// [Form submission](https://html.spec.whatwg.org/multipage/#concept-form-submit) /// [Form submission](https://html.spec.whatwg.org/multipage/#concept-form-submit)
pub fn submit(&self, submit_method_flag: SubmittedFrom, submitter: FormSubmitterElement) { pub fn submit(
&self,
submit_method_flag: SubmittedFrom,
submitter: FormSubmitterElement,
can_gc: CanGc,
) {
// Step 1 // Step 1
if self.upcast::<Element>().cannot_navigate() { if self.upcast::<Element>().cannot_navigate() {
return; return;
@ -769,7 +779,7 @@ impl HTMLFormElement {
let encoding = self.pick_encoding(); let encoding = self.pick_encoding();
// Step 8 // Step 8
let mut form_data = match self.get_form_dataset(Some(submitter), Some(encoding)) { let mut form_data = match self.get_form_dataset(Some(submitter), Some(encoding), can_gc) {
Some(form_data) => form_data, Some(form_data) => form_data,
None => return, None => return,
}; };
@ -1179,6 +1189,7 @@ impl HTMLFormElement {
&self, &self,
submitter: Option<FormSubmitterElement>, submitter: Option<FormSubmitterElement>,
encoding: Option<&'static Encoding>, encoding: Option<&'static Encoding>,
can_gc: CanGc,
) -> Option<Vec<FormDatum>> { ) -> Option<Vec<FormDatum>> {
// Step 1 // Step 1
if self.constructing_entry_list.get() { if self.constructing_entry_list.get() {
@ -1194,7 +1205,7 @@ impl HTMLFormElement {
let window = window_from_node(self); let window = window_from_node(self);
// Step 6 // Step 6
let form_data = FormData::new(Some(ret), &window.global()); let form_data = FormData::new(Some(ret), &window.global(), can_gc);
// Step 7 // Step 7
let event = FormDataEvent::new( let event = FormDataEvent::new(

View file

@ -75,7 +75,7 @@ use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable};
use crate::dom::validitystate::{ValidationFlags, ValidityState}; use crate::dom::validitystate::{ValidationFlags, ValidityState};
use crate::dom::virtualmethods::VirtualMethods; use crate::dom::virtualmethods::VirtualMethods;
use crate::realms::enter_realm; use crate::realms::enter_realm;
use crate::script_runtime::JSContext as SafeJSContext; use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
use crate::textinput::KeyReaction::{ use crate::textinput::KeyReaction::{
DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction, DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction,
}; };
@ -2048,7 +2048,7 @@ impl HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#implicit-submission // https://html.spec.whatwg.org/multipage/#implicit-submission
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn implicit_submission(&self) { fn implicit_submission(&self, can_gc: CanGc) {
let doc = document_from_node(self); let doc = document_from_node(self);
let node = doc.upcast::<Node>(); let node = doc.upcast::<Node>();
let owner = self.form_owner(); let owner = self.form_owner();
@ -2103,7 +2103,11 @@ impl HTMLInputElement {
// lazily test for > 1 submission-blocking inputs // lazily test for > 1 submission-blocking inputs
return; return;
} }
form.submit(SubmittedFrom::NotFromForm, FormSubmitterElement::Form(form)); form.submit(
SubmittedFrom::NotFromForm,
FormSubmitterElement::Form(form),
can_gc,
);
}, },
} }
} }
@ -2533,7 +2537,7 @@ impl VirtualMethods for HTMLInputElement {
let action = self.textinput.borrow_mut().handle_keydown(keyevent); let action = self.textinput.borrow_mut().handle_keydown(keyevent);
match action { match action {
TriggerDefaultAction => { TriggerDefaultAction => {
self.implicit_submission(); self.implicit_submission(CanGc::note());
}, },
DispatchInput => { DispatchInput => {
self.value_dirty.set(true); self.value_dirty.set(true);
@ -2808,6 +2812,7 @@ impl Activatable for HTMLInputElement {
o.submit( o.submit(
SubmittedFrom::NotFromForm, SubmittedFrom::NotFromForm,
FormSubmitterElement::Input(self), FormSubmitterElement::Input(self),
CanGc::note(),
) )
} }
}, },

View file

@ -90,7 +90,7 @@ impl WebRtcSignaller for RTCSignaller {
let _ = self.task_source.queue_with_canceller( let _ = self.task_source.queue_with_canceller(
task!(on_ice_candidate: move || { task!(on_ice_candidate: move || {
let this = this.root(); let this = this.root();
this.on_ice_candidate(candidate); this.on_ice_candidate(candidate, CanGc::note());
}), }),
&self.canceller, &self.canceller,
); );
@ -112,7 +112,7 @@ impl WebRtcSignaller for RTCSignaller {
let _ = self.task_source.queue_with_canceller( let _ = self.task_source.queue_with_canceller(
task!(update_gathering_state: move || { task!(update_gathering_state: move || {
let this = this.root(); let this = this.root();
this.update_gathering_state(state); this.update_gathering_state(state, CanGc::note());
}), }),
&self.canceller, &self.canceller,
); );
@ -249,7 +249,7 @@ impl RTCPeerConnection {
}) })
} }
fn on_ice_candidate(&self, candidate: IceCandidate) { fn on_ice_candidate(&self, candidate: IceCandidate, can_gc: CanGc) {
if self.closed.get() { if self.closed.get() {
return; return;
} }
@ -266,6 +266,7 @@ impl RTCPeerConnection {
Some(&candidate), Some(&candidate),
None, None,
true, true,
can_gc,
); );
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
} }
@ -361,7 +362,7 @@ impl RTCPeerConnection {
} }
/// <https://www.w3.org/TR/webrtc/#update-ice-gathering-state> /// <https://www.w3.org/TR/webrtc/#update-ice-gathering-state>
fn update_gathering_state(&self, state: GatheringState) { fn update_gathering_state(&self, state: GatheringState, can_gc: CanGc) {
// step 1 // step 1
if self.closed.get() { if self.closed.get() {
return; return;
@ -396,6 +397,7 @@ impl RTCPeerConnection {
None, None,
None, None,
true, true,
can_gc,
); );
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
} }

View file

@ -46,8 +46,9 @@ impl RTCPeerConnectionIceEvent {
candidate: Option<&RTCIceCandidate>, candidate: Option<&RTCIceCandidate>,
url: Option<DOMString>, url: Option<DOMString>,
trusted: bool, trusted: bool,
can_gc: CanGc,
) -> DomRoot<RTCPeerConnectionIceEvent> { ) -> DomRoot<RTCPeerConnectionIceEvent> {
Self::new_with_proto(global, None, ty, candidate, url, trusted, CanGc::note()) Self::new_with_proto(global, None, ty, candidate, url, trusted, can_gc)
} }
fn new_with_proto( fn new_with_proto(

View file

@ -384,7 +384,7 @@ impl ServiceWorkerGlobalScope {
scope.execute_script(DOMString::from(source)); scope.execute_script(DOMString::from(source));
} }
global.dispatch_activate(); global.dispatch_activate(can_gc);
let reporter_name = format!("service-worker-reporter-{}", random::<u64>()); let reporter_name = format!("service-worker-reporter-{}", random::<u64>());
scope scope
.upcast::<GlobalScope>() .upcast::<GlobalScope>()
@ -478,8 +478,8 @@ impl ServiceWorkerGlobalScope {
}) })
} }
fn dispatch_activate(&self) { fn dispatch_activate(&self, can_gc: CanGc) {
let event = ExtendableEvent::new(self, atom!("activate"), false, false); let event = ExtendableEvent::new(self, atom!("activate"), false, false, can_gc);
let event = (*event).upcast::<Event>(); let event = (*event).upcast::<Event>();
self.upcast::<EventTarget>().dispatch_event(event); self.upcast::<EventTarget>().dispatch_event(event);
} }

View file

@ -297,7 +297,8 @@ impl XRSession {
promise.resolve_native(&()); promise.resolve_native(&());
} }
// Step 7 // Step 7
let event = XRSessionEvent::new(&self.global(), atom!("end"), false, false, self); let event =
XRSessionEvent::new(&self.global(), atom!("end"), false, false, self, can_gc);
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
}, },
XREvent::Select(input, kind, ty, frame) => { XREvent::Select(input, kind, ty, frame) => {
@ -360,6 +361,7 @@ impl XRSession {
false, false,
false, false,
self, self,
can_gc,
); );
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
// The page may be visible again, dirty the layers // The page may be visible again, dirty the layers
@ -607,6 +609,7 @@ impl XRSession {
false, false,
false, false,
self, self,
CanGc::note(),
); );
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
} }

View file

@ -40,16 +40,9 @@ impl XRSessionEvent {
bubbles: bool, bubbles: bool,
cancelable: bool, cancelable: bool,
session: &XRSession, session: &XRSession,
can_gc: CanGc,
) -> DomRoot<XRSessionEvent> { ) -> DomRoot<XRSessionEvent> {
Self::new_with_proto( Self::new_with_proto(global, None, type_, bubbles, cancelable, session, can_gc)
global,
None,
type_,
bubbles,
cancelable,
session,
CanGc::note(),
)
} }
fn new_with_proto( fn new_with_proto(