mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
LibJS: Replace GlobalObject with VM in Temporal AOs [Part 2/19]
This commit is contained in:
parent
f9705eb2f4
commit
694f66b5ca
58 changed files with 1564 additions and 1600 deletions
|
@ -63,8 +63,11 @@ String default_time_zone()
|
|||
}
|
||||
|
||||
// 11.6.1 CreateTemporalTimeZone ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaltimezone
|
||||
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
|
||||
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, String const& identifier, FunctionObject const* new_target)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%.
|
||||
if (!new_target)
|
||||
new_target = global_object.temporal_time_zone_constructor();
|
||||
|
@ -73,7 +76,7 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_obje
|
|||
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype));
|
||||
|
||||
// 3. Let offsetNanosecondsResult be Completion(ParseTimeZoneOffsetString(identifier)).
|
||||
auto offset_nanoseconds_result = parse_time_zone_offset_string(global_object, identifier);
|
||||
auto offset_nanoseconds_result = parse_time_zone_offset_string(vm, identifier);
|
||||
|
||||
// 4. If offsetNanosecondsResult is an abrupt completion, then
|
||||
if (offset_nanoseconds_result.is_throw_completion()) {
|
||||
|
@ -100,10 +103,8 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_obje
|
|||
}
|
||||
|
||||
// 11.6.2 GetISOPartsFromEpoch ( epochNanoseconds ), https://tc39.es/proposal-temporal/#sec-temporal-getisopartsfromepoch
|
||||
ISODateTime get_iso_parts_from_epoch(GlobalObject& global_object, Crypto::SignedBigInteger const& epoch_nanoseconds)
|
||||
ISODateTime get_iso_parts_from_epoch(VM& vm, Crypto::SignedBigInteger const& epoch_nanoseconds)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: ! IsValidEpochNanoseconds(ℤ(epochNanoseconds)) is true.
|
||||
VERIFY(is_valid_epoch_nanoseconds(*js_bigint(vm, epoch_nanoseconds)));
|
||||
|
||||
|
@ -150,7 +151,7 @@ ISODateTime get_iso_parts_from_epoch(GlobalObject& global_object, Crypto::Signed
|
|||
}
|
||||
|
||||
// 11.6.3 GetIANATimeZoneEpochValue ( timeZoneIdentifier, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneepochvalue
|
||||
MarkedVector<BigInt*> get_iana_time_zone_epoch_value(GlobalObject& global_object, [[maybe_unused]] StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
|
||||
MarkedVector<BigInt*> get_iana_time_zone_epoch_value(VM& vm, [[maybe_unused]] StringView time_zone_identifier, i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond)
|
||||
{
|
||||
// The implementation-defined abstract operation GetIANATimeZoneEpochValue takes arguments timeZoneIdentifier (a String), year (an integer), month (an integer between 1 and 12 inclusive), day (an integer between 1 and 31 inclusive), hour (an integer between 0 and 23 inclusive), minute (an integer between 0 and 59 inclusive), second (an integer between 0 and 59 inclusive), millisecond (an integer between 0 and 999 inclusive), microsecond (an integer between 0 and 999 inclusive), and nanosecond (an integer between 0 and 999 inclusive) and returns a List of BigInts.
|
||||
// Each value in the returned List represents a number of nanoseconds since the Unix epoch in UTC that corresponds to the given ISO 8601 calendar date and wall-clock time in the IANA time zone identified by timeZoneIdentifier.
|
||||
|
@ -158,9 +159,8 @@ MarkedVector<BigInt*> get_iana_time_zone_epoch_value(GlobalObject& global_object
|
|||
// It is an error to call GetIANATimeZoneEpochValue with arguments such that IsValidISODate(year, month, day) is false.
|
||||
|
||||
// FIXME: Implement this properly for non-UTC timezones.
|
||||
auto& vm = global_object.vm();
|
||||
auto list = MarkedVector<BigInt*> { vm.heap() };
|
||||
list.append(get_epoch_from_iso_parts(global_object, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
|
||||
list.append(get_epoch_from_iso_parts(vm, year, month, day, hour, minute, second, millisecond, microsecond, nanosecond));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, Strin
|
|||
}
|
||||
|
||||
// 11.6.5 GetIANATimeZoneNextTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezonenexttransition
|
||||
BigInt* get_iana_time_zone_next_transition(GlobalObject&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
|
||||
BigInt* get_iana_time_zone_next_transition(VM&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
|
||||
{
|
||||
// The implementation-defined abstract operation GetIANATimeZoneNextTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null.
|
||||
// The returned value t represents the number of nanoseconds since the Unix epoch in UTC that corresponds to the first time zone transition after epochNanoseconds in the IANA time zone identified by timeZoneIdentifier. The operation returns null if no such transition exists for which t ≤ ℤ(nsMaxInstant).
|
||||
|
@ -208,7 +208,7 @@ BigInt* get_iana_time_zone_next_transition(GlobalObject&, [[maybe_unused]] BigIn
|
|||
}
|
||||
|
||||
// 11.6.6 GetIANATimeZonePreviousTransition ( epochNanoseconds, timeZoneIdentifier ), https://tc39.es/proposal-temporal/#sec-temporal-getianatimezoneprevioustransition
|
||||
BigInt* get_iana_time_zone_previous_transition(GlobalObject&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
|
||||
BigInt* get_iana_time_zone_previous_transition(VM&, [[maybe_unused]] BigInt const& epoch_nanoseconds, [[maybe_unused]] StringView time_zone_identifier)
|
||||
{
|
||||
// The implementation-defined abstract operation GetIANATimeZonePreviousTransition takes arguments epochNanoseconds (a BigInt) and timeZoneIdentifier (a String) and returns a BigInt or null.
|
||||
// The returned value t represents the number of nanoseconds since the Unix epoch in UTC that corresponds to the last time zone transition before epochNanoseconds in the IANA time zone identified by timeZoneIdentifier. The operation returns null if no such transition exists for which t ≥ ℤ(nsMinInstant).
|
||||
|
@ -262,10 +262,8 @@ bool is_valid_time_zone_numeric_utc_offset_syntax(String const& offset_string)
|
|||
}
|
||||
|
||||
// 11.6.7 ParseTimeZoneOffsetString ( offsetString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetimezoneoffsetstring
|
||||
ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject& global_object, String const& offset_string)
|
||||
ThrowCompletionOr<double> parse_time_zone_offset_string(VM& vm, String const& offset_string)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let parseResult be ParseText(StringToCodePoints(offsetString), TimeZoneNumericUTCOffset).
|
||||
auto parse_result = parse_iso8601(Production::TimeZoneNumericUTCOffset, offset_string);
|
||||
|
||||
|
@ -418,9 +416,10 @@ String format_iso_time_zone_offset_string(double offset_nanoseconds)
|
|||
}
|
||||
|
||||
// 11.6.10 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone
|
||||
ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Value temporal_time_zone_like)
|
||||
ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zone_like)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If Type(temporalTimeZoneLike) is Object, then
|
||||
if (temporal_time_zone_like.is_object()) {
|
||||
|
@ -448,7 +447,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
|
|||
auto identifier = TRY(temporal_time_zone_like.to_string(global_object));
|
||||
|
||||
// 3. Let parseResult be ? ParseTemporalTimeZoneString(identifier).
|
||||
auto parse_result = TRY(parse_temporal_time_zone_string(global_object, identifier));
|
||||
auto parse_result = TRY(parse_temporal_time_zone_string(vm, identifier));
|
||||
|
||||
// 4. If parseResult.[[Name]] is not undefined, then
|
||||
if (parse_result.name.has_value()) {
|
||||
|
@ -466,21 +465,22 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
|
|||
}
|
||||
|
||||
// c. Return ! CreateTemporalTimeZone(name).
|
||||
return MUST(create_temporal_time_zone(global_object, name));
|
||||
return MUST(create_temporal_time_zone(vm, name));
|
||||
}
|
||||
|
||||
// 5. If parseResult.[[Z]] is true, return ! CreateTemporalTimeZone("UTC").
|
||||
if (parse_result.z)
|
||||
return MUST(create_temporal_time_zone(global_object, "UTC"sv));
|
||||
return MUST(create_temporal_time_zone(vm, "UTC"sv));
|
||||
|
||||
// 6. Return ! CreateTemporalTimeZone(parseResult.[[OffsetString]]).
|
||||
return MUST(create_temporal_time_zone(global_object, *parse_result.offset_string));
|
||||
return MUST(create_temporal_time_zone(vm, *parse_result.offset_string));
|
||||
}
|
||||
|
||||
// 11.6.11 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor
|
||||
ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject& global_object, Value time_zone, Instant& instant)
|
||||
ThrowCompletionOr<double> get_offset_nanoseconds_for(VM& vm, Value time_zone, Instant& instant)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Let getOffsetNanosecondsFor be ? GetMethod(timeZone, "getOffsetNanosecondsFor").
|
||||
auto* get_offset_nanoseconds_for = TRY(time_zone.get_method(global_object, vm.names.getOffsetNanosecondsFor));
|
||||
|
@ -508,50 +508,48 @@ ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject& global_object
|
|||
}
|
||||
|
||||
// 11.6.12 BuiltinTimeZoneGetOffsetStringFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetoffsetstringfor
|
||||
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(GlobalObject& global_object, Value time_zone, Instant& instant)
|
||||
ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(VM& vm, Value time_zone, Instant& instant)
|
||||
{
|
||||
// 1. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
|
||||
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, time_zone, instant));
|
||||
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
|
||||
|
||||
// 2. Return ! FormatTimeZoneOffsetString(offsetNanoseconds).
|
||||
return format_time_zone_offset_string(offset_nanoseconds);
|
||||
}
|
||||
|
||||
// 11.6.13 BuiltinTimeZoneGetPlainDateTimeFor ( timeZone, instant, calendar ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetplaindatetimefor
|
||||
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(GlobalObject& global_object, Value time_zone, Instant& instant, Object& calendar)
|
||||
ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(VM& vm, Value time_zone, Instant& instant, Object& calendar)
|
||||
{
|
||||
// 1. Assert: instant has an [[InitializedTemporalInstant]] internal slot.
|
||||
|
||||
// 2. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
|
||||
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, time_zone, instant));
|
||||
auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(vm, time_zone, instant));
|
||||
|
||||
// 3. Let result be ! GetISOPartsFromEpoch(ℝ(instant.[[Nanoseconds]])).
|
||||
auto result = get_iso_parts_from_epoch(global_object, instant.nanoseconds().big_integer());
|
||||
auto result = get_iso_parts_from_epoch(vm, instant.nanoseconds().big_integer());
|
||||
|
||||
// 4. Set result to BalanceISODateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]] + offsetNanoseconds).
|
||||
result = balance_iso_date_time(result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond + offset_nanoseconds);
|
||||
|
||||
// 5. Return ? CreateTemporalDateTime(result.[[Year]], result.[[Month]], result.[[Day]], result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]], calendar).
|
||||
return create_temporal_date_time(global_object, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar);
|
||||
return create_temporal_date_time(vm, result.year, result.month, result.day, result.hour, result.minute, result.second, result.millisecond, result.microsecond, result.nanosecond, calendar);
|
||||
}
|
||||
|
||||
// 11.6.14 BuiltinTimeZoneGetInstantFor ( timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetinstantfor
|
||||
ThrowCompletionOr<Instant*> builtin_time_zone_get_instant_for(GlobalObject& global_object, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
|
||||
ThrowCompletionOr<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 possible_instants = TRY(get_possible_instants_for(global_object, time_zone, date_time));
|
||||
auto possible_instants = TRY(get_possible_instants_for(vm, time_zone, date_time));
|
||||
|
||||
// 3. Return ? DisambiguatePossibleInstants(possibleInstants, timeZone, dateTime, disambiguation).
|
||||
return disambiguate_possible_instants(global_object, possible_instants, time_zone, date_time, disambiguation);
|
||||
return disambiguate_possible_instants(vm, possible_instants, time_zone, date_time, disambiguation);
|
||||
}
|
||||
|
||||
// 11.6.15 DisambiguatePossibleInstants ( possibleInstants, timeZone, dateTime, disambiguation ), https://tc39.es/proposal-temporal/#sec-temporal-disambiguatepossibleinstants
|
||||
ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_object, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
|
||||
ThrowCompletionOr<Instant*> disambiguate_possible_instants(VM& vm, MarkedVector<Instant*> const& possible_instants, Value time_zone, PlainDateTime& date_time, StringView disambiguation)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
|
||||
|
||||
// 2. Let n be possibleInstants's length.
|
||||
|
@ -594,7 +592,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
|
|||
}
|
||||
|
||||
// 7. Let epochNanoseconds be GetEpochFromISOParts(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]]).
|
||||
auto* epoch_nanoseconds = get_epoch_from_iso_parts(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
|
||||
auto* epoch_nanoseconds = get_epoch_from_iso_parts(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond());
|
||||
|
||||
// 8. Let dayBeforeNs be epochNanoseconds - ℤ(nsPerDay).
|
||||
auto* day_before_ns = js_bigint(vm, epoch_nanoseconds->big_integer().minus(ns_per_day_bigint));
|
||||
|
@ -604,7 +602,7 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
|
|||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||
|
||||
// 10. Let dayBefore be ! CreateTemporalInstant(dayBeforeNs).
|
||||
auto* day_before = MUST(create_temporal_instant(global_object, *day_before_ns));
|
||||
auto* day_before = MUST(create_temporal_instant(vm, *day_before_ns));
|
||||
|
||||
// 11. Let dayAfterNs be epochNanoseconds + ℤ(nsPerDay).
|
||||
auto* day_after_ns = js_bigint(vm, epoch_nanoseconds->big_integer().plus(ns_per_day_bigint));
|
||||
|
@ -614,13 +612,13 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
|
|||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidEpochNanoseconds);
|
||||
|
||||
// 13. Let dayAfter be ! CreateTemporalInstant(dayAfterNs).
|
||||
auto* day_after = MUST(create_temporal_instant(global_object, *day_after_ns));
|
||||
auto* day_after = MUST(create_temporal_instant(vm, *day_after_ns));
|
||||
|
||||
// 14. Let offsetBefore be ? GetOffsetNanosecondsFor(timeZone, dayBefore).
|
||||
auto offset_before = TRY(get_offset_nanoseconds_for(global_object, time_zone, *day_before));
|
||||
auto offset_before = TRY(get_offset_nanoseconds_for(vm, time_zone, *day_before));
|
||||
|
||||
// 15. Let offsetAfter be ? GetOffsetNanosecondsFor(timeZone, dayAfter).
|
||||
auto offset_after = TRY(get_offset_nanoseconds_for(global_object, time_zone, *day_after));
|
||||
auto offset_after = TRY(get_offset_nanoseconds_for(vm, time_zone, *day_after));
|
||||
|
||||
// 16. Let nanoseconds be offsetAfter - offsetBefore.
|
||||
auto nanoseconds = offset_after - offset_before;
|
||||
|
@ -628,13 +626,13 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
|
|||
// 17. If disambiguation is "earlier", then
|
||||
if (disambiguation == "earlier"sv) {
|
||||
// a. Let earlier be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, undefined).
|
||||
auto earlier = TRY(add_date_time(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, nullptr));
|
||||
auto earlier = TRY(add_date_time(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, -nanoseconds, nullptr));
|
||||
|
||||
// b. Let earlierDateTime be ! CreateTemporalDateTime(earlier.[[Year]], earlier.[[Month]], earlier.[[Day]], earlier.[[Hour]], earlier.[[Minute]], earlier.[[Second]], earlier.[[Millisecond]], earlier.[[Microsecond]], earlier.[[Nanosecond]], dateTime.[[Calendar]]).
|
||||
auto* earlier_date_time = MUST(create_temporal_date_time(global_object, earlier.year, earlier.month, earlier.day, earlier.hour, earlier.minute, earlier.second, earlier.millisecond, earlier.microsecond, earlier.nanosecond, date_time.calendar()));
|
||||
auto* earlier_date_time = MUST(create_temporal_date_time(vm, earlier.year, earlier.month, earlier.day, earlier.hour, earlier.minute, earlier.second, earlier.millisecond, earlier.microsecond, earlier.nanosecond, date_time.calendar()));
|
||||
|
||||
// c. Set possibleInstants to ? GetPossibleInstantsFor(timeZone, earlierDateTime).
|
||||
auto possible_instants_ = TRY(get_possible_instants_for(global_object, time_zone, *earlier_date_time));
|
||||
auto possible_instants_ = TRY(get_possible_instants_for(vm, time_zone, *earlier_date_time));
|
||||
|
||||
// d. If possibleInstants is empty, throw a RangeError exception.
|
||||
if (possible_instants_.is_empty())
|
||||
|
@ -648,13 +646,13 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
|
|||
VERIFY(disambiguation.is_one_of("compatible"sv, "later"sv));
|
||||
|
||||
// 19. Let later be ? AddDateTime(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], dateTime.[[Calendar]], 0, 0, 0, 0, 0, 0, 0, 0, 0, nanoseconds, undefined).
|
||||
auto later = TRY(add_date_time(global_object, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, nanoseconds, nullptr));
|
||||
auto later = TRY(add_date_time(vm, date_time.iso_year(), date_time.iso_month(), date_time.iso_day(), date_time.iso_hour(), date_time.iso_minute(), date_time.iso_second(), date_time.iso_millisecond(), date_time.iso_microsecond(), date_time.iso_nanosecond(), date_time.calendar(), 0, 0, 0, 0, 0, 0, 0, 0, 0, nanoseconds, nullptr));
|
||||
|
||||
// 20. Let laterDateTime be ! CreateTemporalDateTime(later.[[Year]], later.[[Month]], later.[[Day]], later.[[Hour]], later.[[Minute]], later.[[Second]], later.[[Millisecond]], later.[[Microsecond]], later.[[Nanosecond]], dateTime.[[Calendar]]).
|
||||
auto* later_date_time = MUST(create_temporal_date_time(global_object, later.year, later.month, later.day, later.hour, later.minute, later.second, later.millisecond, later.microsecond, later.nanosecond, date_time.calendar()));
|
||||
auto* later_date_time = MUST(create_temporal_date_time(vm, later.year, later.month, later.day, later.hour, later.minute, later.second, later.millisecond, later.microsecond, later.nanosecond, date_time.calendar()));
|
||||
|
||||
// 21. Set possibleInstants to ? GetPossibleInstantsFor(timeZone, laterDateTime).
|
||||
auto possible_instants_ = TRY(get_possible_instants_for(global_object, time_zone, *later_date_time));
|
||||
auto possible_instants_ = TRY(get_possible_instants_for(vm, time_zone, *later_date_time));
|
||||
|
||||
// 22. Set n to possibleInstants's length.
|
||||
n = possible_instants_.size();
|
||||
|
@ -668,9 +666,10 @@ ThrowCompletionOr<Instant*> disambiguate_possible_instants(GlobalObject& global_
|
|||
}
|
||||
|
||||
// 11.6.16 GetPossibleInstantsFor ( timeZone, dateTime ), https://tc39.es/proposal-temporal/#sec-temporal-getpossibleinstantsfor
|
||||
ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(GlobalObject& global_object, Value time_zone, PlainDateTime& date_time)
|
||||
ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Value time_zone, PlainDateTime& date_time)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. Assert: dateTime has an [[InitializedTemporalDateTime]] internal slot.
|
||||
|
||||
|
@ -715,8 +714,11 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(GlobalObject
|
|||
}
|
||||
|
||||
// 11.6.17 TimeZoneEquals ( one, two ), https://tc39.es/proposal-temporal/#sec-temporal-timezoneequals
|
||||
ThrowCompletionOr<bool> time_zone_equals(GlobalObject& global_object, Object& one, Object& two)
|
||||
ThrowCompletionOr<bool> time_zone_equals(VM& vm, Object& one, Object& two)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
auto& global_object = realm.global_object();
|
||||
|
||||
// 1. If one and two are the same Object value, return true.
|
||||
if (&one == &two)
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue