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

@ -35,6 +35,7 @@ use crate::dom::node::{Node, ShadowIncluding, UnbindContext};
use crate::dom::selection::Selection;
use crate::dom::text::Text;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
#[dom_struct]
pub struct Range {
@ -71,9 +72,13 @@ impl Range {
}
}
pub fn new_with_doc(document: &Document, proto: Option<HandleObject>) -> DomRoot<Range> {
pub fn new_with_doc(
document: &Document,
proto: Option<HandleObject>,
can_gc: CanGc,
) -> DomRoot<Range> {
let root = document.upcast();
Range::new_with_proto(document, proto, root, 0, root, 0)
Range::new_with_proto(document, proto, root, 0, root, 0, can_gc)
}
pub fn new(
@ -90,6 +95,7 @@ impl Range {
start_offset,
end_container,
end_offset,
CanGc::note(),
)
}
@ -100,6 +106,7 @@ impl Range {
start_offset: u32,
end_container: &Node,
end_offset: u32,
can_gc: CanGc,
) -> DomRoot<Range> {
let range = reflect_dom_object_with_proto(
Box::new(Range::new_inherited(
@ -110,6 +117,7 @@ impl Range {
)),
document.window(),
proto,
can_gc,
);
start_container.ranges().push(WeakRef::new(&range));
if start_container != end_container {
@ -120,9 +128,13 @@ impl Range {
/// <https://dom.spec.whatwg.org/#dom-range>
#[allow(non_snake_case)]
pub fn Constructor(window: &Window, proto: Option<HandleObject>) -> Fallible<DomRoot<Range>> {
pub fn Constructor(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
) -> Fallible<DomRoot<Range>> {
let document = window.Document();
Ok(Range::new_with_doc(&document, proto))
Ok(Range::new_with_doc(&document, proto, can_gc))
}
/// <https://dom.spec.whatwg.org/#contained>