瀏覽代碼

LibJS: Use IteratorStepValue in ECMA-402

This is an editorial change in the ECMA-402 spec. See:
https://github.com/tc39/ecma402/commit/e295500
Timothy Flynn 1 年之前
父節點
當前提交
0d3072bdac
共有 1 個文件被更改,包括 19 次插入25 次删除
  1. 19 25
      Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp

+ 19 - 25
Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp

@@ -251,35 +251,29 @@ ThrowCompletionOr<Vector<String>> string_list_from_iterable(VM& vm, Value iterab
     // 3. Let list be a new empty List.
     Vector<String> list;
 
-    // 4. Let next be true.
-    GCPtr<Object> next;
-
-    // 5. Repeat, while next is not false,
-    do {
-        // a. Set next to ? IteratorStep(iteratorRecord).
-        next = TRY(iterator_step(vm, iterator_record));
-
-        // b. If next is not false, then
-        if (next != nullptr) {
-            // i. Let nextValue be ? IteratorValue(next).
-            auto next_value = TRY(iterator_value(vm, *next));
-
-            // ii. If Type(nextValue) is not String, then
-            if (!next_value.is_string()) {
-                // 1. Let error be ThrowCompletion(a newly created TypeError object).
-                auto error = vm.throw_completion<TypeError>(ErrorType::NotAString, next_value);
+    // 4. Repeat,
+    while (true) {
+        // a. Let next be ? IteratorStepValue(iteratorRecord).
+        auto next = TRY(iterator_step_value(vm, iterator_record));
+
+        // b. If next is DONE, then
+        if (!next.has_value()) {
+            // a. Return list.
+            return list;
+        }
 
-                // 2. Return ? IteratorClose(iteratorRecord, error).
-                return iterator_close(vm, iterator_record, move(error));
-            }
+        // c. If Type(next) is not String, then
+        if (!next->is_string()) {
+            // 1. Let error be ThrowCompletion(a newly created TypeError object).
+            auto error = vm.throw_completion<TypeError>(ErrorType::NotAString, *next);
 
-            // iii. Append nextValue to the end of the List list.
-            list.append(next_value.as_string().utf8_string());
+            // 2. Return ? IteratorClose(iteratorRecord, error).
+            return iterator_close(vm, iterator_record, move(error));
         }
-    } while (next != nullptr);
 
-    // 6. Return list.
-    return list;
+        // iii. Append next to list.
+        list.append(next->as_string().utf8_string());
+    }
 }
 
 }