fix(geometry): correct operation descriptors

This commit is contained in:
ldm0
2026-10-02 03:27:49 +08:00
parent 65a6463f30
commit 38309acb2b
5 changed files with 79 additions and 8 deletions
@@ -82,7 +82,7 @@ struct DomQuadPrototypeDeclaration {
}
#[derive(WebApiFunctionTemplate)]
#[webapi(interface = web_api_interfaces::DOMQuad)]
#[webapi(interface = web_api_interfaces::DOMQuad, enumerable)]
struct DomQuadConstructorDeclaration {
#[webapi(
static_method = "fromRect",
@@ -136,7 +136,7 @@ struct DomRectPrototypeDeclaration {
}
#[derive(WebApiFunctionTemplate)]
#[webapi(interface = web_api_interfaces::DOMRectReadOnly)]
#[webapi(interface = web_api_interfaces::DOMRectReadOnly, enumerable)]
struct DomRectReadOnlyConstructorDeclaration {
#[webapi(
static_method = "fromRect",
@@ -147,7 +147,7 @@ struct DomRectReadOnlyConstructorDeclaration {
}
#[derive(WebApiFunctionTemplate)]
#[webapi(interface = web_api_interfaces::DOMRect)]
#[webapi(interface = web_api_interfaces::DOMRect, enumerable)]
struct DomRectConstructorDeclaration {
#[webapi(
static_method = "fromRect",
@@ -420,6 +420,37 @@ fn worker_geometry_interfaces_use_worker_specific_matrix_surface() {
return error.name;
}
};
const operationSets = [
[DOMPointReadOnly, ["fromPoint"]],
[DOMPointReadOnly.prototype, ["matrixTransform"]],
[DOMPoint, ["fromPoint"]],
[DOMRectReadOnly, ["fromRect"]],
[DOMRect, ["fromRect"]],
[DOMQuad, ["fromRect", "fromQuad"]],
[DOMMatrixReadOnly, [
"fromMatrix", "fromFloat32Array", "fromFloat64Array"
]],
[DOMMatrixReadOnly.prototype, [
"translate", "scale", "scaleNonUniform", "scale3d", "rotate",
"rotateFromVector", "rotateAxisAngle", "skewX", "skewY",
"multiply", "flipX", "flipY", "inverse", "transformPoint",
"toFloat32Array", "toFloat64Array"
]],
[DOMMatrix, [
"fromMatrix", "fromFloat32Array", "fromFloat64Array"
]],
[DOMMatrix.prototype, [
"multiplySelf", "preMultiplySelf", "translateSelf", "scaleSelf",
"scale3dSelf", "rotateSelf", "rotateFromVectorSelf",
"rotateAxisAngleSelf", "skewXSelf", "skewYSelf", "invertSelf"
]]
];
const hasWebIdlOperationDescriptor = (owner, name) => {
const descriptor = Object.getOwnPropertyDescriptor(owner, name);
return descriptor !== undefined &&
typeof descriptor.value === "function" &&
descriptor.enumerable && descriptor.writable && descriptor.configurable;
};
return JSON.stringify({
constructors: names.map(name => typeof globalThis[name]).join(","),
strings: [
@@ -436,6 +467,9 @@ fn worker_geometry_interfaces_use_worker_specific_matrix_surface() {
"setMatrixValue" in DOMMatrix.prototype,
"WebKitCSSMatrix" in globalThis
].join(","),
operations: operationSets.every(([owner, operationNames]) =>
operationNames.every(name => hasWebIdlOperationDescriptor(owner, name))
),
lengths: [DOMMatrix.length, DOMMatrixReadOnly.length].join(",")
});
})()
@@ -450,6 +484,6 @@ fn worker_geometry_interfaces_use_worker_specific_matrix_surface() {
assert_eq!(
result,
r#"{"constructors":"function,function,function,function,function,function,function","strings":"TypeError,TypeError","tags":"[object DOMMatrix],[object DOMMatrixReadOnly],[object DOMMatrix]","windowOnly":"false,false,false","lengths":"0,0"}"#
r#"{"constructors":"function,function,function,function,function,function,function","strings":"TypeError,TypeError","tags":"[object DOMMatrix],[object DOMMatrixReadOnly],[object DOMMatrix]","windowOnly":"false,false,false","operations":true,"lengths":"0,0"}"#
);
}
@@ -216,7 +216,7 @@ struct DomPointPrototypeAccessorsDeclaration {
}
#[derive(WebApiFunctionTemplate)]
#[webapi(interface = web_api_interfaces::DOMPointReadOnly)]
#[webapi(interface = web_api_interfaces::DOMPointReadOnly, enumerable)]
struct DomPointReadOnlyPrototypeMethodsDeclaration {
#[webapi(
method = "matrixTransform",
@@ -243,14 +243,14 @@ struct DomPointReadOnlyPrototypeAccessorsDeclaration {
}
#[derive(WebApiFunctionTemplate)]
#[webapi(interface = web_api_interfaces::DOMPoint)]
#[webapi(interface = web_api_interfaces::DOMPoint, enumerable)]
struct DomPointConstructorDeclaration {
#[webapi(static_method = "fromPoint", length = 0, callback = dom_point_from_point_callback)]
from_point: (),
}
#[derive(WebApiFunctionTemplate)]
#[webapi(interface = web_api_interfaces::DOMPointReadOnly)]
#[webapi(interface = web_api_interfaces::DOMPointReadOnly, enumerable)]
struct DomPointReadOnlyConstructorDeclaration {
#[webapi(
static_method = "fromPoint",
@@ -495,7 +495,11 @@ struct DomMatrixPrototypeMethodsDeclaration {
#[derive(WebApiFunctionTemplate)]
#[webapi(name = "DOMMatrix", enumerable)]
struct DomMatrixWindowPrototypeMethodsDeclaration {
#[webapi(method = "setMatrixValue", length = 1, callback = dom_matrix_set_matrix_value_callback)]
#[webapi(
method = "setMatrixValue",
length = 1,
callback = dom_matrix_set_matrix_value_callback
)]
set_matrix_value: (),
}
@@ -165,3 +165,36 @@ fn dom_matrix_exposes_webkit_css_matrix_alias() {
assert_eq!(result, "true|true|DOMMatrix|true|true|true,false,true");
}
#[test]
fn dom_matrix_window_operations_use_webidl_descriptors() {
let mut vm = new_storage_test_vm("https://dommatrix-operation-descriptors.test/");
let result = vm
.eval(
r#"
(() => {
const descriptorShape = (owner, name) => {
const descriptor = Object.getOwnPropertyDescriptor(owner, name);
return [
typeof descriptor.value,
descriptor.value.length,
descriptor.enumerable,
descriptor.writable,
descriptor.configurable
].join(",");
};
return [
descriptorShape(DOMMatrixReadOnly.prototype, "toString"),
descriptorShape(DOMMatrix.prototype, "setMatrixValue")
].join("|");
})()
"#,
)
.expect("DOMMatrix Window operation descriptors should evaluate");
assert_eq!(
result,
"function,0,true,true,true|function,1,true,true,true"
);
}