1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 08:07:44 +00:00

LibJS: Convert ordinary_create_from_constructor<T> to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-09-16 00:57:38 +03:00 committed by Linus Groh
parent b61eff8730
commit 5a4c90fcb1
30 changed files with 38 additions and 93 deletions

View file

@ -31,8 +31,6 @@ Calendar::Calendar(String identifier, Object& prototype)
// 12.1.1 CreateTemporalCalendar ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalcalendar
Calendar* create_temporal_calendar(GlobalObject& global_object, String const& identifier, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
// 1. Assert: ! IsBuiltinCalendar(identifier) is true.
VERIFY(is_builtin_calendar(identifier));
@ -42,9 +40,7 @@ Calendar* create_temporal_calendar(GlobalObject& global_object, String const& id
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
// 4. Set object.[[Identifier]] to identifier.
auto* object = ordinary_create_from_constructor<Calendar>(global_object, *new_target, &GlobalObject::temporal_calendar_prototype, identifier);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<Calendar>(global_object, *new_target, &GlobalObject::temporal_calendar_prototype, identifier));
// 5. Return object.
return object;

View file

@ -262,9 +262,7 @@ Duration* create_temporal_duration(GlobalObject& global_object, double years, do
// 11. Set object.[[Milliseconds]] to milliseconds.
// 12. Set object.[[Microseconds]] to microseconds.
// 13. Set object.[[Nanoseconds]] to nanoseconds.
auto* object = ordinary_create_from_constructor<Duration>(global_object, *new_target, &GlobalObject::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<Duration>(global_object, *new_target, &GlobalObject::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
// 14. Return object.
return object;

View file

@ -51,8 +51,6 @@ bool is_valid_epoch_nanoseconds(BigInt const& epoch_nanoseconds)
// 8.5.2 CreateTemporalInstant ( epochNanoseconds [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalinstant
Instant* create_temporal_instant(GlobalObject& global_object, BigInt const& epoch_nanoseconds, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
// 1. Assert: Type(epochNanoseconds) is BigInt.
// 2. Assert: ! IsValidEpochNanoseconds(epochNanoseconds) is true.
@ -64,9 +62,7 @@ Instant* create_temporal_instant(GlobalObject& global_object, BigInt const& epoc
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[Nanoseconds]] »).
// 5. Set object.[[Nanoseconds]] to epochNanoseconds.
auto* object = ordinary_create_from_constructor<Instant>(global_object, *new_target, &GlobalObject::temporal_instant_prototype, epoch_nanoseconds);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<Instant>(global_object, *new_target, &GlobalObject::temporal_instant_prototype, epoch_nanoseconds));
// 6. Return object.
return object;

View file

@ -65,9 +65,7 @@ PlainDate* create_temporal_date(GlobalObject& global_object, i32 iso_year, u8 is
// 10. Set object.[[ISOMonth]] to isoMonth.
// 11. Set object.[[ISODay]] to isoDay.
// 12. Set object.[[Calendar]] to calendar.
auto* object = ordinary_create_from_constructor<PlainDate>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<PlainDate>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar));
return object;
}

View file

@ -294,9 +294,7 @@ PlainDateTime* create_temporal_date_time(GlobalObject& global_object, i32 iso_ye
// 15. Set object.[[ISOMicrosecond]] to microsecond.
// 16. Set object.[[ISONanosecond]] to nanosecond.
// 17. Set object.[[Calendar]] to calendar.
auto* object = ordinary_create_from_constructor<PlainDateTime>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<PlainDateTime>(global_object, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar));
// 18. Return object.
return object;

View file

@ -161,9 +161,7 @@ PlainMonthDay* create_temporal_month_day(GlobalObject& global_object, u8 iso_mon
// 7. Set object.[[ISODay]] to isoDay.
// 8. Set object.[[Calendar]] to calendar.
// 9. Set object.[[ISOYear]] to referenceISOYear.
auto* object = ordinary_create_from_constructor<PlainMonthDay>(global_object, *new_target, &GlobalObject::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<PlainMonthDay>(global_object, *new_target, &GlobalObject::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar));
// 10. Return object.
return object;

View file

@ -365,9 +365,7 @@ PlainTime* create_temporal_time(GlobalObject& global_object, u8 hour, u8 minute,
// 9. Set object.[[ISOMicrosecond]] to microsecond.
// 10. Set object.[[ISONanosecond]] to nanosecond.
// 11. Set object.[[Calendar]] to ! GetISO8601Calendar().
auto* object = ordinary_create_from_constructor<PlainTime>(global_object, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(global_object));
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<PlainTime>(global_object, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(global_object)));
// 12. Return object.
return object;

View file

@ -251,9 +251,7 @@ PlainYearMonth* create_temporal_year_month(GlobalObject& global_object, i32 iso_
// 8. Set object.[[ISOMonth]] to isoMonth.
// 9. Set object.[[Calendar]] to calendar.
// 10. Set object.[[ISODay]] to referenceISODay.
auto* object = ordinary_create_from_constructor<PlainYearMonth>(global_object, *new_target, &GlobalObject::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<PlainYearMonth>(global_object, *new_target, &GlobalObject::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar));
// 11. Return object.
return object;

View file

@ -88,17 +88,13 @@ String parse_temporal_time_zone(GlobalObject& global_object, String const& strin
// 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)
{
auto& vm = global_object.vm();
// 1. If newTarget is not present, set it to %Temporal.TimeZone%.
if (!new_target)
new_target = global_object.temporal_time_zone_constructor();
// 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »).
// 3. Set object.[[Identifier]] to identifier.
auto* object = ordinary_create_from_constructor<TimeZone>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype, identifier);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(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)) {

View file

@ -33,8 +33,6 @@ void ZonedDateTime::visit_edges(Cell::Visitor& visitor)
// 6.5.3 CreateTemporalZonedDateTime ( epochNanoseconds, timeZone, calendar [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalzoneddatetime
ZonedDateTime* create_temporal_zoned_date_time(GlobalObject& global_object, BigInt const& epoch_nanoseconds, Object& time_zone, Object& calendar, FunctionObject const* new_target)
{
auto& vm = global_object.vm();
// 1. Assert: Type(epochNanoseconds) is BigInt.
// 3. Assert: Type(timeZone) is Object.
// 4. Assert: Type(calendar) is Object.
@ -50,9 +48,7 @@ ZonedDateTime* create_temporal_zoned_date_time(GlobalObject& global_object, BigI
// 7. Set object.[[Nanoseconds]] to epochNanoseconds.
// 8. Set object.[[TimeZone]] to timeZone.
// 9. Set object.[[Calendar]] to calendar.
auto* object = ordinary_create_from_constructor<ZonedDateTime>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar);
if (vm.exception())
return {};
auto* object = TRY_OR_DISCARD(ordinary_create_from_constructor<ZonedDateTime>(global_object, *new_target, &GlobalObject::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar));
// 10. Return object.
return object;