LibJS: Implement the Temporal.PlainDate constructor

And the simple Temporal.PlainDate.prototype getters, so that the
constructed Temporal.PlainDate may actually be validated.
This commit is contained in:
Timothy Flynn 2024-11-22 09:23:09 -05:00 committed by Andreas Kling
commit a0c55f76e7
Notes: github-actions[bot] 2024-11-23 13:48:20 +00:00
30 changed files with 856 additions and 0 deletions

View file

@ -11,6 +11,7 @@
#include <AK/Types.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
namespace JS::Temporal {
@ -22,7 +23,26 @@ struct ISODate {
u8 day { 0 };
};
class PlainDate final : public Object {
JS_OBJECT(PlainDate, Object);
GC_DECLARE_ALLOCATOR(PlainDate);
public:
virtual ~PlainDate() override = default;
[[nodiscard]] ISODate iso_date() const { return m_iso_date; }
[[nodiscard]] String const& calendar() const { return m_calendar; }
private:
PlainDate(ISODate, String calendar, Object& prototype);
ISODate m_iso_date; // [[ISODate]]
String m_calendar; // [[Calendar]]
};
ISODate create_iso_date_record(double year, double month, double day);
ThrowCompletionOr<GC::Ref<PlainDate>> to_temporal_date(VM& vm, Value item, Value options = js_undefined());
ThrowCompletionOr<GC::Ref<PlainDate>> create_temporal_date(VM&, ISODate, String calendar, GC::Ptr<FunctionObject> new_target = {});
bool iso_date_surpasses(i8 sign, double year1, double month1, double day1, ISODate iso_date2);
ThrowCompletionOr<ISODate> regulate_iso_date(VM& vm, double year, double month, double day, Overflow overflow);
bool is_valid_iso_date(double year, double month, double day);