mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 07:42:43 +00:00 
			
		
		
		
	 fc5cab5c21
			
		
	
	
		fc5cab5c21
		
	
	
	
	
		
			
			This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
		
			
				
	
	
		
			48 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <AK/Time.h>
 | |
| #include <LibJS/Contrib/Test262/AgentObject.h>
 | |
| #include <LibJS/Runtime/GlobalObject.h>
 | |
| #include <LibJS/Runtime/Object.h>
 | |
| #include <unistd.h>
 | |
| 
 | |
| namespace JS::Test262 {
 | |
| 
 | |
| AgentObject::AgentObject(Realm& realm)
 | |
|     : Object(Object::ConstructWithoutPrototypeTag::Tag, realm)
 | |
| {
 | |
| }
 | |
| 
 | |
| JS::ThrowCompletionOr<void> AgentObject::initialize(JS::Realm& realm)
 | |
| {
 | |
|     MUST_OR_THROW_OOM(Base::initialize(realm));
 | |
| 
 | |
|     u8 attr = Attribute::Writable | Attribute::Configurable;
 | |
|     define_native_function(realm, "monotonicNow", monotonic_now, 0, attr);
 | |
|     define_native_function(realm, "sleep", sleep, 1, attr);
 | |
|     // TODO: broadcast
 | |
|     // TODO: getReport
 | |
|     // TODO: start
 | |
| 
 | |
|     return {};
 | |
| }
 | |
| 
 | |
| JS_DEFINE_NATIVE_FUNCTION(AgentObject::monotonic_now)
 | |
| {
 | |
|     auto time = MonotonicTime::now();
 | |
|     auto milliseconds = time.milliseconds();
 | |
|     return Value(static_cast<double>(milliseconds));
 | |
| }
 | |
| 
 | |
| JS_DEFINE_NATIVE_FUNCTION(AgentObject::sleep)
 | |
| {
 | |
|     auto milliseconds = TRY(vm.argument(0).to_i32(vm));
 | |
|     ::usleep(milliseconds * 1000);
 | |
|     return js_undefined();
 | |
| }
 | |
| 
 | |
| }
 |