More CanGc fixes (#33888)

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-18 01:06:42 +05:30 committed by GitHub
parent 720d632170
commit 9c893c7f4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 102 additions and 58 deletions

View file

@ -96,8 +96,9 @@ impl AnalyserNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &AnalyserOptions, options: &AnalyserOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<AnalyserNode>> { ) -> Fallible<DomRoot<AnalyserNode>> {
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)] #[allow(crown::unrooted_must_root)]

View file

@ -100,8 +100,9 @@ impl AudioBufferSourceNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &AudioBufferSourceOptions, options: &AudioBufferSourceOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<AudioBufferSourceNode>> { ) -> Fallible<DomRoot<AudioBufferSourceNode>> {
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)] #[allow(crown::unrooted_must_root)]

View file

@ -372,16 +372,22 @@ impl BaseAudioContextMethods for BaseAudioContext {
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createanalyser> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createanalyser>
fn CreateAnalyser(&self) -> Fallible<DomRoot<AnalyserNode>> { fn CreateAnalyser(&self, can_gc: CanGc) -> Fallible<DomRoot<AnalyserNode>> {
AnalyserNode::new(self.global().as_window(), self, &AnalyserOptions::empty()) AnalyserNode::new(
self.global().as_window(),
self,
&AnalyserOptions::empty(),
can_gc,
)
} }
/// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbiquadfilter> /// <https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbiquadfilter>
fn CreateBiquadFilter(&self) -> Fallible<DomRoot<BiquadFilterNode>> { fn CreateBiquadFilter(&self, can_gc: CanGc) -> Fallible<DomRoot<BiquadFilterNode>> {
BiquadFilterNode::new( BiquadFilterNode::new(
self.global().as_window(), self.global().as_window(),
self, self,
&BiquadFilterOptions::empty(), &BiquadFilterOptions::empty(),
can_gc,
) )
} }
@ -442,11 +448,12 @@ impl BaseAudioContextMethods for BaseAudioContext {
} }
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffersource // https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffersource
fn CreateBufferSource(&self) -> Fallible<DomRoot<AudioBufferSourceNode>> { fn CreateBufferSource(&self, can_gc: CanGc) -> Fallible<DomRoot<AudioBufferSourceNode>> {
AudioBufferSourceNode::new( AudioBufferSourceNode::new(
self.global().as_window(), self.global().as_window(),
self, self,
&AudioBufferSourceOptions::empty(), &AudioBufferSourceOptions::empty(),
can_gc,
) )
} }

View file

@ -25,7 +25,7 @@ DOMInterfaces = {
'BaseAudioContext': { 'BaseAudioContext': {
'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'], 'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'],
'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter'], 'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser'],
}, },
'Blob': { 'Blob': {
@ -74,13 +74,16 @@ DOMInterfaces = {
}, },
'DOMQuad': { 'DOMQuad': {
'canGc': ['FromRect', 'FromQuad'], 'canGc': ['FromRect', 'FromQuad', 'GetBounds'],
}, },
'DOMPoint': { 'DOMPoint': {
'canGc': ['FromPoint'], 'canGc': ['FromPoint'],
}, },
'DOMPointReadOnly': {
'canGc': ['FromPoint'],
},
'DOMMatrixReadOnly': { 'DOMMatrixReadOnly': {
'canGc': ['Multiply', 'Inverse', 'Scale', 'Translate', 'Rotate', 'RotateFromVector','FlipY', 'ScaleNonUniform', 'Scale3d', 'RotateAxisAngle', 'SkewX', 'SkewY', 'FlipX', 'TransformPoint', 'FromFloat32Array', 'FromFloat64Array','FromMatrix'], 'canGc': ['Multiply', 'Inverse', 'Scale', 'Translate', 'Rotate', 'RotateFromVector','FlipY', 'ScaleNonUniform', 'Scale3d', 'RotateAxisAngle', 'SkewX', 'SkewY', 'FlipX', 'TransformPoint', 'FromFloat32Array', 'FromFloat64Array','FromMatrix'],
@ -247,7 +250,7 @@ DOMInterfaces = {
}, },
'Window': { 'Window': {
'canGc': ['Stop'], 'canGc': ['Stop', 'Fetch'],
'inRealms': ['Fetch', 'GetOpener'], 'inRealms': ['Fetch', 'GetOpener'],
}, },
@ -277,6 +280,18 @@ DOMInterfaces = {
'inRealms': ['RequestSession', 'SupportsSessionMode'], 'inRealms': ['RequestSession', 'SupportsSessionMode'],
}, },
'XRBoundedReferenceSpace': {
'canGc': ['BoundsGeometry'],
},
'XRRay': {
'canGc': ['Origin', 'Direction'],
},
'XRRigidTransform': {
'canGc': ['Position', 'Orientation'],
},
'SubtleCrypto': { 'SubtleCrypto': {
'inRealms': ['GenerateKey', 'ExportKey'] 'inRealms': ['GenerateKey', 'ExportKey']
} }

View file

@ -117,8 +117,9 @@ impl BiquadFilterNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &BiquadFilterOptions, options: &BiquadFilterOptions,
can_gc: CanGc,
) -> Fallible<DomRoot<BiquadFilterNode>> { ) -> Fallible<DomRoot<BiquadFilterNode>> {
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)] #[allow(crown::unrooted_must_root)]

View file

@ -45,17 +45,10 @@ impl CloseEvent {
wasClean: bool, wasClean: bool,
code: u16, code: u16,
reason: DOMString, reason: DOMString,
can_gc: CanGc,
) -> DomRoot<CloseEvent> { ) -> DomRoot<CloseEvent> {
Self::new_with_proto( Self::new_with_proto(
global, global, None, type_, bubbles, cancelable, wasClean, code, reason, can_gc,
None,
type_,
bubbles,
cancelable,
wasClean,
code,
reason,
CanGc::note(),
) )
} }

View file

@ -43,17 +43,10 @@ impl CompositionEvent {
view: Option<&Window>, view: Option<&Window>,
detail: i32, detail: i32,
data: DOMString, data: DOMString,
can_gc: CanGc,
) -> DomRoot<CompositionEvent> { ) -> DomRoot<CompositionEvent> {
Self::new_with_proto( Self::new_with_proto(
window, window, None, type_, can_bubble, cancelable, view, detail, data, can_gc,
None,
type_,
can_bubble,
cancelable,
view,
detail,
data,
CanGc::note(),
) )
} }

View file

@ -1905,6 +1905,7 @@ impl Document {
pub fn dispatch_composition_event( pub fn dispatch_composition_event(
&self, &self,
composition_event: ::keyboard_types::CompositionEvent, composition_event: ::keyboard_types::CompositionEvent,
can_gc: CanGc,
) { ) {
// spec: https://w3c.github.io/uievents/#compositionstart // spec: https://w3c.github.io/uievents/#compositionstart
// spec: https://w3c.github.io/uievents/#compositionupdate // spec: https://w3c.github.io/uievents/#compositionupdate
@ -1928,6 +1929,7 @@ impl Document {
Some(&self.window), Some(&self.window),
0, 0,
DOMString::from(composition_event.data), DOMString::from(composition_event.data),
can_gc,
); );
let event = compositionevent.upcast::<Event>(); let event = compositionevent.upcast::<Event>();
event.fire(target); event.fire(target);

View file

@ -37,8 +37,15 @@ impl DOMPointReadOnly {
} }
} }
pub fn new(global: &GlobalScope, x: f64, y: f64, z: f64, w: f64) -> DomRoot<DOMPointReadOnly> { pub fn new(
Self::new_with_proto(global, None, x, y, z, w, CanGc::note()) global: &GlobalScope,
x: f64,
y: f64,
z: f64,
w: f64,
can_gc: CanGc,
) -> DomRoot<DOMPointReadOnly> {
Self::new_with_proto(global, None, x, y, z, w, can_gc)
} }
fn new_with_proto( fn new_with_proto(
@ -77,8 +84,8 @@ impl DOMPointReadOnlyMethods for DOMPointReadOnly {
} }
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint // https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
fn FromPoint(global: &GlobalScope, init: &DOMPointInit) -> DomRoot<Self> { fn FromPoint(global: &GlobalScope, init: &DOMPointInit, can_gc: CanGc) -> DomRoot<Self> {
Self::new(global, init.x, init.y, init.z, init.w) Self::new(global, init.x, init.y, init.z, init.w, can_gc)
} }
// https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x // https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x

View file

@ -43,8 +43,9 @@ impl DOMQuad {
p2: &DOMPoint, p2: &DOMPoint,
p3: &DOMPoint, p3: &DOMPoint,
p4: &DOMPoint, p4: &DOMPoint,
can_gc: CanGc,
) -> DomRoot<DOMQuad> { ) -> DomRoot<DOMQuad> {
Self::new_with_proto(global, None, p1, p2, p3, p4, CanGc::note()) Self::new_with_proto(global, None, p1, p2, p3, p4, can_gc)
} }
fn new_with_proto( fn new_with_proto(
@ -102,6 +103,7 @@ impl DOMQuadMethods for DOMQuad {
can_gc, can_gc,
), ),
&DOMPoint::new(global, other.x, other.y + other.height, 0f64, 1f64, can_gc), &DOMPoint::new(global, other.x, other.y + other.height, 0f64, 1f64, can_gc),
can_gc,
) )
} }
@ -113,6 +115,7 @@ impl DOMQuadMethods for DOMQuad {
&DOMPoint::new_from_init(global, &other.p2, 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.p3, can_gc),
&DOMPoint::new_from_init(global, &other.p4, can_gc), &DOMPoint::new_from_init(global, &other.p4, can_gc),
can_gc,
) )
} }
@ -137,7 +140,7 @@ impl DOMQuadMethods for DOMQuad {
} }
// https://drafts.fxtf.org/geometry/#dom-domquad-getbounds // https://drafts.fxtf.org/geometry/#dom-domquad-getbounds
fn GetBounds(&self) -> DomRoot<DOMRect> { fn GetBounds(&self, can_gc: CanGc) -> DomRoot<DOMRect> {
// https://drafts.fxtf.org/geometry/#nan-safe-minimum // https://drafts.fxtf.org/geometry/#nan-safe-minimum
let nan_safe_minimum = |a: f64, b: f64| { let nan_safe_minimum = |a: f64, b: f64| {
if a.is_nan() || b.is_nan() { if a.is_nan() || b.is_nan() {
@ -196,7 +199,7 @@ impl DOMQuadMethods for DOMQuad {
top, top,
right - left, right - left,
bottom - top, bottom - top,
CanGc::note(), can_gc,
) )
} }
} }

View file

@ -203,6 +203,7 @@ impl GPUDevice {
error, error,
parent: EventInit::empty(), parent: EventInit::empty(),
}, },
can_gc,
); );
let _ = self.eventtarget.DispatchEvent(ev.event()); let _ = self.eventtarget.DispatchEvent(ev.event());
} }

