summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-08-08 00:03:10 +0100
committerLinus Groh <mail@linusgroh.de>2021-08-08 17:45:06 +0100
commitd9ed0f1f4755f16c5f9f7f0bd286cb7fc3150b69 (patch)
tree8c530fb4d6c68481f17b1a39259d83ef3f0e0dfb /Userland/Libraries/LibJS/Runtime
parent3592a748b69e36b654422193cd7564dbb7eb2706 (diff)
downloadserenity-d9ed0f1f4755f16c5f9f7f0bd286cb7fc3150b69.zip
LibJS: Implement Temporal.PlainYearMonth.prototype.inLeapYear
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp17
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
index 1ea02379db..ea4e44ca38 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.cpp
@@ -34,6 +34,7 @@ void PlainYearMonthPrototype::initialize(GlobalObject& global_object)
define_native_accessor(vm.names.daysInYear, days_in_year_getter, {}, Attribute::Configurable);
define_native_accessor(vm.names.daysInMonth, days_in_month_getter, {}, Attribute::Configurable);
define_native_accessor(vm.names.monthsInYear, months_in_year_getter, {}, Attribute::Configurable);
+ define_native_accessor(vm.names.inLeapYear, in_leap_year_getter, {}, Attribute::Configurable);
}
static PlainYearMonth* typed_this(GlobalObject& global_object)
@@ -158,4 +159,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::months_in_year_getter)
return Value(calendar_months_in_year(global_object, calendar, *year_month));
}
+// 9.3.10 get Temporal.PlainYearMonth.prototype.inLeapYear, https://tc39.es/proposal-temporal/#sec-get-temporal.plainyearmonth.prototype.inleapyear
+JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::in_leap_year_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 ? CalendarInLeapYear(calendar, yearMonth).
+ return Value(calendar_in_leap_year(global_object, calendar, *year_month));
+}
+
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h
index 468a574615..3a256a5081 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonthPrototype.h
@@ -26,6 +26,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(days_in_year_getter);
JS_DECLARE_NATIVE_FUNCTION(days_in_month_getter);
JS_DECLARE_NATIVE_FUNCTION(months_in_year_getter);
+ JS_DECLARE_NATIVE_FUNCTION(in_leap_year_getter);
};
}