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

@ -23,6 +23,7 @@ use crate::dom::blob::Blob;
use crate::dom::globalscope::GlobalScope;
use crate::dom::urlhelper::UrlHelper;
use crate::dom::urlsearchparams::URLSearchParams;
use crate::script_runtime::CanGc;
/// <https://url.spec.whatwg.org/#url>
#[dom_struct]
@ -46,8 +47,13 @@ impl URL {
}
}
fn new(global: &GlobalScope, proto: Option<HandleObject>, url: ServoUrl) -> DomRoot<URL> {
reflect_dom_object_with_proto(Box::new(URL::new_inherited(url)), global, proto)
fn new(
global: &GlobalScope,
proto: Option<HandleObject>,
url: ServoUrl,
can_gc: CanGc,
) -> DomRoot<URL> {
reflect_dom_object_with_proto(Box::new(URL::new_inherited(url)), global, proto, can_gc)
}
pub fn query_pairs(&self) -> Vec<(String, String)> {
@ -79,6 +85,7 @@ impl URL {
pub fn Constructor(
global: &GlobalScope,
proto: Option<HandleObject>,
can_gc: CanGc,
url: USVString,
base: Option<USVString>,
) -> Fallible<DomRoot<URL>> {
@ -113,7 +120,7 @@ impl URL {
// Step 7. Set thiss query objects URL object to this.
// Step 4. Set thiss URL to parsedURL.
Ok(URL::new(global, proto, parsed_url))
Ok(URL::new(global, proto, parsed_url, can_gc))
}
/// <https://url.spec.whatwg.org/#dom-url-canparse>
@ -152,7 +159,7 @@ impl URL {
// These steps are all handled while mapping the Result to an Option<ServoUrl>.
// Regarding initialization, the same condition should apply here as stated in the comments
// in Self::Constructor above - construct it on-demand inside `URL::SearchParams`.
Some(URL::new(global, None, parsed_url.ok()?))
Some(URL::new(global, None, parsed_url.ok()?, CanGc::note()))
}
/// <https://w3c.github.io/FileAPI/#dfn-createObjectURL>