Browse Source

LibJS: Stop propagating small OOM errors from Intl.Locale

Timothy Flynn 1 year ago
parent
commit
746ce6f9a1

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Intl/Locale.cpp

@@ -206,7 +206,7 @@ static u8 weekday_to_integer(Optional<::Locale::Weekday> weekday, ::Locale::Week
     VERIFY_NOT_REACHED();
 }
 
-static ThrowCompletionOr<Vector<u8>> weekend_of_locale(VM& vm, StringView locale)
+static Vector<u8> weekend_of_locale(StringView locale)
 {
     auto weekend_start = weekday_to_integer(::Locale::get_locale_weekend_start(locale), ::Locale::Weekday::Saturday);
     auto weekend_end = weekday_to_integer(::Locale::get_locale_weekend_end(locale), ::Locale::Weekday::Sunday);
@@ -216,7 +216,7 @@ static ThrowCompletionOr<Vector<u8>> weekend_of_locale(VM& vm, StringView locale
     VERIFY(weekend_start <= weekend_end);
 
     Vector<u8> weekend;
-    TRY_OR_THROW_OOM(vm, weekend.try_ensure_capacity(weekend_end - weekend_start + 1));
+    weekend.ensure_capacity(weekend_end - weekend_start + 1);
 
     for (auto day = weekend_start; day <= weekend_end; ++day)
         weekend.unchecked_append(day);
@@ -225,7 +225,7 @@ static ThrowCompletionOr<Vector<u8>> weekend_of_locale(VM& vm, StringView locale
 }
 
 // 1.1.8 WeekInfoOfLocale ( loc ), https://tc39.es/proposal-intl-locale-info/#sec-week-info-of-locale
-ThrowCompletionOr<WeekInfo> week_info_of_locale(VM& vm, Locale const& locale_object)
+WeekInfo week_info_of_locale(Locale const& locale_object)
 {
     // 1. Let locale be loc.[[Locale]].
     auto const& locale = locale_object.locale();
@@ -237,7 +237,7 @@ ThrowCompletionOr<WeekInfo> week_info_of_locale(VM& vm, Locale const& locale_obj
     WeekInfo week_info {};
     week_info.minimal_days = ::Locale::get_locale_minimum_days(locale).value_or(1);
     week_info.first_day = weekday_to_integer(::Locale::get_locale_first_day(locale), ::Locale::Weekday::Monday);
-    week_info.weekend = MUST_OR_THROW_OOM(weekend_of_locale(vm, locale));
+    week_info.weekend = weekend_of_locale(locale);
 
     return week_info;
 }

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/Locale.h

@@ -88,6 +88,6 @@ NonnullGCPtr<Array> hour_cycles_of_locale(VM&, Locale const& locale);
 NonnullGCPtr<Array> numbering_systems_of_locale(VM&, Locale const&);
 NonnullGCPtr<Array> time_zones_of_locale(VM&, StringView region);
 StringView character_direction_of_locale(Locale const&);
-ThrowCompletionOr<WeekInfo> week_info_of_locale(VM&, Locale const&);
+WeekInfo week_info_of_locale(Locale const&);
 
 }

+ 3 - 3
Userland/Libraries/LibJS/Runtime/Intl/LocaleConstructor.cpp

@@ -105,7 +105,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(VM& vm, StringView tag, Ob
 }
 
 // 14.1.3 ApplyUnicodeExtensionToTag ( tag, options, relevantExtensionKeys ), https://tc39.es/ecma402/#sec-apply-unicode-extension-to-tag
-static ThrowCompletionOr<LocaleAndKeys> apply_unicode_extension_to_tag(VM& vm, StringView tag, LocaleAndKeys options, ReadonlySpan<StringView> relevant_extension_keys)
+static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKeys options, ReadonlySpan<StringView> relevant_extension_keys)
 {
     // 1. Assert: Type(tag) is String.
     // 2. Assert: tag matches the unicode_locale_id production.
@@ -188,7 +188,7 @@ static ThrowCompletionOr<LocaleAndKeys> apply_unicode_extension_to_tag(VM& vm, S
             // iv. Else,
             else {
                 // 1. Append the Record { [[Key]]: key, [[Value]]: value } to keywords.
-                TRY_OR_THROW_OOM(vm, keywords.try_append({ TRY_OR_THROW_OOM(vm, String::from_utf8(key)), *value }));
+                keywords.append({ MUST(String::from_utf8(key)), *value });
             }
         }
 
@@ -322,7 +322,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> LocaleConstructor::construct(FunctionObj
     opt.nu = TRY(get_string_option(vm, *options, vm.names.numberingSystem, ::Locale::is_type_identifier));
 
     // 29. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
-    auto result = MUST_OR_THROW_OOM(apply_unicode_extension_to_tag(vm, tag, move(opt), relevant_extension_keys));
+    auto result = apply_unicode_extension_to_tag(tag, move(opt), relevant_extension_keys);
 
     // 30. Set locale.[[Locale]] to r.[[locale]].
     locale->set_locale(move(result.locale));

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Intl/LocalePrototype.cpp

@@ -283,7 +283,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info)
     auto info = Object::create(realm, realm.intrinsics().object_prototype());
 
     // 4. Let wi be ! WeekInfoOfLocale(loc).
-    auto week_info = MUST_OR_THROW_OOM(week_info_of_locale(vm, locale_object));
+    auto week_info = week_info_of_locale(locale_object);
 
     // 5. Let we be ! CreateArrayFromList( wi.[[Weekend]] ).
     auto weekend = Array::create_from<u8>(realm, week_info.weekend, [](auto day) { return Value(day); });