|
@@ -5,6 +5,7 @@
|
|
|
*/
|
|
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
+#include <LibJS/Runtime/Temporal/Calendar.h>
|
|
|
#include <LibJS/Runtime/Temporal/PlainDate.h>
|
|
|
#include <LibJS/Runtime/Temporal/PlainDatePrototype.h>
|
|
|
|
|
@@ -28,6 +29,7 @@ void PlainDatePrototype::initialize(GlobalObject& global_object)
|
|
|
define_native_accessor(vm.names.calendar, calendar_getter, {}, Attribute::Configurable);
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
|
+ define_native_function(vm.names.equals, equals, 1, attr);
|
|
|
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
|
|
}
|
|
|
|
|
@@ -57,6 +59,33 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::calendar_getter)
|
|
|
return Value(&temporal_date->calendar());
|
|
|
}
|
|
|
|
|
|
+// 3.3.25 Temporal.PlainDate.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.equals
|
|
|
+JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::equals)
|
|
|
+{
|
|
|
+ // 1. Let temporalDate be the this value.
|
|
|
+ // 2. Perform ? RequireInternalSlot(temporalDate, [[InitializedTemporalDate]]).
|
|
|
+ auto* temporal_date = typed_this(global_object);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ // 3. Set other to ? ToTemporalDate(other).
|
|
|
+ auto* other = to_temporal_date(global_object, vm.argument(0));
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ // 4. If temporalDate.[[ISOYear]] ≠ other.[[ISOYear]], return false.
|
|
|
+ if (temporal_date->iso_year() != other->iso_year())
|
|
|
+ return Value(false);
|
|
|
+ // 5. If temporalDate.[[ISOMonth]] ≠ other.[[ISOMonth]], return false.
|
|
|
+ if (temporal_date->iso_month() != other->iso_month())
|
|
|
+ return Value(false);
|
|
|
+ // 6. If temporalDate.[[ISODay]] ≠ other.[[ISODay]], return false.
|
|
|
+ if (temporal_date->iso_day() != other->iso_day())
|
|
|
+ return Value(false);
|
|
|
+ // 7. Return ? CalendarEquals(temporalDate.[[Calendar]], other.[[Calendar]]).
|
|
|
+ return Value(calendar_equals(global_object, temporal_date->calendar(), other->calendar()));
|
|
|
+}
|
|
|
+
|
|
|
// 3.3.31 Temporal.PlainDate.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.valueof
|
|
|
JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::value_of)
|
|
|
{
|