mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
LibJS: Implement Temporal.PlainMonthDay.prototype.day
This commit is contained in:
parent
9551aa17d3
commit
c2ed3ad66b
Notes:
sideshowbarker
2024-07-18 05:41:47 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/c2ed3ad66bf Pull-request: https://github.com/SerenityOS/serenity/pull/9429 Reviewed-by: https://github.com/IdanHo ✅
@ -29,6 +29,7 @@ void PlainMonthDayPrototype::initialize(GlobalObject& global_object)
|
||||
|
||||
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.monthCode, month_code_getter, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.day, day_getter, {}, Attribute::Configurable);
|
||||
}
|
||||
|
||||
static PlainMonthDay* typed_this(GlobalObject& global_object)
|
||||
@ -73,4 +74,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::month_code_getter)
|
||||
return js_string(vm, calendar_month_code(global_object, calendar, *month_day));
|
||||
}
|
||||
|
||||
// 10.3.5 get Temporal.PlainMonthDay.prototype.day, https://tc39.es/proposal-temporal/#sec-get-temporal.plainmonthday.prototype.day
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::day_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 𝔽(? CalendarDay(calendar, monthDay)).
|
||||
return Value(calendar_day(global_object, calendar, *month_day));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(day_getter);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(7, 6);
|
||||
expect(plainMonthDay.day).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a Temporal.PlainMonthDay object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainMonthDay.prototype, "day", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainMonthDay");
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user