1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:07:45 +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

@ -44,9 +44,9 @@ Value perform_eval(Value, GlobalObject&, CallerMode, EvalMode);
// 10.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinarycreatefromconstructor
template<typename T, typename... Args>
T* ordinary_create_from_constructor(GlobalObject& global_object, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)(), Args&&... args)
ThrowCompletionOr<T*> ordinary_create_from_constructor(GlobalObject& global_object, FunctionObject const& constructor, Object* (GlobalObject::*intrinsic_default_prototype)(), Args&&... args)
{
auto* prototype = TRY_OR_DISCARD(get_prototype_from_constructor(global_object, constructor, intrinsic_default_prototype));
auto* prototype = TRY(get_prototype_from_constructor(global_object, constructor, intrinsic_default_prototype));
return global_object.heap().allocate<T>(global_object, forward<Args>(args)..., *prototype);
}

View file

@ -42,9 +42,7 @@ Value AggregateErrorConstructor::construct(FunctionObject& new_target)
auto& vm = this->vm();
auto& global_object = this->global_object();
auto* aggregate_error = ordinary_create_from_constructor<AggregateError>(global_object, new_target, &GlobalObject::aggregate_error_prototype);
if (vm.exception())
return {};
auto* aggregate_error = TRY_OR_DISCARD(ordinary_create_from_constructor<AggregateError>(global_object, new_target, &GlobalObject::aggregate_error_prototype));
if (!vm.argument(1).is_undefined()) {
auto message = vm.argument(1).to_string(global_object);

View file

@ -47,7 +47,7 @@ Value BooleanConstructor::construct(FunctionObject& new_target)
auto& global_object = this->global_object();
auto b = vm.argument(0).to_boolean();
return ordinary_create_from_constructor<BooleanObject>(global_object, new_target, &GlobalObject::boolean_prototype, b);
return TRY_OR_DISCARD(ordinary_create_from_constructor<BooleanObject>(global_object, new_target, &GlobalObject::boolean_prototype, b));
}
}

View file

@ -81,9 +81,7 @@ Value DataViewConstructor::construct(FunctionObject& new_target)
}
}
auto* data_view = ordinary_create_from_constructor<DataView>(global_object, new_target, &GlobalObject::data_view_prototype, &array_buffer, view_byte_length, offset);
if (vm.exception())
return {};
auto* data_view = TRY_OR_DISCARD(ordinary_create_from_constructor<DataView>(global_object, new_target, &GlobalObject::data_view_prototype, &array_buffer, view_byte_length, offset));
if (array_buffer.is_detached()) {
vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer);

View file

@ -181,13 +181,13 @@ Value DateConstructor::construct(FunctionObject& new_target)
if (vm.argument_count() == 0) {
auto [datetime, milliseconds] = JS::now();
return ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, false);
return TRY_OR_DISCARD(ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, false));
}
auto create_invalid_date = [&global_object, &new_target]() {
auto create_invalid_date = [&global_object, &new_target]() -> Date* {
auto datetime = Core::DateTime::create(1970, 1, 1, 0, 0, 0);
auto milliseconds = static_cast<i16>(0);
return ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, true);
return TRY_OR_DISCARD(ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, true));
};
if (vm.argument_count() == 1) {
@ -210,7 +210,7 @@ Value DateConstructor::construct(FunctionObject& new_target)
return create_invalid_date();
auto datetime = Core::DateTime::from_timestamp(static_cast<time_t>(value_as_double / 1000));
auto milliseconds = static_cast<i16>(fmod(value_as_double, 1000));
return ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, false);
return TRY_OR_DISCARD(ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, false));
}
// A date/time in components, in local time.
@ -288,7 +288,7 @@ Value DateConstructor::construct(FunctionObject& new_target)
auto time = datetime.timestamp() * 1000.0 + milliseconds;
if (time > Date::time_clip)
return create_invalid_date();
return ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, false);
return TRY_OR_DISCARD(ordinary_create_from_constructor<Date>(global_object, new_target, &GlobalObject::date_prototype, datetime, milliseconds, false));
}
// 21.4.3.1 Date.now ( ), https://tc39.es/ecma262/#sec-date.now

View file

