summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authordavidot <davidot@serenityos.org>2022-08-31 17:41:41 +0200
committerLinus Groh <mail@linusgroh.de>2022-09-02 02:07:37 +0100
commitfb61e9274af8ef328ed0ebcd0fdc510b0dbf6a46 (patch)
treef1d38064875150a1fd33aee1008aa86418b21f64 /Userland
parent3b1c3e574f51e1ca4efc725813a1b10bba19fc63 (diff)
downloadserenity-fb61e9274af8ef328ed0ebcd0fdc510b0dbf6a46.zip
LibJS: Call resolve instead of reject in AsyncFromSyncIteratorPrototype
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp2
-rw-r--r--Userland/Libraries/LibJS/Tests/loops/for-await-of.js24
2 files changed, 25 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
index 4e71468cfd..83c913d77e 100644
--- a/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AsyncFromSyncIteratorPrototype.cpp
@@ -118,7 +118,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
auto* iter_result = create_iterator_result_object(vm, vm.argument(0), true);
// b. Perform ! Call(promiseCapability.[[Resolve]], undefined, ยซ iterResult ยป).
- MUST(call(vm, *promise_capability.reject, js_undefined(), iter_result));
+ MUST(call(vm, *promise_capability.resolve, js_undefined(), iter_result));
// c. Return promiseCapability.[[Promise]].
return promise_capability.promise;
diff --git a/Userland/Libraries/LibJS/Tests/loops/for-await-of.js b/Userland/Libraries/LibJS/Tests/loops/for-await-of.js
index c6e30a15e9..d3bcf12820 100644
--- a/Userland/Libraries/LibJS/Tests/loops/for-await-of.js
+++ b/Userland/Libraries/LibJS/Tests/loops/for-await-of.js
@@ -44,6 +44,30 @@ describe("basic behavior", () => {
expect(loopIterations).toBe(1);
expect(rejected).toBeFalse();
});
+
+ test("can break a for-await-of loop", () => {
+ var loopIterations = 0;
+ var rejected = false;
+ async function f() {
+ for await (const v of [1, 2, 3]) {
+ expect(v).toBe(1);
+ loopIterations++;
+ break;
+ }
+ }
+
+ f().then(
+ () => {
+ expect(loopIterations).toBe(1);
+ },
+ () => {
+ rejected = true;
+ }
+ );
+ runQueuedPromiseJobs();
+ expect(loopIterations).toBe(1);
+ expect(rejected).toBeFalse();
+ });
});
describe("only allowed in async functions", () => {