mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Add calendar id getter to ZonedDateTimePrototype
This commit is contained in:
parent
2ad48b64ca
commit
ba71cb1ca4
Notes:
github-actions[bot]
2024-10-30 09:30:50 +00:00
Author: https://github.com/shlyakpavel Commit: https://github.com/LadybirdBrowser/ladybird/commit/ba71cb1ca43 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1960
3 changed files with 34 additions and 0 deletions
|
@ -38,6 +38,7 @@ void ZonedDateTimePrototype::initialize(Realm& realm)
|
|||
define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal.ZonedDateTime"_string), Attribute::Configurable);
|
||||
|
||||
define_native_accessor(realm, vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.calendarId, calendar_id_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.timeZone, time_zone_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.year, year_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.month, month_getter, {}, Attribute::Configurable);
|
||||
|
@ -1401,4 +1402,17 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields)
|
|||
return fields;
|
||||
}
|
||||
|
||||
// 6.3.3 get Temporal.ZonedDateTime.prototype.calendarId
|
||||
// https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.calendarid
|
||||
JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::calendar_id_getter)
|
||||
{
|
||||
// 1. Let zonedDateTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(zonedDateTime, [[InitializedTemporalZonedDateTime]]).
|
||||
auto zoned_date_time = TRY(typed_this_object(vm));
|
||||
|
||||
// 3. Return zonedDateTime.[[Calendar]].identifier
|
||||
auto& calendar = static_cast<Calendar&>(zoned_date_time->calendar());
|
||||
return PrimitiveString::create(vm, calendar.identifier());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ private:
|
|||
explicit ZonedDateTimePrototype(Realm&);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar_id_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(time_zone_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(year_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_getter);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
describe("correct behavior", () => {
|
||||
test("calendarId basic functionality", () => {
|
||||
const calendar = "iso8601";
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(
|
||||
0n,
|
||||
Temporal.TimeZone.from("UTC"),
|
||||
Temporal.Calendar.from(calendar)
|
||||
);
|
||||
expect(zonedDateTime.calendarId).toBe("iso8601");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.ZonedDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.ZonedDateTime.prototype, "calendarId", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue