mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:47:45 +00:00
LibJS: Implement Temporal.Instant.fromEpochNanoseconds()
This commit is contained in:
parent
5872357b56
commit
ca71d99c66
4 changed files with 72 additions and 0 deletions
|
@ -145,6 +145,7 @@ namespace JS {
|
|||
P(fromEntries) \
|
||||
P(fromEpochMicroseconds) \
|
||||
P(fromEpochMilliseconds) \
|
||||
P(fromEpochNanoseconds) \
|
||||
P(fromEpochSeconds) \
|
||||
P(fround) \
|
||||
P(gc) \
|
||||
|
|
|
@ -30,6 +30,7 @@ void InstantConstructor::initialize(GlobalObject& global_object)
|
|||
define_native_function(vm.names.fromEpochSeconds, from_epoch_seconds, 1, attr);
|
||||
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_direct_property(vm.names.length, Value(1), Attribute::Configurable);
|
||||
}
|
||||
|
@ -139,4 +140,22 @@ JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_microseconds)
|
|||
return create_temporal_instant(global_object, *epoch_nanoseconds);
|
||||
}
|
||||
|
||||
// 8.2.6 Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds )
|
||||
JS_DEFINE_NATIVE_FUNCTION(InstantConstructor::from_epoch_nanoseconds)
|
||||
{
|
||||
// 1. Set epochNanoseconds to ? ToBigInt(epochNanoseconds).
|
||||
auto* epoch_nanoseconds = vm.argument(0).to_bigint(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 2. If ! IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception.
|
||||
if (!is_valid_epoch_nanoseconds(*epoch_nanoseconds)) {
|
||||
vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidEpochNanoseconds);
|
||||
return {};
|
||||
}
|
||||
|
||||
// 3. Return ? CreateTemporalInstant(epochNanoseconds).
|
||||
return create_temporal_instant(global_object, *epoch_nanoseconds);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(from_epoch_seconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(from_epoch_milliseconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(from_epoch_microseconds);
|
||||
JS_DECLARE_NATIVE_FUNCTION(from_epoch_nanoseconds);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue