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

@ -33,6 +33,7 @@ use crate::dom::event::Event;
use crate::dom::node::{from_untrusted_node_address, window_from_node, Node, NodeDamage};
use crate::dom::transitionevent::TransitionEvent;
use crate::dom::window::Window;
use crate::script_runtime::CanGc;
/// The set of animations for a document.
#[derive(Default, JSTraceable, MallocSizeOf)]
@ -456,7 +457,7 @@ impl Animations {
});
}
pub(crate) fn send_pending_events(&self, window: &Window) {
pub(crate) fn send_pending_events(&self, window: &Window, can_gc: CanGc) {
// Take all of the events here, in case sending one of these events
// triggers adding new events by forcing a layout.
let events = std::mem::take(&mut *self.pending_events.borrow_mut());
@ -517,7 +518,7 @@ impl Animations {
elapsedTime: elapsed_time,
pseudoElement: pseudo_element,
};
AnimationEvent::new(&window, event_atom, &event_init)
AnimationEvent::new(&window, event_atom, &event_init, can_gc)
.upcast::<Event>()
.fire(node.upcast());
}

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());

View file

@ -154,7 +154,7 @@ pub fn Fetch(
// Step 7. Let responseObject be null.
// NOTE: We do initialize the object earlier earlier so we can use it to track errors
let response = Response::new(global);
let response = Response::new(global, can_gc);
response.Headers().set_guard(Guard::Immutable);
// Step 2. Let requestObject be the result of invoking the initial value of Request as constructor

View file

@ -1707,7 +1707,7 @@ impl ScriptThread {
}
// Update animations and send events.
self.update_animations_and_send_events();
self.update_animations_and_send_events(can_gc);
// TODO(#31866): Implement "run the fullscreen steps" from
// https://fullscreen.spec.whatwg.org/multipage/#run-the-fullscreen-steps.
@ -1723,7 +1723,7 @@ impl ScriptThread {
let mut depth = Default::default();
while document.gather_active_resize_observations_at_depth(&depth) {
// Note: this will reflow the doc.
depth = document.broadcast_active_resize_observations();
depth = document.broadcast_active_resize_observations(can_gc);
}
if document.has_skipped_resize_observations() {
@ -2071,7 +2071,7 @@ impl ScriptThread {
// Perform step 7.10 from https://html.spec.whatwg.org/multipage/#event-loop-processing-model.
// Described at: https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events
fn update_animations_and_send_events(&self) {
fn update_animations_and_send_events(&self, can_gc: CanGc) {
for (_, document) in self.documents.borrow().iter() {
document.update_animation_timeline();
document.maybe_mark_animating_nodes_as_dirty();
@ -2079,7 +2079,9 @@ impl ScriptThread {
for (_, document) in self.documents.borrow().iter() {
let _realm = enter_realm(&*document);
document.animations().send_pending_events(document.window());
document
.animations()
.send_pending_events(document.window(), can_gc);
}
}