Start marking functions that can transitively trigger a GC (#33144)

* Mark JS reflector wrappers as CanGc.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Propagate CanGc from reflect_dom_object_with_proto.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Mark DOM constructors as GC operations.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-08-22 07:42:36 -04:00 committed by GitHub
parent 9a1051c917
commit 60ef6bc461
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
140 changed files with 1336 additions and 304 deletions

View file

@ -19,6 +19,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
// https://w3c.github.io/uievents/#interface-uievent
#[dom_struct]
@ -38,14 +39,15 @@ impl UIEvent {
}
pub fn new_uninitialized(window: &Window) -> DomRoot<UIEvent> {
Self::new_uninitialized_with_proto(window, None)
Self::new_uninitialized_with_proto(window, None, CanGc::note())
}
fn new_uninitialized_with_proto(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
) -> DomRoot<UIEvent> {
reflect_dom_object_with_proto(Box::new(UIEvent::new_inherited()), window, proto)
reflect_dom_object_with_proto(Box::new(UIEvent::new_inherited()), window, proto, can_gc)
}
pub fn new(
@ -56,7 +58,16 @@ impl UIEvent {
view: Option<&Window>,
detail: i32,
) -> DomRoot<UIEvent> {
Self::new_with_proto(window, None, type_, can_bubble, cancelable, view, detail)
Self::new_with_proto(
window,
None,
type_,
can_bubble,
cancelable,
view,
detail,
CanGc::note(),
)
}
fn new_with_proto(
@ -67,8 +78,9 @@ impl UIEvent {
cancelable: EventCancelable,
view: Option<&Window>,
detail: i32,
can_gc: CanGc,
) -> DomRoot<UIEvent> {
let ev = UIEvent::new_uninitialized_with_proto(window, proto);
let ev = UIEvent::new_uninitialized_with_proto(window, proto, can_gc);
ev.InitUIEvent(
type_,
bool::from(can_bubble),
@ -83,6 +95,7 @@ impl UIEvent {
pub fn Constructor(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
type_: DOMString,
init: &UIEventBinding::UIEventInit,
) -> Fallible<DomRoot<UIEvent>> {
@ -96,6 +109,7 @@ impl UIEvent {
cancelable,
init.view.as_deref(),
init.detail,
can_gc,
);
Ok(event)
}