ladybird/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp
Linus Groh 40a70461a0 LibWeb: Replace GlobalObject with Realm in wrapper functions
Similar to create() in LibJS, wrap() et al. are on a low enough level to
warrant passing a Realm directly instead of relying on the current realm
from the VM, as a wrapper may need to be allocated while no JS is being
executed.
2022-08-23 13:58:30 +01:00

47 lines
996 B
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/PerformanceWrapper.h>
#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>
namespace Web::HighResolutionTime {
Performance::Performance(HTML::Window& window)
: DOM::EventTarget()
, m_window(window)
, m_timing(make<NavigationTiming::PerformanceTiming>(window))
{
m_timer.start();
}
Performance::~Performance() = default;
double Performance::time_origin() const
{
auto origin = m_timer.origin_time();
return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
}
void Performance::ref_event_target()
{
m_window.ref();
}
void Performance::unref_event_target()
{
m_window.unref();
}
JS::Object* Performance::create_wrapper(JS::Realm& realm)
{
return Bindings::wrap(realm, *this);
}
}