Propagate CanGc through dommatrix, dommatrixreadonly, and testbindings (#33822)

* CanGc fixes starting from dommatrix.rs
fixed conflicts
Signed-off-by: L Ashwin B <lashwinib@gmail.com>

~

* cleaning up

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* fixed cannot find value can_gc in this scope error

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-10-13 21:41:46 +05:30 committed by GitHub
parent bdd5fb2e5b
commit 92f12ff7cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 124 additions and 62 deletions

View file

@ -1552,12 +1552,12 @@ impl CanvasState {
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
pub fn get_transform(&self, global: &GlobalScope) -> DomRoot<DOMMatrix> {
pub fn get_transform(&self, global: &GlobalScope, can_gc: CanGc) -> DomRoot<DOMMatrix> {
let (sender, receiver) = ipc::channel::<Transform2D<f32>>().unwrap();
self.send_canvas_2d_msg(Canvas2dMsg::GetTransform(sender));
let transform = receiver.recv().unwrap();
DOMMatrix::new(global, true, transform.cast::<f64>().to_3d())
DOMMatrix::new(global, true, transform.cast::<f64>().to_3d(), can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform

View file

@ -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': {

View file

@ -199,8 +199,8 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.canvas_state.get_transform(&self.global())
fn GetTransform(&self, can_gc: CanGc) -> DomRoot<DOMMatrix> {
self.canvas_state.get_transform(&self.global(), can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform

View file

@ -29,8 +29,13 @@ pub struct DOMMatrix {
#[allow(non_snake_case)]
impl DOMMatrix {
pub fn new(global: &GlobalScope, is2D: bool, matrix: Transform3D<f64>) -> DomRoot<Self> {
Self::new_with_proto(global, None, is2D, matrix, CanGc::note())
pub fn new(
global: &GlobalScope,
is2D: bool,
matrix: Transform3D<f64>,
can_gc: CanGc,
) -> DomRoot<Self> {
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> {
Self::new(global, ro.is2D(), *ro.matrix())
pub fn from_readonly(
global: &GlobalScope,
ro: &DOMMatrixReadOnly,
can_gc: CanGc,
) -> DomRoot<Self> {
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<DomRoot<Self>> {
dommatrixinit_to_matrix(other).map(|(is2D, matrix)| Self::new(global, is2D, matrix))
fn FromMatrix(
global: &GlobalScope,
other: &DOMMatrixInit,
can_gc: CanGc,
) -> Fallible<DomRoot<Self>> {
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<Float32Array>,
can_gc: CanGc,
) -> Fallible<DomRoot<DOMMatrix>> {
let vec: Vec<f64> = 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<Float64Array>,
can_gc: CanGc,
) -> Fallible<DomRoot<DOMMatrix>> {
let vec: Vec<f64> = array.to_vec();
DOMMatrix::Constructor(
global,
None,
CanGc::note(),
can_gc,
Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)),
)
}

View file

@ -46,8 +46,13 @@ pub struct DOMMatrixReadOnly {
#[allow(non_snake_case)]
impl DOMMatrixReadOnly {
pub fn new(global: &GlobalScope, is2D: bool, matrix: Transform3D<f64>) -> DomRoot<Self> {
Self::new_with_proto(global, None, is2D, matrix, CanGc::note())
pub fn new(
global: &GlobalScope,
is2D: bool,
matrix: Transform3D<f64>,
can_gc: CanGc,
) -> DomRoot<Self> {
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<DomRoot<Self>> {
dommatrixinit_to_matrix(other).map(|(is2D, matrix)| Self::new(global, is2D, matrix))
fn FromMatrix(
global: &GlobalScope,
other: &DOMMatrixInit,
can_gc: CanGc,
) -> Fallible<DomRoot<Self>> {
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<Float32Array>,
can_gc: CanGc,
) -> Fallible<DomRoot<DOMMatrixReadOnly>> {
let vec: Vec<f64> = 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<Float64Array>,
can_gc: CanGc,
) -> Fallible<DomRoot<DOMMatrixReadOnly>> {
let vec: Vec<f64> = 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> {
DOMMatrix::from_readonly(&self.global(), self).TranslateSelf(tx, ty, tz)
fn Translate(&self, tx: f64, ty: f64, tz: f64, can_gc: CanGc) -> DomRoot<DOMMatrix> {
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> {
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> {
DOMMatrix::from_readonly(&self.global(), self).ScaleSelf(
fn ScaleNonUniform(&self, scaleX: f64, scaleY: f64, can_gc: CanGc) -> DomRoot<DOMMatrix> {
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> {
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> {
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<f64>, rotZ: Option<f64>) -> DomRoot<DOMMatrix> {
DOMMatrix::from_readonly(&self.global(), self).RotateSelf(rotX, rotY, rotZ)
fn Rotate(
&self,
rotX: f64,
rotY: Option<f64>,
rotZ: Option<f64>,
can_gc: CanGc,
) -> DomRoot<DOMMatrix> {
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> {
DOMMatrix::from_readonly(&self.global(), self).RotateFromVectorSelf(x, y)
fn RotateFromVector(&self, x: f64, y: f64, can_gc: CanGc) -> DomRoot<DOMMatrix> {
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> {
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> {
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> {
DOMMatrix::from_readonly(&self.global(), self).SkewXSelf(sx)
fn SkewX(&self, sx: f64, can_gc: CanGc) -> DomRoot<DOMMatrix> {
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> {
DOMMatrix::from_readonly(&self.global(), self).SkewYSelf(sy)
fn SkewY(&self, sy: f64, can_gc: CanGc) -> DomRoot<DOMMatrix> {
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<DomRoot<DOMMatrix>> {
DOMMatrix::from_readonly(&self.global(), self).MultiplySelf(other)
fn Multiply(&self, other: &DOMMatrixInit, can_gc: CanGc) -> Fallible<DomRoot<DOMMatrix>> {
DOMMatrix::from_readonly(&self.global(), self, can_gc).MultiplySelf(other)
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-flipx
fn FlipX(&self) -> DomRoot<DOMMatrix> {
fn FlipX(&self, can_gc: CanGc) -> DomRoot<DOMMatrix> {
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<DOMMatrix> {
fn FlipY(&self, can_gc: CanGc) -> DomRoot<DOMMatrix> {
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> {
DOMMatrix::from_readonly(&self.global(), self).InvertSelf()
fn Inverse(&self, can_gc: CanGc) -> DomRoot<DOMMatrix> {
DOMMatrix::from_readonly(&self.global(), self, can_gc).InvertSelf()
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-transformpoint
fn TransformPoint(&self, point: &DOMPointInit) -> 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

View file

@ -501,8 +501,8 @@ impl OffscreenCanvasRenderingContext2DMethods for OffscreenCanvasRenderingContex
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-gettransform
fn GetTransform(&self) -> DomRoot<DOMMatrix> {
self.canvas_state.get_transform(&self.global())
fn GetTransform(&self, can_gc: CanGc) -> DomRoot<DOMMatrix> {
self.canvas_state.get_transform(&self.global(), can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform

View file

@ -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<DOMMatrix> {
self.context.GetTransform()
fn GetTransform(&self, can_gc: CanGc) -> DomRoot<DOMMatrix> {
self.context.GetTransform(can_gc)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-settransform

View file

@ -178,11 +178,11 @@ impl TestBindingMethods for TestBinding {
TestEnum::_empty
}
fn SetEnumAttribute(&self, _: TestEnum) {}
fn InterfaceAttribute(&self) -> DomRoot<Blob> {
fn InterfaceAttribute(&self, can_gc: CanGc) -> DomRoot<Blob> {
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<TestEnum> {
Some(TestEnum::_empty)
}
fn GetInterfaceAttributeNullable(&self) -> Option<DomRoot<Blob>> {
fn GetInterfaceAttributeNullable(&self, can_gc: CanGc) -> Option<DomRoot<Blob>> {
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<Blob> {
fn ReceiveInterface(&self, can_gc: CanGc) -> DomRoot<Blob> {
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<i32> {
vec![1]
}
fn ReceiveInterfaceSequence(&self) -> Vec<DomRoot<Blob>> {
fn ReceiveInterfaceSequence(&self, can_gc: CanGc) -> Vec<DomRoot<Blob>> {
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<TestEnum> {
Some(TestEnum::_empty)
}
fn ReceiveNullableInterface(&self) -> Option<DomRoot<Blob>> {
fn ReceiveNullableInterface(&self, can_gc: CanGc) -> Option<DomRoot<Blob>> {
Some(Blob::new(
&self.global(),
BlobImpl::new_from_bytes(vec![], "".to_owned()),
CanGc::note(),
can_gc,
))
}
fn ReceiveNullableObject(&self, cx: SafeJSContext) -> Option<NonNull<JSObject>> {