CanGc fixes (#33852)

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-16 08:20:28 +05:30 committed by GitHub
parent 5b8fbb023d
commit a2f81d69c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 92 additions and 63 deletions

View file

@ -265,10 +265,11 @@ impl AudioContextMethods for AudioContext {
fn CreateMediaElementSource(
&self,
media_element: &HTMLMediaElement,
can_gc: CanGc,
) -> Fallible<DomRoot<MediaElementAudioSourceNode>> {
let global = self.global();
let window = global.as_window();
MediaElementAudioSourceNode::new(window, self, media_element)
MediaElementAudioSourceNode::new(window, self, media_element, can_gc)
}
/// <https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediastreamsource>

View file

@ -357,8 +357,13 @@ impl BaseAudioContextMethods for BaseAudioContext {
}
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-creategain>
fn CreateGain(&self) -> Fallible<DomRoot<GainNode>> {
GainNode::new(self.global().as_window(), self, &GainOptions::empty())
fn CreateGain(&self, can_gc: CanGc) -> Fallible<DomRoot<GainNode>> {
GainNode::new(
self.global().as_window(),
self,
&GainOptions::empty(),
can_gc,
)
}
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createpanner>

View file

@ -20,12 +20,12 @@ DOMInterfaces = {
'AudioContext': {
'inRealms': ['Close', 'Suspend'],
'canGc':['CreateMediaStreamDestination'],
'canGc':['CreateMediaStreamDestination', 'CreateMediaElementSource'],
},
'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'],
'canGc': ['CreateOscillator', 'CreateStereoPanner'],
'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain'],
},
'Blob': {
@ -73,6 +73,15 @@ DOMInterfaces = {
'canGc': ['FromMatrix', 'FromFloat32Array', 'FromFloat64Array'],
},
'DOMQuad': {
'canGc': ['FromRect', 'FromQuad'],
},
'DOMPoint': {
'canGc': ['FromPoint'],
},
'DOMMatrixReadOnly': {
'canGc': ['Multiply', 'Inverse', 'Scale', 'Translate', 'Rotate', 'RotateFromVector','FlipY', 'ScaleNonUniform', 'Scale3d', 'RotateAxisAngle', 'SkewX', 'SkewY', 'FlipX', 'TransformPoint', 'FromFloat32Array', 'FromFloat64Array','FromMatrix'],
},
@ -145,6 +154,11 @@ DOMInterfaces = {
'canGc': ['Clone'],
},
'MediaSession': {
'canGc': ['GetMetadata'],
},
'MediaQueryList': {
'weakReferenceable': True,
},
@ -251,6 +265,7 @@ DOMInterfaces = {
'XRSession': {
'inRealms': ['RequestReferenceSpace', 'UpdateRenderState', 'UpdateTargetFrameRate'],
'canGc': ['End'],
},
'XRSystem': {

View file

@ -4641,9 +4641,10 @@ impl DocumentMethods for Document {
"messageevent" => Ok(DomRoot::upcast(MessageEvent::new_uninitialized(
self.window.upcast(),
))),
"mouseevent" | "mouseevents" => {
Ok(DomRoot::upcast(MouseEvent::new_uninitialized(&self.window)))
},
"mouseevent" | "mouseevents" => Ok(DomRoot::upcast(MouseEvent::new_uninitialized(
&self.window,
can_gc,
))),
"storageevent" => Ok(DomRoot::upcast(StorageEvent::new_uninitialized(
&self.window,
"".into(),

View file

@ -759,7 +759,7 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-transformpoint
fn TransformPoint(&self, point: &DOMPointInit, _can_gc: CanGc) -> DomRoot<DOMPoint> {
fn TransformPoint(&self, point: &DOMPointInit, can_gc: CanGc) -> DomRoot<DOMPoint> {
// Euclid always normalizes the homogeneous coordinate which is usually the right
// thing but may (?) not be compliant with the CSS matrix spec (or at least is
// probably not the behavior web authors will expect even if it is mathematically
@ -772,7 +772,7 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
let z = point.x * mat.m13 + point.y * mat.m23 + point.z * mat.m33 + point.w * mat.m43;
let w = point.x * mat.m14 + point.y * mat.m24 + point.z * mat.m34 + point.w * mat.m44;
DOMPoint::new(&self.global(), x, y, z, w)
DOMPoint::new(&self.global(), x, y, z, w, can_gc)
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-tofloat32array

View file

@ -28,8 +28,15 @@ impl DOMPoint {
}
}
pub fn new(global: &GlobalScope, x: f64, y: f64, z: f64, w: f64) -> DomRoot<DOMPoint> {
Self::new_with_proto(global, None, x, y, z, w, CanGc::note())
pub fn new(
global: &GlobalScope,
x: f64,
y: f64,
z: f64,
w: f64,
can_gc: CanGc,
) -> DomRoot<DOMPoint> {
Self::new_with_proto(global, None, x, y, z, w, can_gc)
}
fn new_with_proto(
@ -49,8 +56,12 @@ impl DOMPoint {
)
}
pub fn new_from_init(global: &GlobalScope, p: &DOMPointInit) -> DomRoot<DOMPoint> {
DOMPoint::new(global, p.x, p.y, p.z, p.w)
pub fn new_from_init(
global: &GlobalScope,
p: &DOMPointInit,
can_gc: CanGc,
) -> DomRoot<DOMPoint> {
DOMPoint::new(global, p.x, p.y, p.z, p.w, can_gc)
}
}
@ -69,8 +80,8 @@ impl DOMPointMethods for DOMPoint {
}
// https://drafts.fxtf.org/geometry/#dom-dompoint-frompoint
fn FromPoint(global: &GlobalScope, init: &DOMPointInit) -> DomRoot<Self> {
Self::new_from_init(global, init)
fn FromPoint(global: &GlobalScope, init: &DOMPointInit, can_gc: CanGc) -> DomRoot<Self> {
Self::new_from_init(global, init, can_gc)
}
// https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x

View file

@ -79,39 +79,40 @@ impl DOMQuadMethods for DOMQuad {
Ok(DOMQuad::new_with_proto(
global,
proto,
&DOMPoint::new_from_init(global, p1),
&DOMPoint::new_from_init(global, p2),
&DOMPoint::new_from_init(global, p3),
&DOMPoint::new_from_init(global, p4),
&DOMPoint::new_from_init(global, p1, can_gc),
&DOMPoint::new_from_init(global, p2, can_gc),
&DOMPoint::new_from_init(global, p3, can_gc),
&DOMPoint::new_from_init(global, p4, can_gc),
can_gc,
))
}
// https://drafts.fxtf.org/geometry/#dom-domquad-fromrect
fn FromRect(global: &GlobalScope, other: &DOMRectInit) -> DomRoot<DOMQuad> {
fn FromRect(global: &GlobalScope, other: &DOMRectInit, can_gc: CanGc) -> DomRoot<DOMQuad> {
DOMQuad::new(
global,
&DOMPoint::new(global, other.x, other.y, 0f64, 1f64),
&DOMPoint::new(global, other.x + other.width, other.y, 0f64, 1f64),
&DOMPoint::new(global, other.x, other.y, 0f64, 1f64, can_gc),
&DOMPoint::new(global, other.x + other.width, other.y, 0f64, 1f64, can_gc),
&DOMPoint::new(
global,
other.x + other.width,
other.y + other.height,
0f64,
1f64,
can_gc,
),
&DOMPoint::new(global, other.x, other.y + other.height, 0f64, 1f64),
&DOMPoint::new(global, other.x, other.y + other.height, 0f64, 1f64, can_gc),
)
}
// https://drafts.fxtf.org/geometry/#dom-domquad-fromquad
fn FromQuad(global: &GlobalScope, other: &DOMQuadInit) -> DomRoot<DOMQuad> {
fn FromQuad(global: &GlobalScope, other: &DOMQuadInit, can_gc: CanGc) -> DomRoot<DOMQuad> {
DOMQuad::new(
global,
&DOMPoint::new_from_init(global, &other.p1),
&DOMPoint::new_from_init(global, &other.p2),
&DOMPoint::new_from_init(global, &other.p3),
&DOMPoint::new_from_init(global, &other.p4),
&DOMPoint::new_from_init(global, &other.p1, can_gc),
&DOMPoint::new_from_init(global, &other.p2, can_gc),
&DOMPoint::new_from_init(global, &other.p3, can_gc),
&DOMPoint::new_from_init(global, &other.p4, can_gc),
)
}

View file

@ -69,8 +69,9 @@ impl GainNode {
window: &Window,
context: &BaseAudioContext,
options: &GainOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<GainNode>> {
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

@ -132,7 +132,7 @@ impl Gamepad {
) -> DomRoot<Gamepad> {
let button_list = GamepadButtonList::init_buttons(global);
let vibration_actuator =
GamepadHapticActuator::new(global, gamepad_id, supported_haptic_effects);
GamepadHapticActuator::new(global, gamepad_id, supported_haptic_effects, can_gc);
let index = if xr { -1 } else { 0 };
let gamepad = reflect_dom_object_with_proto(
Box::new(Gamepad::new_inherited(

View file

@ -109,14 +109,16 @@ impl GamepadHapticActuator {
global: &GlobalScope,
gamepad_index: u32,
supported_haptic_effects: GamepadSupportedHapticEffects,
can_gc: CanGc,
) -> DomRoot<GamepadHapticActuator> {
Self::new_with_proto(global, gamepad_index, supported_haptic_effects)
Self::new_with_proto(global, gamepad_index, supported_haptic_effects, can_gc)
}
fn new_with_proto(
global: &GlobalScope,
gamepad_index: u32,
supported_haptic_effects: GamepadSupportedHapticEffects,
can_gc: CanGc,
) -> DomRoot<GamepadHapticActuator> {
reflect_dom_object_with_proto(
Box::new(GamepadHapticActuator::new_inherited(
@ -125,7 +127,7 @@ impl GamepadHapticActuator {
)),
global,
None,
CanGc::note(),
can_gc,
)
}
}

View file

@ -58,8 +58,9 @@ impl MediaElementAudioSourceNode {
window: &Window,
context: &AudioContext,
media_element: &HTMLMediaElement,
can_gc: CanGc,
) -> Fallible<DomRoot<MediaElementAudioSourceNode>> {
Self::new_with_proto(window, None, context, media_element, CanGc::note())
Self::new_with_proto(window, None, context, media_element, can_gc)
}
#[allow(crown::unrooted_must_root)]

View file

@ -37,8 +37,8 @@ impl MediaMetadata {
}
}
pub fn new(global: &Window, init: &MediaMetadataInit) -> DomRoot<MediaMetadata> {
Self::new_with_proto(global, None, init, CanGc::note())
pub fn new(global: &Window, init: &MediaMetadataInit, can_gc: CanGc) -> DomRoot<MediaMetadata> {
Self::new_with_proto(global, None, init, can_gc)
}
fn new_with_proto(

View file

@ -53,16 +53,10 @@ impl MediaQueryListEvent {
cancelable: bool,
media: DOMString,
matches: bool,
can_gc: CanGc,
) -> DomRoot<MediaQueryListEvent> {
Self::new_with_proto(
global,
None,
type_,
bubbles,
cancelable,
media,
matches,
CanGc::note(),
global, None, type_, bubbles, cancelable, media, matches, can_gc,
)
}

View file

@ -126,14 +126,14 @@ impl MediaSession {
impl MediaSessionMethods for MediaSession {
/// <https://w3c.github.io/mediasession/#dom-mediasession-metadata>
fn GetMetadata(&self) -> Option<DomRoot<MediaMetadata>> {
fn GetMetadata(&self, can_gc: CanGc) -> Option<DomRoot<MediaMetadata>> {
if let Some(ref metadata) = *self.metadata.borrow() {
let mut init = MediaMetadataInit::empty();
init.title = DOMString::from_string(metadata.title.clone());
init.artist = DOMString::from_string(metadata.artist.clone());
init.album = DOMString::from_string(metadata.album.clone());
let global = self.global();
Some(MediaMetadata::new(global.as_window(), &init))
Some(MediaMetadata::new(global.as_window(), &init, can_gc))
} else {
None
}

View file

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

View file

@ -2446,7 +2446,7 @@ impl Window {
/// Evaluate media query lists and report changes
/// <https://drafts.csswg.org/cssom-view/#evaluate-media-queries-and-report-changes>
pub fn evaluate_media_queries_and_report_changes(&self) {
pub fn evaluate_media_queries_and_report_changes(&self, can_gc: CanGc) {
rooted_vec!(let mut mql_list);
self.media_query_lists.for_each(|mql| {
if let MediaQueryListMatchState::Changed = mql.evaluate_changes() {
@ -2463,6 +2463,7 @@ impl Window {
false,
mql.Media(),
mql.Matches(),
can_gc,
);
event.upcast::<Event>().fire(mql.upcast::<EventTarget>());
}

View file

@ -60,13 +60,14 @@ impl XRInputSourceArray {
session,
&added,
&[],
can_gc,
);
// Release the refcell guard
drop(input_sources);
event.upcast::<Event>().fire(session.upcast());
}
pub fn remove_input_source(&self, session: &XRSession, id: InputId) {
pub fn remove_input_source(&self, session: &XRSession, id: InputId, can_gc: CanGc) {
let mut input_sources = self.input_sources.borrow_mut();
let global = self.global();
let removed = if let Some(i) = input_sources.iter().find(|i| i.id() == id) {
@ -84,6 +85,7 @@ impl XRInputSourceArray {
session,
&[],
&removed,
can_gc,
);
input_sources.retain(|i| i.id() != id);
// release the refcell guard
@ -123,6 +125,7 @@ impl XRInputSourceArray {
session,
&added,
removed,
can_gc,
);
// release the refcell guard
drop(input_sources);

View file

@ -54,17 +54,10 @@ impl XRInputSourcesChangeEvent {
session: &XRSession,
added: &[DomRoot<XRInputSource>],
removed: &[DomRoot<XRInputSource>],
can_gc: CanGc,
) -> DomRoot<XRInputSourcesChangeEvent> {
Self::new_with_proto(
global,
None,
type_,
bubbles,
cancelable,
session,
added,
removed,
CanGc::note(),
global, None, type_, bubbles, cancelable, session, added, removed, can_gc,
)
}

View file

@ -370,7 +370,7 @@ impl XRSession {
self.input_sources.add_input_sources(self, &[info], can_gc);
},
XREvent::RemoveInput(id) => {
self.input_sources.remove_input_source(self, id);
self.input_sources.remove_input_source(self, id, can_gc);
},
XREvent::UpdateInput(id, source) => {
self.input_sources
@ -878,7 +878,7 @@ impl XRSessionMethods for XRSession {
}
/// <https://immersive-web.github.io/webxr/#dom-xrsession-end>
fn End(&self) -> Rc<Promise> {
fn End(&self, can_gc: CanGc) -> Rc<Promise> {
let global = self.global();
let p = Promise::new(&global);
if self.ended.get() && self.end_promises.borrow().is_empty() {
@ -904,7 +904,7 @@ impl XRSessionMethods for XRSession {
// Disconnect any still-attached XRInputSources
for source in 0..self.input_sources.Length() {
self.input_sources
.remove_input_source(self, InputId(source));
.remove_input_source(self, InputId(source), can_gc);
}
p
}

View file

@ -1700,7 +1700,7 @@ impl ScriptThread {
// Evaluate media queries and report changes.
document
.window()
.evaluate_media_queries_and_report_changes();
.evaluate_media_queries_and_report_changes(can_gc);
// https://html.spec.whatwg.org/multipage/#img-environment-changes
// As per the spec, this can be run at any time.