script: Include constructors and static methods in generated DOM traits (#33665)

* Add all constructors, special operations, and static methods to generated DOM interface traits.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Move all constructors and static methods defined in bare impl blocks inside FooMethods trait impls.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Add missing doc links.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-10-07 21:51:58 -04:00 committed by GitHub
parent 946fa9cdee
commit 7d931e673a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
133 changed files with 1479 additions and 1438 deletions

View file

@ -67,47 +67,6 @@ impl DOMMatrixReadOnly {
}
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly
pub fn Constructor(
global: &GlobalScope,
proto: Option<HandleObject>,
can_gc: CanGc,
init: Option<StringOrUnrestrictedDoubleSequence>,
) -> Fallible<DomRoot<Self>> {
if init.is_none() {
return Ok(Self::new_with_proto(
global,
proto,
true,
Transform3D::identity(),
can_gc,
));
}
match init.unwrap() {
StringOrUnrestrictedDoubleSequence::String(ref s) => {
if global.downcast::<Window>().is_none() {
return Err(error::Error::Type(
"String constructor is only supported in the main thread.".to_owned(),
));
}
if s.is_empty() {
return Ok(Self::new(global, true, Transform3D::identity()));
}
transform_to_matrix(s.to_string())
.map(|(is2D, matrix)| Self::new_with_proto(global, proto, is2D, matrix, can_gc))
},
StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(ref entries) => {
entries_to_matrix(&entries[..])
.map(|(is2D, matrix)| Self::new_with_proto(global, proto, is2D, matrix, can_gc))
},
}
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-frommatrix
pub fn FromMatrix(global: &GlobalScope, other: &DOMMatrixInit) -> Fallible<DomRoot<Self>> {
dommatrixinit_to_matrix(other).map(|(is2D, matrix)| Self::new(global, is2D, matrix))
}
pub fn matrix(&self) -> Ref<Transform3D<f64>> {
self.matrix.borrow()
}
@ -403,10 +362,53 @@ impl DOMMatrixReadOnly {
})
// Step 3 in DOMMatrix.InvertSelf
}
}
#[allow(non_snake_case)]
impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-dommatrixreadonly
fn Constructor(
global: &GlobalScope,
proto: Option<HandleObject>,
can_gc: CanGc,
init: Option<StringOrUnrestrictedDoubleSequence>,
) -> Fallible<DomRoot<Self>> {
if init.is_none() {
return Ok(Self::new_with_proto(
global,
proto,
true,
Transform3D::identity(),
can_gc,
));
}
match init.unwrap() {
StringOrUnrestrictedDoubleSequence::String(ref s) => {
if global.downcast::<Window>().is_none() {
return Err(error::Error::Type(
"String constructor is only supported in the main thread.".to_owned(),
));
}
if s.is_empty() {
return Ok(Self::new(global, true, Transform3D::identity()));
}
transform_to_matrix(s.to_string())
.map(|(is2D, matrix)| Self::new_with_proto(global, proto, is2D, matrix, can_gc))
},
StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(ref entries) => {
entries_to_matrix(&entries[..])
.map(|(is2D, matrix)| Self::new_with_proto(global, proto, is2D, matrix, can_gc))
},
}
}
// 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))
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat32array
#[allow(unsafe_code)]
pub fn FromFloat32Array(
fn FromFloat32Array(
global: &GlobalScope,
array: CustomAutoRooterGuard<Float32Array>,
) -> Fallible<DomRoot<DOMMatrixReadOnly>> {
@ -420,8 +422,7 @@ impl DOMMatrixReadOnly {
}
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-fromfloat64array
#[allow(unsafe_code)]
pub fn FromFloat64Array(
fn FromFloat64Array(
global: &GlobalScope,
array: CustomAutoRooterGuard<Float64Array>,
) -> Fallible<DomRoot<DOMMatrixReadOnly>> {
@ -433,10 +434,7 @@ impl DOMMatrixReadOnly {
Some(StringOrUnrestrictedDoubleSequence::UnrestrictedDoubleSequence(vec)),
)
}
}
#[allow(non_snake_case)]
impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
// https://drafts.fxtf.org/geometry-1/#dom-dommatrixreadonly-m11
fn M11(&self) -> f64 {
self.matrix.borrow().m11