mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:07:35 +00:00
LibJS: Implement Temporal.Calendar.prototype.era()
This commit is contained in:
parent
525a7e487b
commit
f746850d1c
4 changed files with 61 additions and 0 deletions
|
@ -54,6 +54,7 @@ void CalendarPrototype::initialize(GlobalObject& global_object)
|
|||
define_native_function(vm.names.mergeFields, merge_fields, 2, attr);
|
||||
define_native_function(vm.names.toString, to_string, 0, attr);
|
||||
define_native_function(vm.names.toJSON, to_json, 0, attr);
|
||||
define_native_function(vm.names.era, era, 1, attr);
|
||||
}
|
||||
|
||||
static Calendar* typed_this(GlobalObject& global_object)
|
||||
|
@ -559,4 +560,36 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json)
|
|||
return js_string(vm, calendar.to_string(global_object));
|
||||
}
|
||||
|
||||
// 15.6.2.6 Temporal.Calendar.prototype.era ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.era
|
||||
JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::era)
|
||||
{
|
||||
auto temporal_date_like = vm.argument(0);
|
||||
|
||||
// 1. Let calendar be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]).
|
||||
auto* calendar = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. If Type(temporalDateLike) is not Object or temporalDateLike does not have an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], or [[InitializedTemporalYearMonth]] internal slot, then
|
||||
if (!temporal_date_like.is_object() || !(is<PlainDate>(temporal_date_like.as_object()) || is<PlainDateTime>(temporal_date_like.as_object()) || is<PlainYearMonth>(temporal_date_like.as_object()))) {
|
||||
// a. Set temporalDateLike to ? ToTemporalDate(temporalDateLike).
|
||||
temporal_date_like = to_temporal_date(global_object, temporal_date_like);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
}
|
||||
|
||||
// 4. If calendar.[[Identifier]] is "iso8601", then
|
||||
if (calendar->identifier() == "iso8601"sv) {
|
||||
// a. Return undefined.
|
||||
return js_undefined();
|
||||
}
|
||||
|
||||
// 5. Let era be the result of implementation-defined processing of temporalDateLike and the value of calendar.[[Identifier]].
|
||||
// 6. Return era.
|
||||
|
||||
// NOTE: No support for non-iso8601 calendars yet.
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(merge_fields);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_json);
|
||||
JS_DECLARE_NATIVE_FUNCTION(era);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue