LibGC+Everywhere: Factor out a LibGC from LibJS

Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
This commit is contained in:
Shannon Booth 2024-11-15 04:01:23 +13:00 committed by Andreas Kling
commit f87041bf3a
Notes: github-actions[bot] 2024-11-15 13:50:17 +00:00
1722 changed files with 9939 additions and 9906 deletions

View file

@ -40,13 +40,13 @@ static Optional<OptionType> to_option_type(Value value)
}
// 13.1 IterableToListOfType ( items, elementTypes ), https://tc39.es/proposal-temporal/#sec-iterabletolistoftype
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(VM& vm, Value items, Vector<OptionType> const& element_types)
ThrowCompletionOr<GC::MarkedVector<Value>> iterable_to_list_of_type(VM& vm, Value items, Vector<OptionType> const& element_types)
{
// 1. Let iteratorRecord be ? GetIterator(items, sync).
auto iterator_record = TRY(get_iterator(vm, items, IteratorHint::Sync));
// 2. Let values be a new empty List.
MarkedVector<Value> values(vm.heap());
GC::MarkedVector<Value> values(vm.heap());
// 3. Let next be true.
auto next = true;
@ -581,7 +581,7 @@ ThrowCompletionOr<RelativeTo> to_relative_temporal_object(VM& vm, Object const&
auto& zoned_relative_to = static_cast<ZonedDateTime&>(value_object);
// i. Let timeZoneRec be ? CreateTimeZoneMethodsRecord(value.[[TimeZone]], « GET-OFFSET-NANOSECONDS-FOR, GET-POSSIBLE-INSTANTS-FOR »).
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { zoned_relative_to.time_zone() }, { { TimeZoneMethod::GetOffsetNanosecondsFor, TimeZoneMethod::GetPossibleInstantsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { zoned_relative_to.time_zone() }, { { TimeZoneMethod::GetOffsetNanosecondsFor, TimeZoneMethod::GetPossibleInstantsFor } }));
// ii. Return the Record { [[PlainRelativeTo]]: undefined, [[ZonedRelativeTo]]: value, [[TimeZoneRec]]: timeZoneRec }.
return RelativeTo {
@ -741,7 +741,7 @@ ThrowCompletionOr<RelativeTo> to_relative_temporal_object(VM& vm, Object const&
auto const* epoch_nanoseconds = TRY(interpret_iso_date_time_offset(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, offset_behavior, offset_ns, time_zone, "compatible"sv, "reject"sv, match_behavior));
// 12. Return ! CreateTemporalZonedDateTime(epochNanoseconds, timeZone, calendar).
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor, TimeZoneMethod::GetPossibleInstantsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor, TimeZoneMethod::GetPossibleInstantsFor } }));
auto* zoned_relative_to = MUST(create_temporal_zoned_date_time(vm, *epoch_nanoseconds, time_zone.as_object(), *calendar));
return RelativeTo {
.plain_relative_to = {},

View file

@ -124,7 +124,7 @@ struct DifferenceSettings {
String largest_unit;
String rounding_mode;
u64 rounding_increment;
NonnullGCPtr<Object> options;
GC::Ref<Object> options;
};
struct TemporalUnitRequired { };
@ -134,7 +134,7 @@ struct GetOptionRequired { };
using OptionDefault = Variant<GetOptionRequired, Empty, bool, StringView, double>;
using TemporalUnitDefault = Variant<TemporalUnitRequired, Optional<StringView>>;
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(VM&, Value items, Vector<OptionType> const& element_types);
ThrowCompletionOr<GC::MarkedVector<Value>> iterable_to_list_of_type(VM&, Value items, Vector<OptionType> const& element_types);
ThrowCompletionOr<Object*> get_options_object(VM&, Value options);
ThrowCompletionOr<Value> get_option(VM&, Object const& options, PropertyKey const& property, OptionType type, ReadonlySpan<StringView> values, OptionDefault const&);
ThrowCompletionOr<String> to_temporal_overflow(VM&, Object const* options);
@ -151,8 +151,8 @@ ThrowCompletionOr<SecondsStringPrecision> to_seconds_string_precision_record(VM&
ThrowCompletionOr<Optional<String>> get_temporal_unit(VM&, Object const& normalized_options, PropertyKey const&, UnitGroup, TemporalUnitDefault const& default_, Vector<StringView> const& extra_values = {});
struct RelativeTo {
GCPtr<PlainDate> plain_relative_to; // [[PlainRelativeTo]]
GCPtr<ZonedDateTime> zoned_relative_to; // [[ZonedRelativeTo]]
GC::Ptr<PlainDate> plain_relative_to; // [[PlainRelativeTo]]
GC::Ptr<ZonedDateTime> zoned_relative_to; // [[ZonedRelativeTo]]
Optional<TimeZoneMethods> time_zone_record; // [[TimeZoneRec]]
};
ThrowCompletionOr<RelativeTo> to_relative_temporal_object(VM&, Object const& options);

View file

@ -28,7 +28,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(Calendar);
GC_DEFINE_ALLOCATOR(Calendar);
// 12 Temporal.Calendar Objects, https://tc39.es/proposal-temporal/#sec-temporal-calendar-objects
Calendar::Calendar(String identifier, Object& prototype)
@ -69,7 +69,7 @@ ReadonlySpan<StringView> available_calendars()
}
// 12.2.2 CreateCalendarMethodsRecord ( calendar, methods ), https://tc39.es/proposal-temporal/#sec-temporal-createcalendarmethodsrecord
ThrowCompletionOr<CalendarMethods> create_calendar_methods_record(VM& vm, Variant<String, NonnullGCPtr<Object>> calendar, ReadonlySpan<CalendarMethod> methods)
ThrowCompletionOr<CalendarMethods> create_calendar_methods_record(VM& vm, Variant<String, GC::Ref<Object>> calendar, ReadonlySpan<CalendarMethod> methods)
{
// 1. Let record be the Calendar Methods Record { [[Receiver]]: calendar, [[DateAdd]]: undefined, [[DateFromFields]]: undefined, [[DateUntil]]: undefined, [[Day]]: undefined, [[Fields]]: undefined, [[MergeFields]]: undefined, [[MonthDayFromFields]]: undefined, [[YearMonthFromFields]]: undefined }.
CalendarMethods record {
@ -94,17 +94,17 @@ ThrowCompletionOr<CalendarMethods> create_calendar_methods_record(VM& vm, Varian
return record;
}
ThrowCompletionOr<Optional<CalendarMethods>> create_calendar_methods_record_from_relative_to(VM& vm, GCPtr<PlainDate> plain_relative_to, GCPtr<ZonedDateTime> zoned_relative_to, ReadonlySpan<CalendarMethod> methods)
ThrowCompletionOr<Optional<CalendarMethods>> create_calendar_methods_record_from_relative_to(VM& vm, GC::Ptr<PlainDate> plain_relative_to, GC::Ptr<ZonedDateTime> zoned_relative_to, ReadonlySpan<CalendarMethod> methods)
{
// FIXME: The casts to NonnullGCPtr<Object> should not be here, and can be fixed once PlainDate & ZonedDateTime have the updated type in the [[Calendar]] slot.
// FIXME: The casts to GC::Ref<Object> should not be here, and can be fixed once PlainDate & ZonedDateTime have the updated type in the [[Calendar]] slot.
// 1. If zonedRelativeTo is not undefined, return ? CreateCalendarMethodsRecord(zonedRelativeTo.[[Calendar]], methods).
if (zoned_relative_to)
return TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { zoned_relative_to->calendar() }, methods));
return TRY(create_calendar_methods_record(vm, GC::Ref<Object> { zoned_relative_to->calendar() }, methods));
// 2. If plainRelativeTo is not undefined, return ? CreateCalendarMethodsRecord(plainRelativeTo.[[Calendar]], methods).
if (plain_relative_to)
return TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { plain_relative_to->calendar() }, methods));
return TRY(create_calendar_methods_record(vm, GC::Ref<Object> { plain_relative_to->calendar() }, methods));
// 3. Return undefined.
return OptionalNone {};
@ -172,7 +172,7 @@ ThrowCompletionOr<void> calendar_methods_record_lookup(VM& vm, CalendarMethods&
const auto& calendar_prototype = *realm.intrinsics().temporal_calendar_prototype(); \
calendar_record.snake_name = calendar_prototype.get_without_side_effects(vm.names.camelName).as_function(); \
} else { \
Value calendar { calendar_record.receiver.get<NonnullGCPtr<Object>>() }; \
Value calendar { calendar_record.receiver.get<GC::Ref<Object>>() }; \
calendar_record.snake_name = TRY(calendar.get_method(vm, vm.names.camelName)); \
if (!calendar_record.snake_name) \
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, #camelName##sv); \
@ -239,11 +239,11 @@ ThrowCompletionOr<Value> calendar_methods_record_call(VM& vm, CalendarMethods co
// 2. Let receiver be calendarRec.[[Receiver]].
// 3. If CalendarMethodsRecordIsBuiltin(calendarRec) is true, then
// a. Set receiver to ! CreateTemporalCalendar(calendarRec.[[Receiver]]).
GCPtr<Object> receiver;
GC::Ptr<Object> receiver;
if (calendar_methods_record_is_builtin(calendar_record))
receiver = MUST(create_temporal_calendar(vm, calendar_record.receiver.get<String>()));
else
receiver = calendar_record.receiver.get<NonnullGCPtr<Object>>();
receiver = calendar_record.receiver.get<GC::Ref<Object>>();
// 4. If methodName is DATE-ADD, then
// a. Return ? Call(calendarRec.[[DateAdd]], receiver, arguments).
@ -392,7 +392,7 @@ ThrowCompletionOr<PlainDate*> calendar_date_add(VM& vm, Object& calendar, Value
}
// 12.2.7 CalendarDateUntil ( calendar, one, two, options [ , dateUntil ] ), https://tc39.es/proposal-temporal/#sec-temporal-calendardateuntil
ThrowCompletionOr<NonnullGCPtr<Duration>> calendar_date_until(VM& vm, CalendarMethods const& calendar_record, Value one, Value two, Object const& options)
ThrowCompletionOr<GC::Ref<Duration>> calendar_date_until(VM& vm, CalendarMethods const& calendar_record, Value one, Value two, Object const& options)
{
// 1. Let duration be ? CalendarMethodsRecordCall(calendarRec, DATE-UNTIL, « one, two, options »).
auto duration = TRY(calendar_methods_record_call(vm, calendar_record, CalendarMethod::DateUntil, Vector<Value> { one, two, &options }));

View file

@ -19,7 +19,7 @@ namespace JS::Temporal {
class Calendar final : public Object {
JS_OBJECT(Calendar, Object);
JS_DECLARE_ALLOCATOR(Calendar);
GC_DECLARE_ALLOCATOR(Calendar);
public:
virtual ~Calendar() override = default;
@ -47,7 +47,7 @@ Calendar* get_iso8601_calendar(VM&);
ThrowCompletionOr<Vector<String>> calendar_fields(VM&, Object& calendar, Vector<StringView> const& field_names);
ThrowCompletionOr<Object*> calendar_merge_fields(VM&, Object& calendar, Object& fields, Object& additional_fields);
ThrowCompletionOr<PlainDate*> calendar_date_add(VM&, Object& calendar, Value date, Duration&, Object* options = nullptr, FunctionObject* date_add = nullptr);
ThrowCompletionOr<NonnullGCPtr<Duration>> calendar_date_until(VM&, CalendarMethods const&, Value one, Value two, Object const& options);
ThrowCompletionOr<GC::Ref<Duration>> calendar_date_until(VM&, CalendarMethods const&, Value one, Value two, Object const& options);
ThrowCompletionOr<double> calendar_year(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<double> calendar_month(VM&, Object& calendar, Object& date_like);
ThrowCompletionOr<String> calendar_month_code(VM&, Object& calendar, Object& date_like);
@ -87,31 +87,31 @@ u8 to_iso_day_of_week(i32 year, u8 month, u8 day);
// https://tc39.es/proposal-temporal/#table-temporal-calendar-methods-record-fields
struct CalendarMethods {
// The calendar object, or a string indicating a built-in time zone.
Variant<String, NonnullGCPtr<Object>> receiver; // [[Reciever]]
Variant<String, GC::Ref<Object>> receiver; // [[Reciever]]
// The calendar's dateAdd method. For a built-in calendar this is always %Temporal.Calendar.prototype.dateAdd%.
GCPtr<FunctionObject> date_add; // [[DateAdd]]
GC::Ptr<FunctionObject> date_add; // [[DateAdd]]
// The calendar's dateFromFields method. For a built-in calendar this is always %Temporal.Calendar.prototype.dateFromFields%.
GCPtr<FunctionObject> date_from_fields; // [[DateFromFields]]
GC::Ptr<FunctionObject> date_from_fields; // [[DateFromFields]]
// The calendar's dateUntil method. For a built-in calendar this is always %Temporal.Calendar.prototype.dateUntil%.
GCPtr<FunctionObject> date_until; // [[DateUntil]]
GC::Ptr<FunctionObject> date_until; // [[DateUntil]]
// The calendar's day method. For a built-in calendar this is always %Temporal.Calendar.prototype.day%.
GCPtr<FunctionObject> day; // [[Day]]
GC::Ptr<FunctionObject> day; // [[Day]]
// The calendar's fields method. For a built-in calendar this is always %Temporal.Calendar.prototype.fields%.
GCPtr<FunctionObject> fields; // [[Fields]]
GC::Ptr<FunctionObject> fields; // [[Fields]]
// The calendar's mergeFields method. For a built-in calendar this is always %Temporal.Calendar.prototype.mergeFields%.
GCPtr<FunctionObject> merge_fields; // [[MergeFields]]
GC::Ptr<FunctionObject> merge_fields; // [[MergeFields]]
// The calendar's monthDayFromFields method. For a built-in calendar this is always %Temporal.Calendar.prototype.monthDayFromFields%.
GCPtr<FunctionObject> month_day_from_fields; // [[MonthDayFromFields]]
GC::Ptr<FunctionObject> month_day_from_fields; // [[MonthDayFromFields]]
// The calendar's yearMonthFromFields method. For a built-in calendar this is always %Temporal.Calendar.prototype.yearMonthFromFields%.
GCPtr<FunctionObject> year_month_from_fields; // [[YearMonthFromFields]]
GC::Ptr<FunctionObject> year_month_from_fields; // [[YearMonthFromFields]]
};
#define JS_ENUMERATE_CALENDAR_METHODS \
@ -132,8 +132,8 @@ enum class CalendarMethod {
};
ThrowCompletionOr<void> calendar_methods_record_lookup(VM&, CalendarMethods&, CalendarMethod);
ThrowCompletionOr<CalendarMethods> create_calendar_methods_record(VM&, Variant<String, NonnullGCPtr<Object>> calendar, ReadonlySpan<CalendarMethod>);
ThrowCompletionOr<Optional<CalendarMethods>> create_calendar_methods_record_from_relative_to(VM&, GCPtr<PlainDate>, GCPtr<ZonedDateTime>, ReadonlySpan<CalendarMethod>);
ThrowCompletionOr<CalendarMethods> create_calendar_methods_record(VM&, Variant<String, GC::Ref<Object>> calendar, ReadonlySpan<CalendarMethod>);
ThrowCompletionOr<Optional<CalendarMethods>> create_calendar_methods_record_from_relative_to(VM&, GC::Ptr<PlainDate>, GC::Ptr<ZonedDateTime>, ReadonlySpan<CalendarMethod>);
bool calendar_methods_record_has_looked_up(CalendarMethods const&, CalendarMethod);
bool calendar_methods_record_is_builtin(CalendarMethods const&);
ThrowCompletionOr<Value> calendar_methods_record_call(VM&, CalendarMethods const&, CalendarMethod, ReadonlySpan<Value> arguments);

View file

@ -10,7 +10,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(CalendarConstructor);
GC_DEFINE_ALLOCATOR(CalendarConstructor);
// 12.2 The Temporal.Calendar Constructor, https://tc39.es/proposal-temporal/#sec-temporal-calendar-constructor
CalendarConstructor::CalendarConstructor(Realm& realm)
@ -44,7 +44,7 @@ ThrowCompletionOr<Value> CalendarConstructor::call()
}
// 12.2.1 Temporal.Calendar ( id ), https://tc39.es/proposal-temporal/#sec-temporal.calendar
ThrowCompletionOr<NonnullGCPtr<Object>> CalendarConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> CalendarConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class CalendarConstructor final : public NativeFunction {
JS_OBJECT(CalendarConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(CalendarConstructor);
GC_DECLARE_ALLOCATOR(CalendarConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~CalendarConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit CalendarConstructor(Realm&);

View file

@ -19,7 +19,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(CalendarPrototype);
GC_DEFINE_ALLOCATOR(CalendarPrototype);
[[nodiscard]] static i32 iso_year(Object& temporal_object);
[[nodiscard]] static u8 iso_month(Object& temporal_object);
@ -537,7 +537,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
auto iterator_record = TRY(get_iterator(vm, fields, IteratorHint::Sync));
// 5. Let fieldNames be a new empty List.
auto field_names = MarkedVector<Value> { vm.heap() };
auto field_names = GC::MarkedVector<Value> { vm.heap() };
// 6. Let next be true.
// 7. Repeat, while next is not false,

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class CalendarPrototype final : public PrototypeObject<CalendarPrototype, Calendar> {
JS_PROTOTYPE_OBJECT(CalendarPrototype, Calendar, Temporal.Calendar);
JS_DECLARE_ALLOCATOR(CalendarPrototype);
GC_DECLARE_ALLOCATOR(CalendarPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -25,7 +25,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(Duration);
GC_DEFINE_ALLOCATOR(Duration);
// 7 Temporal.Duration Objects, https://tc39.es/proposal-temporal/#sec-temporal-duration-objects
Duration::Duration(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object& prototype)
@ -127,7 +127,7 @@ ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(VM& vm, double
}
// 7.5.8 ToTemporalDuration ( item ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalduration
ThrowCompletionOr<NonnullGCPtr<Duration>> to_temporal_duration(VM& vm, Value item)
ThrowCompletionOr<GC::Ref<Duration>> to_temporal_duration(VM& vm, Value item)
{
// 1. If Type(item) is Object and item has an [[InitializedTemporalDuration]] internal slot, then
if (item.is_object() && is<Duration>(item.as_object())) {
@ -433,7 +433,7 @@ ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(VM&
}
// 7.5.14 CreateTemporalDuration ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalduration
ThrowCompletionOr<NonnullGCPtr<Duration>> create_temporal_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target)
ThrowCompletionOr<GC::Ref<Duration>> create_temporal_duration(VM& vm, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target)
{
auto& realm = *vm.current_realm();
@ -463,7 +463,7 @@ ThrowCompletionOr<NonnullGCPtr<Duration>> create_temporal_duration(VM& vm, doubl
}
// 7.5.15 CreateNegatedTemporalDuration ( duration ), https://tc39.es/proposal-temporal/#sec-temporal-createnegatedtemporalduration
NonnullGCPtr<Duration> create_negated_temporal_duration(VM& vm, Duration const& duration)
GC::Ref<Duration> create_negated_temporal_duration(VM& vm, Duration const& duration)
{
// 1. Return ! CreateTemporalDuration(-duration.[[Years]], -duration.[[Months]], -duration.[[Weeks]], -duration.[[Days]], -duration.[[Hours]], -duration.[[Minutes]], -duration.[[Seconds]], -duration.[[Milliseconds]], -duration.[[Microseconds]], -duration.[[Nanoseconds]]).
return MUST(create_temporal_duration(vm, -duration.years(), -duration.months(), -duration.weeks(), -duration.days(), -duration.hours(), -duration.minutes(), -duration.seconds(), -duration.milliseconds(), -duration.microseconds(), -duration.nanoseconds()));
@ -477,7 +477,7 @@ ThrowCompletionOr<double> calculate_offset_shift(VM& vm, Value relative_to_value
return 0.0;
auto& relative_to = static_cast<ZonedDateTime&>(relative_to_value.as_object());
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { relative_to.time_zone() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { relative_to.time_zone() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
// 2. Let instant be ! CreateTemporalInstant(relativeTo.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(vm, relative_to.nanoseconds()));
@ -921,7 +921,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
// FIXME: AD-HOC calendar records use as this AO is not up to date with latest spec
// iv. Let untilResult be ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { *calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { *calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto until_result = TRY(calendar_date_until(vm, calendar_record, relative_to, new_relative_to, *until_options));
// v. Let oneYearMonths be untilResult.[[Months]].
@ -1159,7 +1159,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
// FIXME: AD-HOC calendar records use as this AO is not up to date with latest spec
// n. Let untilResult be ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto until_result = TRY(calendar_date_until(vm, calendar_record, relative_to, new_relative_to, *until_options));
// o. Let oneYearMonths be untilResult.[[Months]].
@ -1342,7 +1342,7 @@ ThrowCompletionOr<DurationRecord> add_duration(VM& vm, double years1, double mon
// j. Let dateDifference be ? CalendarDateUntil(calendar, relativeTo, end, differenceOptions).
// FIXME: AD-HOC calendar records use as this AO is not up to date with latest spec
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto date_difference = TRY(calendar_date_until(vm, calendar_record, &relative_to, end, *difference_options));
// k. Let result be ? BalanceDuration(dateDifference.[[Days]], h1 + h2, min1 + min2, s1 + s2, ms1 + ms2, mus1 + mus2, ns1 + ns2, largestUnit).
@ -1398,7 +1398,7 @@ ThrowCompletionOr<MoveRelativeDateResult> move_relative_date(VM& vm, Object& cal
auto days = days_until(relative_to, *new_date);
// 3. Return the Record { [[RelativeTo]]: newDate, [[Days]]: days }.
return MoveRelativeDateResult { .relative_to = make_handle(new_date), .days = days };
return MoveRelativeDateResult { .relative_to = make_root(new_date), .days = days };
}
// 7.5.24 MoveRelativeZonedDateTime ( zonedDateTime, years, months, weeks, days ), https://tc39.es/proposal-temporal/#sec-temporal-moverelativezoneddatetime
@ -2068,7 +2068,7 @@ ThrowCompletionOr<String> temporal_duration_to_string(VM& vm, double years, doub
}
// 7.5.28 AddDurationToOrSubtractDurationFromDuration ( operation, duration, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoorsubtractdurationfromduration
ThrowCompletionOr<NonnullGCPtr<Duration>> add_duration_to_or_subtract_duration_from_duration(VM& vm, ArithmeticOperation operation, Duration const& duration, Value other_value, Value options_value)
ThrowCompletionOr<GC::Ref<Duration>> add_duration_to_or_subtract_duration_from_duration(VM& vm, ArithmeticOperation operation, Duration const& duration, Value other_value, Value options_value)
{
// 1. If operation is subtract, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == ArithmeticOperation::Subtract ? -1 : 1;

View file

@ -8,7 +8,7 @@
#pragma once
#include <AK/Optional.h>
#include <LibJS/Heap/Handle.h>
#include <LibGC/Root.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Date.h>
#include <LibJS/Runtime/Object.h>
@ -21,7 +21,7 @@ namespace JS::Temporal {
class Duration final : public Object {
JS_OBJECT(Duration, Object);
JS_DECLARE_ALLOCATOR(Duration);
GC_DECLARE_ALLOCATOR(Duration);
public:
virtual ~Duration() override = default;
@ -102,7 +102,7 @@ struct PartialDurationRecord {
// Used by MoveRelativeDate to temporarily hold values
struct MoveRelativeDateResult {
Handle<PlainDate> relative_to;
GC::Root<PlainDate> relative_to;
double days;
};
@ -125,14 +125,14 @@ ThrowCompletionOr<DurationRecord> create_duration_record(VM&, double years, doub
DateDurationRecord create_date_duration_record(double years, double months, double weeks, double days);
ThrowCompletionOr<DateDurationRecord> create_date_duration_record(VM&, double years, double months, double weeks, double days);
ThrowCompletionOr<TimeDurationRecord> create_time_duration_record(VM&, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
ThrowCompletionOr<NonnullGCPtr<Duration>> to_temporal_duration(VM&, Value item);
ThrowCompletionOr<GC::Ref<Duration>> to_temporal_duration(VM&, Value item);
ThrowCompletionOr<DurationRecord> to_temporal_duration_record(VM&, Value temporal_duration_like);
i8 duration_sign(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
bool is_valid_duration(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
StringView default_temporal_largest_unit(double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds);
ThrowCompletionOr<PartialDurationRecord> to_temporal_partial_duration_record(VM&, Value temporal_duration_like);
ThrowCompletionOr<NonnullGCPtr<Duration>> create_temporal_duration(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target = nullptr);
NonnullGCPtr<Duration> create_negated_temporal_duration(VM&, Duration const& duration);
ThrowCompletionOr<GC::Ref<Duration>> create_temporal_duration(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, FunctionObject const* new_target = nullptr);
GC::Ref<Duration> create_negated_temporal_duration(VM&, Duration const& duration);
ThrowCompletionOr<double> calculate_offset_shift(VM&, Value relative_to_value, double years, double months, double weeks, double days);
Crypto::SignedBigInteger total_duration_nanoseconds(double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, Crypto::SignedBigInteger const& nanoseconds, double offset_shift);
ThrowCompletionOr<TimeDurationRecord> balance_time_duration(VM& vm, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, Crypto::SignedBigInteger const& nanoseconds, StringView largest_unit);
@ -153,7 +153,7 @@ ThrowCompletionOr<ZonedDateTime*> move_relative_zoned_date_time(VM&, ZonedDateTi
ThrowCompletionOr<RoundedDuration> round_duration(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object = nullptr, Optional<CalendarMethods> const& = {});
ThrowCompletionOr<DurationRecord> adjust_rounded_duration_days(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, u32 increment, StringView unit, StringView rounding_mode, Object* relative_to_object);
ThrowCompletionOr<String> temporal_duration_to_string(VM&, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Variant<StringView, u8> const& precision);
ThrowCompletionOr<NonnullGCPtr<Duration>> add_duration_to_or_subtract_duration_from_duration(VM&, ArithmeticOperation, Duration const&, Value other_value, Value options_value);
ThrowCompletionOr<GC::Ref<Duration>> add_duration_to_or_subtract_duration_from_duration(VM&, ArithmeticOperation, Duration const&, Value other_value, Value options_value);
// 7.5.22 DaysUntil ( earlier, later ), https://tc39.es/proposal-temporal/#sec-temporal-daysuntil
template<typename EarlierObjectType, typename LaterObjectType>

View file

@ -14,7 +14,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(DurationConstructor);
GC_DEFINE_ALLOCATOR(DurationConstructor);
// 7.1 The Temporal.Duration Constructor, https://tc39.es/proposal-temporal/#sec-temporal-duration-constructor
DurationConstructor::DurationConstructor(Realm& realm)
@ -49,7 +49,7 @@ ThrowCompletionOr<Value> DurationConstructor::call()
}
// 7.1.1 Temporal.Duration ( [ years [ , months [ , weeks [ , days [ , hours [ , minutes [ , seconds [ , milliseconds [ , microseconds [ , nanoseconds ] ] ] ] ] ] ] ] ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration
ThrowCompletionOr<NonnullGCPtr<Object>> DurationConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> DurationConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class DurationConstructor final : public NativeFunction {
JS_OBJECT(DurationConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(DurationConstructor);
GC_DECLARE_ALLOCATOR(DurationConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~DurationConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit DurationConstructor(Realm&);

View file

@ -14,7 +14,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(DurationPrototype);
GC_DEFINE_ALLOCATOR(DurationPrototype);
// 7.3 Properties of the Temporal.Duration Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-duration-prototype-object
DurationPrototype::DurationPrototype(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class DurationPrototype final : public PrototypeObject<DurationPrototype, Duration> {
JS_PROTOTYPE_OBJECT(DurationPrototype, Duration, Temporal.Duration);
JS_DECLARE_ALLOCATOR(DurationPrototype);
GC_DECLARE_ALLOCATOR(DurationPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -23,7 +23,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(Instant);
GC_DEFINE_ALLOCATOR(Instant);
// 8 Temporal.Instant Objects, https://tc39.es/proposal-temporal/#sec-temporal-instant-objects
Instant::Instant(BigInt const& nanoseconds, Object& prototype)
@ -300,7 +300,7 @@ ThrowCompletionOr<String> temporal_instant_to_string(VM& vm, Instant& instant, V
}
// 9. Else,
else {
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
// a. Let offsetNs be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, time_zone_record, instant));
@ -314,7 +314,7 @@ ThrowCompletionOr<String> temporal_instant_to_string(VM& vm, Instant& instant, V
}
// 8.5.9 DifferenceTemporalInstant ( operation, instant, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalinstant
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_instant(VM& vm, DifferenceOperation operation, Instant const& instant, Value other_value, Value options)
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_instant(VM& vm, DifferenceOperation operation, Instant const& instant, Value other_value, Value options)
{
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;

View file

@ -18,7 +18,7 @@ namespace JS::Temporal {
class Instant final : public Object {
JS_OBJECT(Instant, Object);
JS_DECLARE_ALLOCATOR(Instant);
GC_DECLARE_ALLOCATOR(Instant);
public:
virtual ~Instant() override = default;
@ -31,7 +31,7 @@ private:
virtual void visit_edges(Visitor&) override;
// 8.4 Properties of Temporal.Instant Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-instant-instances
NonnullGCPtr<BigInt const> m_nanoseconds; // [[Nanoseconds]]
GC::Ref<BigInt const> m_nanoseconds; // [[Nanoseconds]]
};
// https://tc39.es/proposal-temporal/#eqn-nsMaxInstant
@ -52,7 +52,7 @@ ThrowCompletionOr<BigInt*> add_instant(VM&, BigInt const& epoch_nanoseconds, dou
TimeDurationRecord difference_instant(VM&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView largest_unit, StringView rounding_mode);
BigInt* round_temporal_instant(VM&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode);
ThrowCompletionOr<String> temporal_instant_to_string(VM&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_instant(VM&, DifferenceOperation, Instant const&, Value other, Value options);
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_instant(VM&, DifferenceOperation, Instant const&, Value other, Value options);
ThrowCompletionOr<Instant*> add_duration_to_or_subtract_duration_from_instant(VM&, ArithmeticOperation, Instant const&, Value temporal_duration_like);
}

View file

@ -13,7 +13,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(InstantConstructor);
GC_DEFINE_ALLOCATOR(InstantConstructor);
// 8.1 The Temporal.Instant Constructor, https://tc39.es/proposal-temporal/#sec-temporal-instant-constructor
InstantConstructor::InstantConstructor(Realm& realm)
@ -52,7 +52,7 @@ ThrowCompletionOr<Value> InstantConstructor::call()
}
// 8.1.1 Temporal.Instant ( epochNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal.instant
ThrowCompletionOr<NonnullGCPtr<Object>> InstantConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> InstantConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class InstantConstructor final : public NativeFunction {
JS_OBJECT(InstantConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(InstantConstructor);
GC_DECLARE_ALLOCATOR(InstantConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~InstantConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit InstantConstructor(Realm&);

View file

@ -18,7 +18,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(InstantPrototype);
GC_DEFINE_ALLOCATOR(InstantPrototype);
// 8.3 Properties of the Temporal.Instant Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-instant-prototype-object
InstantPrototype::InstantPrototype(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class InstantPrototype final : public PrototypeObject<InstantPrototype, Instant> {
JS_PROTOTYPE_OBJECT(InstantPrototype, Instant, Temporal.Instant);
JS_DECLARE_ALLOCATOR(InstantPrototype);
GC_DECLARE_ALLOCATOR(InstantPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -20,7 +20,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(Now);
GC_DEFINE_ALLOCATOR(Now);
// 2 The Temporal.Now Object, https://tc39.es/proposal-temporal/#sec-temporal-now-object
Now::Now(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class Now final : public Object {
JS_OBJECT(Now, Object);
JS_DECLARE_ALLOCATOR(Now);
GC_DECLARE_ALLOCATOR(Now);
public:
virtual void initialize(Realm&) override;

View file

@ -23,7 +23,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainDate);
GC_DEFINE_ALLOCATOR(PlainDate);
// 3 Temporal.PlainDate Objects, https://tc39.es/proposal-temporal/#sec-temporal-plaindate-objects
PlainDate::PlainDate(i32 year, u8 month, u8 day, Object& calendar, Object& prototype)
@ -382,7 +382,7 @@ bool is_valid_iso_date(i32 year, u8 month, u8 day)
}
// 3.5.6 DifferenceDate ( calendarRec, one, two, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencedate
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_date(VM& vm, CalendarMethods const& calendar_record, PlainDate const& one, PlainDate const& two, Object const& options)
ThrowCompletionOr<GC::Ref<Duration>> difference_date(VM& vm, CalendarMethods const& calendar_record, PlainDate const& one, PlainDate const& two, Object const& options)
{
// FIXME: 1. Assert: one.[[Calendar]] and two.[[Calendar]] have been determined to be equivalent as with CalendarEquals.
// FIXME: 2. Assert: options is an ordinary Object.
@ -529,7 +529,7 @@ i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2
}
// 3.5.11 DifferenceTemporalPlainDate ( operation, temporalDate, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplaindate
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_date(VM& vm, DifferenceOperation operation, PlainDate& temporal_date, Value other_value, Value options)
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_date(VM& vm, DifferenceOperation operation, PlainDate& temporal_date, Value other_value, Value options)
{
// 1. If operation is SINCE, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
@ -555,7 +555,7 @@ ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_date(VM& vm,
// 7. Let calendarRec be ? CreateCalendarMethodsRecord(temporalDate.[[Calendar]], « DATE-ADD, DATE-UNTIL »).
// FIXME: The type of calendar in PlainDate does not align with latest spec
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { temporal_date.calendar() }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { temporal_date.calendar() }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
// 8. Perform ! CreateDataPropertyOrThrow(resolvedOptions, "largestUnit", settings.[[LargestUnit]]).
MUST(resolved_options->create_data_property_or_throw(vm.names.largestUnit, PrimitiveString::create(vm, settings.largest_unit)));

View file

@ -17,7 +17,7 @@ namespace JS::Temporal {
class PlainDate final : public Object {
JS_OBJECT(PlainDate, Object);
JS_DECLARE_ALLOCATOR(PlainDate);
GC_DECLARE_ALLOCATOR(PlainDate);
public:
virtual ~PlainDate() override = default;
@ -34,10 +34,10 @@ private:
virtual void visit_edges(Visitor&) override;
// 3.4 Properties of Temporal.PlainDate Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-plaindate-instances
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 1 }; // [[ISOMonth]]
u8 m_iso_day { 1 }; // [[ISODay]]
NonnullGCPtr<Object> m_calendar; // [[Calendar]]
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 1 }; // [[ISOMonth]]
u8 m_iso_day { 1 }; // [[ISODay]]
GC::Ref<Object> m_calendar; // [[Calendar]]
};
// 3.5.1 ISO Date Records, https://tc39.es/proposal-temporal/#sec-temporal-iso-date-records
@ -58,7 +58,7 @@ ThrowCompletionOr<String> pad_iso_year(VM&, i32 y);
ThrowCompletionOr<String> temporal_date_to_string(VM&, PlainDate&, StringView show_calendar);
ThrowCompletionOr<ISODateRecord> add_iso_date(VM&, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow);
i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2);
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_date(VM&, DifferenceOperation, PlainDate&, Value other, Value options);
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_date(VM& vm, CalendarMethods const&, PlainDate const& one, PlainDate const& two, Object const& options);
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_date(VM&, DifferenceOperation, PlainDate&, Value other, Value options);
ThrowCompletionOr<GC::Ref<Duration>> difference_date(VM& vm, CalendarMethods const&, PlainDate const& one, PlainDate const& two, Object const& options);
}

View file

@ -14,7 +14,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainDateConstructor);
GC_DEFINE_ALLOCATOR(PlainDateConstructor);
// 3.1 The Temporal.PlainDate Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaindate-constructor
PlainDateConstructor::PlainDateConstructor(Realm& realm)
@ -48,7 +48,7 @@ ThrowCompletionOr<Value> PlainDateConstructor::call()
}
// 3.1.1 Temporal.PlainDate ( isoYear, isoMonth, isoDay [ , calendarLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindate
ThrowCompletionOr<NonnullGCPtr<Object>> PlainDateConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> PlainDateConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class PlainDateConstructor final : public NativeFunction {
JS_OBJECT(PlainDateConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(PlainDateConstructor);
GC_DECLARE_ALLOCATOR(PlainDateConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~PlainDateConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit PlainDateConstructor(Realm&);

View file

@ -19,7 +19,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainDatePrototype);
GC_DEFINE_ALLOCATOR(PlainDatePrototype);
// 3.3 Properties of the Temporal.PlainDate Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindate-prototype-object
PlainDatePrototype::PlainDatePrototype(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class PlainDatePrototype final : public PrototypeObject<PlainDatePrototype, PlainDate> {
JS_PROTOTYPE_OBJECT(PlainDatePrototype, PlainDate, Temporal.PlainDate);
JS_DECLARE_ALLOCATOR(PlainDatePrototype);
GC_DECLARE_ALLOCATOR(PlainDatePrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -23,7 +23,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainDateTime);
GC_DEFINE_ALLOCATOR(PlainDateTime);
// 5 Temporal.PlainDateTime Objects, https://tc39.es/proposal-temporal/#sec-temporal-plaindatetime-objects
PlainDateTime::PlainDateTime(i32 iso_year, u8 iso_month, u8 iso_day, u8 iso_hour, u8 iso_minute, u8 iso_second, u16 iso_millisecond, u16 iso_microsecond, u16 iso_nanosecond, Object& calendar, Object& prototype)
@ -375,7 +375,7 @@ ThrowCompletionOr<DurationRecord> difference_iso_date_time(VM& vm, i32 year1, u8
// 12. Let dateDifference be ? CalendarDateUntil(calendar, date1, date2, untilOptions).
// FIXME: AD-HOC calendar records use as this AO is not up to date with latest spec
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto date_difference = TRY(calendar_date_until(vm, calendar_record, date1, date2, *until_options));
// 13. Let balanceResult be ? BalanceDuration(dateDifference.[[Days]], timeDifference.[[Hours]], timeDifference.[[Minutes]], timeDifference.[[Seconds]], timeDifference.[[Milliseconds]], timeDifference.[[Microseconds]], timeDifference.[[Nanoseconds]], largestUnit).
@ -386,7 +386,7 @@ ThrowCompletionOr<DurationRecord> difference_iso_date_time(VM& vm, i32 year1, u8
}
// 5.5.11 DifferenceTemporalPlainDateTime ( operation, dateTime, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplaindatetime
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_date_time(VM& vm, DifferenceOperation operation, PlainDateTime& date_time, Value other_value, Value options_value)
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_date_time(VM& vm, DifferenceOperation operation, PlainDateTime& date_time, Value other_value, Value options_value)
{
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
@ -409,7 +409,7 @@ ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_date_time(VM
// 7. Let roundResult be (? RoundDuration(diff.[[Years]], diff.[[Months]], diff.[[Weeks]], diff.[[Days]], diff.[[Hours]], diff.[[Minutes]], diff.[[Seconds]], diff.[[Milliseconds]], diff.[[Microseconds]], diff.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]], relativeTo)).[[DurationRecord]].
// FIXME: AD-HOC calendar records use as this AO is not up to date with latest spec
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { date_time.calendar() }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { date_time.calendar() }, { { CalendarMethod::DateAdd, CalendarMethod::DateUntil } }));
auto round_result = TRY(round_duration(vm, diff.years, diff.months, diff.weeks, diff.days, diff.hours, diff.minutes, diff.seconds, diff.milliseconds, diff.microseconds, diff.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, relative_to, calendar_record)).duration_record;
// 8. Let result be ? BalanceDuration(roundResult.[[Days]], roundResult.[[Hours]], roundResult.[[Minutes]], roundResult.[[Seconds]], roundResult.[[Milliseconds]], roundResult.[[Microseconds]], roundResult.[[Nanoseconds]], settings.[[LargestUnit]]).

View file

@ -17,7 +17,7 @@ namespace JS::Temporal {
class PlainDateTime final : public Object {
JS_OBJECT(PlainDateTime, Object);
JS_DECLARE_ALLOCATOR(PlainDateTime);
GC_DECLARE_ALLOCATOR(PlainDateTime);
public:
virtual ~PlainDateTime() override = default;
@ -40,16 +40,16 @@ private:
virtual void visit_edges(Visitor&) override;
// 5.4 Properties of Temporal.PlainDateTime Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-plaindatetime-instances
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 0 }; // [[ISOMonth]]
u8 m_iso_day { 0 }; // [[ISODay]]
u8 m_iso_hour { 0 }; // [[ISOHour]]
u8 m_iso_minute { 0 }; // [[ISOMinute]]
u8 m_iso_second { 0 }; // [[ISOSecond]]
u16 m_iso_millisecond { 0 }; // [[ISOMillisecond]]
u16 m_iso_microsecond { 0 }; // [[ISOMicrosecond]]
u16 m_iso_nanosecond { 0 }; // [[ISONanosecond]]
NonnullGCPtr<Object> m_calendar; // [[Calendar]]
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 0 }; // [[ISOMonth]]
u8 m_iso_day { 0 }; // [[ISODay]]
u8 m_iso_hour { 0 }; // [[ISOHour]]
u8 m_iso_minute { 0 }; // [[ISOMinute]]
u8 m_iso_second { 0 }; // [[ISOSecond]]
u16 m_iso_millisecond { 0 }; // [[ISOMillisecond]]
u16 m_iso_microsecond { 0 }; // [[ISOMicrosecond]]
u16 m_iso_nanosecond { 0 }; // [[ISONanosecond]]
GC::Ref<Object> m_calendar; // [[Calendar]]
};
// Used by AddDateTime to temporarily hold values
@ -75,7 +75,7 @@ i8 compare_iso_date_time(i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8
ThrowCompletionOr<TemporalPlainDateTime> add_date_time(VM&, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options);
ISODateTime round_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length = {});
ThrowCompletionOr<DurationRecord> difference_iso_date_time(VM&, i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2, Object& calendar, StringView largest_unit, Object const& options);
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_date_time(VM&, DifferenceOperation, PlainDateTime&, Value other, Value options);
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_date_time(VM&, DifferenceOperation, PlainDateTime&, Value other, Value options);
ThrowCompletionOr<PlainDateTime*> add_duration_to_or_subtract_duration_from_plain_date_time(VM&, ArithmeticOperation, PlainDateTime&, Value temporal_duration_like, Value options_value);
}

View file

@ -14,7 +14,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainDateTimeConstructor);
GC_DEFINE_ALLOCATOR(PlainDateTimeConstructor);
// 5.1 The Temporal.PlainDateTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaindatetime-constructor
PlainDateTimeConstructor::PlainDateTimeConstructor(Realm& realm)
@ -48,7 +48,7 @@ ThrowCompletionOr<Value> PlainDateTimeConstructor::call()
}
// 5.1.1 Temporal.PlainDateTime ( isoYear, isoMonth, isoDay [ , hour [ , minute [ , second [ , millisecond [ , microsecond [ , nanosecond [ , calendarLike ] ] ] ] ] ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime
ThrowCompletionOr<NonnullGCPtr<Object>> PlainDateTimeConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> PlainDateTimeConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class PlainDateTimeConstructor final : public NativeFunction {
JS_OBJECT(PlainDateTimeConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(PlainDateTimeConstructor);
GC_DECLARE_ALLOCATOR(PlainDateTimeConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~PlainDateTimeConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit PlainDateTimeConstructor(Realm&);

View file

@ -20,7 +20,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainDateTimePrototype);
GC_DEFINE_ALLOCATOR(PlainDateTimePrototype);
// 5.3 Properties of the Temporal.PlainDateTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindatetime-prototype-object
PlainDateTimePrototype::PlainDateTimePrototype(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class PlainDateTimePrototype final : public PrototypeObject<PlainDateTimePrototype, PlainDateTime> {
JS_PROTOTYPE_OBJECT(PlainDateTimePrototype, PlainDateTime, Temporal.PlainDateTime);
JS_DECLARE_ALLOCATOR(PlainDateTimePrototype);
GC_DECLARE_ALLOCATOR(PlainDateTimePrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -18,7 +18,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainMonthDay);
GC_DEFINE_ALLOCATOR(PlainMonthDay);
// 10 Temporal.PlainMonthDay Objects, https://tc39.es/proposal-temporal/#sec-temporal-plainmonthday-objects
PlainMonthDay::PlainMonthDay(u8 iso_month, u8 iso_day, i32 iso_year, Object& calendar, Object& prototype)

View file

@ -12,7 +12,7 @@ namespace JS::Temporal {
class PlainMonthDay final : public Object {
JS_OBJECT(PlainMonthDay, Object);
JS_DECLARE_ALLOCATOR(PlainMonthDay);
GC_DECLARE_ALLOCATOR(PlainMonthDay);
public:
virtual ~PlainMonthDay() override = default;
@ -29,10 +29,10 @@ private:
virtual void visit_edges(Visitor&) override;
// 10.4 Properties of Temporal.PlainMonthDay Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-plainmonthday-instances
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 0 }; // [[ISOMonth]]
u8 m_iso_day { 0 }; // [[ISODay]]
NonnullGCPtr<Object> m_calendar; // [[Calendar]]
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 0 }; // [[ISOMonth]]
u8 m_iso_day { 0 }; // [[ISODay]]
GC::Ref<Object> m_calendar; // [[Calendar]]
};
struct ISOMonthDay {

View file

@ -13,7 +13,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainMonthDayConstructor);
GC_DEFINE_ALLOCATOR(PlainMonthDayConstructor);
// 10.1 The Temporal.PlainMonthDay Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plainmonthday-constructor
PlainMonthDayConstructor::PlainMonthDayConstructor(Realm& realm)
@ -46,7 +46,7 @@ ThrowCompletionOr<Value> PlainMonthDayConstructor::call()
}
// 10.1.1 Temporal.PlainMonthDay ( isoMonth, isoDay [ , calendarLike [ , referenceISOYear ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday
ThrowCompletionOr<NonnullGCPtr<Object>> PlainMonthDayConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> PlainMonthDayConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class PlainMonthDayConstructor final : public NativeFunction {
JS_OBJECT(PlainMonthDayConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(PlainMonthDayConstructor);
GC_DECLARE_ALLOCATOR(PlainMonthDayConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~PlainMonthDayConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit PlainMonthDayConstructor(Realm&);

View file

@ -14,7 +14,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainMonthDayPrototype);
GC_DEFINE_ALLOCATOR(PlainMonthDayPrototype);
// 10.3 Properties of the Temporal.PlainMonthDay Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainmonthday-prototype-object
PlainMonthDayPrototype::PlainMonthDayPrototype(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class PlainMonthDayPrototype final : public PrototypeObject<PlainMonthDayPrototype, PlainMonthDay> {
JS_PROTOTYPE_OBJECT(PlainMonthDayPrototype, PlainMonthDay, Temporal.PlainMonthDay);
JS_DECLARE_ALLOCATOR(PlainMonthDayPrototype);
GC_DECLARE_ALLOCATOR(PlainMonthDayPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -22,7 +22,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainTime);
GC_DEFINE_ALLOCATOR(PlainTime);
// 4 Temporal.PlainTime Objects, https://tc39.es/proposal-temporal/#sec-temporal-plaintime-objects
PlainTime::PlainTime(u8 iso_hour, u8 iso_minute, u8 iso_second, u16 iso_millisecond, u16 iso_microsecond, u16 iso_nanosecond, Calendar& calendar, Object& prototype)
@ -644,7 +644,7 @@ DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 micro
}
// 4.5.13 DifferenceTemporalPlainTime ( operation, temporalTime, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplaintime
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_time(VM& vm, DifferenceOperation operation, PlainTime const& temporal_time, Value other_value, Value options_value)
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_time(VM& vm, DifferenceOperation operation, PlainTime const& temporal_time, Value other_value, Value options_value)
{
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;

View file

@ -17,7 +17,7 @@ namespace JS::Temporal {
class PlainTime final : public Object {
JS_OBJECT(PlainTime, Object);
JS_DECLARE_ALLOCATOR(PlainTime);
GC_DECLARE_ALLOCATOR(PlainTime);
public:
virtual ~PlainTime() override = default;
@ -37,13 +37,13 @@ private:
virtual void visit_edges(Visitor&) override;
// 4.4 Properties of Temporal.PlainTime Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-plaintime-instances
u8 m_iso_hour { 0 }; // [[ISOHour]]
u8 m_iso_minute { 0 }; // [[ISOMinute]]
u8 m_iso_second { 0 }; // [[ISOSecond]]
u16 m_iso_millisecond { 0 }; // [[ISOMillisecond]]
u16 m_iso_microsecond { 0 }; // [[ISOMicrosecond]]
u16 m_iso_nanosecond { 0 }; // [[ISONanosecond]]
NonnullGCPtr<Calendar> m_calendar; // [[Calendar]] (always the built-in ISO 8601 calendar)
u8 m_iso_hour { 0 }; // [[ISOHour]]
u8 m_iso_minute { 0 }; // [[ISOMinute]]
u8 m_iso_second { 0 }; // [[ISOSecond]]
u16 m_iso_millisecond { 0 }; // [[ISOMillisecond]]
u16 m_iso_microsecond { 0 }; // [[ISOMicrosecond]]
u16 m_iso_nanosecond { 0 }; // [[ISONanosecond]]
GC::Ref<Calendar> m_calendar; // [[Calendar]] (always the built-in ISO 8601 calendar)
};
struct DaysAndTime {
@ -90,7 +90,7 @@ ThrowCompletionOr<String> temporal_time_to_string(VM&, u8 hour, u8 minute, u8 se
i8 compare_temporal_time(u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
DaysAndTime add_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
DaysAndTime round_time(u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, u64 increment, StringView unit, StringView rounding_mode, Optional<double> day_length_ns = {});
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_time(VM&, DifferenceOperation, PlainTime const&, Value other, Value options);
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_time(VM&, DifferenceOperation, PlainTime const&, Value other, Value options);
ThrowCompletionOr<PlainTime*> add_duration_to_or_subtract_duration_from_plain_time(VM&, ArithmeticOperation, PlainTime const&, Value temporal_duration_like);
}

View file

@ -12,7 +12,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainTimeConstructor);
GC_DEFINE_ALLOCATOR(PlainTimeConstructor);
// 4.1 The Temporal.PlainTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaintime-constructor
PlainTimeConstructor::PlainTimeConstructor(Realm& realm)
@ -46,7 +46,7 @@ ThrowCompletionOr<Value> PlainTimeConstructor::call()
}
// 4.1.1 Temporal.PlainTime ( [ hour [ , minute [ , second [ , millisecond [ , microsecond [ , nanosecond ] ] ] ] ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime
ThrowCompletionOr<NonnullGCPtr<Object>> PlainTimeConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> PlainTimeConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class PlainTimeConstructor final : public NativeFunction {
JS_OBJECT(PlainTimeConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(PlainTimeConstructor);
GC_DECLARE_ALLOCATOR(PlainTimeConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~PlainTimeConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit PlainTimeConstructor(Realm&);

View file

@ -19,7 +19,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainTimePrototype);
GC_DEFINE_ALLOCATOR(PlainTimePrototype);
// 4.3 Properties of the Temporal.PlainTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaintime-prototype-object
PlainTimePrototype::PlainTimePrototype(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class PlainTimePrototype final : public PrototypeObject<PlainTimePrototype, PlainTime> {
JS_PROTOTYPE_OBJECT(PlainTimePrototype, PlainTime, Temporal.PlainTime);
JS_DECLARE_ALLOCATOR(PlainTimePrototype);
GC_DECLARE_ALLOCATOR(PlainTimePrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -17,7 +17,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainYearMonth);
GC_DEFINE_ALLOCATOR(PlainYearMonth);
// 9 Temporal.PlainYearMonth Objects, https://tc39.es/proposal-temporal/#sec-temporal-plainyearmonth-objects
PlainYearMonth::PlainYearMonth(i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, Object& prototype)
@ -232,7 +232,7 @@ ThrowCompletionOr<String> temporal_year_month_to_string(VM& vm, PlainYearMonth&
}
// 9.5.7 DifferenceTemporalPlainYearMonth ( operation, yearMonth, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplainyearmonth
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_year_month(VM& vm, DifferenceOperation operation, PlainYearMonth& year_month, Value other_value, Value options_value)
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_year_month(VM& vm, DifferenceOperation operation, PlainYearMonth& year_month, Value other_value, Value options_value)
{
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
@ -264,7 +264,7 @@ ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_year_month(V
// 9. Let calendarRec be ? CreateCalendarMethodsRecord(calendar, « dateAdd, dateFromFields, dateUntil, fields »).
// FIXME: The type of calendar in PlainYearMonth does not align with latest spec
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateFromFields, CalendarMethod::DateUntil, CalendarMethod::Fields } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { calendar }, { { CalendarMethod::DateAdd, CalendarMethod::DateFromFields, CalendarMethod::DateUntil, CalendarMethod::Fields } }));
// 10. Let fieldNames be ? CalendarFields(calendarRec, « "monthCode", "year" »).
// FIXME: Pass through calendar record

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class PlainYearMonth final : public Object {
JS_OBJECT(PlainYearMonth, Object);
JS_DECLARE_ALLOCATOR(PlainYearMonth);
GC_DECLARE_ALLOCATOR(PlainYearMonth);
public:
virtual ~PlainYearMonth() override = default;
@ -30,10 +30,10 @@ private:
virtual void visit_edges(Visitor&) override;
// 9.4 Properties of Temporal.PlainYearMonth Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-plainyearmonth-instances
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 0 }; // [[ISOMonth]]
u8 m_iso_day { 0 }; // [[ISODay]]
NonnullGCPtr<Object> m_calendar; // [[Calendar]]
i32 m_iso_year { 0 }; // [[ISOYear]]
u8 m_iso_month { 0 }; // [[ISOMonth]]
u8 m_iso_day { 0 }; // [[ISODay]]
GC::Ref<Object> m_calendar; // [[Calendar]]
};
struct ISOYearMonth {
@ -48,7 +48,7 @@ bool iso_year_month_within_limits(i32 year, u8 month);
ISOYearMonth balance_iso_year_month(double year, double month);
ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM&, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target = nullptr);
ThrowCompletionOr<String> temporal_year_month_to_string(VM&, PlainYearMonth&, StringView show_calendar);
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_plain_year_month(VM&, DifferenceOperation, PlainYearMonth&, Value other, Value options);
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_year_month(VM&, DifferenceOperation, PlainYearMonth&, Value other, Value options);
ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(VM&, ArithmeticOperation, PlainYearMonth&, Value temporal_duration_like, Value options_value);
}

View file

@ -14,7 +14,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainYearMonthConstructor);
GC_DEFINE_ALLOCATOR(PlainYearMonthConstructor);
// 9.1 The Temporal.PlainYearMonth Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plainyearmonth-constructor
PlainYearMonthConstructor::PlainYearMonthConstructor(Realm& realm)
@ -48,7 +48,7 @@ ThrowCompletionOr<Value> PlainYearMonthConstructor::call()
}
// 9.1.1 Temporal.PlainYearMonth ( isoYear, isoMonth [ , calendarLike [ , referenceISODay ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth
ThrowCompletionOr<NonnullGCPtr<Object>> PlainYearMonthConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> PlainYearMonthConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class PlainYearMonthConstructor final : public NativeFunction {
JS_OBJECT(PlainYearMonthConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(PlainYearMonthConstructor);
GC_DECLARE_ALLOCATOR(PlainYearMonthConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~PlainYearMonthConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit PlainYearMonthConstructor(Realm&);

View file

@ -16,7 +16,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(PlainYearMonthPrototype);
GC_DEFINE_ALLOCATOR(PlainYearMonthPrototype);
// 9.3 Properties of the Temporal.PlainYearMonth Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainyearmonth-prototype-object
PlainYearMonthPrototype::PlainYearMonthPrototype(Realm& realm)

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class PlainYearMonthPrototype final : public PrototypeObject<PlainYearMonthPrototype, PlainYearMonth> {
JS_PROTOTYPE_OBJECT(PlainYearMonthPrototype, PlainYearMonth, Temporal.PlainYearMonth);
JS_DECLARE_ALLOCATOR(PlainYearMonthPrototype);
GC_DECLARE_ALLOCATOR(PlainYearMonthPrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -20,7 +20,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(Temporal);
GC_DEFINE_ALLOCATOR(Temporal);
// 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects
Temporal::Temporal(Realm& realm)

View file

@ -12,7 +12,7 @@ namespace JS::Temporal {
class Temporal final : public Object {
JS_OBJECT(Temporal, Object);
JS_DECLARE_ALLOCATOR(Temporal);
GC_DECLARE_ALLOCATOR(Temporal);
public:
virtual void initialize(Realm&) override;

View file

@ -24,7 +24,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(TimeZone);
GC_DEFINE_ALLOCATOR(TimeZone);
// 11 Temporal.TimeZone Objects, https://tc39.es/proposal-temporal/#sec-temporal-timezone-objects
TimeZone::TimeZone(Object& prototype)
@ -378,7 +378,7 @@ ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, TimeZoneMethods con
// 11.6.9 BuiltinTimeZoneGetOffsetStringFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetoffsetstringfor
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM& vm, Value time_zone, Instant& instant)
{
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
// 1. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(vm, time_zone_record, instant));
@ -390,7 +390,7 @@ ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM& vm, Value
// 11.6.10 BuiltinTimeZoneGetPlainDateTimeFor ( timeZone, instant, calendar ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetplaindatetimefor
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM& vm, Value time_zone, Instant& instant, Object& calendar)
{
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
// 1. Assert: instant has an [[InitializedTemporalInstant]] internal slot.
@ -408,12 +408,12 @@ ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM&
}
// 11.6.11 BuiltinTimeZoneGetInstantFor ( timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetinstantfor
ThrowCompletionOr<NonnullGCPtr<Instant>> builtin_time_zone_get_instant_for(VM& vm, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
ThrowCompletionOr<GC::Ref<Instant>> builtin_time_zone_get_instant_for(VM& vm, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
{
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
// 2. Let possibleInstants be ? GetPossibleInstantsFor(timeZone, dateTime).
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor, TimeZoneMethod::GetPossibleInstantsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetOffsetNanosecondsFor, TimeZoneMethod::GetPossibleInstantsFor } }));
auto possible_instants = TRY(get_possible_instants_for(vm, time_zone_record, date_time));
// 3. Return ? DisambiguatePossibleInstants(possibleInstants, timeZone, dateTime, disambiguation).
@ -421,7 +421,7 @@ ThrowCompletionOr<NonnullGCPtr<Instant>> builtin_time_zone_get_instant_for(VM& v
}
// 11.6.12 DisambiguatePossibleInstants ( possibleInstants, timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-disambiguatepossibleinstants
ThrowCompletionOr<NonnullGCPtr<Instant>> disambiguate_possible_instants(VM& vm, MarkedVector<NonnullGCPtr<Instant>> const& possible_instants, TimeZoneMethods const& time_zone_record, PlainDateTime& date_time, StringView disambiguation)
ThrowCompletionOr<GC::Ref<Instant>> disambiguate_possible_instants(VM& vm, GC::MarkedVector<GC::Ref<Instant>> const& possible_instants, TimeZoneMethods const& time_zone_record, PlainDateTime& date_time, StringView disambiguation)
{
// 1. Assert: TimeZoneMethodsRecordHasLookedUp(timeZoneRec, GET-POSSIBLE-INSTANTS-FOR) is true.
VERIFY(time_zone_methods_record_has_looked_up(time_zone_record, TimeZoneMethod::GetPossibleInstantsFor));
@ -544,14 +544,14 @@ ThrowCompletionOr<NonnullGCPtr<Instant>> disambiguate_possible_instants(VM& vm,
}
// 11.5.24 GetPossibleInstantsFor ( timeZoneRec, dateTime ), https://tc39.es/proposal-temporal/#sec-temporal-getpossibleinstantsfor
ThrowCompletionOr<MarkedVector<NonnullGCPtr<Instant>>> get_possible_instants_for(VM& vm, TimeZoneMethods const& time_zone_record, PlainDateTime const& date_time)
ThrowCompletionOr<GC::MarkedVector<GC::Ref<Instant>>> get_possible_instants_for(VM& vm, TimeZoneMethods const& time_zone_record, PlainDateTime const& date_time)
{
// 1. Let possibleInstants be ? TimeZoneMethodsRecordCall(timeZoneRec, GET-POSSIBLE-INSTANTS-FOR, « dateTime »).
auto possible_instants = TRY(time_zone_methods_record_call(vm, time_zone_record, TimeZoneMethod::GetPossibleInstantsFor, { { &date_time } }));
// 2. If TimeZoneMethodsRecordIsBuiltin(timeZoneRec), return ! CreateListFromArrayLike(possibleInstants, « Object »).
if (time_zone_methods_record_is_builtin(time_zone_record)) {
auto list = MarkedVector<NonnullGCPtr<Instant>> { vm.heap() };
auto list = GC::MarkedVector<GC::Ref<Instant>> { vm.heap() };
(void)MUST(create_list_from_array_like(vm, possible_instants, [&list](auto value) -> ThrowCompletionOr<void> {
list.append(verify_cast<Instant>(value.as_object()));
@ -565,7 +565,7 @@ ThrowCompletionOr<MarkedVector<NonnullGCPtr<Instant>>> get_possible_instants_for
auto iterator = TRY(get_iterator(vm, possible_instants, IteratorHint::Sync));
// 4. Let list be a new empty List.
auto list = MarkedVector<NonnullGCPtr<Instant>> { vm.heap() };
auto list = GC::MarkedVector<GC::Ref<Instant>> { vm.heap() };
// 5. Repeat,
while (true) {

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/Optional.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibGC/MarkedVector.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
@ -15,7 +15,7 @@ namespace JS::Temporal {
class TimeZone final : public Object {
JS_OBJECT(TimeZone, Object);
JS_DECLARE_ALLOCATOR(TimeZone);
GC_DECLARE_ALLOCATOR(TimeZone);
public:
// Needs to store values in the range -8.64 * 10^13 to 8.64 * 10^13
@ -49,9 +49,9 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM&, Value temporal_time_zone_l
ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, TimeZoneMethods const& time_zone_record, Instant const& instant);
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM&, Value time_zone, Instant&);
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM&, Value time_zone, Instant&, Object& calendar);
ThrowCompletionOr<NonnullGCPtr<Instant>> builtin_time_zone_get_instant_for(VM&, Value time_zone, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<NonnullGCPtr<Instant>> disambiguate_possible_instants(VM&, MarkedVector<NonnullGCPtr<Instant>> const& possible_instants, TimeZoneMethods const&, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<MarkedVector<NonnullGCPtr<Instant>>> get_possible_instants_for(VM&, TimeZoneMethods const&, PlainDateTime const&);
ThrowCompletionOr<GC::Ref<Instant>> builtin_time_zone_get_instant_for(VM&, Value time_zone, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<GC::Ref<Instant>> disambiguate_possible_instants(VM&, GC::MarkedVector<GC::Ref<Instant>> const& possible_instants, TimeZoneMethods const&, PlainDateTime&, StringView disambiguation);
ThrowCompletionOr<GC::MarkedVector<GC::Ref<Instant>>> get_possible_instants_for(VM&, TimeZoneMethods const&, PlainDateTime const&);
ThrowCompletionOr<bool> time_zone_equals(VM&, Object& one, Object& two);
}

View file

@ -11,7 +11,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(TimeZoneConstructor);
GC_DEFINE_ALLOCATOR(TimeZoneConstructor);
// 11.2 The Temporal.TimeZone Constructor, https://tc39.es/proposal-temporal/#sec-temporal-timezone-constructor
TimeZoneConstructor::TimeZoneConstructor(Realm& realm)
@ -45,7 +45,7 @@ ThrowCompletionOr<Value> TimeZoneConstructor::call()
}
// 11.2.1 Temporal.TimeZone ( identifier ), https://tc39.es/proposal-temporal/#sec-temporal.timezone
ThrowCompletionOr<NonnullGCPtr<Object>> TimeZoneConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> TimeZoneConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class TimeZoneConstructor final : public NativeFunction {
JS_OBJECT(TimeZoneConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(TimeZoneConstructor);
GC_DECLARE_ALLOCATOR(TimeZoneConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~TimeZoneConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit TimeZoneConstructor(Realm&);

View file

@ -11,7 +11,7 @@
namespace JS::Temporal {
// 11.5.2 CreateTimeZoneMethodsRecord ( timeZone, methods ), https://tc39.es/proposal-temporal/#sec-temporal-createtimezonemethodsrecord
ThrowCompletionOr<TimeZoneMethods> create_time_zone_methods_record(VM& vm, Variant<String, NonnullGCPtr<Object>> time_zone, ReadonlySpan<TimeZoneMethod> methods)
ThrowCompletionOr<TimeZoneMethods> create_time_zone_methods_record(VM& vm, Variant<String, GC::Ref<Object>> time_zone, ReadonlySpan<TimeZoneMethod> methods)
{
// 1. Let record be the Time Zone Methods Record { [[Receiver]]: timeZone, [[GetOffsetNanosecondsFor]]: undefined, [[GetPossibleInstantsFor]]: undefined }.
TimeZoneMethods record {
@ -56,7 +56,7 @@ ThrowCompletionOr<void> time_zone_methods_record_lookup(VM& vm, TimeZoneMethods&
const auto& time_zone_prototype = *realm.intrinsics().temporal_time_zone_prototype(); \
time_zone_record.snake_name = time_zone_prototype.get_without_side_effects(vm.names.camelName).as_function(); \
} else { \
Value time_zone { time_zone_record.receiver.get<NonnullGCPtr<Object>>() }; \
Value time_zone { time_zone_record.receiver.get<GC::Ref<Object>>() }; \
time_zone_record.snake_name = TRY(time_zone.get_method(vm, vm.names.camelName)); \
if (!time_zone_record.snake_name) \
return vm.throw_completion<TypeError>(ErrorType::IsUndefined, #camelName##sv); \
@ -110,11 +110,11 @@ ThrowCompletionOr<Value> time_zone_methods_record_call(VM& vm, TimeZoneMethods c
// 2. Let receiver be timeZoneRec.[[Receiver]].
// 3. If TimeZoneMethodsRecordIsBuiltin(timeZoneRec) is true, then
// a. Set receiver to ! CreateTemporalTimeZone(timeZoneRec.[[Receiver]]).
GCPtr<Object> receiver;
GC::Ptr<Object> receiver;
if (time_zone_methods_record_is_builtin(time_zone_record))
receiver = MUST(create_temporal_time_zone(vm, time_zone_record.receiver.get<String>()));
else
receiver = time_zone_record.receiver.get<NonnullGCPtr<Object>>();
receiver = time_zone_record.receiver.get<GC::Ref<Object>>();
// 4. If methodName is GET-OFFSET-NANOSECONDS-FOR, then
// a. Return ? Call(timeZoneRec.[[GetOffsetNanosecondsFor]], receiver, arguments).

View file

@ -7,21 +7,21 @@
#pragma once
#include <AK/String.h>
#include <LibGC/Ptr.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
namespace JS::Temporal {
// 11.5.1 Time Zone Methods Records, https://tc39.es/proposal-temporal/#sec-temporal-time-zone-methods-records
struct TimeZoneMethods {
// The time zone object, or a string indicating a built-in time zone.
Variant<String, NonnullGCPtr<Object>> receiver; // [[Reciever]]
Variant<String, GC::Ref<Object>> receiver; // [[Reciever]]
// The time zone's getOffsetNanosecondsFor method. For a built-in time zone this is always %Temporal.TimeZone.prototype.getOffsetNanosecondsFor%.
GCPtr<FunctionObject> get_offset_nanoseconds_for; // [[GetOffsetNanosecondsFor]]
GC::Ptr<FunctionObject> get_offset_nanoseconds_for; // [[GetOffsetNanosecondsFor]]
// The time zone's getPossibleInstantsFor method. For a built-in time zone this is always %Temporal.TimeZone.prototype.getPossibleInstantsFor%.
GCPtr<FunctionObject> get_possible_instants_for; // [[GetPossibleInstantsFor]]
GC::Ptr<FunctionObject> get_possible_instants_for; // [[GetPossibleInstantsFor]]
};
#define JS_ENUMERATE_TIME_ZONE_METHODS \
@ -36,7 +36,7 @@ enum class TimeZoneMethod {
};
ThrowCompletionOr<void> time_zone_methods_record_lookup(VM&, TimeZoneMethods&, TimeZoneMethod);
ThrowCompletionOr<TimeZoneMethods> create_time_zone_methods_record(VM&, Variant<String, NonnullGCPtr<Object>> time_zone, ReadonlySpan<TimeZoneMethod>);
ThrowCompletionOr<TimeZoneMethods> create_time_zone_methods_record(VM&, Variant<String, GC::Ref<Object>> time_zone, ReadonlySpan<TimeZoneMethod>);
bool time_zone_methods_record_has_looked_up(TimeZoneMethods const&, TimeZoneMethod);
bool time_zone_methods_record_is_builtin(TimeZoneMethods const&);
ThrowCompletionOr<Value> time_zone_methods_record_call(VM&, TimeZoneMethods const&, TimeZoneMethod, ReadonlySpan<Value> arguments);

View file

@ -17,7 +17,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(TimeZonePrototype);
GC_DEFINE_ALLOCATOR(TimeZonePrototype);
// 11.4 Properties of the Temporal.TimeZone Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-timezone-prototype-object
TimeZonePrototype::TimeZonePrototype(Realm& realm)
@ -158,7 +158,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_possible_instants_for)
}
// 6. Let possibleInstants be a new empty List.
auto possible_instants = MarkedVector<Value> { vm.heap() };
auto possible_instants = GC::MarkedVector<Value> { vm.heap() };
// 7. For each value epochNanoseconds in possibleEpochNanoseconds, do
for (auto& epoch_nanoseconds : possible_epoch_nanoseconds) {

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class TimeZonePrototype final : public PrototypeObject<TimeZonePrototype, TimeZone> {
JS_PROTOTYPE_OBJECT(TimeZonePrototype, TimeZone, Temporal.TimeZone);
JS_DECLARE_ALLOCATOR(TimeZonePrototype);
GC_DECLARE_ALLOCATOR(TimeZonePrototype);
public:
virtual void initialize(Realm&) override;

View file

@ -20,7 +20,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(ZonedDateTime);
GC_DEFINE_ALLOCATOR(ZonedDateTime);
// 6 Temporal.ZonedDateTime Objects, https://tc39.es/proposal-temporal/#sec-temporal-zoneddatetime-objects
ZonedDateTime::ZonedDateTime(BigInt const& nanoseconds, Object& time_zone, Object& calendar, Object& prototype)
@ -81,7 +81,7 @@ ThrowCompletionOr<BigInt const*> interpret_iso_date_time_offset(VM& vm, i32 year
VERIFY(offset_option.is_one_of("prefer"sv, "reject"sv));
// 7. Let possibleInstants be ? GetPossibleInstantsFor(timeZone, dateTime).
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetPossibleInstantsFor, TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone.as_object() }, { { TimeZoneMethod::GetPossibleInstantsFor, TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto possible_instants = TRY(get_possible_instants_for(vm, time_zone_record, *date_time));
// 8. For each element candidate of possibleInstants, do
@ -329,7 +329,7 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM& vm, ZonedDateTi
}
// 11. Else,
else {
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
// a. Let offsetNs be ? GetOffsetNanosecondsFor(timeZone, instant).
auto offset_ns = TRY(get_offset_nanoseconds_for(vm, time_zone_record, *instant));
@ -574,7 +574,7 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
}
// 6.5.8 DifferenceTemporalZonedDateTime ( operation, zonedDateTime, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalzoneddatetime
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_zoned_date_time(VM& vm, DifferenceOperation operation, ZonedDateTime& zoned_date_time, Value other_value, Value options_value)
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_zoned_date_time(VM& vm, DifferenceOperation operation, ZonedDateTime& zoned_date_time, Value other_value, Value options_value)
{
// 1. If operation is since, let sign be -1. Otherwise, let sign be 1.
i8 sign = operation == DifferenceOperation::Since ? -1 : 1;
@ -612,7 +612,7 @@ ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_zoned_date_time(VM
// 8. Let difference be ? DifferenceZonedDateTime(zonedDateTime.[[Nanoseconds]], other.[[Nanoseconds]], zonedDateTime.[[TimeZone]], zonedDateTime.[[Calendar]], settings.[[LargestUnit]], untilOptions).
auto difference = TRY(difference_zoned_date_time(vm, zoned_date_time.nanoseconds(), other->nanoseconds(), zoned_date_time.time_zone(), zoned_date_time.calendar(), settings.largest_unit, *until_options));
auto calendar_record = TRY(create_calendar_methods_record(vm, NonnullGCPtr<Object> { zoned_date_time.calendar() }, { { CalendarMethod::DateAdd, CalendarMethod::DateFromFields, CalendarMethod::DateUntil, CalendarMethod::Fields } }));
auto calendar_record = TRY(create_calendar_methods_record(vm, GC::Ref<Object> { zoned_date_time.calendar() }, { { CalendarMethod::DateAdd, CalendarMethod::DateFromFields, CalendarMethod::DateUntil, CalendarMethod::Fields } }));
// 9. Let roundResult be (? RoundDuration(difference.[[Years]], difference.[[Months]], difference.[[Weeks]], difference.[[Days]], difference.[[Hours]], difference.[[Minutes]], difference.[[Seconds]], difference.[[Milliseconds]], difference.[[Microseconds]], difference.[[Nanoseconds]], settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]], zonedDateTime)).[[DurationRecord]].
auto round_result = TRY(round_duration(vm, difference.years, difference.months, difference.weeks, difference.days, difference.hours, difference.minutes, difference.seconds, difference.milliseconds, difference.microseconds, difference.nanoseconds, settings.rounding_increment, settings.smallest_unit, settings.rounding_mode, &zoned_date_time, calendar_record)).duration_record;

View file

@ -14,7 +14,7 @@ namespace JS::Temporal {
class ZonedDateTime final : public Object {
JS_OBJECT(ZonedDateTime, Object);
JS_DECLARE_ALLOCATOR(ZonedDateTime);
GC_DECLARE_ALLOCATOR(ZonedDateTime);
public:
virtual ~ZonedDateTime() override = default;
@ -31,9 +31,9 @@ private:
virtual void visit_edges(Visitor&) override;
// 6.4 Properties of Temporal.ZonedDateTime Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-zoneddatetime-instances
NonnullGCPtr<BigInt const> m_nanoseconds; // [[Nanoseconds]]
NonnullGCPtr<Object> m_time_zone; // [[TimeZone]]
NonnullGCPtr<Object> m_calendar; // [[Calendar]]
GC::Ref<BigInt const> m_nanoseconds; // [[Nanoseconds]]
GC::Ref<Object> m_time_zone; // [[TimeZone]]
GC::Ref<Object> m_calendar; // [[Calendar]]
};
struct NanosecondsToDaysResult {
@ -60,7 +60,7 @@ ThrowCompletionOr<String> temporal_zoned_date_time_to_string(VM&, ZonedDateTime&
ThrowCompletionOr<BigInt*> add_zoned_date_time(VM&, BigInt const& epoch_nanoseconds, Value time_zone, Object& calendar, double years, double months, double weeks, double days, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds, Object* options = nullptr);
ThrowCompletionOr<DurationRecord> difference_zoned_date_time(VM&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, Object& time_zone, Object& calendar, StringView largest_unit, Object const& options);
ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM&, Crypto::SignedBigInteger nanoseconds, Value relative_to);
ThrowCompletionOr<NonnullGCPtr<Duration>> difference_temporal_zoned_date_time(VM&, DifferenceOperation, ZonedDateTime&, Value other, Value options);
ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_zoned_date_time(VM&, DifferenceOperation, ZonedDateTime&, Value other, Value options);
ThrowCompletionOr<ZonedDateTime*> add_duration_to_or_subtract_duration_from_zoned_date_time(VM&, ArithmeticOperation, ZonedDateTime&, Value temporal_duration_like, Value options_value);
}

View file

@ -15,7 +15,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(ZonedDateTimeConstructor);
GC_DEFINE_ALLOCATOR(ZonedDateTimeConstructor);
// 6.1 The Temporal.ZonedDateTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-zoneddatetime-constructor
ZonedDateTimeConstructor::ZonedDateTimeConstructor(Realm& realm)
@ -50,7 +50,7 @@ ThrowCompletionOr<Value> ZonedDateTimeConstructor::call()
}
// 6.1.1 Temporal.ZonedDateTime ( epochNanoseconds, timeZoneLike [ , calendarLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime
ThrowCompletionOr<NonnullGCPtr<Object>> ZonedDateTimeConstructor::construct(FunctionObject& new_target)
ThrowCompletionOr<GC::Ref<Object>> ZonedDateTimeConstructor::construct(FunctionObject& new_target)
{
auto& vm = this->vm();

View file

@ -12,14 +12,14 @@ namespace JS::Temporal {
class ZonedDateTimeConstructor final : public NativeFunction {
JS_OBJECT(ZonedDateTimeConstructor, NativeFunction);
JS_DECLARE_ALLOCATOR(ZonedDateTimeConstructor);
GC_DECLARE_ALLOCATOR(ZonedDateTimeConstructor);
public:
virtual void initialize(Realm&) override;
virtual ~ZonedDateTimeConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
private:
explicit ZonedDateTimeConstructor(Realm&);

View file

@ -20,7 +20,7 @@
namespace JS::Temporal {
JS_DEFINE_ALLOCATOR(ZonedDateTimePrototype);
GC_DEFINE_ALLOCATOR(ZonedDateTimePrototype);
// 6.3 Properties of the Temporal.ZonedDateTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-zoneddatetime-prototype-object
ZonedDateTimePrototype::ZonedDateTimePrototype(Realm& realm)
@ -676,7 +676,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::offset_nanoseconds_getter)
// 3. Let timeZone be zonedDateTime.[[TimeZone]].
// 3. Let timeZoneRec be ? CreateTimeZoneMethodsRecord(zonedDateTime.[[TimeZone]], « GET-OFFSET-NANOSECONDS-FOR »).
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { zoned_date_time->time_zone() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { zoned_date_time->time_zone() }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
// 4. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));
@ -1045,7 +1045,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::round)
// 12. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time->time_zone();
auto time_zone_record = TRY(create_time_zone_methods_record(vm, NonnullGCPtr<Object> { time_zone }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
auto time_zone_record = TRY(create_time_zone_methods_record(vm, GC::Ref<Object> { time_zone }, { { TimeZoneMethod::GetOffsetNanosecondsFor } }));
// 13. Let instant be ! CreateTemporalInstant(zonedDateTime.[[Nanoseconds]]).
auto* instant = MUST(create_temporal_instant(vm, zoned_date_time->nanoseconds()));

View file

@ -13,7 +13,7 @@ namespace JS::Temporal {
class ZonedDateTimePrototype final : public PrototypeObject<ZonedDateTimePrototype, ZonedDateTime> {
JS_PROTOTYPE_OBJECT(ZonedDateTimePrototype, ZonedDateTime, Temporal.ZonedDateTime);
JS_DECLARE_ALLOCATOR(ZonedDateTimePrototype);
GC_DECLARE_ALLOCATOR(ZonedDateTimePrototype);
public:
virtual void initialize(Realm&) override;