DOMRectReadOnly.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/Geometry/DOMRectReadOnly.h>
  8. #include <LibWeb/WebIDL/ExceptionOr.h>
  9. namespace Web::Geometry {
  10. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> DOMRectReadOnly::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
  11. {
  12. return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectReadOnly>(realm, realm, x, y, width, height));
  13. }
  14. // https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
  15. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> DOMRectReadOnly::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
  16. {
  17. auto& realm = *vm.current_realm();
  18. return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectReadOnly>(realm, realm, other.x, other.y, other.width, other.height));
  19. }
  20. DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height)
  21. : PlatformObject(realm)
  22. , m_rect(x, y, width, height)
  23. {
  24. }
  25. DOMRectReadOnly::~DOMRectReadOnly() = default;
  26. JS::ThrowCompletionOr<void> DOMRectReadOnly::initialize(JS::Realm& realm)
  27. {
  28. MUST_OR_THROW_OOM(Base::initialize(realm));
  29. set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMRectReadOnlyPrototype>(realm, "DOMRectReadOnly"));
  30. return {};
  31. }
  32. }