@ -39,9 +39,7 @@ Value ErrorConstructor::construct(FunctionObject& new_target)
auto& vm = this->vm();
auto& global_object = this->global_object();
auto* error = ordinary_create_from_constructor<Error>(global_object, new_target, &GlobalObject::error_prototype);
if (vm.exception())
return {};
auto* error = TRY_OR_DISCARD(ordinary_create_from_constructor<Error>(global_object, new_target, &GlobalObject::error_prototype));
if (!vm.argument(0).is_undefined()) {
auto message = vm.argument(0).to_string(global_object);
@ -89,10 +87,8 @@ Value ErrorConstructor::construct(FunctionObject& new_target)
auto& vm = this->vm(); \
auto& global_object = this->global_object(); \
\
auto* error = ordinary_create_from_constructor<ClassName>( \
global_object, new_target, &GlobalObject::snake_name##_prototype); \
if (vm.exception()) \
return {}; \
auto* error = TRY_OR_DISCARD(ordinary_create_from_constructor<ClassName>( \
global_object, new_target, &GlobalObject::snake_name##_prototype)); \
\
if (!vm.argument(0).is_undefined()) { \
auto message = vm.argument(0).to_string(global_object); \

View file

@ -51,7 +51,7 @@ Value FinalizationRegistryConstructor::construct(FunctionObject& new_target)
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunction, cleanup_callback.to_string_without_side_effects());
return {};
}
return ordinary_create_from_constructor<FinalizationRegistry>(global_object, new_target, &GlobalObject::finalization_registry_prototype, cleanup_callback.as_function());
return TRY_OR_DISCARD(ordinary_create_from_constructor<FinalizationRegistry>(global_object, new_target, &GlobalObject::finalization_registry_prototype, cleanup_callback.as_function()));
}
}

View file

@ -54,9 +54,7 @@ Value DisplayNamesConstructor::construct(FunctionObject& new_target)
auto options_value = vm.argument(1);
// 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »).
auto* display_names = ordinary_create_from_constructor<DisplayNames>(global_object, new_target, &GlobalObject::intl_display_names_prototype);
if (vm.exception())
return {};
auto* display_names = TRY_OR_DISCARD(ordinary_create_from_constructor<DisplayNames>(global_object, new_target, &GlobalObject::intl_display_names_prototype));
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = canonicalize_locale_list(global_object, locale_value);

View file

@ -53,9 +53,7 @@ Value ListFormatConstructor::construct(FunctionObject& new_target)
auto options_value = vm.argument(1);
// 2. Let listFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%ListFormat.prototype%", « [[InitializedListFormat]], [[Locale]], [[Type]], [[Style]], [[Templates]] »).
auto* list_format = ordinary_create_from_constructor<ListFormat>(global_object, new_target, &GlobalObject::intl_list_format_prototype);
if (vm.exception())
return {};
auto* list_format = TRY_OR_DISCARD(ordinary_create_from_constructor<ListFormat>(global_object, new_target, &GlobalObject::intl_list_format_prototype));
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = canonicalize_locale_list(global_object, locale_value);

View file

@ -275,9 +275,7 @@ Value LocaleConstructor::construct(FunctionObject& new_target)
// a. Append [[Numeric]] as the last element of internalSlotsList.
// 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, "%Locale.prototype%", internalSlotsList).
auto* locale = ordinary_create_from_constructor<Locale>(global_object, new_target, &GlobalObject::intl_locale_prototype);
if (vm.exception())
return {};
auto* locale = TRY_OR_DISCARD(ordinary_create_from_constructor<Locale>(global_object, new_target, &GlobalObject::intl_locale_prototype));
String tag;

View file

@ -51,9 +51,7 @@ Value NumberFormatConstructor::construct(FunctionObject& new_target)
auto options = vm.argument(1);
// 2. Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%NumberFormat.prototype%", « [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »).
auto* number_format = ordinary_create_from_constructor<NumberFormat>(global_object, new_target, &GlobalObject::intl_number_format_prototype);
if (vm.exception())
return {};
auto* number_format = TRY_OR_DISCARD(ordinary_create_from_constructor<NumberFormat>(global_object, new_target, &GlobalObject::intl_number_format_prototype));
// 3. Perform ? InitializeNumberFormat(numberFormat, locales, options).
initialize_number_format(global_object, *number_format, locales, options);

View file

@ -49,9 +49,7 @@ Value MapConstructor::construct(FunctionObject& new_target)
auto& vm = this->vm();
auto& global_object = this->global_object();
auto* map = ordinary_create_from_constructor<Map>(global_object, new_target, &GlobalObject::map_prototype);
if (vm.exception())
return {};
auto* map = TRY_OR_DISCARD(ordinary_create_from_constructor<Map>(global_object, new_target, &GlobalObject::map_prototype));
if (vm.argument(0).is_nullish())
return map;

View file

@ -103,7 +103,7 @@ Value NumberConstructor::construct(FunctionObject& new_target)
auto number = get_value_from_constructor_argument(global_object);
if (vm.exception())
return {};
return ordinary_create_from_constructor<NumberObject>(global_object, new_target, &GlobalObject::number_prototype, number.as_double());
return TRY_OR_DISCARD(ordinary_create_from_constructor<NumberObject>(global_object, new_target, &GlobalObject::number_prototype, number.as_double()));
}
// 21.1.2.2 Number.isFinite ( number ), https://tc39.es/ecma262/#sec-number.isfinite

