From 9c893c7f4def4ffa635587ea85d5e4c3ba6ecac3 Mon Sep 17 00:00:00 2001 From: chickenleaf Date: Fri, 18 Oct 2024 01:06:42 +0530 Subject: [PATCH] More CanGc fixes (#33888) Signed-off-by: L Ashwin B --- components/script/dom/analysernode.rs | 3 ++- .../script/dom/audiobuffersourcenode.rs | 3 ++- components/script/dom/baseaudiocontext.rs | 15 +++++++++---- .../script/dom/bindings/codegen/Bindings.conf | 21 ++++++++++++++++--- components/script/dom/biquadfilternode.rs | 3 ++- components/script/dom/closeevent.rs | 11 ++-------- components/script/dom/compositionevent.rs | 11 ++-------- components/script/dom/document.rs | 2 ++ components/script/dom/dompointreadonly.rs | 15 +++++++++---- components/script/dom/domquad.rs | 9 +++++--- components/script/dom/gpudevice.rs | 1 + .../script/dom/gpuuncapturederrorevent.rs | 3 ++- components/script/dom/htmlscriptelement.rs | 2 +- .../script/dom/offlineaudiocompletionevent.rs | 3 ++- components/script/dom/offlineaudiocontext.rs | 2 +- components/script/dom/resizeobserver.rs | 1 + components/script/dom/resizeobserverentry.rs | 3 ++- components/script/dom/websocket.rs | 1 + components/script/dom/window.rs | 3 ++- .../script/dom/xrboundedreferencespace.rs | 13 +++++++++--- components/script/dom/xrinputsourceevent.rs | 10 ++------- components/script/dom/xrray.rs | 6 ++++-- components/script/dom/xrrigidtransform.rs | 14 ++++++++++--- components/script/dom/xrsession.rs | 3 +++ components/script/script_thread.rs | 2 +- 25 files changed, 102 insertions(+), 58 deletions(-) diff --git a/components/script/dom/analysernode.rs b/components/script/dom/analysernode.rs index afe77851f6b..ddee7e39f5d 100644 --- a/components/script/dom/analysernode.rs +++ b/components/script/dom/analysernode.rs @@ -96,8 +96,9 @@ impl AnalyserNode { window: &Window, context: &BaseAudioContext, options: &AnalyserOptions, + can_gc: CanGc, ) -> Fallible> { - 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)] diff --git a/components/script/dom/audiobuffersourcenode.rs b/components/script/dom/audiobuffersourcenode.rs index bf98ca84bde..a261aea9d1f 100644 --- a/components/script/dom/audiobuffersourcenode.rs +++ b/components/script/dom/audiobuffersourcenode.rs @@ -100,8 +100,9 @@ impl AudioBufferSourceNode { window: &Window, context: &BaseAudioContext, options: &AudioBufferSourceOptions, + can_gc: CanGc, ) -> Fallible> { - 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)] diff --git a/components/script/dom/baseaudiocontext.rs b/components/script/dom/baseaudiocontext.rs index 180fca65efe..cdb8320d75d 100644 --- a/components/script/dom/baseaudiocontext.rs +++ b/components/script/dom/baseaudiocontext.rs @@ -372,16 +372,22 @@ impl BaseAudioContextMethods for BaseAudioContext { } /// - fn CreateAnalyser(&self) -> Fallible> { - AnalyserNode::new(self.global().as_window(), self, &AnalyserOptions::empty()) + fn CreateAnalyser(&self, can_gc: CanGc) -> Fallible> { + AnalyserNode::new( + self.global().as_window(), + self, + &AnalyserOptions::empty(), + can_gc, + ) } /// - fn CreateBiquadFilter(&self) -> Fallible> { + fn CreateBiquadFilter(&self, can_gc: CanGc) -> Fallible> { BiquadFilterNode::new( self.global().as_window(), self, &BiquadFilterOptions::empty(), + can_gc, ) } @@ -442,11 +448,12 @@ impl BaseAudioContextMethods for BaseAudioContext { } // https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createbuffersource - fn CreateBufferSource(&self) -> Fallible> { + fn CreateBufferSource(&self, can_gc: CanGc) -> Fallible> { AudioBufferSourceNode::new( self.global().as_window(), self, &AudioBufferSourceOptions::empty(), + can_gc, ) } diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 1bb3f5ba472..99ac357781e 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -25,7 +25,7 @@ DOMInterfaces = { 'BaseAudioContext': { 'inRealms': ['DecodeAudioData', 'Resume', 'ParseFromString', 'GetBounds', 'GetClientRects'], - 'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter'], + 'canGc': ['CreateOscillator', 'CreateStereoPanner', 'CreateGain', 'CreateIIRFilter', 'CreateBiquadFilter', 'CreateBufferSource', 'CreateAnalyser'], }, 'Blob': { @@ -74,13 +74,16 @@ DOMInterfaces = { }, 'DOMQuad': { - 'canGc': ['FromRect', 'FromQuad'], + 'canGc': ['FromRect', 'FromQuad', 'GetBounds'], }, 'DOMPoint': { 'canGc': ['FromPoint'], }, +'DOMPointReadOnly': { + 'canGc': ['FromPoint'], +}, 'DOMMatrixReadOnly': { 'canGc': ['Multiply', 'Inverse', 'Scale', 'Translate', 'Rotate', 'RotateFromVector','FlipY', 'ScaleNonUniform', 'Scale3d', 'RotateAxisAngle', 'SkewX', 'SkewY', 'FlipX', 'TransformPoint', 'FromFloat32Array', 'FromFloat64Array','FromMatrix'], @@ -247,7 +250,7 @@ DOMInterfaces = { }, 'Window': { - 'canGc': ['Stop'], + 'canGc': ['Stop', 'Fetch'], 'inRealms': ['Fetch', 'GetOpener'], }, @@ -277,6 +280,18 @@ DOMInterfaces = { 'inRealms': ['RequestSession', 'SupportsSessionMode'], }, +'XRBoundedReferenceSpace': { + 'canGc': ['BoundsGeometry'], +}, + +'XRRay': { + 'canGc': ['Origin', 'Direction'], +}, + +'XRRigidTransform': { + 'canGc': ['Position', 'Orientation'], +}, + 'SubtleCrypto': { 'inRealms': ['GenerateKey', 'ExportKey'] } diff --git a/components/script/dom/biquadfilternode.rs b/components/script/dom/biquadfilternode.rs index e461cf2e3f9..92d39503690 100644 --- a/components/script/dom/biquadfilternode.rs +++ b/components/script/dom/biquadfilternode.rs @@ -117,8 +117,9 @@ impl BiquadFilterNode { window: &Window, context: &BaseAudioContext, options: &BiquadFilterOptions, + can_gc: CanGc, ) -> Fallible> { - 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)] diff --git a/components/script/dom/closeevent.rs b/components/script/dom/closeevent.rs index 278b2c6fe06..381b7c853f0 100644 --- a/components/script/dom/closeevent.rs +++ b/components/script/dom/closeevent.rs @@ -45,17 +45,10 @@ impl CloseEvent { wasClean: bool, code: u16, reason: DOMString, + can_gc: CanGc, ) -> DomRoot { Self::new_with_proto( - global, - None, - type_, - bubbles, - cancelable, - wasClean, - code, - reason, - CanGc::note(), + global, None, type_, bubbles, cancelable, wasClean, code, reason, can_gc, ) } diff --git a/components/script/dom/compositionevent.rs b/components/script/dom/compositionevent.rs index f9c36603807..ef9b914fb12 100644 --- a/components/script/dom/compositionevent.rs +++ b/components/script/dom/compositionevent.rs @@ -43,17 +43,10 @@ impl CompositionEvent { view: Option<&Window>, detail: i32, data: DOMString, + can_gc: CanGc, ) -> DomRoot { Self::new_with_proto( - window, - None, - type_, - can_bubble, - cancelable, - view, - detail, - data, - CanGc::note(), + window, None, type_, can_bubble, cancelable, view, detail, data, can_gc, ) } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index aa58c423298..b0a3436d930 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1905,6 +1905,7 @@ impl Document { pub fn dispatch_composition_event( &self, composition_event: ::keyboard_types::CompositionEvent, + can_gc: CanGc, ) { // spec: https://w3c.github.io/uievents/#compositionstart // spec: https://w3c.github.io/uievents/#compositionupdate @@ -1928,6 +1929,7 @@ impl Document { Some(&self.window), 0, DOMString::from(composition_event.data), + can_gc, ); let event = compositionevent.upcast::(); event.fire(target); diff --git a/components/script/dom/dompointreadonly.rs b/components/script/dom/dompointreadonly.rs index 286e449f08f..a52c0d7b65b 100644 --- a/components/script/dom/dompointreadonly.rs +++ b/components/script/dom/dompointreadonly.rs @@ -37,8 +37,15 @@ impl DOMPointReadOnly { } } - pub fn new(global: &GlobalScope, x: f64, y: f64, z: f64, w: f64) -> DomRoot { - 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 { + Self::new_with_proto(global, None, x, y, z, w, can_gc) } fn new_with_proto( @@ -77,8 +84,8 @@ impl DOMPointReadOnlyMethods for DOMPointReadOnly { } // https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint - fn FromPoint(global: &GlobalScope, init: &DOMPointInit) -> DomRoot { - Self::new(global, init.x, init.y, init.z, init.w) + fn FromPoint(global: &GlobalScope, init: &DOMPointInit, can_gc: CanGc) -> DomRoot { + Self::new(global, init.x, init.y, init.z, init.w, can_gc) } // https://dev.w3.org/fxtf/geometry/Overview.html#dom-dompointreadonly-x diff --git a/components/script/dom/domquad.rs b/components/script/dom/domquad.rs index 3ceb00ab59c..bbcaa115943 100644 --- a/components/script/dom/domquad.rs +++ b/components/script/dom/domquad.rs @@ -43,8 +43,9 @@ impl DOMQuad { p2: &DOMPoint, p3: &DOMPoint, p4: &DOMPoint, + can_gc: CanGc, ) -> DomRoot { - 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( @@ -102,6 +103,7 @@ impl DOMQuadMethods for DOMQuad { 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.p3, 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 - fn GetBounds(&self) -> DomRoot { + fn GetBounds(&self, can_gc: CanGc) -> DomRoot { // https://drafts.fxtf.org/geometry/#nan-safe-minimum let nan_safe_minimum = |a: f64, b: f64| { if a.is_nan() || b.is_nan() { @@ -196,7 +199,7 @@ impl DOMQuadMethods for DOMQuad { top, right - left, bottom - top, - CanGc::note(), + can_gc, ) } } diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs index 0e029eeea03..29e2231b99b 100644 --- a/components/script/dom/gpudevice.rs +++ b/components/script/dom/gpudevice.rs @@ -203,6 +203,7 @@ impl GPUDevice { error, parent: EventInit::empty(), }, + can_gc, ); let _ = self.eventtarget.DispatchEvent(ev.event()); } diff --git a/components/script/dom/gpuuncapturederrorevent.rs b/components/script/dom/gpuuncapturederrorevent.rs index f1a93809f75..262c8207d7e 100644 --- a/components/script/dom/gpuuncapturederrorevent.rs +++ b/components/script/dom/gpuuncapturederrorevent.rs @@ -37,8 +37,9 @@ impl GPUUncapturedErrorEvent { global: &GlobalScope, type_: DOMString, init: &GPUUncapturedErrorEventInit, + can_gc: CanGc, ) -> DomRoot { - Self::new_with_proto(global, None, type_, init, CanGc::note()) + Self::new_with_proto(global, None, type_, init, can_gc) } fn new_with_proto( diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 7685a91cab5..4ad5d40c1a7 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -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>; diff --git a/components/script/dom/offlineaudiocompletionevent.rs b/components/script/dom/offlineaudiocompletionevent.rs index a54b432ffb3..9cdbcea66c6 100644 --- a/components/script/dom/offlineaudiocompletionevent.rs +++ b/components/script/dom/offlineaudiocompletionevent.rs @@ -40,6 +40,7 @@ impl OfflineAudioCompletionEvent { bubbles: EventBubbles, cancelable: EventCancelable, rendered_buffer: &AudioBuffer, + can_gc: CanGc, ) -> DomRoot { Self::new_with_proto( window, @@ -48,7 +49,7 @@ impl OfflineAudioCompletionEvent { bubbles, cancelable, rendered_buffer, - CanGc::note(), + can_gc, ) } diff --git a/components/script/dom/offlineaudiocontext.rs b/components/script/dom/offlineaudiocontext.rs index 278392d469d..f0e2d7d1747 100644 --- a/components/script/dom/offlineaudiocontext.rs +++ b/components/script/dom/offlineaudiocontext.rs @@ -205,7 +205,7 @@ impl OfflineAudioContextMethods for OfflineAudioContext { atom!("complete"), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, - &buffer); + &buffer, CanGc::note()); event.upcast::().fire(this.upcast()); }), &canceller, diff --git a/components/script/dom/resizeobserver.rs b/components/script/dom/resizeobserver.rs index cd7effb6f56..8a6cbeaebcd 100644 --- a/components/script/dom/resizeobserver.rs +++ b/components/script/dom/resizeobserver.rs @@ -127,6 +127,7 @@ impl ResizeObserver { &[], &[&*observer_size], &[], + can_gc, ); entries.push(entry); diff --git a/components/script/dom/resizeobserverentry.rs b/components/script/dom/resizeobserverentry.rs index f3afec9f26b..5d94db2abab 100644 --- a/components/script/dom/resizeobserverentry.rs +++ b/components/script/dom/resizeobserverentry.rs @@ -65,6 +65,7 @@ impl ResizeObserverEntry { border_box_size: &[&ResizeObserverSize], content_box_size: &[&ResizeObserverSize], device_pixel_content_box_size: &[&ResizeObserverSize], + can_gc: CanGc, ) -> DomRoot { let entry = Box::new(ResizeObserverEntry::new_inherited( target, @@ -73,7 +74,7 @@ impl ResizeObserverEntry { 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) } } diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index 7410082cf9b..ba82450f5df 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -539,6 +539,7 @@ impl TaskOnce for CloseTask { clean_close, code, reason, + CanGc::note(), ); close_event.upcast::().fire(ws.upcast()); } diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 1741eddde25..24c32223520 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1341,8 +1341,9 @@ impl WindowMethods for Window { input: RequestOrUSVString, init: RootedTraceableBox, comp: InRealm, + can_gc: CanGc, ) -> Rc { - fetch::Fetch(self.upcast(), input, init, comp, CanGc::note()) + fetch::Fetch(self.upcast(), input, init, comp, can_gc) } fn TestRunner(&self) -> DomRoot { diff --git a/components/script/dom/xrboundedreferencespace.rs b/components/script/dom/xrboundedreferencespace.rs index db890922944..912955ea66b 100644 --- a/components/script/dom/xrboundedreferencespace.rs +++ b/components/script/dom/xrboundedreferencespace.rs @@ -15,7 +15,7 @@ use crate::dom::globalscope::GlobalScope; use crate::dom::xrreferencespace::XRReferenceSpace; use crate::dom::xrrigidtransform::XRRigidTransform; use crate::dom::xrsession::XRSession; -use crate::script_runtime::JSContext; +use crate::script_runtime::{CanGc, JSContext}; #[dom_struct] pub struct XRBoundedReferenceSpace { @@ -63,12 +63,19 @@ impl XRBoundedReferenceSpace { impl XRBoundedReferenceSpaceMethods for XRBoundedReferenceSpace { /// - fn BoundsGeometry(&self, cx: JSContext) -> JSVal { + fn BoundsGeometry(&self, cx: JSContext, can_gc: CanGc) -> JSVal { if let Some(bounds) = self.reference_space.get_bounds() { let points: Vec> = bounds .into_iter() .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(); diff --git a/components/script/dom/xrinputsourceevent.rs b/components/script/dom/xrinputsourceevent.rs index 74eda74a6c9..701b5d26cb8 100644 --- a/components/script/dom/xrinputsourceevent.rs +++ b/components/script/dom/xrinputsourceevent.rs @@ -46,16 +46,10 @@ impl XRInputSourceEvent { cancelable: bool, frame: &XRFrame, source: &XRInputSource, + can_gc: CanGc, ) -> DomRoot { Self::new_with_proto( - global, - None, - type_, - bubbles, - cancelable, - frame, - source, - CanGc::note(), + global, None, type_, bubbles, cancelable, frame, source, can_gc, ) } diff --git a/components/script/dom/xrray.rs b/components/script/dom/xrray.rs index 25ab2ffed46..52be024a027 100644 --- a/components/script/dom/xrray.rs +++ b/components/script/dom/xrray.rs @@ -112,24 +112,26 @@ impl XRRayMethods for XRRay { } /// - fn Origin(&self) -> DomRoot { + fn Origin(&self, can_gc: CanGc) -> DomRoot { DOMPointReadOnly::new( &self.global(), self.ray.origin.x as f64, self.ray.origin.y as f64, self.ray.origin.z as f64, 1., + can_gc, ) } /// - fn Direction(&self) -> DomRoot { + fn Direction(&self, can_gc: CanGc) -> DomRoot { DOMPointReadOnly::new( &self.global(), self.ray.direction.x as f64, self.ray.direction.y as f64, self.ray.direction.z as f64, 0., + can_gc, ) } diff --git a/components/script/dom/xrrigidtransform.rs b/components/script/dom/xrrigidtransform.rs index 2d0e5847dcb..93ea951d693 100644 --- a/components/script/dom/xrrigidtransform.rs +++ b/components/script/dom/xrrigidtransform.rs @@ -127,14 +127,21 @@ impl XRRigidTransformMethods for XRRigidTransform { } // https://immersive-web.github.io/webxr/#dom-xrrigidtransform-position - fn Position(&self) -> DomRoot { + fn Position(&self, can_gc: CanGc) -> DomRoot { self.position.or_init(|| { 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 - fn Orientation(&self) -> DomRoot { + fn Orientation(&self, can_gc: CanGc) -> DomRoot { self.orientation.or_init(|| { let r = &self.transform.rotation; DOMPointReadOnly::new( @@ -143,6 +150,7 @@ impl XRRigidTransformMethods for XRRigidTransform { r.j.into(), r.k.into(), r.r.into(), + can_gc, ) }) } diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index 5a041cf0504..9734d1e3fac 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -321,6 +321,7 @@ impl XRSession { false, &frame, &source, + can_gc, ); event.upcast::().fire(self.upcast()); } else { @@ -332,6 +333,7 @@ impl XRSession { false, &frame, &source, + can_gc, ); event.upcast::().fire(self.upcast()); } @@ -342,6 +344,7 @@ impl XRSession { false, &frame, &source, + can_gc, ); event.upcast::().fire(self.upcast()); } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 840fb0a4535..4424307269d 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1632,7 +1632,7 @@ impl ScriptThread { }, CompositorEvent::CompositionEvent(composition_event) => { - document.dispatch_composition_event(composition_event); + document.dispatch_composition_event(composition_event, can_gc); }, CompositorEvent::GamepadEvent(gamepad_event) => {