CanGc fixes in focusevent.rs oscillartornode.rs response.rs resizeobserversize.rs animationevent.rs (#33827)

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-14 03:05:59 +05:30 committed by GitHub
parent 92f12ff7cd
commit fc0835bae3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 65 additions and 28 deletions

View file

@ -38,8 +38,13 @@ impl AnimationEvent {
}
}
pub fn new(window: &Window, type_: Atom, init: &AnimationEventInit) -> DomRoot<AnimationEvent> {
Self::new_with_proto(window, None, type_, init, CanGc::note())
pub fn new(
window: &Window,
type_: Atom,
init: &AnimationEventInit,
can_gc: CanGc,
) -> DomRoot<AnimationEvent> {
Self::new_with_proto(window, None, type_, init, can_gc)
}
fn new_with_proto(

View file

@ -66,6 +66,7 @@ use crate::dom::promise::Promise;
use crate::dom::stereopannernode::StereoPannerNode;
use crate::dom::window::Window;
use crate::realms::InRealm;
use crate::script_runtime::CanGc;
use crate::task_source::TaskSource;
#[allow(dead_code)]
@ -346,8 +347,13 @@ impl BaseAudioContextMethods for BaseAudioContext {
event_handler!(statechange, GetOnstatechange, SetOnstatechange);
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createoscillator>
fn CreateOscillator(&self) -> Fallible<DomRoot<OscillatorNode>> {
OscillatorNode::new(self.global().as_window(), self, &OscillatorOptions::empty())
fn CreateOscillator(&self, can_gc: CanGc) -> Fallible<DomRoot<OscillatorNode>> {
OscillatorNode::new(
self.global().as_window(),
self,
&OscillatorOptions::empty(),
can_gc,
)
}
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain>

View file

@ -25,6 +25,7 @@ DOMInterfaces = {
'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'],
'canGc': ['CreateOscillator'],
},
'Blob': {
@ -189,6 +190,11 @@ DOMInterfaces = {
'weakReferenceable': True,
},
'Response': {
'canGc': ['Error', 'Redirect', 'Clone'],
},
'Selection': {
'canGc': ['Collapse', 'CollapseToEnd', 'CollapseToStart', 'Extend', 'SelectAllChildren', 'SetBaseAndExtent', 'SetPosition'],
},

View file

@ -2982,7 +2982,10 @@ impl Document {
}
/// <https://drafts.csswg.org/resize-observer/#broadcast-active-resize-observations>
pub(crate) fn broadcast_active_resize_observations(&self) -> ResizeObservationDepth {
pub(crate) fn broadcast_active_resize_observations(
&self,
can_gc: CanGc,
) -> ResizeObservationDepth {
let mut shallowest = ResizeObservationDepth::max();
// Breaking potential re-borrow cycle on `resize_observers`:
// broadcasting resize observations calls into a JS callback,
@ -2993,7 +2996,7 @@ impl Document {
.iter()
.map(|obs| DomRoot::from_ref(&**obs))
{
observer.broadcast_active_resize_observations(&mut shallowest);
observer.broadcast_active_resize_observations(&mut shallowest, can_gc);
}
shallowest
}
@ -4623,7 +4626,10 @@ impl DocumentMethods for Document {
"events" | "event" | "htmlevents" | "svgevents" => {
Ok(Event::new_uninitialized(self.window.upcast(), can_gc))
},
"focusevent" => Ok(DomRoot::upcast(FocusEvent::new_uninitialized(&self.window))),
"focusevent" => Ok(DomRoot::upcast(FocusEvent::new_uninitialized(
&self.window,
can_gc,
))),
"hashchangeevent" => Ok(DomRoot::upcast(HashChangeEvent::new_uninitialized(
&self.window,
))),

View file

@ -35,8 +35,8 @@ impl FocusEvent {
}
}
pub fn new_uninitialized(window: &Window) -> DomRoot<FocusEvent> {
Self::new_uninitialized_with_proto(window, None, CanGc::note())
pub fn new_uninitialized(window: &Window, can_gc: CanGc) -> DomRoot<FocusEvent> {
Self::new_uninitialized_with_proto(window, None, can_gc)
}
pub fn new_uninitialized_with_proto(

View file

@ -91,8 +91,9 @@ impl OscillatorNode {
window: &Window,
context: &BaseAudioContext,
options: &OscillatorOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<OscillatorNode>> {
Self::new_with_proto(window, None, context, options, CanGc::note())
Self::new_with_proto(window, None, context, options, can_gc)
}
#[allow(crown::unrooted_must_root)]

View file

@ -93,6 +93,7 @@ impl ResizeObserver {
pub fn broadcast_active_resize_observations(
&self,
shallowest_target_depth: &mut ResizeObservationDepth,
can_gc: CanGc,
) {
let mut entries: Vec<DomRoot<ResizeObserverEntry>> = Default::default();
for (observation, target) in self.observation_targets.borrow_mut().iter_mut() {
@ -107,7 +108,7 @@ impl ResizeObserver {
let height = box_size.height().to_f64_px();
let size_impl = ResizeObserverSizeImpl::new(width, height);
let window = window_from_node(&**target);
let observer_size = ResizeObserverSize::new(&window, size_impl);
let observer_size = ResizeObserverSize::new(&window, size_impl, can_gc);
// Note: content rect is built from content box size.
let content_rect = DOMRectReadOnly::new(

View file

@ -49,9 +49,13 @@ impl ResizeObserverSize {
}
}
pub fn new(window: &Window, size_impl: ResizeObserverSizeImpl) -> DomRoot<ResizeObserverSize> {
pub fn new(
window: &Window,
size_impl: ResizeObserverSizeImpl,
can_gc: CanGc,
) -> DomRoot<ResizeObserverSize> {
let observer_size = Box::new(ResizeObserverSize::new_inherited(size_impl));
reflect_dom_object_with_proto(observer_size, window, None, CanGc::note())
reflect_dom_object_with_proto(observer_size, window, None, can_gc)
}
}

View file

@ -72,8 +72,8 @@ impl Response {
}
// https://fetch.spec.whatwg.org/#dom-response
pub fn new(global: &GlobalScope) -> DomRoot<Response> {
Self::new_with_proto(global, None, CanGc::note())
pub fn new(global: &GlobalScope, can_gc: CanGc) -> DomRoot<Response> {
Self::new_with_proto(global, None, can_gc)
}
fn new_with_proto(
@ -218,8 +218,8 @@ impl ResponseMethods for Response {
}
// https://fetch.spec.whatwg.org/#dom-response-error
fn Error(global: &GlobalScope) -> DomRoot<Response> {
let r = Response::new(global);
fn Error(global: &GlobalScope, can_gc: CanGc) -> DomRoot<Response> {
let r = Response::new(global, can_gc);
*r.response_type.borrow_mut() = DOMResponseType::Error;
r.Headers().set_guard(Guard::Immutable);
*r.status.borrow_mut() = HttpStatus::new_error();
@ -227,7 +227,12 @@ impl ResponseMethods for Response {
}
// https://fetch.spec.whatwg.org/#dom-response-redirect
fn Redirect(global: &GlobalScope, url: USVString, status: u16) -> Fallible<DomRoot<Response>> {
fn Redirect(
global: &GlobalScope,
url: USVString,
status: u16,
can_gc: CanGc,
) -> Fallible<DomRoot<Response>> {
// Step 1
let base_url = global.api_base_url();
let parsed_url = base_url.join(&url.0);
@ -245,7 +250,7 @@ impl ResponseMethods for Response {
// Step 4
// see Step 4 continued
let r = Response::new(global);
let r = Response::new(global, can_gc);
// Step 5
*r.status.borrow_mut() = HttpStatus::new_raw(status, vec![]);
@ -306,14 +311,14 @@ impl ResponseMethods for Response {
}
// https://fetch.spec.whatwg.org/#dom-response-clone
fn Clone(&self) -> Fallible<DomRoot<Response>> {
fn Clone(&self, can_gc: CanGc) -> Fallible<DomRoot<Response>> {
// Step 1
if self.is_locked() || self.is_disturbed() {
return Err(Error::Type("cannot clone a disturbed response".to_string()));
}
// Step 2
let new_response = Response::new(&self.global());
let new_response = Response::new(&self.global(), can_gc);
new_response.Headers().copy_from_headers(self.Headers())?;
new_response.Headers().set_guard(self.Headers().get_guard());