summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-09-16 01:49:19 +0300
committerLinus Groh <mail@linusgroh.de>2021-09-16 13:53:37 +0100
commitcc00a726a8ce9781445a5d402d9bec72e1189d3c (patch)
tree3edf0f588f4d6b306bed50c013d19d91bacada20
parent830d484d78e37106cf7163189b51e7f413ca0232 (diff)
downloadserenity-cc00a726a8ce9781445a5d402d9bec72e1189d3c.zip
LibJS: Convert TimeZone AOs to ThrowCompletionOr
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp18
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp93
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h14
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp8
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp115
12 files changed, 99 insertions, 195 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp
index 46ed524bbd..7e194666fd 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Instant.cpp
@@ -135,9 +135,7 @@ BigInt* parse_temporal_instant(GlobalObject& global_object, String const& iso_st
}
// 7. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(offsetString).
- auto offset_nanoseconds = parse_time_zone_offset_string(global_object, *offset_string);
- if (vm.exception())
- return {};
+ auto offset_nanoseconds = TRY_OR_DISCARD(parse_time_zone_offset_string(global_object, *offset_string));
// 8. Return utc − offsetNanoseconds.
return js_bigint(vm, utc->big_integer().minus(Crypto::SignedBigInteger::create_from(offset_nanoseconds)));
@@ -256,20 +254,16 @@ Optional<String> temporal_instant_to_string(GlobalObject& global_object, Instant
// 4. If outputTimeZone is undefined, then
if (output_time_zone.is_undefined()) {
- // a. Set outputTimeZone to ? CreateTemporalTimeZone("UTC").
- output_time_zone = create_temporal_time_zone(global_object, "UTC"sv);
// TODO: Can this really throw...?
- if (vm.exception())
- return {};
+ // a. Set outputTimeZone to ? CreateTemporalTimeZone("UTC").
+ output_time_zone = TRY_OR_DISCARD(create_temporal_time_zone(global_object, "UTC"sv));
}
// 5. Let isoCalendar be ! GetISO8601Calendar().
auto* iso_calendar = get_iso8601_calendar(global_object);
// 6. Let dateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(outputTimeZone, instant, isoCalendar).
- auto* date_time = builtin_time_zone_get_plain_date_time_for(global_object, output_time_zone, instant, *iso_calendar);
- if (vm.exception())
- return {};
+ auto* date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, output_time_zone, instant, *iso_calendar));
// 7. Let dateTimeString be ? TemporalDateTimeToString(dateTime.[[ISOYear]], dateTime.[[ISOMonth]], dateTime.[[ISODay]], dateTime.[[ISOHour]], dateTime.[[ISOMinute]], dateTime.[[ISOSecond]], dateTime.[[ISOMillisecond]], dateTime.[[ISOMicrosecond]], dateTime.[[ISONanosecond]], undefined, precision, "never").
auto date_time_string = temporal_date_time_to_string(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(), js_undefined(), precision, "never"sv);
@@ -286,9 +280,7 @@ Optional<String> temporal_instant_to_string(GlobalObject& global_object, Instant
// 9. Else,
else {
// a. Let timeZoneString be ? BuiltinTimeZoneGetOffsetStringFor(timeZone, instant).
- time_zone_string = builtin_time_zone_get_offset_string_for(global_object, time_zone, instant);
- if (vm.exception())
- return {};
+ time_zone_string = TRY_OR_DISCARD(builtin_time_zone_get_offset_string_for(global_object, time_zone, instant));
}
// 10. Return the string-concatenation of dateTimeString and timeZoneString.
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp
index ed96c10be9..449dce9ed2 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/InstantPrototype.cpp
@@ -426,9 +426,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_string)
// 5. If timeZone is not undefined, then
if (!time_zone.is_undefined()) {
// a. Set timeZone to ? ToTemporalTimeZone(timeZone).
- time_zone = to_temporal_time_zone(global_object, time_zone);
- if (vm.exception())
- return {};
+ time_zone = TRY_OR_DISCARD(to_temporal_time_zone(global_object, time_zone));
}
// 6. Let precision be ? ToSecondsStringPrecision(options).
@@ -548,9 +546,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time)
}
// 9. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
- auto* time_zone = to_temporal_time_zone(global_object, temporal_time_zone_like);
- if (vm.exception())
- return {};
+ auto* time_zone = TRY_OR_DISCARD(to_temporal_time_zone(global_object, temporal_time_zone_like));
// 10. Return ? CreateTemporalZonedDateTime(instant.[[Nanoseconds]], timeZone, calendar).
return TRY_OR_DISCARD(create_temporal_zoned_date_time(global_object, instant->nanoseconds(), *time_zone, *calendar));
@@ -582,9 +578,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time_iso)
}
// 4. Let timeZone be ? ToTemporalTimeZone(item).
- auto* time_zone = to_temporal_time_zone(global_object, item);
- if (vm.exception())
- return {};
+ auto* time_zone = TRY_OR_DISCARD(to_temporal_time_zone(global_object, item));
// 5. Let calendar be ! GetISO8601Calendar().
auto* calendar = get_iso8601_calendar(global_object);
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
index 3a732631a5..5d86a882ff 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp
@@ -159,7 +159,7 @@ TimeZone* system_time_zone(GlobalObject& global_object)
auto identifier = default_time_zone();
// 2. Return ! CreateTemporalTimeZone(identifier).
- return create_temporal_time_zone(global_object, identifier);
+ return TRY_OR_DISCARD(create_temporal_time_zone(global_object, identifier));
}
// 2.3.2 SystemUTCEpochNanoseconds ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemutcepochnanoseconds
@@ -209,9 +209,7 @@ PlainDateTime* system_date_time(GlobalObject& global_object, Value temporal_time
// 2. Else,
else {
// a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
- time_zone = to_temporal_time_zone(global_object, temporal_time_zone_like);
- if (vm.exception())
- return {};
+ time_zone = TRY_OR_DISCARD(to_temporal_time_zone(global_object, temporal_time_zone_like));
}
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
@@ -223,7 +221,7 @@ PlainDateTime* system_date_time(GlobalObject& global_object, Value temporal_time
auto* instant = system_instant(global_object);
// 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- return builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar);
+ return TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar));
}
// 2.3.5 SystemZonedDateTime ( temporalTimeZoneLike, calendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-systemzoneddatetime
@@ -240,9 +238,7 @@ ZonedDateTime* system_zoned_date_time(GlobalObject& global_object, Value tempora
// 2. Else,
else {
// a. Let timeZone be ? ToTemporalTimeZone(temporalTimeZoneLike).
- time_zone = to_temporal_time_zone(global_object, temporal_time_zone_like);
- if (vm.exception())
- return {};
+ time_zone = TRY_OR_DISCARD(to_temporal_time_zone(global_object, temporal_time_zone_like));
}
// 3. Let calendar be ? ToTemporalCalendar(calendarLike).
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
index 5482e2880a..b9365fd39a 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
@@ -98,9 +98,7 @@ PlainDate* to_temporal_date(GlobalObject& global_object, Value item, Object* opt
auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds());
// ii. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]).
- auto* plain_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar());
- if (vm.exception())
- return {};
+ auto* plain_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
// iii. Return ! CreateTemporalDate(plainDateTime.[[ISOYear]], plainDateTime.[[ISOMonth]], plainDateTime.[[ISODay]], plainDateTime.[[Calendar]]).
return create_temporal_date(global_object, plain_date_time->iso_year(), plain_date_time->iso_month(), plain_date_time->iso_day(), plain_date_time->calendar());
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp
index 8abc504921..7adb749702 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDateTime.cpp
@@ -167,7 +167,7 @@ PlainDateTime* to_temporal_date_time(GlobalObject& global_object, Value item, Ob
auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds());
// ii. Return ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]).
- return builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar());
+ return TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
}
// c. If item has an [[InitializedTemporalDate]] internal slot, then
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp
index bd51cc1f72..023c15882e 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainTime.cpp
@@ -68,9 +68,7 @@ PlainTime* to_temporal_time(GlobalObject& global_object, Value item, Optional<St
// i. Let instant be ! CreateTemporalInstant(item.[[Nanoseconds]]).
auto* instant = create_temporal_instant(global_object, zoned_date_time.nanoseconds());
// ii. Set plainDateTime to ? BuiltinTimeZoneGetPlainDateTimeFor(item.[[TimeZone]], instant, item.[[Calendar]]).
- auto* plain_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar());
- if (vm.exception())
- return {};
+ auto* plain_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &zoned_date_time.time_zone(), *instant, zoned_date_time.calendar()));
// iii. Return ! CreateTemporalTime(plainDateTime.[[ISOHour]], plainDateTime.[[ISOMinute]], plainDateTime.[[ISOSecond]], plainDateTime.[[ISOMillisecond]], plainDateTime.[[ISOMicrosecond]], plainDateTime.[[ISONanosecond]]).
return create_temporal_time(global_object, plain_date_time->iso_hour(), plain_date_time->iso_minute(), plain_date_time->iso_second(), plain_date_time->iso_millisecond(), plain_date_time->iso_microsecond(), plain_date_time->iso_nanosecond());
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
index 34a4f0ca9a..45255ef4c1 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
@@ -66,7 +66,7 @@ String default_time_zone()
}
// 11.6.1 ParseTemporalTimeZone ( string ), https://tc39.es/proposal-temporal/#sec-temporal-parsetemporaltimezone
-String parse_temporal_time_zone(GlobalObject& global_object, String const& string)
+ThrowCompletionOr<String> parse_temporal_time_zone(GlobalObject& global_object, String const& string)
{
auto& vm = global_object.vm();
@@ -74,19 +74,19 @@ String parse_temporal_time_zone(GlobalObject& global_object, String const& strin
// 2. Let result be ? ParseTemporalTimeZoneString(string).
auto result = parse_temporal_time_zone_string(global_object, string);
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// 3. If result.[[Z]] is not undefined, return "UTC".
if (result->z)
- return "UTC";
+ return String { "UTC" };
// 4. Return result.[[Name]].
return *result->name;
}
// 11.6.2 CreateTemporalTimeZone ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaltimezone
-TimeZone* create_temporal_time_zone(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
+ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
{
// 1. If newTarget is not present, set it to %Temporal.TimeZone%.
if (!new_target)
@@ -94,12 +94,12 @@ TimeZone* create_temporal_time_zone(GlobalObject& global_object, String const& i
// 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »).
// 3. Set object.[[Identifier]] to identifier.
- auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype, identifier));
+ auto* object = TRY(ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype, identifier));
// 4. If identifier satisfies the syntax of a TimeZoneNumericUTCOffset (see 13.33), then
if (is_valid_time_zone_numeric_utc_offset_syntax(identifier)) {
// a. Set object.[[OffsetNanoseconds]] to ! ParseTimeZoneOffsetString(identifier).
- object->set_offset_nanoseconds(parse_time_zone_offset_string(global_object, identifier));
+ object->set_offset_nanoseconds(TRY(parse_time_zone_offset_string(global_object, identifier)));
}
// 5. Else,
else {
@@ -207,7 +207,7 @@ bool is_valid_time_zone_numeric_utc_offset_syntax(String const& offset_string)
}
// 11.6.8 ParseTimeZoneOffsetString ( offsetString ), https://tc39.es/proposal-temporal/#sec-temporal-parsetimezoneoffsetstring
-double parse_time_zone_offset_string(GlobalObject& global_object, String const& offset_string)
+ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject& global_object, String const& offset_string)
{
auto& vm = global_object.vm();
@@ -222,10 +222,8 @@ double parse_time_zone_offset_string(GlobalObject& global_object, String const&
Optional<StringView> seconds_part;
Optional<StringView> fraction_part;
auto success = parse_time_zone_numeric_utc_offset_syntax(offset_string, sign_part, hours_part, minutes_part, seconds_part, fraction_part);
- if (!success) {
- vm.throw_exception<RangeError>(global_object, ErrorType::InvalidFormat, "TimeZone offset");
- return {};
- }
+ if (!success)
+ return vm.throw_completion<RangeError>(global_object, ErrorType::InvalidFormat, "TimeZone offset");
// 4. If either hours or sign are undefined, throw a RangeError exception.
// NOTE: Both of these checks are always false, due to the handling of Step 2
@@ -317,7 +315,7 @@ String format_time_zone_offset_string(double offset_nanoseconds)
}
// 11.6.10 ToTemporalTimeZone ( temporalTimeZoneLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporaltimezone
-Object* to_temporal_time_zone(GlobalObject& global_object, Value temporal_time_zone_like)
+ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Value temporal_time_zone_like)
{
auto& vm = global_object.vm();
@@ -333,21 +331,21 @@ Object* to_temporal_time_zone(GlobalObject& global_object, Value temporal_time_z
// b. If ? HasProperty(temporalTimeZoneLike, "timeZone") is false, return temporalTimeZoneLike.
auto has_property = temporal_time_zone_like.as_object().has_property(vm.names.timeZone);
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
if (!has_property)
return &temporal_time_zone_like.as_object();
// c. Set temporalTimeZoneLike to ? Get(temporalTimeZoneLike, "timeZone").
temporal_time_zone_like = temporal_time_zone_like.as_object().get(vm.names.timeZone);
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// d. If Type(temporalTimeZoneLike) is Object and ? HasProperty(temporalTimeZoneLike, "timeZone") is false, return temporalTimeZoneLike.
if (temporal_time_zone_like.is_object()) {
has_property = temporal_time_zone_like.as_object().has_property(vm.names.timeZone);
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
if (!has_property)
return &temporal_time_zone_like.as_object();
}
@@ -355,27 +353,25 @@ Object* to_temporal_time_zone(GlobalObject& global_object, Value temporal_time_z
// 2. Let identifier be ? ToString(temporalTimeZoneLike).
auto identifier = temporal_time_zone_like.to_string(global_object);
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// 3. Let result be ? ParseTemporalTimeZone(identifier).
- auto result = parse_temporal_time_zone(global_object, identifier);
- if (vm.exception())
- return {};
+ auto result = TRY(parse_temporal_time_zone(global_object, identifier));
// 4. Return ? CreateTemporalTimeZone(result).
- return create_temporal_time_zone(global_object, result);
+ return TRY(create_temporal_time_zone(global_object, result));
}
// 11.6.11 GetOffsetNanosecondsFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-getoffsetnanosecondsfor
-double get_offset_nanoseconds_for(GlobalObject& global_object, Value time_zone, Instant& instant)
+ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject& global_object, Value time_zone, Instant& instant)
{
auto& vm = global_object.vm();
// 1. Let getOffsetNanosecondsFor be ? GetMethod(timeZone, "getOffsetNanosecondsFor").
auto* get_offset_nanoseconds_for = time_zone.get_method(global_object, vm.names.getOffsetNanosecondsFor);
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// 2. If getOffsetNanosecondsFor is undefined, set getOffsetNanosecondsFor to %Temporal.TimeZone.prototype.getOffsetNanosecondsFor%.
if (!get_offset_nanoseconds_for)
@@ -383,57 +379,45 @@ double get_offset_nanoseconds_for(GlobalObject& global_object, Value time_zone,
// 3. Let offsetNanoseconds be ? Call(getOffsetNanosecondsFor, timeZone, « instant »).
auto offset_nanoseconds_value = vm.call(*get_offset_nanoseconds_for, time_zone, &instant);
- if (vm.exception())
- return {};
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// 4. If Type(offsetNanoseconds) is not Number, throw a TypeError exception.
- if (!offset_nanoseconds_value.is_number()) {
- vm.throw_exception<TypeError>(global_object, ErrorType::IsNotA, "Offset nanoseconds value", "number");
- return {};
- }
+ if (!offset_nanoseconds_value.is_number())
+ return vm.throw_completion<TypeError>(global_object, ErrorType::IsNotA, "Offset nanoseconds value", "number");
// 5. If ! IsIntegralNumber(offsetNanoseconds) is false, throw a RangeError exception.
- if (!offset_nanoseconds_value.is_integral_number()) {
- vm.throw_exception<RangeError>(global_object, ErrorType::IsNotAn, "Offset nanoseconds value", "integral number");
- return {};
- }
+ if (!offset_nanoseconds_value.is_integral_number())
+ return vm.throw_completion<RangeError>(global_object, ErrorType::IsNotAn, "Offset nanoseconds value", "integral number");
// 6. Set offsetNanoseconds to ℝ(offsetNanoseconds).
auto offset_nanoseconds = offset_nanoseconds_value.as_double();
// 7. If abs(offsetNanoseconds) > 86400 × 10^9, throw a RangeError exception.
- if (fabs(offset_nanoseconds) > 86400000000000.0) {
- vm.throw_exception<RangeError>(global_object, ErrorType::TemporalInvalidOffsetNanosecondsValue);
- return {};
- }
+ if (fabs(offset_nanoseconds) > 86400000000000.0)
+ return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidOffsetNanosecondsValue);
// 8. Return offsetNanoseconds.
return offset_nanoseconds;
}
// 11.6.12 BuiltinTimeZoneGetOffsetStringFor ( timeZone, instant ), https://tc39.es/proposal-temporal/#sec-temporal-builtintimezonegetoffsetstringfor
-Optional<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(GlobalObject& global_object, Value time_zone, Instant& instant)
{
- auto& vm = global_object.vm();
-
// 1. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
- auto offset_nanoseconds = get_offset_nanoseconds_for(global_object, time_zone, instant);
- if (vm.exception())
- return {};
+ auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, 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
-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(GlobalObject& global_object, Value time_zone, Instant& instant, Object& calendar)
{
auto& vm = global_object.vm();
// 1. Let offsetNanoseconds be ? GetOffsetNanosecondsFor(timeZone, instant).
- auto offset_nanoseconds = get_offset_nanoseconds_for(global_object, time_zone, instant);
- if (vm.exception())
- return {};
+ auto offset_nanoseconds = TRY(get_offset_nanoseconds_for(global_object, time_zone, instant));
// 2. Let result be ! GetISOPartsFromEpoch(instant.[[Nanoseconds]]).
auto result = get_iso_parts_from_epoch(instant.nanoseconds());
@@ -442,7 +426,10 @@ PlainDateTime* builtin_time_zone_get_plain_date_time_for(GlobalObject& global_ob
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);
// 4. 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);
+ auto* date_time = 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);
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
+ return date_time;
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h
index 1e4d3e3051..8923d7fc93 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h
@@ -35,16 +35,16 @@ private:
bool is_valid_time_zone_name(String const& time_zone);
String canonicalize_time_zone_name(String const& time_zone);
String default_time_zone();
-String parse_temporal_time_zone(GlobalObject&, String const&);
-TimeZone* create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr);
+ThrowCompletionOr<String> parse_temporal_time_zone(GlobalObject&, String const&);
+ThrowCompletionOr<TimeZone*> create_temporal_time_zone(GlobalObject&, String const& identifier, FunctionObject const* new_target = nullptr);
ISODateTime get_iso_parts_from_epoch(BigInt const& epoch_nanoseconds);
i64 get_iana_time_zone_offset_nanoseconds(BigInt const& epoch_nanoseconds, String const& time_zone_identifier);
-double parse_time_zone_offset_string(GlobalObject&, String const&);
+ThrowCompletionOr<double> parse_time_zone_offset_string(GlobalObject&, String const&);
String format_time_zone_offset_string(double offset_nanoseconds);
-Object* to_temporal_time_zone(GlobalObject&, Value temporal_time_zone_like);
-double get_offset_nanoseconds_for(GlobalObject&, Value time_zone, Instant&);
-Optional<String> builtin_time_zone_get_offset_string_for(GlobalObject&, Value time_zone, Instant&);
-PlainDateTime* builtin_time_zone_get_plain_date_time_for(GlobalObject&, Value time_zone, Instant&, Object& calendar);
+ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject&, Value temporal_time_zone_like);
+ThrowCompletionOr<double> get_offset_nanoseconds_for(GlobalObject&, Value time_zone, Instant&);
+ThrowCompletionOr<String> builtin_time_zone_get_offset_string_for(GlobalObject&, Value time_zone, Instant&);
+ThrowCompletionOr<PlainDateTime*> builtin_time_zone_get_plain_date_time_for(GlobalObject&, Value time_zone, Instant&, Object& calendar);
bool is_valid_time_zone_numeric_utc_offset_syntax(String const&);
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp
index ac5a8c7065..0767be28fd 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp
@@ -58,9 +58,7 @@ Value TimeZoneConstructor::construct(FunctionObject& new_target)
// 3. If identifier satisfies the syntax of a TimeZoneNumericUTCOffset (see 13.33), then
if (is_valid_time_zone_numeric_utc_offset_syntax(identifier)) {
// a. Let offsetNanoseconds be ? ParseTimeZoneOffsetString(identifier).
- auto offset_nanoseconds = parse_time_zone_offset_string(global_object, identifier);
- if (vm.exception())
- return {};
+ auto offset_nanoseconds = TRY_OR_DISCARD(parse_time_zone_offset_string(global_object, identifier));
// b. Let canonical be ! FormatTimeZoneOffsetString(offsetNanoseconds).
canonical = format_time_zone_offset_string(offset_nanoseconds);
@@ -79,7 +77,7 @@ Value TimeZoneConstructor::construct(FunctionObject& new_target)
}
// 5. Return ? CreateTemporalTimeZone(canonical, NewTarget).
- return create_temporal_time_zone(global_object, canonical, &new_target);
+ return TRY_OR_DISCARD(create_temporal_time_zone(global_object, canonical, &new_target));
}
// 11.3.2 Temporal.TimeZone.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.from
@@ -88,7 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZoneConstructor::from)
auto item = vm.argument(0);
// 1. Return ? ToTemporalTimeZone(item).
- return to_temporal_time_zone(global_object, item);
+ return TRY_OR_DISCARD(to_temporal_time_zone(global_object, item));
}
}
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp
index 60e7b26edb..a1ea6c2046 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZonePrototype.cpp
@@ -85,10 +85,8 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_offset_string_for)
return {};
// 4. Return ? BuiltinTimeZoneGetOffsetStringFor(timeZone, instant).
- auto offset_string = builtin_time_zone_get_offset_string_for(global_object, time_zone, *instant);
- if (vm.exception())
- return {};
- return js_string(vm, move(*offset_string));
+ auto offset_string = TRY_OR_DISCARD(builtin_time_zone_get_offset_string_for(global_object, time_zone, *instant));
+ return js_string(vm, move(offset_string));
}
// 11.4.6 Temporal.TimeZone.prototype.getPlainDateTimeFor ( instant [ , calendarLike ] ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.getplaindatetimefor
@@ -108,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(TimeZonePrototype::get_plain_date_time_for)
return {};
// 4. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- return builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar);
+ return TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, time_zone, *instant, *calendar));
}
// 11.4.11 Temporal.TimeZone.prototype.toString ( ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype.tostring
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp
index d9ca18db8a..6ae094c632 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimeConstructor.cpp
@@ -60,9 +60,7 @@ Value ZonedDateTimeConstructor::construct(FunctionObject& new_target)
}
// 4. Let timeZone be ? ToTemporalTimeZone(timeZoneLike).
- auto* time_zone = to_temporal_time_zone(global_object, vm.argument(1));
- if (vm.exception())
- return {};
+ auto* time_zone = TRY_OR_DISCARD(to_temporal_time_zone(global_object, vm.argument(1)));
// 5. Let calendar be ? ToTemporalCalendarWithISODefault(calendarLike).
auto* calendar = to_temporal_calendar_with_iso_default(global_object, vm.argument(2));
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp
index e30d6118d4..43f7535d6c 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTimePrototype.cpp
@@ -118,9 +118,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::year_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarYear(calendar, temporalDateTime).
return Value(calendar_year(global_object, calendar, *temporal_date_time));
@@ -145,9 +143,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::month_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarMonth(calendar, temporalDateTime).
return Value(calendar_month(global_object, calendar, *temporal_date_time));
@@ -172,9 +168,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::month_code_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarMonthCode(calendar, temporalDateTime).
return js_string(vm, calendar_month_code(global_object, calendar, *temporal_date_time));
@@ -199,9 +193,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::day_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarDay(calendar, temporalDateTime).
return Value(calendar_day(global_object, calendar, *temporal_date_time));
@@ -226,9 +218,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::hour_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOHour]]).
return Value(temporal_date_time->iso_hour());
@@ -253,9 +243,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::minute_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOMinute]]).
return Value(temporal_date_time->iso_minute());
@@ -280,9 +268,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::second_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOSecond]]).
return Value(temporal_date_time->iso_second());
@@ -307,9 +293,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::millisecond_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOMillisecond]]).
return Value(temporal_date_time->iso_millisecond());
@@ -334,9 +318,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::microsecond_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISOMicrosecond]]).
return Value(temporal_date_time->iso_microsecond());
@@ -361,9 +343,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::nanosecond_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return 𝔽(temporalDateTime.[[ISONanosecond]]).
return Value(temporal_date_time->iso_nanosecond());
@@ -458,9 +438,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::day_of_week_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarDayOfWeek(calendar, temporalDateTime).
return calendar_day_of_week(global_object, calendar, *temporal_date_time);
@@ -485,9 +463,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::day_of_year_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarDayOfYear(calendar, temporalDateTime).
return calendar_day_of_year(global_object, calendar, *temporal_date_time);
@@ -512,9 +488,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::week_of_year_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarWeekOfYear(calendar, temporalDateTime).
return calendar_week_of_year(global_object, calendar, *temporal_date_time);
@@ -539,9 +513,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::days_in_week_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarDaysInWeek(calendar, temporalDateTime).
return calendar_days_in_week(global_object, calendar, *temporal_date_time);
@@ -566,9 +538,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::days_in_month_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarDaysInMonth(calendar, temporalDateTime).
return calendar_days_in_month(global_object, calendar, *temporal_date_time);
@@ -593,9 +563,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::days_in_year_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarDaysInYear(calendar, temporalDateTime).
return calendar_days_in_year(global_object, calendar, *temporal_date_time);
@@ -620,9 +588,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::months_in_year_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarMonthsInYear(calendar, temporalDateTime).
return calendar_months_in_year(global_object, calendar, *temporal_date_time);
@@ -647,9 +613,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::in_leap_year_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarInLeapYear(calendar, temporalDateTime).
return calendar_in_leap_year(global_object, calendar, *temporal_date_time);
@@ -671,7 +635,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::offset_nanoseconds_getter)
auto* instant = create_temporal_instant(global_object, zoned_date_time->nanoseconds());
// 5. Return 𝔽(? GetOffsetNanosecondsFor(timeZone, instant)).
- return Value(get_offset_nanoseconds_for(global_object, &time_zone, *instant));
+ return Value(TRY_OR_DISCARD(get_offset_nanoseconds_for(global_object, &time_zone, *instant)));
}
// 6.3.29 get Temporal.ZonedDateTime.prototype.offset, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.offset
@@ -687,10 +651,8 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::offset_getter)
auto* instant = create_temporal_instant(global_object, zoned_date_time->nanoseconds());
// 4. Return ? BuiltinTimeZoneGetOffsetStringFor(zonedDateTime.[[TimeZone]], instant).
- auto offset_string = builtin_time_zone_get_offset_string_for(global_object, &zoned_date_time->time_zone(), *instant);
- if (vm.exception())
- return {};
- return js_string(vm, move(*offset_string));
+ auto offset_string = TRY_OR_DISCARD(builtin_time_zone_get_offset_string_for(global_object, &zoned_date_time->time_zone(), *instant));
+ return js_string(vm, move(offset_string));
}
// 15.6.10.2 get Temporal.ZonedDateTime.prototype.era, https://tc39.es/proposal-temporal/#sec-get-temporal.zoneddatetime.prototype.era
@@ -712,9 +674,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::era_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* plain_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* plain_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarEra(calendar, plainDateTime).
return calendar_era(global_object, calendar, *plain_date_time);
@@ -739,9 +699,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::era_year_getter)
auto& calendar = zoned_date_time->calendar();
// 6. Let plainDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* plain_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* plain_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CalendarEraYear(calendar, plainDateTime).
return calendar_era_year(global_object, calendar, *plain_date_time);
@@ -787,9 +745,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_date)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CreateTemporalDate(temporalDateTime.[[ISOYear]], temporalDateTime.[[ISOMonth]], temporalDateTime.[[ISODay]], calendar).
return create_temporal_date(global_object, temporal_date_time->iso_year(), temporal_date_time->iso_month(), temporal_date_time->iso_day(), calendar);
@@ -814,9 +770,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_time)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, zonedDateTime.[[Calendar]]).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Return ? CreateTemporalTime(temporalDateTime.[[ISOHour]], temporalDateTime.[[ISOMinute]], temporalDateTime.[[ISOSecond]], temporalDateTime.[[ISOMillisecond]], temporalDateTime.[[ISOMicrosecond]], temporalDateTime.[[ISONanosecond]]).
return create_temporal_time(global_object, temporal_date_time->iso_hour(), temporal_date_time->iso_minute(), temporal_date_time->iso_second(), temporal_date_time->iso_millisecond(), temporal_date_time->iso_microsecond(), temporal_date_time->iso_nanosecond());
@@ -838,7 +792,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_date_time)
auto* instant = create_temporal_instant(global_object, zoned_date_time->nanoseconds());
// 5. Return ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, zonedDateTime.[[Calendar]]).
- return builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, zoned_date_time->calendar());
+ return TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, zoned_date_time->calendar()));
}
// 6.3.50 Temporal.ZonedDateTime.prototype.toPlainYearMonth ( ), https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.toplainyearmonth
@@ -860,9 +814,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_year_month)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Let fieldNames be ? CalendarFields(calendar, « "monthCode", "year" »).
auto field_names = calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv });
@@ -897,9 +849,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_month_day)
auto& calendar = zoned_date_time->calendar();
// 6. Let temporalDateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* temporal_date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* temporal_date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 7. Let fieldNames be ? CalendarFields(calendar, « "day", "monthCode" »).
auto field_names = calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv });
@@ -937,15 +887,10 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields)
auto& calendar = zoned_date_time->calendar();
// 7. Let dateTime be ? BuiltinTimeZoneGetPlainDateTimeFor(timeZone, instant, calendar).
- auto* date_time = builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar);
- if (vm.exception())
- return {};
+ auto* date_time = TRY_OR_DISCARD(builtin_time_zone_get_plain_date_time_for(global_object, &time_zone, *instant, calendar));
// 8. Let offset be ? BuiltinTimeZoneGetOffsetStringFor(timeZone, instant).
- auto maybe_offset = builtin_time_zone_get_offset_string_for(global_object, &time_zone, *instant);
- if (vm.exception())
- return {};
- auto offset = move(*maybe_offset);
+ auto offset = TRY_OR_DISCARD(builtin_time_zone_get_offset_string_for(global_object, &time_zone, *instant));
// 9. Perform ! CreateDataPropertyOrThrow(fields, "calendar", calendar).
fields->create_data_property_or_throw(vm.names.calendar, Value(&calendar));