LibWeb: Validate arguments when creating DOMPoint from matrix transform

Previously, it was possible to create a DOMPoint from a matrix
transform with inconsistent arguments. A TypeError is now thrown in
this case.
This commit is contained in:
Tim Ledbetter 2024-02-17 08:09:53 +00:00 committed by Jelle Raaijmakers
parent c5d1ec4dea
commit fe66aeb225
Notes: sideshowbarker 2024-07-16 21:30:46 +09:00
3 changed files with 14 additions and 2 deletions

View File

@ -4,3 +4,4 @@
4. {"x":750,"y":1060,"z":0,"w":1}
5. {"x":750,"y":1060,"z":0,"w":1}
6. {"x":750,"y":1060,"z":0,"w":1}
7. Exception: TypeError

View File

@ -3,7 +3,12 @@
test(() => {
let testCounter = 1;
function testPart(part) {
println(`${testCounter++}. ${JSON.stringify(part())}`);
try {
println(`${testCounter}. ${JSON.stringify(part())}`);
} catch (e) {
println(`${testCounter}. Exception: ${e.name}`);
}
testCounter++;
}
// 1. Creating a DOMPoint
@ -33,5 +38,11 @@
const matrix = new DOMMatrix([10, 20, 30, 40, 50, 60]);
return matrix.transformPoint({x: 10, y: 20});
});
// 7. Transforming a point using a matrixTransform with an invalid DOMMatrixInit
testPart(function () {
const point = new DOMPoint(10, 20);
return point.matrixTransform({ is2D: true, m33: 1.0000001 });
});
});
</script>

View File

@ -41,7 +41,7 @@ DOMPointReadOnly::~DOMPointReadOnly() = default;
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMPoint>> DOMPointReadOnly::matrix_transform(DOMMatrixInit& matrix) const
{
// 1. Let matrixObject be the result of invoking create a DOMMatrix from the dictionary matrix.
auto matrix_object = TRY(DOMMatrix::create_from_dom_matrix_2d_init(realm(), matrix));
auto matrix_object = TRY(DOMMatrix::create_from_dom_matrix_init(realm(), matrix));
// 2. Return the result of invoking transform a point with a matrix, given the current point and matrixObject. The current point does not get modified.
return matrix_object->transform_point(*this);