mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:27:44 +00:00
AK: Make "foo"_string infallible
Stop worrying about tiny OOMs. Work towards #20405.
This commit is contained in:
parent
db2a8725c6
commit
34344120f2
181 changed files with 626 additions and 630 deletions
|
@ -47,7 +47,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
|
|||
|
||||
// 4. If name is undefined, set name to "Error"; otherwise set name to ? ToString(name).
|
||||
auto name = name_property.is_undefined()
|
||||
? TRY_OR_THROW_OOM(vm, "Error"_string)
|
||||
? "Error"_string
|
||||
: TRY(name_property.to_string(vm));
|
||||
|
||||
// 5. Let msg be ? Get(O, "message").
|
||||
|
@ -90,7 +90,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_getter)
|
|||
if (auto name_property = TRY(error.get(vm.names.name)); !name_property.is_undefined())
|
||||
name = TRY(name_property.to_string(vm));
|
||||
else
|
||||
name = TRY_OR_THROW_OOM(vm, "Error"_string);
|
||||
name = "Error"_string;
|
||||
|
||||
String message {};
|
||||
if (auto message_property = TRY(error.get(vm.names.message)); !message_property.is_undefined())
|
||||
|
|
|
@ -463,7 +463,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
|
|||
// 4. Else if keyLocaleData contains "true", then
|
||||
else if (key_locale_data.contains_slow("true"sv)) {
|
||||
// a. Let value be "true".
|
||||
value = TRY_OR_THROW_OOM(vm, "true"_string);
|
||||
value = "true"_string;
|
||||
|
||||
// b. Let supportedExtensionAddition be the string-concatenation of "-" and key.
|
||||
supported_extension_addition = ::Locale::Keyword { TRY_OR_THROW_OOM(vm, String::from_utf8(key)), {} };
|
||||
|
@ -486,7 +486,7 @@ ThrowCompletionOr<LocaleResult> resolve_locale(VM& vm, Vector<String> const& req
|
|||
// 3. If optionsValue is the empty String, then
|
||||
if (options_value->is_empty()) {
|
||||
// a. Let optionsValue be "true".
|
||||
options_value = TRY_OR_THROW_OOM(vm, "true"_string);
|
||||
options_value = "true"_string;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
|
|||
// 21. Let collation be r.[[co]].
|
||||
// 22. If collation is null, let collation be "default".
|
||||
// 23. Set collator.[[Collation]] to collation.
|
||||
collator.set_collation(result.co.has_value() ? result.co.release_value() : TRY_OR_THROW_OOM(vm, "default"_string));
|
||||
collator.set_collation(result.co.has_value() ? result.co.release_value() : "default"_string);
|
||||
|
||||
// 24. If relevantExtensionKeys contains "kn", then
|
||||
if (relevant_extension_keys.span().contains_slow("kn"sv) && result.kn.has_value()) {
|
||||
|
|
|
@ -159,7 +159,7 @@ ThrowCompletionOr<String> to_temporal_overflow(VM& vm, Object const* options)
|
|||
{
|
||||
// 1. If options is undefined, return "constrain".
|
||||
if (options == nullptr)
|
||||
return TRY_OR_THROW_OOM(vm, "constrain"_string);
|
||||
return "constrain"_string;
|
||||
|
||||
// 2. Return ? GetOption(options, "overflow", "string", « "constrain", "reject" », "constrain").
|
||||
auto option = TRY(get_option(vm, *options, vm.names.overflow, OptionType::String, { "constrain"sv, "reject"sv }, "constrain"sv));
|
||||
|
@ -173,7 +173,7 @@ ThrowCompletionOr<String> to_temporal_disambiguation(VM& vm, Object const* optio
|
|||
{
|
||||
// 1. If options is undefined, return "compatible".
|
||||
if (options == nullptr)
|
||||
return TRY_OR_THROW_OOM(vm, "compatible"_string);
|
||||
return "compatible"_string;
|
||||
|
||||
// 2. Return ? GetOption(options, "disambiguation", "string", « "compatible", "earlier", "later", "reject" », "compatible").
|
||||
auto option = TRY(get_option(vm, *options, vm.names.disambiguation, OptionType::String, { "compatible"sv, "earlier"sv, "later"sv, "reject"sv }, "compatible"sv));
|
||||
|
@ -1425,7 +1425,7 @@ ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM& vm, StringV
|
|||
// 4. If result.[[TimeZone]].[[Z]] is true, then
|
||||
if (result.time_zone.z) {
|
||||
// a. Set offsetString to "+00:00".
|
||||
offset_string = TRY_OR_THROW_OOM(vm, "+00:00"_string);
|
||||
offset_string = "+00:00"_string;
|
||||
}
|
||||
|
||||
// 6. Assert: offsetString is not undefined.
|
||||
|
@ -1460,7 +1460,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, StringView iso_
|
|||
|
||||
// b. If calendar is undefined, return "iso8601".
|
||||
if (!calendar.has_value())
|
||||
return TRY_OR_THROW_OOM(vm, "iso8601"_string);
|
||||
return "iso8601"_string;
|
||||
// c. Else, return calendar.
|
||||
else
|
||||
return calendar.release_value();
|
||||
|
|
|
@ -99,7 +99,7 @@ ThrowCompletionOr<Calendar*> get_builtin_calendar(VM& vm, String const& identifi
|
|||
Calendar* get_iso8601_calendar(VM& vm)
|
||||
{
|
||||
// 1. Return ! GetBuiltinCalendar("iso8601").
|
||||
return MUST(get_builtin_calendar(vm, "iso8601"_string.release_value_but_fixme_should_propagate_errors()));
|
||||
return MUST(get_builtin_calendar(vm, "iso8601"_string));
|
||||
}
|
||||
|
||||
// 12.2.4 CalendarFields ( calendar, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarfields
|
||||
|
@ -825,9 +825,9 @@ ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM& vm, Object const& fiel
|
|||
// 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "year", "day" »).
|
||||
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
|
||||
{ "day"_short_string,
|
||||
TRY_OR_THROW_OOM(vm, "month"_string),
|
||||
TRY_OR_THROW_OOM(vm, "monthCode"_string),
|
||||
TRY_OR_THROW_OOM(vm, "year"_string) },
|
||||
"month"_string,
|
||||
"monthCode"_string,
|
||||
"year"_string },
|
||||
Vector<StringView> { "year"sv, "day"sv }));
|
||||
|
||||
// 3. Let overflow be ? ToTemporalOverflow(options).
|
||||
|
@ -859,9 +859,9 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM& vm, Object const&
|
|||
|
||||
// 2. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », « "year" »).
|
||||
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
|
||||
{ TRY_OR_THROW_OOM(vm, "month"_string),
|
||||
TRY_OR_THROW_OOM(vm, "monthCode"_string),
|
||||
TRY_OR_THROW_OOM(vm, "year"_string) },
|
||||
{ "month"_string,
|
||||
"monthCode"_string,
|
||||
"year"_string },
|
||||
Vector<StringView> { "year"sv }));
|
||||
|
||||
// 3. Let overflow be ? ToTemporalOverflow(options).
|
||||
|
@ -891,9 +891,9 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(VM& vm, Object const& f
|
|||
// 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
|
||||
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
|
||||
{ "day"_short_string,
|
||||
TRY_OR_THROW_OOM(vm, "month"_string),
|
||||
TRY_OR_THROW_OOM(vm, "monthCode"_string),
|
||||
TRY_OR_THROW_OOM(vm, "year"_string) },
|
||||
"month"_string,
|
||||
"monthCode"_string,
|
||||
"year"_string },
|
||||
Vector<StringView> { "day"sv }));
|
||||
|
||||
// 3. Let overflow be ? ToTemporalOverflow(options).
|
||||
|
|
|
@ -369,7 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
|
|||
smallest_unit_present = false;
|
||||
|
||||
// b. Set smallestUnit to "nanosecond".
|
||||
smallest_unit = TRY_OR_THROW_OOM(vm, "nanosecond"_string);
|
||||
smallest_unit = "nanosecond"_string;
|
||||
}
|
||||
|
||||
// 10. Let defaultLargestUnit be ! DefaultTemporalLargestUnit(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]]).
|
||||
|
|
|
@ -344,12 +344,12 @@ ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(VM& vm, Object
|
|||
|
||||
// 2. Let partial be ? PrepareTemporalFields(temporalTimeLike, « "hour", "microsecond", "millisecond", "minute", "nanosecond", "second" », partial).
|
||||
auto* partial = TRY(prepare_temporal_fields(vm, temporal_time_like,
|
||||
{ TRY_OR_THROW_OOM(vm, "hour"_string),
|
||||
TRY_OR_THROW_OOM(vm, "microsecond"_string),
|
||||
TRY_OR_THROW_OOM(vm, "millisecond"_string),
|
||||
TRY_OR_THROW_OOM(vm, "minute"_string),
|
||||
TRY_OR_THROW_OOM(vm, "nanosecond"_string),
|
||||
TRY_OR_THROW_OOM(vm, "second"_string) },
|
||||
{ "hour"_string,
|
||||
"microsecond"_string,
|
||||
"millisecond"_string,
|
||||
"minute"_string,
|
||||
"nanosecond"_string,
|
||||
"second"_string },
|
||||
PrepareTemporalFieldsPartial {}));
|
||||
|
||||
TemporalTimeLikeRecord result;
|
||||
|
|
|
@ -150,10 +150,10 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
|
||||
|
||||
// d. Append "timeZone" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "timeZone"_string));
|
||||
field_names.append("timeZone"_string);
|
||||
|
||||
// e. Append "offset" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "offset"_string));
|
||||
field_names.append("offset"_string);
|
||||
|
||||
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, « "timeZone" »).
|
||||
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> { "timeZone"sv }));
|
||||
|
|
|
@ -769,7 +769,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
|
|||
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
|
||||
|
||||
// 7. Append "offset" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "offset"_string));
|
||||
field_names.append("offset"_string);
|
||||
|
||||
// 8. Let partialZonedDateTime be ? PrepareTemporalFields(temporalZonedDateTimeLike, fieldNames, partial).
|
||||
auto* partial_zoned_date_time = TRY(prepare_temporal_fields(vm, temporal_zoned_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
|
||||
|
@ -787,7 +787,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
|
|||
auto& time_zone = zoned_date_time->time_zone();
|
||||
|
||||
// 13. Append "timeZone" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "timeZone"_string));
|
||||
field_names.append("timeZone"_string);
|
||||
|
||||
// 14. Let fields be ? PrepareTemporalFields(zonedDateTime, fieldNames, « "timeZone", "offset" »).
|
||||
auto* fields = TRY(prepare_temporal_fields(vm, zoned_date_time, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
|
||||
|
|
|
@ -44,7 +44,7 @@ ErrorOr<NonnullRefPtr<VM>> VM::create(OwnPtr<CustomData> custom_data)
|
|||
|
||||
WellKnownSymbols well_known_symbols {
|
||||
#define __JS_ENUMERATE(SymbolName, snake_name) \
|
||||
Symbol::create(*vm, TRY("Symbol." #SymbolName##_string), false),
|
||||
Symbol::create(*vm, "Symbol." #SymbolName##_string, false),
|
||||
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
|
||||
#undef __JS_ENUMERATE
|
||||
};
|
||||
|
|
|
@ -420,14 +420,14 @@ ThrowCompletionOr<String> Value::to_string(VM& vm) const
|
|||
return vm.throw_completion<TypeError>(ErrorType::Convert, "symbol", "string");
|
||||
// 3. If argument is undefined, return "undefined".
|
||||
case UNDEFINED_TAG:
|
||||
return TRY_OR_THROW_OOM(vm, "undefined"_string);
|
||||
return "undefined"_string;
|
||||
// 4. If argument is null, return "null".
|
||||
case NULL_TAG:
|
||||
return TRY_OR_THROW_OOM(vm, "null"_string);
|
||||
return "null"_string;
|
||||
// 5. If argument is true, return "true".
|
||||
// 6. If argument is false, return "false".
|
||||
case BOOLEAN_TAG:
|
||||
return TRY_OR_THROW_OOM(vm, as_bool() ? "true"_string : "false"_string);
|
||||
return as_bool() ? "true"_string : "false"_string;
|
||||
// 7. If argument is a Number, return Number::toString(argument, 10).
|
||||
case INT32_TAG:
|
||||
return TRY_OR_THROW_OOM(vm, String::number(as_i32()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue