mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:17:35 +00:00
LibJS: Implement Temporal.Instant.prototype.epochMicroseconds
This commit is contained in:
parent
b157ab3f12
commit
b5d0cdc97e
4 changed files with 56 additions and 0 deletions
|
@ -113,6 +113,7 @@ namespace JS {
|
|||
P(endsWith) \
|
||||
P(entries) \
|
||||
P(enumerable) \
|
||||
P(epochMicroseconds) \
|
||||
P(epochMilliseconds) \
|
||||
P(epochSeconds) \
|
||||
P(error) \
|
||||
|
|
|
@ -25,6 +25,7 @@ void InstantPrototype::initialize(GlobalObject& global_object)
|
|||
|
||||
define_native_accessor(vm.names.epochSeconds, epoch_seconds_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.epochMilliseconds, epoch_milliseconds_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.epochMicroseconds, epoch_microseconds_getter, {}, Attribute::Configurable);
|
||||
|
||||
// 8.3.2 Temporal.Instant.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal.Instant"), Attribute::Configurable);
|
||||
|
@ -81,4 +82,23 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_milliseconds_getter)
|
|||
return Value((double)ms.to_base(10).to_int<i64>().value());
|
||||
}
|
||||
|
||||
// 8.3.5 get Temporal.Instant.prototype.epochMicroseconds, https://tc39.es/proposal-temporal/#sec-get-temporal.instant.prototype.epochmicroseconds
|
||||
JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_microseconds_getter)
|
||||
{
|
||||
// 1. Let instant be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
|
||||
auto* instant = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Let ns be instant.[[Nanoseconds]].
|
||||
auto& ns = instant->nanoseconds();
|
||||
|
||||
// 4. Let µs be RoundTowardsZero(ℝ(ns) / 10^3).
|
||||
auto [us, _] = ns.big_integer().divided_by(Crypto::SignedBigInteger::create_from(1'000));
|
||||
|
||||
// 5. Return ℤ(µs).
|
||||
return js_bigint(vm.heap(), move(us));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(epoch_seconds_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(epoch_milliseconds_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(epoch_microseconds_getter);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue