summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/Temporal
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2021-09-10 17:45:32 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-10 23:10:18 +0100
commit3548b08de2d903d77a467f19c8d060bd9769a699 (patch)
tree5679966bf8d667b90950fcf57f9e4571d70e4b96 /Userland/Libraries/LibJS/Runtime/Temporal
parent2d5b15295a9c02f3743dba6ca457cf968be40b75 (diff)
downloadserenity-3548b08de2d903d77a467f19c8d060bd9769a699.zip
LibJS: Implement Temporal.PlainMonthDay.prototype.equals
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp31
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h1
2 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
index 0cc9bf35d6..67900d8d9a 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.cpp
@@ -33,6 +33,7 @@ void PlainMonthDayPrototype::initialize(GlobalObject& global_object)
define_native_accessor(vm.names.day, day_getter, {}, Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
+ define_native_function(vm.names.equals, equals, 1, attr);
define_native_function(vm.names.toString, to_string, 0, attr);
define_native_function(vm.names.toLocaleString, to_locale_string, 0, attr);
define_native_function(vm.names.toJSON, to_json, 0, attr);
@@ -98,6 +99,36 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::day_getter)
return Value(calendar_day(global_object, calendar, *month_day));
}
+// 10.3.7 Temporal.PlainMonthDay.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.equals
+JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::equals)
+{
+ // 1. Let monthDay be the this value.
+ // 2. Perform ? RequireInternalSlot(monthDay, [[InitializedTemporalMonthDay]]).
+ auto* month_day = typed_this(global_object);
+ if (vm.exception())
+ return {};
+
+ // 3. Set other to ? ToTemporalMonthDay(other).
+ auto* other = to_temporal_month_day(global_object, vm.argument(0));
+ if (vm.exception())
+ return {};
+
+ // 4. If monthDay.[[ISOMonth]] ≠ other.[[ISOMonth]], return false.
+ if (month_day->iso_month() != other->iso_month())
+ return Value(false);
+
+ // 5. If monthDay.[[ISODay]] ≠ other.[[ISODay]], return false.
+ if (month_day->iso_day() != other->iso_day())
+ return Value(false);
+
+ // 6. If monthDay.[[ISOYear]] ≠ other.[[ISOYear]], return false.
+ if (month_day->iso_year() != other->iso_year())
+ return Value(false);
+
+ // 7. Return ? CalendarEquals(monthDay.[[Calendar]], other.[[Calendar]]).
+ return Value(calendar_equals(global_object, month_day->calendar(), other->calendar()));
+}
+
// 10.3.8 Temporal.PlainMonthDay.prototype.toString ( [ options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.tostring
JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_string)
{
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h
index 7af50f88ae..e512fe24a2 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainMonthDayPrototype.h
@@ -22,6 +22,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(calendar_getter);
JS_DECLARE_NATIVE_FUNCTION(month_code_getter);
JS_DECLARE_NATIVE_FUNCTION(day_getter);
+ JS_DECLARE_NATIVE_FUNCTION(equals);
JS_DECLARE_NATIVE_FUNCTION(to_string);
JS_DECLARE_NATIVE_FUNCTION(to_locale_string);
JS_DECLARE_NATIVE_FUNCTION(to_json);