1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:47:44 +00:00

LibJS: Implement Temporal.ZonedDateTime.prototype.toInstant()

This commit is contained in:
Linus Groh 2021-08-05 21:48:23 +01:00
parent 20300bd7c4
commit 96a0c201d5
4 changed files with 37 additions and 0 deletions

View file

@ -59,6 +59,7 @@ void ZonedDateTimePrototype::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.toInstant, to_instant, 0, attr);
}
static ZonedDateTime* typed_this(GlobalObject& global_object)
@ -702,4 +703,17 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::value_of)
return {};
}
// 6.3.46 Temporal.ZonedDateTime.prototype.toInstant ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toinstant
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_instant)
{
// 1. Let zonedDateTime be the this value.
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
auto* zoned_date_time = typed_this(global_object);
if (vm.exception())
return {};
// 3. Return ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
return create_temporal_instant(global_object, zoned_date_time->nanoseconds());
}
}

View file

@ -46,6 +46,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(offset_nanoseconds_getter);
JS_DECLARE_NATIVE_FUNCTION(offset_getter);
JS_DECLARE_NATIVE_FUNCTION(value_of);
JS_DECLARE_NATIVE_FUNCTION(to_instant);
};
}