Skip to content

Commit

Permalink
LibJS: Only run queued promise jobs if there is no embedder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shannonbooth committed Jan 12, 2025
1 parent fef1f62 commit e853020
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Libraries/LibJS/Runtime/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ ThrowCompletionOr<Value> 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.
Expand All @@ -113,8 +115,6 @@ ThrowCompletionOr<Value> 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());
Expand Down

0 comments on commit e853020

Please sign in to comment.