mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-25 18:58:56 +00:00
LibJS: Add calendar id getter to PlainMonthDayPrototype
This commit is contained in:
parent
0e1e8c908e
commit
2ad48b64ca
Notes:
github-actions[bot]
2024-10-30 09:30:57 +00:00
Author: https://github.com/shlyakpavel
Commit: 2ad48b64ca
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1960
3 changed files with 29 additions and 0 deletions
|
@ -32,6 +32,7 @@ void PlainMonthDayPrototype::initialize(Realm& realm)
|
||||||
define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal.PlainMonthDay"_string), Attribute::Configurable);
|
define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal.PlainMonthDay"_string), Attribute::Configurable);
|
||||||
|
|
||||||
define_native_accessor(realm, vm.names.calendar, calendar_getter, {}, 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.monthCode, month_code_getter, {}, Attribute::Configurable);
|
define_native_accessor(realm, vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
||||||
define_native_accessor(realm, vm.names.day, day_getter, {}, Attribute::Configurable);
|
define_native_accessor(realm, vm.names.day, day_getter, {}, Attribute::Configurable);
|
||||||
|
|
||||||
|
@ -280,4 +281,16 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields)
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 10.3.3 get Temporal.PlainMonthDay.prototype.calendarId
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::calendar_id_getter)
|
||||||
|
{
|
||||||
|
// Step 1: Let monthDay be the this value
|
||||||
|
// Step 2: Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
||||||
|
auto month_day = TRY(typed_this_object(vm));
|
||||||
|
|
||||||
|
// Step 3: Return monthDay.[[Calendar]].
|
||||||
|
auto& calendar = static_cast<Calendar&>(month_day->calendar());
|
||||||
|
return PrimitiveString::create(vm, calendar.identifier());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ private:
|
||||||
explicit PlainMonthDayPrototype(Realm&);
|
explicit PlainMonthDayPrototype(Realm&);
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(calendar_id_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(day_getter);
|
JS_DECLARE_NATIVE_FUNCTION(day_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(with);
|
JS_DECLARE_NATIVE_FUNCTION(with);
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
describe("correct behavior", () => {
|
||||||
|
test("calendarId basic functionality", () => {
|
||||||
|
const calendar = "iso8601";
|
||||||
|
const plainMonthDay = new Temporal.PlainMonthDay(5, 1, calendar);
|
||||||
|
expect(plainMonthDay.calendarId).toBe("iso8601");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("errors", () => {
|
||||||
|
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||||
|
expect(() => {
|
||||||
|
Reflect.get(Temporal.PlainMonthDay.prototype, "calendarId", "foo");
|
||||||
|
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.PlainMonthDay");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue