DOMRect.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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/DOMRect.h>
  8. #include <LibWeb/WebIDL/ExceptionOr.h>
  9. namespace Web::Geometry {
  10. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height)
  11. {
  12. return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRect>(realm, realm, x, y, width, height));
  13. }
  14. WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect)
  15. {
  16. return construct_impl(realm, rect.x(), rect.y(), rect.width(), rect.height());
  17. }
  18. DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
  19. : DOMRectReadOnly(realm, x, y, width, height)
  20. {
  21. }
  22. DOMRect::~DOMRect() = default;
  23. JS::ThrowCompletionOr<void> DOMRect::initialize(JS::Realm& realm)
  24. {
  25. MUST_OR_THROW_OOM(Base::initialize(realm));
  26. set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMRectPrototype>(realm, "DOMRect"));
  27. return {};
  28. }
  29. }