From 92f12ff7cda3d3da667d2358ab3867b1dcc5b9a2 Mon Sep 17 00:00:00 2001 From: chickenleaf Date: Sun, 13 Oct 2024 21:41:46 +0530 Subject: [PATCH] Propagate CanGc through dommatrix, dommatrixreadonly, and testbindings (#33822) * CanGc fixes starting from dommatrix.rs fixed conflicts Signed-off-by: L Ashwin B ~ * cleaning up Signed-off-by: L Ashwin B * fixed cannot find value can_gc in this scope error Signed-off-by: L Ashwin B --------- Signed-off-by: L Ashwin B --- components/script/canvas_state.rs | 4 +- .../script/dom/bindings/codegen/Bindings.conf | 17 +++- .../script/dom/canvasrenderingcontext2d.rs | 4 +- components/script/dom/dommatrix.rs | 33 +++++-- components/script/dom/dommatrixreadonly.rs | 99 ++++++++++++------- .../dom/offscreencanvasrenderingcontext2d.rs | 4 +- .../script/dom/paintrenderingcontext2d.rs | 5 +- components/script/dom/testbinding.rs | 20 ++-- 8 files changed, 124 insertions(+), 62 deletions(-) diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index 1f14f5a902c..b426c2a1551 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -1552,12 +1552,12 @@ impl CanvasState { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform - pub fn get_transform(&self, global: &GlobalScope) -> DomRoot { + pub fn get_transform(&self, global: &GlobalScope, can_gc: CanGc) -> DomRoot { let (sender, receiver) = ipc::channel::>().unwrap(); self.send_canvas_2d_msg(Canvas2dMsg::GetTransform(sender)); let transform = receiver.recv().unwrap(); - DOMMatrix::new(global, true, transform.cast::().to_3d()) + DOMMatrix::new(global, true, transform.cast::().to_3d(), can_gc) } // https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 5ac224923b1..f826f0e9f42 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -57,7 +57,7 @@ DOMInterfaces = { }, 'CanvasRenderingContext2D': { - 'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData'], + 'canGc': ['GetTransform','GetImageData', 'CreateImageData', 'CreateImageData_'], }, 'DOMImplementation': { @@ -68,6 +68,14 @@ DOMInterfaces = { 'canGc': ['ParseFromString'], }, +'DOMMatrix': { + 'canGc': ['FromMatrix', 'FromFloat32Array', 'FromFloat64Array'], +}, + +'DOMMatrixReadOnly': { + 'canGc': ['Multiply', 'Inverse', 'Scale', 'Translate', 'Rotate', 'RotateFromVector','FlipY', 'ScaleNonUniform', 'Scale3d', 'RotateAxisAngle', 'SkewX', 'SkewY', 'FlipX', 'TransformPoint', 'FromFloat32Array', 'FromFloat64Array','FromMatrix'], +}, + 'Document': { 'canGc': ['Close', 'CreateElement', 'CreateElementNS', 'ImportNode', 'SetTitle', 'Write', 'Writeln', 'CreateEvent', 'CreateRange', 'Open', 'Open_'], }, @@ -161,7 +169,11 @@ DOMInterfaces = { }, 'OffscreenCanvasRenderingContext2D': { - 'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData'], + 'canGc': ['CreateImageData', 'CreateImageData_', 'GetImageData', 'GetTransform'], +}, + +'PaintRenderingContext2D': { + 'canGc': ['GetTransform'], }, 'Promise': { @@ -193,6 +205,7 @@ DOMInterfaces = { #FIXME(jdm): This should be 'register': False, but then we don't generate enum types 'TestBinding': { 'inRealms': ['PromiseAttribute', 'PromiseNativeHandler'], + 'canGc': ['InterfaceAttribute', 'GetInterfaceAttributeNullable', 'ReceiveInterface', 'ReceiveInterfaceSequence', 'ReceiveNullableInterface'], }, 'TestWorklet': { diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index e1124facaa4..1f3420457fb 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -199,8 +199,8 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform - fn GetTransform(&self) -> DomRoot { - self.canvas_state.get_transform(&self.global()) + fn GetTransform(&self, can_gc: CanGc) -> DomRoot { + self.canvas_state.get_transform(&self.global(), can_gc) } // https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform diff --git a/components/script/dom/dommatrix.rs b/components/script/dom/dommatrix.rs index 2acdadf489f..95ad8fc7ef2 100644 --- a/components/script/dom/dommatrix.rs +++ b/components/script/dom/dommatrix.rs @@ -29,8 +29,13 @@ pub struct DOMMatrix { #[allow(non_snake_case)] impl DOMMatrix { - pub fn new(global: &GlobalScope, is2D: bool, matrix: Transform3D) -> DomRoot { - Self::new_with_proto(global, None, is2D, matrix, CanGc::note()) + pub fn new( + global: &GlobalScope, + is2D: bool, + matrix: Transform3D, + can_gc: CanGc, + ) -> DomRoot { + Self::new_with_proto(global, None, is2D, matrix, can_gc) } #[allow(crown::unrooted_must_root)] @@ -51,8 +56,12 @@ impl DOMMatrix { } } - pub fn from_readonly(global: &GlobalScope, ro: &DOMMatrixReadOnly) -> DomRoot { - Self::new(global, ro.is2D(), *ro.matrix()) + pub fn from_readonly( + global: &GlobalScope, + ro: &DOMMatrixReadOnly, + can_gc: CanGc, + ) -> DomRoot { + Self::new(global, ro.is2D(), *ro.matrix(), can_gc) } } @@ -82,7 +91,7 @@ impl DOMMatrixMethods for DOMMatrix { )); } if s.is_empty() { - return Ok(Self::new(global, true, Transform3D::identity())); + return Ok(Self::new(global, true, Transform3D::identity(), can_gc)); } transform_to_matrix(s.to_string()) .map(|(is2D, matrix)| Self::new_with_proto(global, proto, is2D, matrix, can_gc)) @@ -95,20 +104,25 @@ impl DOMMatrixMethods for DOMMatrix { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-frommatrix - fn FromMatrix(global: &GlobalScope, other: &DOMMatrixInit) -> Fallible> { - dommatrixinit_to_matrix(other).map(|(is2D, matrix)| Self::new(global, is2D, matrix)) + fn FromMatrix( + global: &GlobalScope, + other: &DOMMatrixInit, + can_gc: CanGc, + ) -> Fallible> { + dommatrixinit_to_matrix(other).map(|(is2D, matrix)| Self::new(global, is2D, matrix, can_gc)) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-fromfloat32array fn FromFloat32Array( global: &GlobalScope, array: CustomAutoRooterGuard, + can_gc: CanGc, ) -> Fallible> { let vec: Vec = array.to_vec().iter().map(|&x| x as f64).collect(); DOMMatrix::Constructor( global, None, - CanGc::note(), + can_gc, Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)), ) } @@ -117,12 +131,13 @@ impl DOMMatrixMethods for DOMMatrix { fn FromFloat64Array( global: &GlobalScope, array: CustomAutoRooterGuard, + can_gc: CanGc, ) -> Fallible> { let vec: Vec = array.to_vec(); DOMMatrix::Constructor( global, None, - CanGc::note(), + can_gc, Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)), ) } diff --git a/components/script/dom/dommatrixreadonly.rs b/components/script/dom/dommatrixreadonly.rs index 5fa5da52ce6..774fcccbfee 100644 --- a/components/script/dom/dommatrixreadonly.rs +++ b/components/script/dom/dommatrixreadonly.rs @@ -46,8 +46,13 @@ pub struct DOMMatrixReadOnly { #[allow(non_snake_case)] impl DOMMatrixReadOnly { - pub fn new(global: &GlobalScope, is2D: bool, matrix: Transform3D) -> DomRoot { - Self::new_with_proto(global, None, is2D, matrix, CanGc::note()) + pub fn new( + global: &GlobalScope, + is2D: bool, + matrix: Transform3D, + can_gc: CanGc, + ) -> DomRoot { + Self::new_with_proto(global, None, is2D, matrix, can_gc) } #[allow(crown::unrooted_must_root)] @@ -453,7 +458,7 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { )); } if s.is_empty() { - return Ok(Self::new(global, true, Transform3D::identity())); + return Ok(Self::new(global, true, Transform3D::identity(), can_gc)); } transform_to_matrix(s.to_string()) .map(|(is2D, matrix)| Self::new_with_proto(global, proto, is2D, matrix, can_gc)) @@ -466,20 +471,25 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-frommatrix - fn FromMatrix(global: &GlobalScope, other: &DOMMatrixInit) -> Fallible> { - dommatrixinit_to_matrix(other).map(|(is2D, matrix)| Self::new(global, is2D, matrix)) + fn FromMatrix( + global: &GlobalScope, + other: &DOMMatrixInit, + can_gc: CanGc, + ) -> Fallible> { + dommatrixinit_to_matrix(other).map(|(is2D, matrix)| Self::new(global, is2D, matrix, can_gc)) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat32array fn FromFloat32Array( global: &GlobalScope, array: CustomAutoRooterGuard, + can_gc: CanGc, ) -> Fallible> { let vec: Vec = array.to_vec().iter().map(|&x| x as f64).collect(); DOMMatrixReadOnly::Constructor( global, None, - CanGc::note(), + can_gc, Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)), ) } @@ -488,12 +498,13 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { fn FromFloat64Array( global: &GlobalScope, array: CustomAutoRooterGuard, + can_gc: CanGc, ) -> Fallible> { let vec: Vec = array.to_vec(); DOMMatrixReadOnly::Constructor( global, None, - CanGc::note(), + can_gc, Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)), ) } @@ -635,8 +646,8 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-translate - fn Translate(&self, tx: f64, ty: f64, tz: f64) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).TranslateSelf(tx, ty, tz) + fn Translate(&self, tx: f64, ty: f64, tz: f64, can_gc: CanGc) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).TranslateSelf(tx, ty, tz) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-scale @@ -648,14 +659,15 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { originX: f64, originY: f64, originZ: f64, + can_gc: CanGc, ) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self) + DOMMatrix::from_readonly(&self.global(), self, can_gc) .ScaleSelf(scaleX, scaleY, scaleZ, originX, originY, originZ) } // https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-scalenonuniform - fn ScaleNonUniform(&self, scaleX: f64, scaleY: f64) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).ScaleSelf( + fn ScaleNonUniform(&self, scaleX: f64, scaleY: f64, can_gc: CanGc) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).ScaleSelf( scaleX, Some(scaleY), 1.0, @@ -666,67 +678,88 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-scale3d - fn Scale3d(&self, scale: f64, originX: f64, originY: f64, originZ: f64) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).Scale3dSelf(scale, originX, originY, originZ) + fn Scale3d( + &self, + scale: f64, + originX: f64, + originY: f64, + originZ: f64, + can_gc: CanGc, + ) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc) + .Scale3dSelf(scale, originX, originY, originZ) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-rotate - fn Rotate(&self, rotX: f64, rotY: Option, rotZ: Option) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).RotateSelf(rotX, rotY, rotZ) + fn Rotate( + &self, + rotX: f64, + rotY: Option, + rotZ: Option, + can_gc: CanGc, + ) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).RotateSelf(rotX, rotY, rotZ) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-rotatefromvector - fn RotateFromVector(&self, x: f64, y: f64) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).RotateFromVectorSelf(x, y) + fn RotateFromVector(&self, x: f64, y: f64, can_gc: CanGc) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).RotateFromVectorSelf(x, y) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-rotateaxisangle - fn RotateAxisAngle(&self, x: f64, y: f64, z: f64, angle: f64) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).RotateAxisAngleSelf(x, y, z, angle) + fn RotateAxisAngle( + &self, + x: f64, + y: f64, + z: f64, + angle: f64, + can_gc: CanGc, + ) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).RotateAxisAngleSelf(x, y, z, angle) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-skewx - fn SkewX(&self, sx: f64) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).SkewXSelf(sx) + fn SkewX(&self, sx: f64, can_gc: CanGc) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).SkewXSelf(sx) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-skewy - fn SkewY(&self, sy: f64) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).SkewYSelf(sy) + fn SkewY(&self, sy: f64, can_gc: CanGc) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).SkewYSelf(sy) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-multiply - fn Multiply(&self, other: &DOMMatrixInit) -> Fallible> { - DOMMatrix::from_readonly(&self.global(), self).MultiplySelf(other) + fn Multiply(&self, other: &DOMMatrixInit, can_gc: CanGc) -> Fallible> { + DOMMatrix::from_readonly(&self.global(), self, can_gc).MultiplySelf(other) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-flipx - fn FlipX(&self) -> DomRoot { + fn FlipX(&self, can_gc: CanGc) -> DomRoot { let is2D = self.is2D.get(); let flip = Transform3D::new( -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, ); let matrix = flip.then(&self.matrix.borrow()); - DOMMatrix::new(&self.global(), is2D, matrix) + DOMMatrix::new(&self.global(), is2D, matrix, can_gc) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-flipy - fn FlipY(&self) -> DomRoot { + fn FlipY(&self, can_gc: CanGc) -> DomRoot { let is2D = self.is2D.get(); let flip = Transform3D::new( 1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, ); let matrix = flip.then(&self.matrix.borrow()); - DOMMatrix::new(&self.global(), is2D, matrix) + DOMMatrix::new(&self.global(), is2D, matrix, can_gc) } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-inverse - fn Inverse(&self) -> DomRoot { - DOMMatrix::from_readonly(&self.global(), self).InvertSelf() + fn Inverse(&self, can_gc: CanGc) -> DomRoot { + DOMMatrix::from_readonly(&self.global(), self, can_gc).InvertSelf() } // https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-transformpoint - fn TransformPoint(&self, point: &DOMPointInit) -> DomRoot { + fn TransformPoint(&self, point: &DOMPointInit, _can_gc: CanGc) -> DomRoot { // 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 diff --git a/components/script/dom/offscreencanvasrenderingcontext2d.rs b/components/script/dom/offscreencanvasrenderingcontext2d.rs index 34c2e5eb944..a7e8ceeb209 100644 --- a/components/script/dom/offscreencanvasrenderingcontext2d.rs +++ b/components/script/dom/offscreencanvasrenderingcontext2d.rs @@ -501,8 +501,8 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex } // https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform - fn GetTransform(&self) -> DomRoot { - self.canvas_state.get_transform(&self.global()) + fn GetTransform(&self, can_gc: CanGc) -> DomRoot { + self.canvas_state.get_transform(&self.global(), can_gc) } // https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform diff --git a/components/script/dom/paintrenderingcontext2d.rs b/components/script/dom/paintrenderingcontext2d.rs index 2aa9cebe244..9b867e80682 100644 --- a/components/script/dom/paintrenderingcontext2d.rs +++ b/components/script/dom/paintrenderingcontext2d.rs @@ -28,6 +28,7 @@ use crate::dom::canvaspattern::CanvasPattern; use crate::dom::canvasrenderingcontext2d::CanvasRenderingContext2D; use crate::dom::dommatrix::DOMMatrix; use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope; +use crate::script_runtime::CanGc; #[dom_struct] pub struct PaintRenderingContext2D { @@ -121,8 +122,8 @@ impl PaintRenderingContext2DMethods for PaintRenderingContext2D { } // https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform - fn GetTransform(&self) -> DomRoot { - self.context.GetTransform() + fn GetTransform(&self, can_gc: CanGc) -> DomRoot { + self.context.GetTransform(can_gc) } // https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index caf0ba1f24b..402a76687e4 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -178,11 +178,11 @@ impl TestBindingMethods for TestBinding { TestEnum::_empty } fn SetEnumAttribute(&self, _: TestEnum) {} - fn InterfaceAttribute(&self) -> DomRoot { + fn InterfaceAttribute(&self, can_gc: CanGc) -> DomRoot { Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), - CanGc::note(), + can_gc, ) } fn SetInterfaceAttribute(&self, _: &Blob) {} @@ -324,11 +324,11 @@ impl TestBindingMethods for TestBinding { fn GetEnumAttributeNullable(&self) -> Option { Some(TestEnum::_empty) } - fn GetInterfaceAttributeNullable(&self) -> Option> { + fn GetInterfaceAttributeNullable(&self, can_gc: CanGc) -> Option> { Some(Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), - CanGc::note(), + can_gc, )) } fn SetInterfaceAttributeNullable(&self, _: Option<&Blob>) {} @@ -419,11 +419,11 @@ impl TestBindingMethods for TestBinding { fn ReceiveEnum(&self) -> TestEnum { TestEnum::_empty } - fn ReceiveInterface(&self) -> DomRoot { + fn ReceiveInterface(&self, can_gc: CanGc) -> DomRoot { Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), - CanGc::note(), + can_gc, ) } fn ReceiveAny(&self, _: SafeJSContext) -> JSVal { @@ -468,11 +468,11 @@ impl TestBindingMethods for TestBinding { fn ReceiveSequence(&self) -> Vec { vec![1] } - fn ReceiveInterfaceSequence(&self) -> Vec> { + fn ReceiveInterfaceSequence(&self, can_gc: CanGc) -> Vec> { vec![Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), - CanGc::note(), + can_gc, )] } fn ReceiveUnionIdentity( @@ -534,11 +534,11 @@ impl TestBindingMethods for TestBinding { fn ReceiveNullableEnum(&self) -> Option { Some(TestEnum::_empty) } - fn ReceiveNullableInterface(&self) -> Option> { + fn ReceiveNullableInterface(&self, can_gc: CanGc) -> Option> { Some(Blob::new( &self.global(), BlobImpl::new_from_bytes(vec![], "".to_owned()), - CanGc::note(), + can_gc, )) } fn ReceiveNullableObject(&self, cx: SafeJSContext) -> Option> {