Repository navigation
fix(bindgen): return JSPI host imports synchronously when the context cannot wait - #2324
Open
chenyan2002 wants to merge 2 commits into
Open
chenyan2002 wants to merge 2 commits into
chenyan2002 wants to merge 2 commits into
Conversation
chenyan2002
requested review from
andreiltd and
vados-cosmonic
as code owners
October 26, 2026 23:27
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With JSPI, an import marked async (via
asyncImports) always returned a promise to the guest, even when the host answered synchronously. So calling from a context that can't wait trapped with "cannot block a synchronous task before returning". This includes two contexts:_initializeor a start function runs with no current task.Changes
yield. A new_maybeSyncGeneratorruns them synchronously and only switches to a promise when a yielded value is a promise.task.enterHost(). It's a new sync method holding the host-entry logic fromenter({ isHost: true })_withGlobalCurrentTaskMetaAsyncis now only async when its closure returns a promise._lowerImportBackwardsCompatcalls the host right away for manually-async imports, and returns the result synchronously when it isn't a promise._suspendingImporttakes a newcallHostflag, set only for these lowered host imports. The call traps only if the host actually returns a promise.This PR doesn't fix the P3 async imports, which may need its own issue: P3 async imports go through
_lowerImport, which always returns a promise, so an async-lowered call from a task that can't block still traps, even though the calls never need to block.