ladybird/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp
Andreas Kling 6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00

39 lines
1,002 B
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/PerformancePrototype.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(window.realm())
, m_window(window)
, m_timing(make<NavigationTiming::PerformanceTiming>(window))
{
set_prototype(&window.ensure_web_prototype<Bindings::PerformancePrototype>("Performance"));
m_timer.start();
}
Performance::~Performance() = default;
void Performance::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_window.ptr());
}
double Performance::time_origin() const
{
auto origin = m_timer.origin_time();
return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
}
}