mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibJS: Add calendar id getter to PlainYearMonthPrototype
This commit is contained in:
parent
44fa8410c0
commit
0e1e8c908e
Notes:
github-actions[bot]
2024-10-30 09:31:03 +00:00
Author: https://github.com/shlyakpavel Commit: https://github.com/LadybirdBrowser/ladybird/commit/0e1e8c908e5 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1960
3 changed files with 29 additions and 0 deletions
|
@ -34,6 +34,7 @@ void PlainYearMonthPrototype::initialize(Realm& realm)
|
|||
define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal.PlainYearMonth"_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.year, year_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.month, month_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
||||
|
@ -447,4 +448,16 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields)
|
|||
return fields;
|
||||
}
|
||||
|
||||
// 9.3.3 get Temporal.PlainYearMonth.prototype.calendarId
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::calendar_id_getter)
|
||||
{
|
||||
// Step 1: Let yearMonth be the this value
|
||||
// Step 2: Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
||||
auto year_month = TRY(typed_this_object(vm));
|
||||
|
||||
// Step 3: Return yearMonth.[[Calendar]].identifier
|
||||
auto& calendar = static_cast<Calendar&>(year_month->calendar());
|
||||
return PrimitiveString::create(vm, calendar.identifier());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ private:
|
|||
explicit PlainYearMonthPrototype(Realm&);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar_id_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(year_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
describe("correct behavior", () => {
|
||||
test("calendarId basic functionality", () => {
|
||||
const calendar = "iso8601";
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5, calendar);
|
||||
expect(plainYearMonth.calendarId).toBe("iso8601");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainYearMonth object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainYearMonth.prototype, "calendarId", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue