mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
LibJS: Implement Temporal.PlainMonthDay.prototype.monthCode
This commit is contained in:
parent
1382be1707
commit
9551aa17d3
3 changed files with 33 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainMonthDay.h>
|
||||
#include <LibJS/Runtime/Temporal/PlainMonthDayPrototype.h>
|
||||
|
||||
|
@ -27,6 +28,7 @@ void PlainMonthDayPrototype::initialize(GlobalObject& global_object)
|
|||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal.PlainMonthDay"), Attribute::Configurable);
|
||||
|
||||
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
||||
}
|
||||
|
||||
static PlainMonthDay* typed_this(GlobalObject& global_object)
|
||||
|
@ -55,4 +57,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::calendar_getter)
|
|||
return Value(&plain_month_day->calendar());
|
||||
}
|
||||
|
||||
// 10.3.4 get Temporal.PlainMonthDay.prototype.monthCode, https://tc39.es/proposal-temporal/#sec-get-temporal.plainmonthday.prototype.monthcode
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::month_code_getter)
|
||||
{
|
||||
// 1. Let monthDay be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
|
||||
auto* month_day = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Let calendar be monthDay.[[Calendar]].
|
||||
auto& calendar = month_day->calendar();
|
||||
|
||||
// 4. Return ? CalendarMonthCode(calendar, monthDay).
|
||||
return js_string(vm, calendar_month_code(global_object, calendar, *month_day));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(plainMonthDay.monthCode).toBe("M07");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainMonthDay.prototype, "monthCode", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainMonthDay");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue