diff options
author | Simon Wülker <simon.wuelker@arcor.de> | 2024-10-11 05:06:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-11 03:06:44 +0000 |
commit | c00c6e728ddb82d6cb646eb924a73c4b43a798a4 (patch) | |
tree | 90b76d1acc39b69fd2224793014f9e7089b6fefd | |
parent | fc2c77be8363759657b50992b93d08d40f8fbf1b (diff) | |
download | servo-c00c6e728ddb82d6cb646eb924a73c4b43a798a4.tar.gz servo-c00c6e728ddb82d6cb646eb924a73c4b43a798a4.zip |
Implement DOMMatrix `stringifier` (#33792)
* Implement DOMMatrix stringifier
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
* Update WPT expectations
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
-rw-r--r-- | components/script/dom/dommatrixreadonly.rs | 128 | ||||
-rw-r--r-- | components/script/dom/webidls/DOMMatrixReadOnly.webidl | 2 | ||||
-rw-r--r-- | tests/wpt/meta/css/geometry/DOMMatrix-001.html.ini | 12 | ||||
-rw-r--r-- | tests/wpt/meta/css/geometry/DOMMatrix-stringifier.html.ini | 234 | ||||
-rw-r--r-- | tests/wpt/meta/css/geometry/idlharness.any.js.ini | 3 | ||||
-rw-r--r-- | tests/wpt/meta/css/geometry/spec-examples.html.ini | 11 |
6 files changed, 129 insertions, 261 deletions
diff --git a/components/script/dom/dommatrixreadonly.rs b/components/script/dom/dommatrixreadonly.rs index 00b0585131a..1362615022c 100644 --- a/components/script/dom/dommatrixreadonly.rs +++ b/components/script/dom/dommatrixreadonly.rs @@ -10,7 +10,8 @@ use dom_struct::dom_struct; use euclid::default::Transform3D; use euclid::Angle; use js::jsapi::JSObject; -use js::rust::{CustomAutoRooterGuard, HandleObject}; +use js::jsval; +use js::rust::{CustomAutoRooterGuard, HandleObject, ToString}; use js::typedarray::{Float32Array, Float64Array}; use style::parser::ParserContext; use url::Url; @@ -21,11 +22,13 @@ use crate::dom::bindings::codegen::Bindings::DOMMatrixBinding::{DOMMatrixInit, D use crate::dom::bindings::codegen::Bindings::DOMMatrixReadOnlyBinding::DOMMatrixReadOnlyMethods; use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit; use crate::dom::bindings::codegen::UnionTypes::StringOrUnrestrictedDoubleSequence; +use crate::dom::bindings::conversions::jsstring_to_str; use crate::dom::bindings::error; use crate::dom::bindings::error::Fallible; use crate::dom::bindings::inheritance::Castable; use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::str::DOMString; use crate::dom::dommatrix::DOMMatrix; use crate::dom::dompoint::DOMPoint; use crate::dom::globalscope::GlobalScope; @@ -759,6 +762,129 @@ impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly { create_buffer_source(cx, &self.matrix.borrow().to_array(), array.handle_mut()) .expect("Converting matrix to float64 array should never fail") } + + // https://drafts.fxtf.org/geometry/#dommatrixreadonly-stringification-behavior + #[allow(unsafe_code)] + fn Stringifier(&self) -> Fallible<DOMString> { + // Step 1. If one or more of m11 element through m44 element are a non-finite value, + // then throw an "InvalidStateError" DOMException. + let mat = self.matrix.borrow(); + if !mat.m11.is_finite() || + !mat.m12.is_finite() || + !mat.m13.is_finite() || + !mat.m14.is_finite() || + !mat.m21.is_finite() || + !mat.m22.is_finite() || + !mat.m23.is_finite() || + !mat.m24.is_finite() || + !mat.m31.is_finite() || + !mat.m32.is_finite() || + !mat.m33.is_finite() || + !mat.m34.is_finite() || + !mat.m41.is_finite() || + !mat.m42.is_finite() || + !mat.m43.is_finite() || + !mat.m44.is_finite() + { + return Err(error::Error::InvalidState); + } + + // Step 2. Let string be the empty string. + let string; + + // Step 3. If is 2D is true, then: + let cx = GlobalScope::get_cx(); + let to_string = |f: f64| { + let value = jsval::DoubleValue(f); + + unsafe { + rooted!(in(*cx) let mut rooted_value = value); + let serialization = ToString(*cx, rooted_value.handle()); + jsstring_to_str( + *cx, + ptr::NonNull::new(serialization).expect("Pointer cannot be null"), + ) + } + }; + if self.is2D() { + // Step 3.1 Append "matrix(" to string. + // Step 3.2 Append ! ToString(m11 element) to string. + // Step 3.3 Append ", " to string. + // Step 3.4 Append ! ToString(m12 element) to string. + // Step 3.5 Append ", " to string. + // Step 3.6 Append ! ToString(m21 element) to string. + // Step 3.7 Append ", " to string. + // Step 3.8 Append ! ToString(m22 element) to string. + // Step 3.9 Append ", " to string. + // Step 3.10 Append ! ToString(m41 element) to string. + // Step 3.11 Append ", " to string. + // Step 3.12 Append ! ToString(m42 element) to string. + // Step 3.13 Append ")" to string. + string = format!( + "matrix({}, {}, {}, {}, {}, {})", + to_string(mat.m11), + to_string(mat.m12), + to_string(mat.m21), + to_string(mat.m22), + to_string(mat.m41), + to_string(mat.m42) + ) + .into(); + } + // Step 4. Otherwise: + else { + // Step 4.1 Append "matrix3d(" to string. + // Step 4.2 Append ! ToString(m11 element) to string. + // Step 4.3 Append ", " to string. + // Step 4.4 Append ! ToString(m12 element) to string. + // Step 4.5 Append ", " to string. + // Step 4.6 Append ! ToString(m13 element) to string. + // Step 4.7 Append ", " to string. + // Step 4.8 Append ! ToString(m14 element) to string. + // Step 4.9 Append ", " to string. + // Step 4.10 Append ! ToString(m21 element) to string. + // Step 4.11 Append ", " to string. + // Step 4.12 Append ! ToString(m22 element) to string. + // Step 4.13 Append ", " to string. + // Step 4.14 Append ! ToString(m23 element) to string. + // Step 4.15 Append ", " to string. + // Step 4.16 Append ! ToString(m24 element) to string. + // Step 4.17 Append ", " to string. + // Step 4.18 Append ! ToString(m41 element) to string. + // Step 4.19 Append ", " to string. + // Step 4.20 Append ! ToString(m42 element) to string. + // Step 4.21 Append ", " to string. + // Step 4.22 Append ! ToString(m43 element) to string. + // Step 4.23 Append ", " to string. + // Step 4.24 Append ! ToString(m44 element) to string. + // Step 4.25 Append ")" to string. + + // NOTE: The spec is wrong and missing the m3* elements. + // (https://github.com/w3c/fxtf-drafts/issues/574) + string = format!( + "matrix3d({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})", + to_string(mat.m11), + to_string(mat.m12), + to_string(mat.m13), + to_string(mat.m14), + to_string(mat.m21), + to_string(mat.m22), + to_string(mat.m23), + to_string(mat.m24), + to_string(mat.m31), + to_string(mat.m32), + to_string(mat.m33), + to_string(mat.m34), + to_string(mat.m41), + to_string(mat.m42), + to_string(mat.m43), + to_string(mat.m44) + ) + .into(); + } + + Ok(string) + } } // https://drafts.fxtf.org/geometry-1/#create-a-2d-matrix diff --git a/components/script/dom/webidls/DOMMatrixReadOnly.webidl b/components/script/dom/webidls/DOMMatrixReadOnly.webidl index 689b83ddc58..92993905db4 100644 --- a/components/script/dom/webidls/DOMMatrixReadOnly.webidl +++ b/components/script/dom/webidls/DOMMatrixReadOnly.webidl @@ -81,6 +81,6 @@ interface DOMMatrixReadOnly { DOMPoint transformPoint(optional DOMPointInit point = {}); Float32Array toFloat32Array(); Float64Array toFloat64Array(); -// [Exposed=Window] stringifier; + [Exposed=Window, Throws] stringifier; [Default] object toJSON(); }; diff --git a/tests/wpt/meta/css/geometry/DOMMatrix-001.html.ini b/tests/wpt/meta/css/geometry/DOMMatrix-001.html.ini deleted file mode 100644 index 76113f20b92..00000000000 --- a/tests/wpt/meta/css/geometry/DOMMatrix-001.html.ini +++ /dev/null @@ -1,12 +0,0 @@ -[DOMMatrix-001.html] - [new DOMMatrix(new DOMMatrix())] - expected: FAIL - - [new DOMMatrix(matrix)] - expected: FAIL - - [new DOMMatrixReadOnly(new DOMMatrixReadOnly())] - expected: FAIL - - [new DOMMatrixReadOnly(matrix)] - expected: FAIL diff --git a/tests/wpt/meta/css/geometry/DOMMatrix-stringifier.html.ini b/tests/wpt/meta/css/geometry/DOMMatrix-stringifier.html.ini deleted file mode 100644 index 186dd7dbb38..00000000000 --- a/tests/wpt/meta/css/geometry/DOMMatrix-stringifier.html.ini +++ /dev/null @@ -1,234 +0,0 @@ -[DOMMatrix-stringifier.html] - [DOMMatrix stringifier: identity (2d)] - expected: FAIL - - [DOMMatrix stringifier: identity (3d)] - expected: FAIL - - [DOMMatrix stringifier: NaN (2d)] - expected: FAIL - - [DOMMatrix stringifier: NaN (3d)] - expected: FAIL - - [DOMMatrix stringifier: Infinity (2d)] - expected: FAIL - - [DOMMatrix stringifier: Infinity (3d)] - expected: FAIL - - [DOMMatrix stringifier: -Infinity (2d)] - expected: FAIL - - [DOMMatrix stringifier: -Infinity (3d)] - expected: FAIL - - [DOMMatrix stringifier: 1/3 (2d)] - expected: FAIL - - [DOMMatrix stringifier: 1/3 (3d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000 (2d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000 (3d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000000 (2d)] - expected: FAIL - - [DOMMatrix stringifier: 1/300000000 (3d)] - expected: FAIL - - [DOMMatrix stringifier: 100000 + (1/3) (2d)] - expected: FAIL - - [DOMMatrix stringifier: 100000 + (1/3) (3d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 1 (2d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 1 (3d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 2 (2d)] - expected: FAIL - - [DOMMatrix stringifier: Math.pow(2, 53) + 2 (3d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MAX_VALUE (2d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MAX_VALUE (3d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MIN_VALUE (2d)] - expected: FAIL - - [DOMMatrix stringifier: Number.MIN_VALUE (3d)] - expected: FAIL - - [DOMMatrix stringifier: throwing getters (2d)] - expected: FAIL - - [DOMMatrix stringifier: throwing getters (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: identity (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: identity (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: NaN (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: NaN (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Infinity (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Infinity (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: -Infinity (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: -Infinity (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/3 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/3 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000000 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 1/300000000 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 100000 + (1/3) (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: 100000 + (1/3) (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 1 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 1 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 2 (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Math.pow(2, 53) + 2 (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MAX_VALUE (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MAX_VALUE (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MIN_VALUE (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: Number.MIN_VALUE (3d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: throwing getters (2d)] - expected: FAIL - - [DOMMatrixReadOnly stringifier: throwing getters (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: identity (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: identity (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: NaN (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: NaN (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Infinity (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Infinity (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: -Infinity (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: -Infinity (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/3 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/3 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000000 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 1/300000000 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 100000 + (1/3) (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: 100000 + (1/3) (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 1 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 1 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 2 (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Math.pow(2, 53) + 2 (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MAX_VALUE (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MAX_VALUE (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MIN_VALUE (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: Number.MIN_VALUE (3d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: throwing getters (2d)] - expected: FAIL - - [WebKitCSSMatrix stringifier: throwing getters (3d)] - expected: FAIL diff --git a/tests/wpt/meta/css/geometry/idlharness.any.js.ini b/tests/wpt/meta/css/geometry/idlharness.any.js.ini index b53b54d4cc1..2c25f767d0e 100644 --- a/tests/wpt/meta/css/geometry/idlharness.any.js.ini +++ b/tests/wpt/meta/css/geometry/idlharness.any.js.ini @@ -55,9 +55,6 @@ [DOMRectList interface: operation item(unsigned long)] expected: FAIL - [DOMMatrixReadOnly interface: stringifier] - expected: FAIL - [DOMRectList interface: existence and properties of interface object] expected: FAIL diff --git a/tests/wpt/meta/css/geometry/spec-examples.html.ini b/tests/wpt/meta/css/geometry/spec-examples.html.ini index d9abe8067fc..3e18f3b85ea 100644 --- a/tests/wpt/meta/css/geometry/spec-examples.html.ini +++ b/tests/wpt/meta/css/geometry/spec-examples.html.ini @@ -1,12 +1,3 @@ [spec-examples.html] [matrixTransform] - expected: FAIL - - [DOMMatrix 2D transformation] - expected: FAIL - - [DOMMatrix 3D transformation] - expected: FAIL - - [DOMMatrix NaN] - expected: FAIL + expected: FAIL
\ No newline at end of file |