mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibJS: Implement Temporal.PlainYearMonth.prototype.monthCode
This commit is contained in:
parent
0edec6578b
commit
5ec70792fd
Notes:
sideshowbarker
2024-07-18 07:13:09 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/5ec70792fda Pull-request: https://github.com/SerenityOS/serenity/pull/9273 Reviewed-by: https://github.com/IdanHo ✅
|
@ -30,6 +30,7 @@ void PlainYearMonthPrototype::initialize(GlobalObject& global_object)
|
|||
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.year, year_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.month, month_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
||||
}
|
||||
|
||||
static PlainYearMonth* typed_this(GlobalObject& global_object)
|
||||
|
@ -90,4 +91,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::month_getter)
|
|||
return Value(calendar_month(global_object, calendar, *year_month));
|
||||
}
|
||||
|
||||
// 9.3.6 get Temporal.PlainYearMonth.prototype.monthCode, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.monthCode
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::month_code_getter)
|
||||
{
|
||||
// 1. Let yearMonth be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
|
||||
auto* year_month = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Let calendar be yearMonth.[[Calendar]].
|
||||
auto& calendar = year_month->calendar();
|
||||
|
||||
// 4. Return ? CalendarMonthCode(calendar, yearMonth).
|
||||
return js_string(vm, calendar_month_code(global_object, calendar, *year_month));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(year_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(2021, 7);
|
||||
expect(plainYearMonth.monthCode).toBe("M07");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainYearMonth object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainYearMonth.prototype, "monthCode", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue