mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:12:43 +00:00 
			
		
		
		
	 ffad902c07
			
		
	
	
		ffad902c07
		
	
	
	
	
		
			
			Unlike ensure_web_prototype<T>(), the cached version doesn't require the prototype type to be fully formed, so we can use it without including the FooPrototype.h header. It's also a bit less verbose. :^)
		
			
				
	
	
		
			46 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
	
		
			1.1 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)
 | |
| {
 | |
|     set_prototype(&window.cached_web_prototype("Performance"));
 | |
|     m_timer.start();
 | |
| }
 | |
| 
 | |
| Performance::~Performance() = default;
 | |
| 
 | |
| 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);
 | |
|     return m_timing;
 | |
| }
 | |
| 
 | |
| double Performance::time_origin() const
 | |
| {
 | |
|     auto origin = m_timer.origin_time();
 | |
|     return (origin.tv_sec * 1000.0) + (origin.tv_usec / 1000.0);
 | |
| }
 | |
| 
 | |
| }
 |