mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:22:45 +00:00 
			
		
		
		
	LibWeb: Partially implement 'relative high resolution time' AOs
This commit is contained in:
		
							parent
							
								
									caa13bf41d
								
							
						
					
					
						commit
						d8ebdef010
					
				
					 2 changed files with 30 additions and 0 deletions
				
			
		|  | @ -6,10 +6,19 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include <AK/Time.h> | #include <AK/Time.h> | ||||||
|  | #include <LibWeb/HTML/Scripting/Environments.h> | ||||||
| #include <LibWeb/HighResolutionTime/TimeOrigin.h> | #include <LibWeb/HighResolutionTime/TimeOrigin.h> | ||||||
| 
 | 
 | ||||||
| namespace Web::HighResolutionTime { | namespace Web::HighResolutionTime { | ||||||
| 
 | 
 | ||||||
|  | // https://w3c.github.io/hr-time/#dfn-get-time-origin-timestamp
 | ||||||
|  | DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const& global) | ||||||
|  | { | ||||||
|  |     // FIXME: Implement this.
 | ||||||
|  |     (void)global; | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // https://w3c.github.io/hr-time/#dfn-coarsen-time
 | // https://w3c.github.io/hr-time/#dfn-coarsen-time
 | ||||||
| DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origin_isolated_capability) | DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origin_isolated_capability) | ||||||
| { | { | ||||||
|  | @ -18,6 +27,23 @@ DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origi | ||||||
|     return timestamp; |     return timestamp; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // https://w3c.github.io/hr-time/#dfn-relative-high-resolution-time
 | ||||||
|  | DOMHighResTimeStamp relative_high_resolution_time(DOMHighResTimeStamp time, JS::Object const& global) | ||||||
|  | { | ||||||
|  |     // 1. Let coarse time be the result of calling coarsen time with time and global's relevant settings object's cross-origin isolated capability.
 | ||||||
|  |     auto coarse_time = coarsen_time(time, HTML::relevant_settings_object(global).cross_origin_isolated_capability() == HTML::CanUseCrossOriginIsolatedAPIs::Yes); | ||||||
|  | 
 | ||||||
|  |     // 2. Return the relative high resolution coarse time for coarse time and global.
 | ||||||
|  |     return relative_high_resolution_coarsen_time(coarse_time, global); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // https://w3c.github.io/hr-time/#dfn-relative-high-resolution-coarse-time
 | ||||||
|  | DOMHighResTimeStamp relative_high_resolution_coarsen_time(DOMHighResTimeStamp coarsen_time, JS::Object const& global) | ||||||
|  | { | ||||||
|  |     // The relative high resolution coarse time given a DOMHighResTimeStamp coarseTime and a global object global, is the difference between coarseTime and the result of calling get time origin timestamp with global.
 | ||||||
|  |     return coarsen_time - get_time_origin_timestamp(global); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // https://w3c.github.io/hr-time/#dfn-coarsened-shared-current-time
 | // https://w3c.github.io/hr-time/#dfn-coarsened-shared-current-time
 | ||||||
| DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability) | DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -7,11 +7,15 @@ | ||||||
| 
 | 
 | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include <LibJS/Forward.h> | ||||||
| #include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h> | #include <LibWeb/HighResolutionTime/DOMHighResTimeStamp.h> | ||||||
| 
 | 
 | ||||||
| namespace Web::HighResolutionTime { | namespace Web::HighResolutionTime { | ||||||
| 
 | 
 | ||||||
|  | DOMHighResTimeStamp get_time_origin_timestamp(JS::Object const&); | ||||||
| DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origin_isolated_capability = false); | DOMHighResTimeStamp coarsen_time(DOMHighResTimeStamp timestamp, bool cross_origin_isolated_capability = false); | ||||||
|  | DOMHighResTimeStamp relative_high_resolution_time(DOMHighResTimeStamp, JS::Object const&); | ||||||
|  | DOMHighResTimeStamp relative_high_resolution_coarsen_time(DOMHighResTimeStamp, JS::Object const&); | ||||||
| DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability = false); | DOMHighResTimeStamp coarsened_shared_current_time(bool cross_origin_isolated_capability = false); | ||||||
| DOMHighResTimeStamp unsafe_shared_current_time(); | DOMHighResTimeStamp unsafe_shared_current_time(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh