Просмотр исходного кода

LibJS: Propagate OOM from remaining Intl Vector operations

Timothy Flynn 2 лет назад
Родитель
Сommit
858126d236

+ 6 - 5
Userland/Libraries/LibJS/Runtime/Intl/Intl.cpp

@@ -70,16 +70,17 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
     auto locale_list = TRY(canonicalize_locale_list(vm, locales));
 
     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)
-        marked_locale_list.append(PrimitiveString::create(vm, move(locale)));
+        marked_locale_list.unchecked_append(PrimitiveString::create(vm, move(locale)));
 
     // 2. Return CreateArrayFromList(ll).
     return Array::create_from(realm, marked_locale_list);
 }
 
 // 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.
     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
         if (!result.contains_slow(canonical)) {
             // 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
     else if (key == "timeZone"sv) {
         // 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();
     }
     // 7. Else if key is "unit", then

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

@@ -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.
-                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 }));
             }
         }