mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
CanGc fixes in components/script/dom (#33880)
Signed-off-by: taniishkaaa <tanishkasingh2004@gmail.com>
This commit is contained in:
parent
72ff89620b
commit
cd7b66be58
12 changed files with 59 additions and 33 deletions
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -132,6 +132,10 @@ DOMInterfaces = {
|
|||
'inRealms': ['PlayEffect', 'Reset']
|
||||
},
|
||||
|
||||
'HTMLFormElement': {
|
||||
'canGc': ['RequestSubmit'],
|
||||
},
|
||||
|
||||
'HTMLMediaElement': {
|
||||
'canGc': ['Load', 'Pause', 'Play', 'SetSrcObject'],
|
||||
'inRealms': ['Play'],
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(),
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue