2022-09-21 00:24:02 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2022 ,  Andreas  Kling  < kling @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-04 21:03:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2022 ,  Linus  Groh  < linusg @ serenityos . org > 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 00:24:02 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-04 21:25:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <AK/Time.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-10-13 23:20:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/HTML/Scripting/Environments.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-10-04 21:30:29 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/HighResolutionTime/TimeOrigin.h> 
  
						 
					
						
							
								
									
										
										
										
											2022-09-21 00:24:02 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  Web : : HighResolutionTime  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-13 23:20:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 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 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 00:24:02 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								// https://w3c.github.io/hr-time/#dfn-coarsen-time
  
						 
					
						
							
								
									
										
										
										
											2022-10-04 21:13:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								DOMHighResTimeStamp  coarsen_time ( DOMHighResTimeStamp  timestamp ,  bool  cross_origin_isolated_capability )  
						 
					
						
							
								
									
										
										
										
											2022-09-21 00:24:02 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // FIXME: Implement this.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ( void ) cross_origin_isolated_capability ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  timestamp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-13 23:20:27 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// 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 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-10-04 21:03:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// https://w3c.github.io/hr-time/#dfn-coarsened-shared-current-time
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								DOMHighResTimeStamp  coarsened_shared_current_time ( bool  cross_origin_isolated_capability )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The coarsened shared current time given an optional boolean crossOriginIsolatedCapability (default false), must return the result of calling coarsen time with the unsafe shared current time and crossOriginIsolatedCapability.
 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-04 21:25:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  coarsen_time ( unsafe_shared_current_time ( ) ,  cross_origin_isolated_capability ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// https://w3c.github.io/hr-time/#dfn-unsafe-shared-current-time
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								DOMHighResTimeStamp  unsafe_shared_current_time ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // The unsafe shared current time must return the current value of the shared monotonic clock.
 
							 
						 
					
						
							
								
									
										
										
										
											2023-03-17 19:50:39 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return  MonotonicTime : : now ( ) . truncated_seconds ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-10-04 21:03:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-21 00:24:02 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}