Browse Source

LibJS: Propagate OOM from PatternPartitionWithSource factory

Timothy Flynn 2 years ago
parent
commit
ea13f3e285

+ 5 - 3
Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.h

@@ -11,9 +11,11 @@
 #include <AK/Variant.h>
 #include <AK/Variant.h>
 #include <AK/Vector.h>
 #include <AK/Vector.h>
 #include <LibJS/Forward.h>
 #include <LibJS/Forward.h>
+#include <LibJS/Runtime/Completion.h>
 #include <LibJS/Runtime/Intl/DisplayNames.h>
 #include <LibJS/Runtime/Intl/DisplayNames.h>
 #include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
 #include <LibJS/Runtime/Intl/SingleUnitIdentifiers.h>
 #include <LibJS/Runtime/Temporal/AbstractOperations.h>
 #include <LibJS/Runtime/Temporal/AbstractOperations.h>
+#include <LibJS/Runtime/VM.h>
 #include <LibJS/Runtime/Value.h>
 #include <LibJS/Runtime/Value.h>
 #include <LibLocale/Forward.h>
 #include <LibLocale/Forward.h>
 
 
@@ -54,16 +56,16 @@ struct PatternPartition {
 };
 };
 
 
 struct PatternPartitionWithSource : public PatternPartition {
 struct PatternPartitionWithSource : public PatternPartition {
-    static Vector<PatternPartitionWithSource> create_from_parent_list(Vector<PatternPartition> partitions)
+    static ThrowCompletionOr<Vector<PatternPartitionWithSource>> create_from_parent_list(VM& vm, Vector<PatternPartition> partitions)
     {
     {
         Vector<PatternPartitionWithSource> result;
         Vector<PatternPartitionWithSource> result;
-        result.ensure_capacity(partitions.size());
+        TRY_OR_THROW_OOM(vm, result.try_ensure_capacity(partitions.size()));
 
 
         for (auto& partition : partitions) {
         for (auto& partition : partitions) {
             PatternPartitionWithSource partition_with_source {};
             PatternPartitionWithSource partition_with_source {};
             partition_with_source.type = partition.type;
             partition_with_source.type = partition.type;
             partition_with_source.value = move(partition.value);
             partition_with_source.value = move(partition.value);
-            result.append(move(partition_with_source));
+            result.unchecked_append(move(partition_with_source));
         }
         }
 
 
         return result;
         return result;

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp

@@ -1079,7 +1079,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
 
 
         // c. Let result be ? FormatDateTimePattern(dateTimeFormat, patternParts, x, undefined).
         // c. Let result be ? FormatDateTimePattern(dateTimeFormat, patternParts, x, undefined).
         auto raw_result = TRY(format_date_time_pattern(vm, date_time_format, move(pattern_parts), start, nullptr));
         auto raw_result = TRY(format_date_time_pattern(vm, date_time_format, move(pattern_parts), start, nullptr));
-        auto result = PatternPartitionWithSource::create_from_parent_list(move(raw_result));
+        auto result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_result)));
 
 
         // d. For each Record { [[Type]], [[Value]] } r in result, do
         // d. For each Record { [[Type]], [[Value]] } r in result, do
         for (auto& part : result) {
         for (auto& part : result) {
@@ -1136,7 +1136,7 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_date_time_range_
 
 
         // f. Let partResult be ? FormatDateTimePattern(dateTimeFormat, patternParts, z, rangePattern).
         // f. Let partResult be ? FormatDateTimePattern(dateTimeFormat, patternParts, z, rangePattern).
         auto raw_part_result = TRY(format_date_time_pattern(vm, date_time_format, move(pattern_parts), time, &range_pattern.value()));
         auto raw_part_result = TRY(format_date_time_pattern(vm, date_time_format, move(pattern_parts), time, &range_pattern.value()));
-        auto part_result = PatternPartitionWithSource::create_from_parent_list(move(raw_part_result));
+        auto part_result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_part_result)));
 
 
         // g. For each Record { [[Type]], [[Value]] } r in partResult, do
         // g. For each Record { [[Type]], [[Value]] } r in partResult, do
         for (auto& part : part_result) {
         for (auto& part : part_result) {

+ 2 - 2
Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp

@@ -1801,11 +1801,11 @@ ThrowCompletionOr<Vector<PatternPartitionWithSource>> partition_number_range_pat
 
 
     // 3. Let xResult be ? PartitionNumberPattern(numberFormat, x).
     // 3. Let xResult be ? PartitionNumberPattern(numberFormat, x).
     auto raw_start_result = TRY(partition_number_pattern(vm, number_format, move(start)));
     auto raw_start_result = TRY(partition_number_pattern(vm, number_format, move(start)));
-    auto start_result = PatternPartitionWithSource::create_from_parent_list(move(raw_start_result));
+    auto start_result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_start_result)));
 
 
     // 4. Let yResult be ? PartitionNumberPattern(numberFormat, y).
     // 4. Let yResult be ? PartitionNumberPattern(numberFormat, y).
     auto raw_end_result = TRY(partition_number_pattern(vm, number_format, move(end)));
     auto raw_end_result = TRY(partition_number_pattern(vm, number_format, move(end)));
-    auto end_result = PatternPartitionWithSource::create_from_parent_list(move(raw_end_result));
+    auto end_result = MUST_OR_THROW_OOM(PatternPartitionWithSource::create_from_parent_list(vm, move(raw_end_result)));
 
 
     // 5. If xResult is equal to yResult, then
     // 5. If xResult is equal to yResult, then
     if (start_result == end_result) {
     if (start_result == end_result) {