1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:37:35 +00:00

LibJS: Add Temporal.Instant.compare()

This commit is contained in:
Idan Horowitz 2021-07-11 21:18:48 +03:00 committed by Linus Groh
parent b816037739
commit 33cf6274e8
6 changed files with 49 additions and 0 deletions

View file

@ -31,6 +31,7 @@ void InstantConstructor::initialize(GlobalObject& global_object)
define_native_function(vm.names.fromEpochMilliseconds, from_epoch_milliseconds, 1, attr);
define_native_function(vm.names.fromEpochMicroseconds, from_epoch_microseconds, 1, attr);
define_native_function(vm.names.fromEpochNanoseconds, from_epoch_nanoseconds, 1, attr);
define_native_function(vm.names.compare, compare, 2, attr);
define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
}
@ -158,4 +159,21 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_nanoseconds)
return create_temporal_instant(global_object, *epoch_nanoseconds);
}
// 8.2.7 Temporal.Instant.compare ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal.instant.compare
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::compare)
{
// 1. Set one to ? ToTemporalInstant(one).
auto* one = to_temporal_instant(global_object, vm.argument(0));
if (vm.exception())
return {};
// 2. Set two to ? ToTemporalInstant(two).
auto* two = to_temporal_instant(global_object, vm.argument(1));
if (vm.exception())
return {};
// 3. Return 𝔽(! CompareEpochNanoseconds(one.[[Nanoseconds]], two.[[Nanoseconds]])).
return Value(compare_epoch_nanoseconds(one->nanoseconds(), two->nanoseconds()));
}
}