2022-03-29 16:36:22 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <AK/Time.h>
|
2024-12-14 09:38:54 -03:00
|
|
|
#include <LibCore/System.h>
|
2022-03-29 16:36:22 -03:00
|
|
|
#include <LibJS/Contrib/Test262/AgentObject.h>
|
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
|
|
namespace JS::Test262 {
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(AgentObject);
|
2023-11-19 05:45:05 -03:00
|
|
|
|
2022-08-15 20:20:49 -03:00
|
|
|
AgentObject::AgentObject(Realm& realm)
|
|
|
|
|
: Object(Object::ConstructWithoutPrototypeTag::Tag, realm)
|
2022-03-29 16:36:22 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
void AgentObject::initialize(JS::Realm& realm)
|
2022-03-29 16:36:22 -03:00
|
|
|
{
|
2023-08-07 03:41:28 -03:00
|
|
|
Base::initialize(realm);
|
2022-03-29 16:36:22 -03:00
|
|
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
2025-08-02 20:27:29 -03:00
|
|
|
define_native_function(realm, "monotonicNow"_utf16_fly_string, monotonic_now, 0, attr);
|
|
|
|
|
define_native_function(realm, "sleep"_utf16_fly_string, sleep, 1, attr);
|
2022-03-29 16:36:22 -03:00
|
|
|
// TODO: broadcast
|
|
|
|
|
// TODO: getReport
|
|
|
|
|
// TODO: start
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS_DEFINE_NATIVE_FUNCTION(AgentObject::monotonic_now)
|
|
|
|
|
{
|
2023-03-17 15:50:39 -03:00
|
|
|
auto time = MonotonicTime::now();
|
|
|
|
|
auto milliseconds = time.milliseconds();
|
2022-03-29 16:36:22 -03:00
|
|
|
return Value(static_cast<double>(milliseconds));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JS_DEFINE_NATIVE_FUNCTION(AgentObject::sleep)
|
|
|
|
|
{
|
2022-08-21 10:00:56 -03:00
|
|
|
auto milliseconds = TRY(vm.argument(0).to_i32(vm));
|
2024-12-14 09:38:54 -03:00
|
|
|
(void)Core::System::sleep_ms(milliseconds);
|
2022-03-29 16:36:22 -03:00
|
|
|
return js_undefined();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|