1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-19 11:27:35 +00:00

LibJS: Propagate OOM from remaining Intl Vector operations

This commit is contained in:
Timothy Flynn 2023-02-02 19:46:33 -05:00 committed by Linus Groh
parent 9af525bbb0
commit 858126d236
2 changed files with 7 additions and 6 deletions

View file

@ -70,16 +70,17 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
auto locale_list = TRY(canonicalize_locale_list(vm, locales)); auto locale_list = TRY(canonicalize_locale_list(vm, locales));
MarkedVector<Value> marked_locale_list { vm.heap() }; MarkedVector<Value> marked_locale_list { vm.heap() };
marked_locale_list.ensure_capacity(locale_list.size()); TRY_OR_THROW_OOM(vm, marked_locale_list.try_ensure_capacity(locale_list.size()));
for (auto& locale : locale_list) for (auto& locale : locale_list)
marked_locale_list.append(PrimitiveString::create(vm, move(locale))); marked_locale_list.unchecked_append(PrimitiveString::create(vm, move(locale)));
// 2. Return CreateArrayFromList(ll). // 2. Return CreateArrayFromList(ll).
return Array::create_from(realm, marked_locale_list); return Array::create_from(realm, marked_locale_list);
} }
// 1.4.4 AvailableCanonicalTimeZones (), https://tc39.es/proposal-intl-enumeration/#sec-availablecanonicaltimezones // 1.4.4 AvailableCanonicalTimeZones (), https://tc39.es/proposal-intl-enumeration/#sec-availablecanonicaltimezones
static Vector<StringView> available_canonical_time_zones() static ThrowCompletionOr<Vector<StringView>> available_canonical_time_zones(VM& vm)
{ {
// 1. Let names be a List of all supported Zone and Link names in the IANA Time Zone Database. // 1. Let names be a List of all supported Zone and Link names in the IANA Time Zone Database.
auto names = TimeZone::all_time_zones(); auto names = TimeZone::all_time_zones();
@ -96,7 +97,7 @@ static Vector<StringView> available_canonical_time_zones()
// c. If result does not contain an element equal to canonical, then // c. If result does not contain an element equal to canonical, then
if (!result.contains_slow(canonical)) { if (!result.contains_slow(canonical)) {
// i. Append canonical to the end of result. // i. Append canonical to the end of result.
result.append(canonical); TRY_OR_THROW_OOM(vm, result.try_append(canonical));
} }
} }
@ -140,7 +141,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
// 6. Else if key is "timeZone", then // 6. Else if key is "timeZone", then
else if (key == "timeZone"sv) { else if (key == "timeZone"sv) {
// a. Let list be ! AvailableCanonicalTimeZones( ). // a. Let list be ! AvailableCanonicalTimeZones( ).
static auto time_zones = available_canonical_time_zones(); static auto time_zones = MUST_OR_THROW_OOM(available_canonical_time_zones(vm));
list = time_zones.span(); list = time_zones.span();
} }
// 7. Else if key is "unit", then // 7. Else if key is "unit", then

View file

@ -188,7 +188,7 @@ static ThrowCompletionOr<LocaleAndKeys> apply_unicode_extension_to_tag(VM& vm, S
// iv. Else, // iv. Else,
else { else {
// 1. Append the Record { [[Key]]: key, [[Value]]: value } to keywords. // 1. Append the Record { [[Key]]: key, [[Value]]: value } to keywords.
keywords.append({ TRY_OR_THROW_OOM(vm, String::from_utf8(key)), *value }); TRY_OR_THROW_OOM(vm, keywords.try_append({ TRY_OR_THROW_OOM(vm, String::from_utf8(key)), *value }));
} }
} }