diff options
author | tanishka <109246904+taniishkaaa@users.noreply.github.com> | 2024-10-17 18:19:00 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-17 12:49:00 +0000 |
commit | cd7b66be58e289faa5a605856500bb1ebd0773bf (patch) | |
tree | f3d8778f7cc1cdc44bb4331e0014e929ad3ce428 | |
parent | 72ff89620bbcc03b1534a092f65e526909df3a4a (diff) | |
download | servo-cd7b66be58e289faa5a605856500bb1ebd0773bf.tar.gz servo-cd7b66be58e289faa5a605856500bb1ebd0773bf.zip |
CanGc fixes in components/script/dom (#33880)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
-rw-r--r-- | components/script/body.rs | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/Bindings.conf | 4 | ||||
-rw-r--r-- | components/script/dom/extendableevent.rs | 3 | ||||
-rw-r--r-- | components/script/dom/formdata.rs | 10 | ||||
-rwxr-xr-x | components/script/dom/htmlbuttonelement.rs | 2 | ||||
-rw-r--r-- | components/script/dom/htmlformelement.rs | 23 | ||||
-rwxr-xr-x | components/script/dom/htmlinputelement.rs | 13 | ||||
-rw-r--r-- | components/script/dom/rtcpeerconnection.rs | 10 | ||||
-rw-r--r-- | components/script/dom/rtcpeerconnectioniceevent.rs | 3 | ||||
-rw-r--r-- | components/script/dom/serviceworkerglobalscope.rs | 6 | ||||
-rw-r--r-- | components/script/dom/xrsession.rs | 5 | ||||
-rw-r--r-- | components/script/dom/xrsessionevent.rs | 11 |
12 files changed, 59 insertions, 33 deletions
diff --git a/components/script/body.rs b/components/script/body.rs index f111ec5f50b..efdcaf3b312 100644 --- a/components/script/body.rs +++ b/components/script/body.rs @@ -878,7 +878,7 @@ fn run_form_data_algorithm( // ... is not fully determined yet. if mime.type_() == mime::APPLICATION && mime.subtype() == mime::WWW_FORM_URLENCODED { 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 { formdata.Append(USVString(k.into_owned()), USVString(e.into_owned())); } diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index e2cd66af44f..1bb3f5ba472 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -132,6 +132,10 @@ DOMInterfaces = { 'inRealms': ['PlayEffect', 'Reset'] }, +'HTMLFormElement': { + 'canGc': ['RequestSubmit'], +}, + 'HTMLMediaElement': { 'canGc': ['Load', 'Pause', 'Play', 'SetSrcObject'], 'inRealms': ['Play'], diff --git a/components/script/dom/extendableevent.rs b/components/script/dom/extendableevent.rs index 925b1cb76f4..2249afb880d 100644 --- a/components/script/dom/extendableevent.rs +++ b/components/script/dom/extendableevent.rs @@ -40,8 +40,9 @@ impl ExtendableEvent { type_: Atom, bubbles: bool, cancelable: bool, + can_gc: CanGc, ) -> 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( diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 35ec6373403..24a83910bd5 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -45,8 +45,12 @@ impl FormData { } } - pub fn new(form_datums: Option<Vec<FormDatum>>, global: &GlobalScope) -> DomRoot<FormData> { - Self::new_with_proto(form_datums, global, None, CanGc::note()) + pub fn new( + 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( @@ -73,7 +77,7 @@ impl FormDataMethods for FormData { form: Option<&HTMLFormElement>, ) -> Fallible<DomRoot<FormData>> { 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), global, diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 4ed72a7ce6d..f0b18725338 100755 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -31,6 +31,7 @@ use crate::dom::nodelist::NodeList; use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable}; use crate::dom::validitystate::{ValidationFlags, ValidityState}; use crate::dom::virtualmethods::VirtualMethods; +use crate::script_runtime::CanGc; #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] enum ButtonType { @@ -352,6 +353,7 @@ impl Activatable for HTMLButtonElement { owner.submit( SubmittedFrom::NotFromForm, FormSubmitterElement::Button(self), + CanGc::note(), ); } }, diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 105cbf74ebe..d13747cd63d 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -82,6 +82,7 @@ use crate::dom::submitevent::SubmitEvent; use crate::dom::virtualmethods::VirtualMethods; use crate::dom::window::Window; use crate::links::{get_element_target, LinkRelations}; +use crate::script_runtime::CanGc; use crate::script_thread::ScriptThread; 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 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 - fn RequestSubmit(&self, submitter: Option<&HTMLElement>) -> Fallible<()> { + fn RequestSubmit(&self, submitter: Option<&HTMLElement>, can_gc: CanGc) -> Fallible<()> { let submitter: FormSubmitterElement = match submitter { Some(submitter_element) => { // Step 1.1 @@ -329,7 +334,7 @@ impl HTMLFormElementMethods for HTMLFormElement { }, }; // Step 3 - self.submit(SubmittedFrom::NotFromForm, submitter); + self.submit(SubmittedFrom::NotFromForm, submitter, can_gc); Ok(()) } @@ -700,7 +705,12 @@ impl HTMLFormElement { } /// [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 if self.upcast::<Element>().cannot_navigate() { return; @@ -769,7 +779,7 @@ impl HTMLFormElement { let encoding = self.pick_encoding(); // 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, None => return, }; @@ -1179,6 +1189,7 @@ impl HTMLFormElement { &self, submitter: Option<FormSubmitterElement>, encoding: Option<&'static Encoding>, + can_gc: CanGc, ) -> Option<Vec<FormDatum>> { // Step 1 if self.constructing_entry_list.get() { @@ -1194,7 +1205,7 @@ impl HTMLFormElement { let window = window_from_node(self); // Step 6 - let form_data = FormData::new(Some(ret), &window.global()); + let form_data = FormData::new(Some(ret), &window.global(), can_gc); // Step 7 let event = FormDataEvent::new( diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 1db376228be..d2ff2590a2d 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -75,7 +75,7 @@ use crate::dom::validation::{is_barred_by_datalist_ancestor, Validatable}; use crate::dom::validitystate::{ValidationFlags, ValidityState}; use crate::dom::virtualmethods::VirtualMethods; use crate::realms::enter_realm; -use crate::script_runtime::JSContext as SafeJSContext; +use crate::script_runtime::{CanGc, JSContext as SafeJSContext}; use crate::textinput::KeyReaction::{ DispatchInput, Nothing, RedrawSelection, TriggerDefaultAction, }; @@ -2048,7 +2048,7 @@ impl HTMLInputElement { // https://html.spec.whatwg.org/multipage/#implicit-submission #[allow(unsafe_code)] - fn implicit_submission(&self) { + fn implicit_submission(&self, can_gc: CanGc) { let doc = document_from_node(self); let node = doc.upcast::<Node>(); let owner = self.form_owner(); @@ -2103,7 +2103,11 @@ impl HTMLInputElement { // lazily test for > 1 submission-blocking inputs 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); match action { TriggerDefaultAction => { - self.implicit_submission(); + self.implicit_submission(CanGc::note()); }, DispatchInput => { self.value_dirty.set(true); @@ -2808,6 +2812,7 @@ impl Activatable for HTMLInputElement { o.submit( SubmittedFrom::NotFromForm, FormSubmitterElement::Input(self), + CanGc::note(), ) } }, diff --git a/components/script/dom/rtcpeerconnection.rs b/components/script/dom/rtcpeerconnection.rs index 7582444b948..f417def0605 100644 --- a/components/script/dom/rtcpeerconnection.rs +++ b/components/script/dom/rtcpeerconnection.rs @@ -90,7 +90,7 @@ impl WebRtcSignaller for RTCSignaller { let _ = self.task_source.queue_with_canceller( task!(on_ice_candidate: move || { let this = this.root(); - this.on_ice_candidate(candidate); + this.on_ice_candidate(candidate, CanGc::note()); }), &self.canceller, ); @@ -112,7 +112,7 @@ impl WebRtcSignaller for RTCSignaller { let _ = self.task_source.queue_with_canceller( task!(update_gathering_state: move || { let this = this.root(); - this.update_gathering_state(state); + this.update_gathering_state(state, CanGc::note()); }), &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() { return; } @@ -266,6 +266,7 @@ impl RTCPeerConnection { Some(&candidate), None, true, + can_gc, ); event.upcast::<Event>().fire(self.upcast()); } @@ -361,7 +362,7 @@ impl RTCPeerConnection { } /// <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 if self.closed.get() { return; @@ -396,6 +397,7 @@ impl RTCPeerConnection { None, None, true, + can_gc, ); event.upcast::<Event>().fire(self.upcast()); } diff --git a/components/script/dom/rtcpeerconnectioniceevent.rs b/components/script/dom/rtcpeerconnectioniceevent.rs index 09cd18b4e69..a1f1aa6575b 100644 --- a/components/script/dom/rtcpeerconnectioniceevent.rs +++ b/components/script/dom/rtcpeerconnectioniceevent.rs @@ -46,8 +46,9 @@ impl RTCPeerConnectionIceEvent { candidate: Option<&RTCIceCandidate>, url: Option<DOMString>, trusted: bool, + can_gc: CanGc, ) -> 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( diff --git a/components/script/dom/serviceworkerglobalscope.rs b/components/script/dom/serviceworkerglobalscope.rs index 65975c5755b..ee6a8da13c2 100644 --- a/components/script/dom/serviceworkerglobalscope.rs +++ b/components/script/dom/serviceworkerglobalscope.rs @@ -384,7 +384,7 @@ impl ServiceWorkerGlobalScope { scope.execute_script(DOMString::from(source)); } - global.dispatch_activate(); + global.dispatch_activate(can_gc); let reporter_name = format!("service-worker-reporter-{}", random::<u64>()); scope .upcast::<GlobalScope>() @@ -478,8 +478,8 @@ impl ServiceWorkerGlobalScope { }) } - fn dispatch_activate(&self) { - let event = ExtendableEvent::new(self, atom!("activate"), false, false); + fn dispatch_activate(&self, can_gc: CanGc) { + let event = ExtendableEvent::new(self, atom!("activate"), false, false, can_gc); let event = (*event).upcast::<Event>(); self.upcast::<EventTarget>().dispatch_event(event); } diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index ab89b6c0d1a..5a041cf0504 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -297,7 +297,8 @@ impl XRSession { promise.resolve_native(&()); } // 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()); }, XREvent::Select(input, kind, ty, frame) => { @@ -360,6 +361,7 @@ impl XRSession { false, false, self, + can_gc, ); event.upcast::<Event>().fire(self.upcast()); // The page may be visible again, dirty the layers @@ -607,6 +609,7 @@ impl XRSession { false, false, self, + CanGc::note(), ); event.upcast::<Event>().fire(self.upcast()); } diff --git a/components/script/dom/xrsessionevent.rs b/components/script/dom/xrsessionevent.rs index ce08805b383..b253f7aa320 100644 --- a/components/script/dom/xrsessionevent.rs +++ b/components/script/dom/xrsessionevent.rs @@ -40,16 +40,9 @@ impl XRSessionEvent { bubbles: bool, cancelable: bool, session: &XRSession, + can_gc: CanGc, ) -> DomRoot<XRSessionEvent> { - Self::new_with_proto( - global, - None, - type_, - bubbles, - cancelable, - session, - CanGc::note(), - ) + Self::new_with_proto(global, None, type_, bubbles, cancelable, session, can_gc) } fn new_with_proto( |