diff --git a/Libraries/LibJS/Runtime/Completion.cpp b/Libraries/LibJS/Runtime/Completion.cpp index e24e363d48f26..8a8381d712631 100644 --- a/Libraries/LibJS/Runtime/Completion.cpp +++ b/Libraries/LibJS/Runtime/Completion.cpp @@ -97,13 +97,15 @@ ThrowCompletionOr await(VM& vm, Value value) promise->perform_then(on_fulfilled, on_rejected, {}); // FIXME: Since we don't support context suspension, we attempt to "wait" for the promise to resolve - // by letting the event loop spin until our promise is no longer pending, and then synchronously - // running all queued promise jobs. - // Note: This is not used by LibJS itself, and is performed for the embedder (i.e. LibWeb). + // by blocking until all our promise is complete. if (auto* custom_data = vm.custom_data()) { + // Embedder case (i.e. LibWeb). custom_data->spin_event_loop_until(GC::create_function(vm.heap(), [success] { return success.has_value(); })); + } else { + // No embbedder, standalone LibJS implementation + vm.run_queued_promise_jobs(); } // 8. Remove asyncContext from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context. @@ -113,8 +115,6 @@ ThrowCompletionOr await(VM& vm, Value value) // 10. Return NormalCompletion(unused). // 11. NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of asyncContext. - vm.run_queued_promise_jobs(); - // Make sure that the promise _actually_ resolved. // Note that this is checked down the chain (result.is_empty()) anyway, but let's make the source of the issue more clear. VERIFY(success.has_value());