mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:47:45 +00:00
LibJS: Add Temporal.Instant.prototype.equals()
This commit is contained in:
parent
84403ab423
commit
2382f67e0b
4 changed files with 41 additions and 0 deletions
|
@ -118,6 +118,7 @@ namespace JS {
|
|||
P(epochMilliseconds) \
|
||||
P(epochNanoseconds) \
|
||||
P(epochSeconds) \
|
||||
P(equals) \
|
||||
P(error) \
|
||||
P(errors) \
|
||||
P(escape) \
|
||||
|
|
|
@ -33,6 +33,7 @@ void InstantPrototype::initialize(GlobalObject& global_object)
|
|||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
define_native_function(vm.names.equals, equals, 1, attr);
|
||||
}
|
||||
|
||||
static Instant* typed_this(GlobalObject& global_object)
|
||||
|
@ -121,6 +122,28 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::epoch_nanoseconds_getter)
|
|||
return &ns;
|
||||
}
|
||||
|
||||
// 8.3.12 Temporal.Instant.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.equals
|
||||
JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::equals)
|
||||
{
|
||||
// 1. Let instant be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(instant, [[InitializedTemporalInstant]]).
|
||||
auto* instant = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Set other to ? ToTemporalInstant(other).
|
||||
auto other = to_temporal_instant(global_object, vm.argument(0));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 4. If instant.[[Nanoseconds]] ≠ other.[[Nanoseconds]], return false.
|
||||
if (instant->nanoseconds().big_integer() != other->nanoseconds().big_integer())
|
||||
return Value(false);
|
||||
|
||||
// 5. Return true.
|
||||
return Value(true);
|
||||
}
|
||||
|
||||
// 8.3.16 Temporal.Instant.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::value_of)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(epoch_microseconds_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(epoch_nanoseconds_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(equals);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue