mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibJS: Implement Temporal.PlainDateTime.prototype.day
This commit is contained in:
parent
677a631e87
commit
f93b6ea58c
Notes:
sideshowbarker
2024-07-18 07:46:25 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/f93b6ea58c3 Pull-request: https://github.com/SerenityOS/serenity/pull/9097 Reviewed-by: https://github.com/linusg ✅
3 changed files with 32 additions and 0 deletions
|
@ -31,6 +31,7 @@ void PlainDateTimePrototype::initialize(GlobalObject& global_object)
|
|||
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);
|
||||
define_native_accessor(vm.names.day, day_getter, {}, Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
||||
|
@ -112,6 +113,22 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::month_code_getter)
|
|||
return js_string(vm, calendar_month_code(global_object, calendar, *date_time));
|
||||
}
|
||||
|
||||
// 5.3.7 get Temporal.PlainDateTime.prototype.day, https://tc39.es/proposal-temporal/#sec-get-temporal.plaindatetime.prototype.day
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::day_getter)
|
||||
{
|
||||
// 1. Let dateTime be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(dateTime, [[InitializedTemporalDateTime]]).
|
||||
auto* date_time = typed_this(global_object);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
// 3. Let calendar be dateTime.[[Calendar]].
|
||||
auto& calendar = date_time->calendar();
|
||||
|
||||
// 4. Return ? CalendarDay(calendar, dateTime).
|
||||
return Value(calendar_day(global_object, calendar, *date_time));
|
||||
}
|
||||
|
||||
// 5.3.35 Temporal.PlainDateTime.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.valueof
|
||||
JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::value_of)
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(year_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(day_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(value_of);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_plain_date);
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_iso_fields);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
describe("correct behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 29);
|
||||
expect(plainDateTime.day).toBe(29);
|
||||
});
|
||||
});
|
||||
|
||||
test("errors", () => {
|
||||
test("this value must be a Temporal.PlainDateTime object", () => {
|
||||
expect(() => {
|
||||
Reflect.get(Temporal.PlainDateTime.prototype, "day", "foo");
|
||||
}).toThrowWithMessage(TypeError, "Not a Temporal.PlainDateTime");
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue