mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:02:43 +00:00 
			
		
		
		
	 834202aeb9
			
		
	
	
		834202aeb9
		
	
	
	
	
		
			
			This needs to happen before prototype/constructor intitialization can be made lazy. Otherwise, GC could run during the C++ constructor and try to collect the object currently being created.
		
			
				
	
	
		
			50 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
	
		
			1.2 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;
 | |
| 
 | |
| void Performance::initialize(JS::Realm& realm)
 | |
| {
 | |
|     Base::initialize(realm);
 | |
|     set_prototype(&Bindings::ensure_web_prototype<Bindings::PerformancePrototype>(realm, "Performance"));
 | |
| }
 | |
| 
 | |
| 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
 | |
| {
 | |
|     return static_cast<double>(m_timer.origin_time().to_milliseconds());
 | |
| }
 | |
| 
 | |
| }
 |