mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:57:45 +00:00
LibJS: Convert Object::get() to ThrowCompletionOr
To no one's surprise, this patch is pretty big - this is possibly the most used AO of all of them. Definitely worth it though.
This commit is contained in:
parent
9b6c09e2c4
commit
b7e5f08e56
61 changed files with 326 additions and 686 deletions
|
@ -113,9 +113,7 @@ ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& o
|
|||
// 2. Assert: Each element of types is Boolean, String, or Number.
|
||||
|
||||
// 3. Let value be ? Get(options, property).
|
||||
auto value = options.get(property);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto value = TRY(options.get(property));
|
||||
|
||||
// 4. If value is undefined, return fallback.
|
||||
if (value.is_undefined())
|
||||
|
@ -1051,9 +1049,7 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object,
|
|||
// 3. For each value property of fieldNames, do
|
||||
for (auto& property : field_names) {
|
||||
// a. Let value be ? Get(fields, property).
|
||||
auto value = fields.get(property);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto value = TRY(fields.get(property));
|
||||
|
||||
// b. If value is undefined, then
|
||||
if (value.is_undefined()) {
|
||||
|
|
|
@ -332,9 +332,7 @@ ThrowCompletionOr<Object*> to_temporal_calendar(GlobalObject& global_object, Val
|
|||
return &temporal_calendar_like_object;
|
||||
|
||||
// c. Set temporalCalendarLike to ? Get(temporalCalendarLike, "calendar").
|
||||
temporal_calendar_like = temporal_calendar_like_object.get(vm.names.calendar);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
temporal_calendar_like = TRY(temporal_calendar_like_object.get(vm.names.calendar));
|
||||
|
||||
// d. If Type(temporalCalendarLike) is Object and ? HasProperty(temporalCalendarLike, "calendar") is false, return temporalCalendarLike.
|
||||
if (temporal_calendar_like.is_object()) {
|
||||
|
@ -394,9 +392,7 @@ ThrowCompletionOr<Object*> get_temporal_calendar_with_iso_default(GlobalObject&
|
|||
return &static_cast<ZonedDateTime&>(item).calendar();
|
||||
|
||||
// 2. Let calendar be ? Get(item, "calendar").
|
||||
auto calendar = item.get(vm.names.calendar);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto calendar = TRY(item.get(vm.names.calendar));
|
||||
|
||||
// 3. Return ? ToTemporalCalendarWithISODefault(calendar).
|
||||
return to_temporal_calendar_with_iso_default(global_object, calendar);
|
||||
|
@ -690,14 +686,10 @@ ThrowCompletionOr<double> resolve_iso_month(GlobalObject& global_object, Object
|
|||
auto& vm = global_object.vm();
|
||||
|
||||
// 1. Let month be ? Get(fields, "month").
|
||||
auto month = fields.get(vm.names.month);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month = TRY(fields.get(vm.names.month));
|
||||
|
||||
// 2. Let monthCode be ? Get(fields, "monthCode").
|
||||
auto month_code = fields.get(vm.names.monthCode);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month_code = TRY(fields.get(vm.names.monthCode));
|
||||
|
||||
// 3. If monthCode is undefined, then
|
||||
if (month_code.is_undefined()) {
|
||||
|
@ -760,9 +752,7 @@ ThrowCompletionOr<ISODate> iso_date_from_fields(GlobalObject& global_object, Obj
|
|||
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day", "month", "monthCode", "year" }, {}));
|
||||
|
||||
// 4. Let year be ? Get(fields, "year").
|
||||
auto year = prepared_fields->get(vm.names.year);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto year = TRY(prepared_fields->get(vm.names.year));
|
||||
|
||||
// 5. If year is undefined, throw a TypeError exception.
|
||||
if (year.is_undefined())
|
||||
|
@ -772,9 +762,7 @@ ThrowCompletionOr<ISODate> iso_date_from_fields(GlobalObject& global_object, Obj
|
|||
auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
|
||||
|
||||
// 7. Let day be ? Get(fields, "day").
|
||||
auto day = prepared_fields->get(vm.names.day);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto day = TRY(prepared_fields->get(vm.names.day));
|
||||
|
||||
// 8. If day is undefined, throw a TypeError exception.
|
||||
if (day.is_undefined())
|
||||
|
@ -798,9 +786,7 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_
|
|||
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "month"sv, "monthCode"sv, "year"sv }, {}));
|
||||
|
||||
// 4. Let year be ? Get(fields, "year").
|
||||
auto year = prepared_fields->get(vm.names.year);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto year = TRY(prepared_fields->get(vm.names.year));
|
||||
|
||||
// 5. If year is undefined, throw a TypeError exception.
|
||||
if (year.is_undefined())
|
||||
|
@ -830,19 +816,13 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_ob
|
|||
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, {}));
|
||||
|
||||
// 4. Let month be ? Get(fields, "month").
|
||||
auto month_value = prepared_fields->get(vm.names.month);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month_value = TRY(prepared_fields->get(vm.names.month));
|
||||
|
||||
// 5. Let monthCode be ? Get(fields, "monthCode").
|
||||
auto month_code = prepared_fields->get(vm.names.monthCode);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month_code = TRY(prepared_fields->get(vm.names.monthCode));
|
||||
|
||||
// 6. Let year be ? Get(fields, "year").
|
||||
auto year = prepared_fields->get(vm.names.year);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto year = TRY(prepared_fields->get(vm.names.year));
|
||||
|
||||
// 7. If month is not undefined, and monthCode and year are both undefined, then
|
||||
if (!month_value.is_undefined() && month_code.is_undefined() && year.is_undefined()) {
|
||||
|
@ -854,9 +834,7 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_ob
|
|||
auto month = TRY(resolve_iso_month(global_object, *prepared_fields));
|
||||
|
||||
// 9. Let day be ? Get(fields, "day").
|
||||
auto day = prepared_fields->get(vm.names.day);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto day = TRY(prepared_fields->get(vm.names.day));
|
||||
|
||||
// 10. If day is undefined, throw a TypeError exception.
|
||||
if (day.is_undefined())
|
||||
|
@ -974,9 +952,7 @@ ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Obj
|
|||
auto property_name = PropertyName::from_value(global_object, next_key);
|
||||
|
||||
// i. Let propValue be ? Get(fields, nextKey).
|
||||
auto prop_value = fields.get(property_name);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto prop_value = TRY(fields.get(property_name));
|
||||
|
||||
// ii. If propValue is not undefined, then
|
||||
if (!prop_value.is_undefined()) {
|
||||
|
@ -999,9 +975,7 @@ ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Obj
|
|||
auto property_name = PropertyName::from_value(global_object, next_key);
|
||||
|
||||
// a. Let propValue be ? Get(additionalFields, nextKey).
|
||||
auto prop_value = additional_fields.get(property_name);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto prop_value = TRY(additional_fields.get(property_name));
|
||||
|
||||
// b. If propValue is not undefined, then
|
||||
if (!prop_value.is_undefined()) {
|
||||
|
@ -1016,9 +990,7 @@ ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Obj
|
|||
// 6. If newKeys does not contain either "month" or "monthCode", then
|
||||
if (!new_keys_contains_month_or_month_code_property) {
|
||||
// a. Let month be ? Get(fields, "month").
|
||||
auto month = fields.get(vm.names.month);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month = TRY(fields.get(vm.names.month));
|
||||
|
||||
// b. If month is not undefined, then
|
||||
if (!month.is_undefined()) {
|
||||
|
@ -1027,9 +999,7 @@ ThrowCompletionOr<Object*> default_merge_fields(GlobalObject& global_object, Obj
|
|||
}
|
||||
|
||||
// c. Let monthCode be ? Get(fields, "monthCode").
|
||||
auto month_code = fields.get(vm.names.monthCode);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month_code = TRY(fields.get(vm.names.monthCode));
|
||||
|
||||
// d. If monthCode is not undefined, then
|
||||
if (!month_code.is_undefined()) {
|
||||
|
|
|
@ -89,9 +89,7 @@ ThrowCompletionOr<TemporalDuration> to_temporal_duration_record(GlobalObject& gl
|
|||
// a. Let prop be the Property value of the current row.
|
||||
|
||||
// b. Let val be ? Get(temporalDurationLike, prop).
|
||||
auto value = temporal_duration_like.get(property);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto value = TRY(temporal_duration_like.get(property));
|
||||
|
||||
// c. If val is undefined, then
|
||||
if (value.is_undefined()) {
|
||||
|
@ -194,9 +192,7 @@ ThrowCompletionOr<PartialDuration> to_partial_duration(GlobalObject& global_obje
|
|||
// a. Let property be the Property value of the current row.
|
||||
|
||||
// b. Let value be ? Get(temporalDurationLike, property).
|
||||
auto value = temporal_duration_like.as_object().get(property);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto value = TRY(temporal_duration_like.as_object().get(property));
|
||||
|
||||
// c. If value is not undefined, then
|
||||
if (!value.is_undefined()) {
|
||||
|
|
|
@ -373,9 +373,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_string)
|
|||
auto* options = TRY_OR_DISCARD(get_options_object(global_object, vm.argument(0)));
|
||||
|
||||
// 4. Let timeZone be ? Get(options, "timeZone").
|
||||
auto time_zone = options->get(vm.names.timeZone);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto time_zone = TRY_OR_DISCARD(options->get(vm.names.timeZone));
|
||||
|
||||
// 5. If timeZone is not undefined, then
|
||||
if (!time_zone.is_undefined()) {
|
||||
|
@ -455,9 +453,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time)
|
|||
}
|
||||
|
||||
// 4. Let calendarLike be ? Get(item, "calendar").
|
||||
auto calendar_like = item.as_object().get(vm.names.calendar);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto calendar_like = TRY_OR_DISCARD(item.as_object().get(vm.names.calendar));
|
||||
|
||||
// 5. If calendarLike is undefined, then
|
||||
if (calendar_like.is_undefined()) {
|
||||
|
@ -470,9 +466,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time)
|
|||
auto* calendar = TRY_OR_DISCARD(to_temporal_calendar(global_object, calendar_like));
|
||||
|
||||
// 7. Let temporalTimeZoneLike be ? Get(item, "timeZone").
|
||||
auto temporal_time_zone_like = item.as_object().get(vm.names.timeZone);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto temporal_time_zone_like = TRY_OR_DISCARD(item.as_object().get(vm.names.timeZone));
|
||||
|
||||
// 8. If temporalTimeZoneLike is undefined, then
|
||||
if (temporal_time_zone_like.is_undefined()) {
|
||||
|
@ -502,9 +496,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_zoned_date_time_iso)
|
|||
// 3. If Type(item) is Object, then
|
||||
if (item.is_object()) {
|
||||
// a. Let timeZoneProperty be ? Get(item, "timeZone").
|
||||
auto time_zone_property = item.as_object().get(vm.names.timeZone);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto time_zone_property = TRY_OR_DISCARD(item.as_object().get(vm.names.timeZone));
|
||||
|
||||
// b. If timeZoneProperty is not undefined, then
|
||||
if (!time_zone_property.is_undefined()) {
|
||||
|
|
|
@ -81,9 +81,7 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject& global_obj
|
|||
calendar_absent = false;
|
||||
} else {
|
||||
// i. Let calendar be ? Get(item, "calendar").
|
||||
auto calendar_value = item_object.get(vm.names.calendar);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto calendar_value = TRY(item_object.get(vm.names.calendar));
|
||||
|
||||
// ii. If calendar is undefined, then
|
||||
// 1. Let calendarAbsent be true.
|
||||
|
@ -102,19 +100,13 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject& global_obj
|
|||
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, {}));
|
||||
|
||||
// f. Let month be ? Get(fields, "month").
|
||||
auto month = fields->get(vm.names.month);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month = TRY(fields->get(vm.names.month));
|
||||
|
||||
// g. Let monthCode be ? Get(fields, "monthCode").
|
||||
auto month_code = fields->get(vm.names.monthCode);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto month_code = TRY(fields->get(vm.names.monthCode));
|
||||
|
||||
// h. Let year be ? Get(fields, "year").
|
||||
auto year = fields->get(vm.names.year);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto year = TRY(fields->get(vm.names.year));
|
||||
|
||||
// i. If calendarAbsent is true, and month is not undefined, and monthCode is undefined and year is undefined, then
|
||||
if (calendar_absent && !month.is_undefined() && month_code.is_undefined() && year.is_undefined()) {
|
||||
|
|
|
@ -140,9 +140,7 @@ ThrowCompletionOr<PartialUnregulatedTemporalTime> to_partial_time(GlobalObject&
|
|||
// a. Let property be the Property value of the current row.
|
||||
|
||||
// b. Let value be ? Get(temporalTimeLike, property).
|
||||
auto value = temporal_time_like.get(property);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto value = TRY(temporal_time_like.get(property));
|
||||
|
||||
// c. If value is not undefined, then
|
||||
if (!value.is_undefined()) {
|
||||
|
@ -367,9 +365,7 @@ ThrowCompletionOr<UnregulatedTemporalTime> to_temporal_time_record(GlobalObject&
|
|||
// a. Let property be the Property value of the current row.
|
||||
|
||||
// b. Let value be ? Get(temporalTimeLike, property).
|
||||
auto value = temporal_time_like.get(property);
|
||||
if (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
auto value = TRY(temporal_time_like.get(property));
|
||||
|
||||
// c. If value is undefined, then
|
||||
if (value.is_undefined()) {
|
||||
|
|
|
@ -163,9 +163,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with)
|
|||
TRY_OR_DISCARD(reject_temporal_calendar_type(global_object, temporal_time_like));
|
||||
|
||||
// 5. Let calendarProperty be ? Get(temporalTimeLike, "calendar").
|
||||
auto calendar_property = temporal_time_like.get(vm.names.calendar);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto calendar_property = TRY_OR_DISCARD(temporal_time_like.get(vm.names.calendar));
|
||||
|
||||
// 6. If calendarProperty is not undefined, then
|
||||
if (!calendar_property.is_undefined()) {
|
||||
|
@ -175,9 +173,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with)
|
|||
}
|
||||
|
||||
// 7. Let timeZoneProperty be ? Get(temporalTimeLike, "timeZone").
|
||||
auto time_zone_property = temporal_time_like.get(vm.names.timeZone);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
auto time_zone_property = TRY_OR_DISCARD(temporal_time_like.get(vm.names.timeZone));
|
||||
|
||||
// 8. If timeZoneProperty is not undefined, then
|
||||
if (!time_zone_property.is_undefined()) {
|
||||
|
|
|
@ -333,9 +333,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(GlobalObject& global_object, Va
|
|||
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 (auto* exception = vm.exception())
|
||||
return throw_completion(exception->value());
|
||||
temporal_time_zone_like = TRY(temporal_time_zone_like.as_object().get(vm.names.timeZone));
|
||||
|
||||
// d. If Type(temporalTimeZoneLike) is Object and ? HasProperty(temporalTimeZoneLike, "timeZone") is false, return temporalTimeZoneLike.
|
||||
if (temporal_time_zone_like.is_object()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue