mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:47:44 +00:00
LibJS: Implement Temporal.PlainTime.prototype.toPlainDateTime
This commit is contained in:
parent
8f9b4a5ea6
commit
d1ee31c5de
4 changed files with 43 additions and 0 deletions
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainDateTime.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainTime.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainTimePrototype.h>
|
||||
|
||||
|
@ -35,6 +37,7 @@ void PlainTimePrototype::initialize(GlobalObject& global_object)
|
|||
define_native_accessor(vm.names.nanosecond, nanosecond_getter, {}, Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.toPlainDateTime, to_plain_date_time, 1, attr);
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
}
|
||||
|
||||
|
@ -142,6 +145,24 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::nanosecond_getter)
|
|||
return Value(temporal_time->iso_nanosecond());
|
||||
}
|
||||
|
||||
// 4.3.17 Temporal.PlainTime.prototype.toPlainDateTime ( temporalDate )
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::to_plain_date_time)
|
||||
{
|
||||
// 1. Let temporalTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
||||
auto* temporal_time = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Set temporalDate to ? ToTemporalDate(temporalDate).
|
||||
auto* temporal_date = to_temporal_date(global_object, vm.argument(0));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 4. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
|
||||
return create_temporal_date_time(global_object, temporal_date->iso_year(), temporal_date->iso_month(), temporal_date->iso_day(), temporal_time->iso_hour(), temporal_time->iso_minute(), temporal_time->iso_second(), temporal_time->iso_millisecond(), temporal_time->iso_microsecond(), temporal_time->iso_nanosecond(), temporal_date->calendar());
|
||||
}
|
||||
|
||||
// 4.3.23 Temporal.PlainTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::value_of)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(millisecond_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(microsecond_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(nanosecond_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_plain_date_time);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue