fix(geometry): expose legacy window aliases

This commit is contained in:
ldm0
2026-09-23 00:11:51 +08:00
parent fefd554760
commit bbd07ee5fa
5 changed files with 61 additions and 17 deletions
@@ -18,6 +18,8 @@ use crate::util::{
const LEGACY_WINDOW_INTERFACE_ALIASES: &[(&str, &str)] = &[
("webkitURL", "URL"),
("SVGPoint", "DOMPoint"),
("SVGMatrix", "DOMMatrix"),
("webkitAudioContext", "AudioContext"),
("WebKitCSSMatrix", "DOMMatrix"),
];
@@ -358,6 +360,9 @@ pub(crate) fn lazy_window_interface_names(scope: &mut v8::PinScope<'_, '_>) -> V
.filter(|metadata| {
metadata.installation == GlobalInstallation::Lazy
&& metadata.is_exposed(RealmKind::Window, true)
&& !LEGACY_WINDOW_INTERFACE_ALIASES
.iter()
.any(|(alias, _)| *alias == metadata.name)
})
.map(|metadata| metadata.name)
.collect()
@@ -465,7 +465,10 @@ fn worker_geometry_interfaces_use_worker_specific_matrix_surface() {
windowOnly: [
Object.hasOwn(DOMMatrixReadOnly.prototype, "toString"),
"setMatrixValue" in DOMMatrix.prototype,
"WebKitCSSMatrix" in globalThis
"WebKitCSSMatrix" in globalThis,
"SVGPoint" in globalThis,
"SVGRect" in globalThis,
"SVGMatrix" in globalThis
].join(","),
operations: operationSets.every(([owner, operationNames]) =>
operationNames.every(name => hasWebIdlOperationDescriptor(owner, name))
@@ -484,6 +487,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","operations":true,"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,false,false,false","operations":true,"lengths":"0,0"}"#
);
}
@@ -416,6 +416,8 @@ pub(super) fn build_svg_matrix<'s>(
scope: &mut v8::PinScope<'s, '_>,
components: SvgMatrixComponents,
) -> v8::Local<'s, v8::Object> {
super::super::ensure_intrinsic_interface_prototype(scope, "SVGMatrix")
.expect("SVGMatrix compatibility prototype should materialize");
SvgMatrixObjectDeclaration::new(
components.a,
components.b,
@@ -5868,29 +5868,63 @@ fn dom_quad_factories_and_default_to_json_use_the_function_realm() {
}
#[test]
fn dom_matrix_exposes_webkit_css_matrix_alias() {
let mut vm = new_storage_test_vm("https://dommatrix-webkit-alias.test/");
fn geometry_exposes_legacy_window_aliases_without_replacing_native_svg_rect() {
let mut vm = new_storage_test_vm("https://geometry-legacy-window-aliases.test/");
let result = vm
.eval(
r#"
(() => {
const webkitDescriptor = Object.getOwnPropertyDescriptor(globalThis, "WebKitCSSMatrix");
const matrix = new WebKitCSSMatrix();
return [
WebKitCSSMatrix === DOMMatrix,
WebKitCSSMatrix.prototype === DOMMatrix.prototype,
WebKitCSSMatrix.name,
matrix instanceof DOMMatrix,
matrix instanceof DOMMatrixReadOnly,
[webkitDescriptor.writable, webkitDescriptor.enumerable, webkitDescriptor.configurable].join(",")
].join("|");
const interfaces = ["SVGPoint", "SVGRect", "SVGMatrix", "WebKitCSSMatrix"];
const descriptorShape = name => {
const descriptor = Object.getOwnPropertyDescriptor(globalThis, name);
return [
descriptor.value === globalThis[name],
descriptor.writable,
descriptor.enumerable,
descriptor.configurable
].join(",");
};
const point = new SVGPoint(1, 2);
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const rect = svg.createSVGRect();
rect.x = 3;
rect.y = 4;
rect.width = 5;
rect.height = 6;
const matrix = svg.createSVGMatrix();
matrix.a = 2;
return JSON.stringify({
identities: [
SVGPoint === DOMPoint,
SVGRect === DOMRect,
SVGMatrix === DOMMatrix,
WebKitCSSMatrix === DOMMatrix
].join(","),
point: [point instanceof DOMPoint, point.x, point.y, String(point)].join(","),
rect: [rect instanceof SVGRect, rect instanceof DOMRect, rect.x, rect.height, String(rect)].join(","),
matrix: [
matrix instanceof DOMMatrix,
matrix instanceof SVGMatrix,
DOMMatrix.prototype.isPrototypeOf(matrix),
matrix.a,
Object.prototype.toString.call(matrix)
].join(","),
descriptors: interfaces.map(descriptorShape).join("|")
});
})()
"#,
)
.expect("DOMMatrix legacy Window aliases should evaluate");
.expect("Geometry legacy Window aliases should evaluate");
assert_eq!(result, "true|true|DOMMatrix|true|true|true,false,true");
assert_eq!(
result,
concat!(
r#"{"identities":"true,false,true,true","point":"true,1,2,[object DOMPoint]","rect":"true,false,3,6,[object SVGRect]","matrix":"true,true,true,2,[object SVGMatrix]","descriptors":""#,
"true,true,false,true|true,true,false,true|",
"true,true,false,true|true,true,false,true\"}"
)
);
}
#[test]
+1 -1
View File
@@ -388,7 +388,7 @@ interfaces! {
SVGLengthList;
SVGLineElement: SVGGeometryElement;
SVGLinearGradientElement: SVGGradientElement;
SVGMatrix;
SVGMatrix: DOMMatrix;
SVGMetadataElement: SVGElement;
SVGNumber;
SVGNumberList;