mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
LibJS: Call resolve instead of reject in AsyncFromSyncIteratorPrototype
This commit is contained in:
parent
3b1c3e574f
commit
fb61e9274a
2 changed files with 25 additions and 1 deletions
|
@ -118,7 +118,7 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::return_)
|
||||||
auto* iter_result = create_iterator_result_object(vm, vm.argument(0), true);
|
auto* iter_result = create_iterator_result_object(vm, vm.argument(0), true);
|
||||||
|
|
||||||
// b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »).
|
// 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]].
|
// c. Return promiseCapability.[[Promise]].
|
||||||
return promise_capability.promise;
|
return promise_capability.promise;
|
||||||
|
|
|
@ -44,6 +44,30 @@ describe("basic behavior", () => {
|
||||||
expect(loopIterations).toBe(1);
|
expect(loopIterations).toBe(1);
|
||||||
expect(rejected).toBeFalse();
|
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", () => {
|
describe("only allowed in async functions", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue