ladybird/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp
Timothy Flynn b75b7f0c0d LibJS+Everywhere: Propagate Cell::initialize errors from Heap::allocate
Callers that are already in a fallible context will now TRY to allocate
cells. Callers in infallible contexts get a FIXME.
2023-01-29 00:02:45 +00:00

53 lines
1.3 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/NavigationTiming/PerformanceTiming.h>
namespace Web::HighResolutionTime {
Performance::Performance(HTML::Window& window)
: DOM::EventTarget(window.realm())
, m_window(window)
{
m_timer.start();
}
Performance::~Performance() = default;
JS::ThrowCompletionOr<void> Performance::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::PerformancePrototype>(realm, "Performance"));
return {};
}
void Performance::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_window.ptr());
visitor.visit(m_timing.ptr());
}
JS::GCPtr<NavigationTiming::PerformanceTiming> Performance::timing()
{
if (!m_timing)
m_timing = heap().allocate<NavigationTiming::PerformanceTiming>(realm(), *m_window).release_allocated_value_but_fixme_should_propagate_errors();
return m_timing;
}
double Performance::time_origin() const
{
return static_cast<double>(m_timer.origin_time().to_milliseconds());
}
}