View file

@ -74,7 +74,7 @@ Value ObjectConstructor::construct(FunctionObject& new_target)
auto& global_object = this->global_object();
if (&new_target != this)
return ordinary_create_from_constructor<Object>(global_object, new_target, &GlobalObject::object_prototype);
return TRY_OR_DISCARD(ordinary_create_from_constructor<Object>(global_object, new_target, &GlobalObject::object_prototype));
auto value = vm.argument(0);
if (value.is_nullish())
return Object::create(global_object, global_object.object_prototype());

View file

@ -263,9 +263,7 @@ Value PromiseConstructor::construct(FunctionObject& new_target)
return {};
}
auto* promise = ordinary_create_from_constructor<Promise>(global_object, new_target, &GlobalObject::promise_prototype);
if (vm.exception())
return {};
auto* promise = TRY_OR_DISCARD(ordinary_create_from_constructor<Promise>(global_object, new_target, &GlobalObject::promise_prototype));
auto [resolve_function, reject_function] = promise->create_resolving_functions();

View file

@ -49,9 +49,7 @@ Value SetConstructor::construct(FunctionObject& new_target)
auto& vm = this->vm();
auto& global_object = this->global_object();
auto* set = ordinary_create_from_constructor<Set>(global_object, new_target, &GlobalObject::set_prototype);
if (vm.exception())
return {};
auto* set = TRY_OR_DISCARD(ordinary_create_from_constructor<Set>(global_object, new_target, &GlobalObject::set_prototype));
if (vm.argument(0).is_nullish())
return set;

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;

View file

@ -475,11 +475,8 @@ Value VM::construct(FunctionObject& function, FunctionObject& new_target, Option
auto& global_object = function.global_object();
Value this_argument;
if (function.constructor_kind() == FunctionObject::ConstructorKind::Base) {
this_argument = ordinary_create_from_constructor<Object>(global_object, new_target, &GlobalObject::object_prototype);
if (exception())
return {};
}
if (function.constructor_kind() == FunctionObject::ConstructorKind::Base)
this_argument = TRY_OR_DISCARD(ordinary_create_from_constructor<Object>(global_object, new_target, &GlobalObject::object_prototype));
// FIXME: prepare_for_ordinary_call() is not supposed to receive a BoundFunction, ProxyObject, etc. - ever.
// This needs to be moved to NativeFunction/OrdinaryFunctionObject's construct() (10.2.2 [[Construct]])

View file

@ -47,9 +47,7 @@ Value WeakMapConstructor::construct(FunctionObject& new_target)
auto& vm = this->vm();
auto& global_object = this->global_object();
auto* weak_map = ordinary_create_from_constructor<WeakMap>(global_object, new_target, &GlobalObject::weak_map_prototype);
if (vm.exception())
return {};
auto* weak_map = TRY_OR_DISCARD(ordinary_create_from_constructor<WeakMap>(global_object, new_target, &GlobalObject::weak_map_prototype));
if (vm.argument(0).is_nullish())
return weak_map;

View file

@ -51,7 +51,7 @@ Value WeakRefConstructor::construct(FunctionObject& new_target)
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, target.to_string_without_side_effects());
return {};
}
return ordinary_create_from_constructor<WeakRef>(global_object, new_target, &GlobalObject::weak_ref_prototype, &target.as_object());
return TRY_OR_DISCARD(ordinary_create_from_constructor<WeakRef>(global_object, new_target, &GlobalObject::weak_ref_prototype, &target.as_object()));
}
}

View file

@ -47,7 +47,7 @@ Value WeakSetConstructor::construct(FunctionObject& new_target)
auto& vm = this->vm();
auto& global_object = this->global_object();
auto* weak_set = ordinary_create_from_constructor<WeakSet>(global_object, new_target, &GlobalObject::weak_set_prototype);
auto* weak_set = TRY_OR_DISCARD(ordinary_create_from_constructor<WeakSet>(global_object, new_target, &GlobalObject::weak_set_prototype));
if (vm.exception())
return {};