View file

@ -37,8 +37,9 @@ impl GPUUncapturedErrorEvent {
global: &GlobalScope, global: &GlobalScope,
type_: DOMString, type_: DOMString,
init: &GPUUncapturedErrorEventInit, init: &GPUUncapturedErrorEventInit,
can_gc: CanGc,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
Self::new_with_proto(global, None, type_, init, CanGc::note()) Self::new_with_proto(global, None, type_, init, can_gc)
} }
fn new_with_proto( fn new_with_proto(

View file

@ -321,7 +321,7 @@ fn finish_fetching_a_classic_script(
}, },
} }
document.finish_load(LoadType::Script(url), CanGc::note()); document.finish_load(LoadType::Script(url), can_gc);
} }
pub type ScriptResult = Result<ScriptOrigin, NoTrace<NetworkError>>; pub type ScriptResult = Result<ScriptOrigin, NoTrace<NetworkError>>;

View file

@ -40,6 +40,7 @@ impl OfflineAudioCompletionEvent {
bubbles: EventBubbles, bubbles: EventBubbles,
cancelable: EventCancelable, cancelable: EventCancelable,
rendered_buffer: &AudioBuffer, rendered_buffer: &AudioBuffer,
can_gc: CanGc,
) -> DomRoot<OfflineAudioCompletionEvent> { ) -> DomRoot<OfflineAudioCompletionEvent> {
Self::new_with_proto( Self::new_with_proto(
window, window,
@ -48,7 +49,7 @@ impl OfflineAudioCompletionEvent {
bubbles, bubbles,
cancelable, cancelable,
rendered_buffer, rendered_buffer,
CanGc::note(), can_gc,
) )
} }

View file

