DOMPointReadOnly.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/Geometry/DOMPointReadOnly.h>
  9. #include <LibWeb/WebIDL/ExceptionOr.h>
  10. namespace Web::Geometry {
  11. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMPointReadOnly>> DOMPointReadOnly::construct_impl(JS::Realm& realm, double x, double y, double z, double w)
  12. {
  13. return MUST_OR_THROW_OOM(realm.heap().allocate<DOMPointReadOnly>(realm, realm, x, y, z, w));
  14. }
  15. DOMPointReadOnly::DOMPointReadOnly(JS::Realm& realm, double x, double y, double z, double w)
  16. : PlatformObject(realm)
  17. , m_x(x)
  18. , m_y(y)
  19. , m_z(z)
  20. , m_w(w)
  21. {
  22. }
  23. // https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
  24. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMPointReadOnly>> DOMPointReadOnly::from_point(JS::VM& vm, DOMPointInit const& other)
  25. {
  26. // The fromPoint(other) static method on DOMPointReadOnly must create a DOMPointReadOnly from the dictionary other.
  27. return construct_impl(*vm.current_realm(), other.x, other.y, other.z, other.w);
  28. }
  29. DOMPointReadOnly::~DOMPointReadOnly() = default;
  30. JS::ThrowCompletionOr<void> DOMPointReadOnly::initialize(JS::Realm& realm)
  31. {
  32. MUST_OR_THROW_OOM(Base::initialize(realm));
  33. set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMPointReadOnlyPrototype>(realm, "DOMPointReadOnly"));
  34. return {};
  35. }
  36. }