LibJS: Implement the Temporal.Instant constructor

And the simple Temporal.Instant.prototype getters, so that the
constructed Temporal.Instant may actually be validated.
This commit is contained in:
Timothy Flynn 2024-11-24 14:12:27 -05:00 committed by Andreas Kling
commit 90820873a2
Notes: github-actions[bot] 2024-11-25 12:34:28 +00:00
22 changed files with 710 additions and 14 deletions

View file

@ -10,9 +10,28 @@
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
#include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/Object.h>
namespace JS::Temporal {
class Instant final : public Object {
JS_OBJECT(Instant, Object);
GC_DECLARE_ALLOCATOR(Instant);
public:
virtual ~Instant() override = default;
[[nodiscard]] GC::Ref<BigInt const> epoch_nanoseconds() const { return m_epoch_nanoseconds; }
private:
Instant(BigInt const& epoch_nanoseconds, Object& prototype);
virtual void visit_edges(Visitor&) override;
GC::Ref<BigInt const> m_epoch_nanoseconds; // [[EpochNanoseconds]]
};
// https://tc39.es/proposal-temporal/#eqn-nsMaxInstant
extern Crypto::SignedBigInteger const NANOSECONDS_MAX_INSTANT;
@ -37,5 +56,8 @@ extern Crypto::UnsignedBigInteger const MINUTES_PER_HOUR;
extern Crypto::UnsignedBigInteger const HOURS_PER_DAY;
bool is_valid_epoch_nanoseconds(Crypto::SignedBigInteger const& epoch_nanoseconds);
ThrowCompletionOr<GC::Ref<Instant>> create_temporal_instant(VM&, BigInt const& epoch_nanoseconds, GC::Ptr<FunctionObject> new_target = {});
ThrowCompletionOr<GC::Ref<Instant>> to_temporal_instant(VM&, Value item);
i8 compare_epoch_nanoseconds(Crypto::SignedBigInteger const& epoch_nanoseconds_one, Crypto::SignedBigInteger const& epoch_nanoseconds_two);
}