mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Add {,de}serialization steps for DOMPointReadonly
This commit is contained in:
parent
8d2f7cfb58
commit
bf4fb39bfb
Notes:
sideshowbarker
2024-07-16 23:34:49 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/bf4fb39bfb Pull-request: https://github.com/SerenityOS/serenity/pull/23538 Reviewed-by: https://github.com/ADKaster
5 changed files with 59 additions and 1 deletions
|
@ -12,3 +12,5 @@ DOMMatrixReadOnly: {"a":10,"b":20,"c":50,"d":60,"e":130,"f":140,"m11":10,"m12":2
|
|||
instanceOf DOMMatrix: true
|
||||
DOMMatrix: {"a":10,"b":20,"c":30,"d":40,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
|
||||
DOMMatrix: {"a":10,"b":20,"c":50,"d":60,"e":130,"f":140,"m11":10,"m12":20,"m13":30,"m14":40,"m21":50,"m22":60,"m23":70,"m24":80,"m31":90,"m32":100,"m33":110,"m34":120,"m41":130,"m42":140,"m43":150,"m44":160,"is2D":false,"isIdentity":false}
|
||||
instanceOf DOMPointReadOnly: true
|
||||
DOMPointReadOnly: {"x":10,"y":20,"z":30,"w":40}
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
domMatrix = structuredClone(new DOMMatrix([10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]));
|
||||
println(`DOMMatrix: ${JSON.stringify(domMatrix)}`);
|
||||
|
||||
let domPointReadOnly = structuredClone(new DOMPointReadOnly(10, 20, 30, 40));
|
||||
println(`instanceOf DOMPointReadOnly: ${domPointReadOnly instanceof DOMPointReadOnly}`);
|
||||
println(`DOMPointReadOnly: ${JSON.stringify(domPointReadOnly)}`);
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2024, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,6 +9,7 @@
|
|||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Geometry/DOMMatrix.h>
|
||||
#include <LibWeb/Geometry/DOMPointReadOnly.h>
|
||||
#include <LibWeb/HTML/StructuredSerialize.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::Geometry {
|
||||
|
@ -19,6 +21,11 @@ JS::NonnullGCPtr<DOMPointReadOnly> DOMPointReadOnly::construct_impl(JS::Realm& r
|
|||
return realm.heap().allocate<DOMPointReadOnly>(realm, realm, x, y, z, w);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<DOMPointReadOnly> DOMPointReadOnly::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<DOMPointReadOnly>(realm, realm);
|
||||
}
|
||||
|
||||
DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double z, double w)
|
||||
: PlatformObject(realm)
|
||||
, m_x(x)
|
||||
|
@ -28,6 +35,11 @@ DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double
|
|||
{
|
||||
}
|
||||
|
||||
DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm)
|
||||
: PlatformObject(realm)
|
||||
{
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
|
||||
JS::NonnullGCPtr<DOMPointReadOnly> DOMPointReadOnly::from_point(JS::VM& vm, DOMPointInit const& other)
|
||||
{
|
||||
|
@ -53,4 +65,31 @@ void DOMPointReadOnly::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(DOMPointReadOnly);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> DOMPointReadOnly::serialization_steps(HTML::SerializationRecord& serialized, bool)
|
||||
{
|
||||
// 1. Set serialized.[[X]] to value’s x coordinate.
|
||||
HTML::serialize_primitive_type(serialized, m_x);
|
||||
// 2. Set serialized.[[Y]] to value’s y coordinate.
|
||||
HTML::serialize_primitive_type(serialized, m_y);
|
||||
// 3. Set serialized.[[Z]] to value’s z coordinate.
|
||||
HTML::serialize_primitive_type(serialized, m_z);
|
||||
// 4. Set serialized.[[W]] to value’s w coordinate.
|
||||
HTML::serialize_primitive_type(serialized, m_w);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> DOMPointReadOnly::deserialization_steps(ReadonlySpan<u32> const& serialized, size_t& position)
|
||||
{
|
||||
// 1. Set value’s x coordinate to serialized.[[X]].
|
||||
m_x = HTML::deserialize_primitive_type<double>(serialized, position);
|
||||
// 2. Set value’s y coordinate to serialized.[[Y]].
|
||||
m_y = HTML::deserialize_primitive_type<double>(serialized, position);
|
||||
// 3. Set value’s z coordinate to serialized.[[Z]].
|
||||
m_z = HTML::deserialize_primitive_type<double>(serialized, position);
|
||||
// 4. Set value’s w coordinate to serialized.[[W]].
|
||||
m_w = HTML::deserialize_primitive_type<double>(serialized, position);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2024, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -9,6 +10,7 @@
|
|||
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Bindings/Serializable.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Geometry {
|
||||
|
@ -21,12 +23,15 @@ struct DOMPointInit {
|
|||
};
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dompointreadonly
|
||||
class DOMPointReadOnly : public Bindings::PlatformObject {
|
||||
class DOMPointReadOnly
|
||||
: public Bindings::PlatformObject
|
||||
, public Bindings::Serializable {
|
||||
WEB_PLATFORM_OBJECT(DOMPointReadOnly, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(DOMPointReadOnly);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<DOMPointReadOnly> construct_impl(JS::Realm&, double x = 0, double y = 0, double z = 0, double w = 1);
|
||||
static JS::NonnullGCPtr<DOMPointReadOnly> create(JS::Realm&);
|
||||
|
||||
static JS::NonnullGCPtr<DOMPointReadOnly> from_point(JS::VM&, DOMPointInit const&);
|
||||
|
||||
|
@ -39,8 +44,13 @@ public:
|
|||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMPoint>> matrix_transform(DOMMatrixInit&) const;
|
||||
|
||||
virtual StringView interface_name() const override { return "DOMPointReadOnly"sv; }
|
||||
virtual WebIDL::ExceptionOr<void> serialization_steps(HTML::SerializationRecord&, bool for_storage) override;
|
||||
virtual WebIDL::ExceptionOr<void> deserialization_steps(ReadonlySpan<u32> const&, size_t& position) override;
|
||||
|
||||
protected:
|
||||
DOMPointReadOnly(JS::Realm&, double x, double y, double z, double w);
|
||||
explicit DOMPointReadOnly(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <LibWeb/FileAPI/File.h>
|
||||
#include <LibWeb/Geometry/DOMMatrix.h>
|
||||
#include <LibWeb/Geometry/DOMMatrixReadOnly.h>
|
||||
#include <LibWeb/Geometry/DOMPointReadOnly.h>
|
||||
#include <LibWeb/HTML/MessagePort.h>
|
||||
#include <LibWeb/HTML/StructuredSerialize.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
@ -969,6 +970,8 @@ private:
|
|||
return Geometry::DOMMatrixReadOnly::create(realm);
|
||||
if (interface_name == "DOMMatrix"sv)
|
||||
return Geometry::DOMMatrix::create(realm);
|
||||
if (interface_name == "DOMPointReadOnly"sv)
|
||||
return Geometry::DOMPointReadOnly::create(realm);
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue