From a8ffb78d10cca9695a48afc2c92a4d59f7431b5a Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 12 Jan 2025 13:33:39 +1300 Subject: [PATCH] LibJS: Only run queued promise jobs if there is no embedder This has no functional difference as run_queued_promise jobs does nothing when LibWeb is used as it has a different implementation of enqueuing and running promise jobs. But this change makes it more obvious that run_queued_promise jobs does nothing when there is an embedder, and adjusts the comment to reflect what the code is actually achieving. --- Libraries/LibJS/Runtime/Completion.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Libraries/LibJS/Runtime/Completion.cpp b/Libraries/LibJS/Runtime/Completion.cpp index e24e363d48f2..7136fb1934c9 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 syncronously running all queued promise jobs. if (auto* custom_data = vm.custom_data()) { + // Embedder case (i.e. LibWeb). Runs all promise jobs be performing a microtask checkpoint. 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());