@ -205,7 +205,7 @@ impl OfflineAudioContextMethods for OfflineAudioContext {
atom!("complete"), atom!("complete"),
EventBubbles::DoesNotBubble, EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable, EventCancelable::NotCancelable,
&buffer); &buffer, CanGc::note());
event.upcast::<Event>().fire(this.upcast()); event.upcast::<Event>().fire(this.upcast());
}), }),
&canceller, &canceller,

View file

@ -127,6 +127,7 @@ impl ResizeObserver {
&[], &[],
&[&*observer_size], &[&*observer_size],
&[], &[],
can_gc,
); );
entries.push(entry); entries.push(entry);

View file

@ -65,6 +65,7 @@ impl ResizeObserverEntry {
border_box_size: &[&ResizeObserverSize], border_box_size: &[&ResizeObserverSize],
content_box_size: &[&ResizeObserverSize], content_box_size: &[&ResizeObserverSize],
device_pixel_content_box_size: &[&ResizeObserverSize], device_pixel_content_box_size: &[&ResizeObserverSize],
can_gc: CanGc,
) -> DomRoot<ResizeObserverEntry> { ) -> DomRoot<ResizeObserverEntry> {
let entry = Box::new(ResizeObserverEntry::new_inherited( let entry = Box::new(ResizeObserverEntry::new_inherited(
target, target,
@ -73,7 +74,7 @@ impl ResizeObserverEntry {
content_box_size, content_box_size,
device_pixel_content_box_size, device_pixel_content_box_size,
)); ));
reflect_dom_object_with_proto(entry, window, None, CanGc::note()) reflect_dom_object_with_proto(entry, window, None, can_gc)
} }
} }

View file

@ -539,6 +539,7 @@ impl TaskOnce for CloseTask {
clean_close, clean_close,
code, code,
reason, reason,
CanGc::note(),
); );
close_event.upcast::<Event>().fire(ws.upcast()); close_event.upcast::<Event>().fire(ws.upcast());
} }

View file

@ -1341,8 +1341,9 @@ impl WindowMethods for Window {
input: RequestOrUSVString, input: RequestOrUSVString,
init: RootedTraceableBox<RequestInit>, init: RootedTraceableBox<RequestInit>,
comp: InRealm, comp: InRealm,
can_gc: CanGc,
) -> Rc<Promise> { ) -> Rc<Promise> {
fetch::Fetch(self.upcast(), input, init, comp, CanGc::note()) fetch::Fetch(self.upcast(), input, init, comp, can_gc)
} }
fn TestRunner(&self) -> DomRoot<TestRunner> { fn TestRunner(&self) -> DomRoot<TestRunner> {

View file

@ -15,7 +15,7 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::xrreferencespace::XRReferenceSpace; use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::XRSession; use crate::dom::xrsession::XRSession;
use crate::script_runtime::JSContext; use crate::script_runtime::{CanGc, JSContext};
#[dom_struct] #[dom_struct]
pub struct XRBoundedReferenceSpace { pub struct XRBoundedReferenceSpace {
@ -63,12 +63,19 @@ impl XRBoundedReferenceSpace {
impl XRBoundedReferenceSpaceMethods for XRBoundedReferenceSpace { impl XRBoundedReferenceSpaceMethods for XRBoundedReferenceSpace {
/// <https://www.w3.org/TR/webxr/#dom-xrboundedreferencespace-boundsgeometry> /// <https://www.w3.org/TR/webxr/#dom-xrboundedreferencespace-boundsgeometry>
fn BoundsGeometry(&self, cx: JSContext) -> JSVal { fn BoundsGeometry(&self, cx: JSContext, can_gc: CanGc) -> JSVal {
if let Some(bounds) = self.reference_space.get_bounds() { if let Some(bounds) = self.reference_space.get_bounds() {
let points: Vec<DomRoot<DOMPointReadOnly>> = bounds let points: Vec<DomRoot<DOMPointReadOnly>> = bounds
.into_iter() .into_iter()
.map(|point| { .map(|point| {
DOMPointReadOnly::new(&self.global(), point.x.into(), 0.0, point.y.into(), 1.0) DOMPointReadOnly::new(
&self.global(),
point.x.into(),
0.0,
point.y.into(),
1.0,
can_gc,
)
}) })
.collect(); .collect();

View file

@ -46,16 +46,10 @@ impl XRInputSourceEvent {
cancelable: bool, cancelable: bool,
frame: &XRFrame, frame: &XRFrame,
source: &XRInputSource, source: &XRInputSource,
can_gc: CanGc,
) -> DomRoot<XRInputSourceEvent> { ) -> DomRoot<XRInputSourceEvent> {
Self::new_with_proto( Self::new_with_proto(
global, global, None, type_, bubbles, cancelable, frame, source, can_gc,
None,
type_,
bubbles,
cancelable,
frame,
source,
CanGc::note(),
) )
} }

View file

@ -112,24 +112,26 @@ impl XRRayMethods for XRRay {
} }
/// <https://immersive-web.github.io/hit-test/#dom-xrray-origin> /// <https://immersive-web.github.io/hit-test/#dom-xrray-origin>
fn Origin(&self) -> DomRoot<DOMPointReadOnly> { fn Origin(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
DOMPointReadOnly::new( DOMPointReadOnly::new(
&self.global(), &self.global(),
self.ray.origin.x as f64, self.ray.origin.x as f64,
self.ray.origin.y as f64, self.ray.origin.y as f64,
self.ray.origin.z as f64, self.ray.origin.z as f64,
1., 1.,
can_gc,
) )
} }
/// <https://immersive-web.github.io/hit-test/#dom-xrray-direction> /// <https://immersive-web.github.io/hit-test/#dom-xrray-direction>
fn Direction(&self) -> DomRoot<DOMPointReadOnly> { fn Direction(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
DOMPointReadOnly::new( DOMPointReadOnly::new(
&self.global(), &self.global(),
self.ray.direction.x as f64, self.ray.direction.x as f64,
self.ray.direction.y as f64, self.ray.direction.y as f64,
self.ray.direction.z as f64, self.ray.direction.z as f64,
0., 0.,
can_gc,
) )
} }

View file

@ -127,14 +127,21 @@ impl XRRigidTransformMethods for XRRigidTransform {
} }
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-position // https://immersive-web.github.io/webxr/#dom-xrrigidtransform-position
fn Position(&self) -> DomRoot<DOMPointReadOnly> { fn Position(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
self.position.or_init(|| { self.position.or_init(|| {
let t = &self.transform.translation; let t = &self.transform.translation;
DOMPointReadOnly::new(&self.global(), t.x.into(), t.y.into(), t.z.into(), 1.0) DOMPointReadOnly::new(
&self.global(),
t.x.into(),
t.y.into(),
t.z.into(),
1.0,
can_gc,
)
}) })
} }
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-orientation // https://immersive-web.github.io/webxr/#dom-xrrigidtransform-orientation
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> { fn Orientation(&self, can_gc: CanGc) -> DomRoot<DOMPointReadOnly> {
self.orientation.or_init(|| { self.orientation.or_init(|| {
let r = &self.transform.rotation; let r = &self.transform.rotation;
DOMPointReadOnly::new( DOMPointReadOnly::new(
@ -143,6 +150,7 @@ impl XRRigidTransformMethods for XRRigidTransform {
r.j.into(), r.j.into(),
r.k.into(), r.k.into(),
r.r.into(), r.r.into(),
can_gc,
) )
}) })
} }

View file

@ -321,6 +321,7 @@ impl XRSession {
false, false,
&frame, &frame,
&source, &source,
can_gc,
); );
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
} else { } else {
@ -332,6 +333,7 @@ impl XRSession {
false, false,
&frame, &frame,
&source, &source,
can_gc,
); );
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
} }
@ -342,6 +344,7 @@ impl XRSession {
false, false,
&frame, &frame,
&source, &source,
can_gc,
); );
event.upcast::<Event>().fire(self.upcast()); event.upcast::<Event>().fire(self.upcast());
} }

View file

@ -1632,7 +1632,7 @@ impl ScriptThread {
}, },
CompositorEvent::CompositionEvent(composition_event) => { CompositorEvent::CompositionEvent(composition_event) => {
document.dispatch_composition_event(composition_event); document.dispatch_composition_event(composition_event, can_gc);
}, },
CompositorEvent::GamepadEvent(gamepad_event) => { CompositorEvent::GamepadEvent(gamepad_event) => {