Serenity Operating System
at master 38 lines 1.1 kB view raw
1/* 2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibWeb/Bindings/Intrinsics.h> 8#include <LibWeb/Geometry/DOMRect.h> 9#include <LibWeb/WebIDL/ExceptionOr.h> 10 11namespace Web::Geometry { 12 13WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::construct_impl(JS::Realm& realm, double x, double y, double width, double height) 14{ 15 return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRect>(realm, realm, x, y, width, height)); 16} 17 18WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const& rect) 19{ 20 return construct_impl(realm, rect.x(), rect.y(), rect.width(), rect.height()); 21} 22 23DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height) 24 : DOMRectReadOnly(realm, x, y, width, height) 25{ 26} 27 28DOMRect::~DOMRect() = default; 29 30JS::ThrowCompletionOr<void> DOMRect::initialize(JS::Realm& realm) 31{ 32 MUST_OR_THROW_OOM(Base::initialize(realm)); 33 set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMRectPrototype>(realm, "DOMRect")); 34 35 return {}; 36} 37 38}