Repository navigation
Promise hooks for await continuations - #1
Merged
Merged
Conversation
Backport of quickjs-ng PR quickjs-ng#1808 (refs quickjs-ng issue quickjs-ng#1740) onto the v0.14.0-based branch. The engine changes are unchanged. The only difference is in api-test.c: promise_reaction_hook_interrupt takes a JSRuntime, because this branch predates quickjs-ng quickjs-ng#1802, which passes a JSContext to JSInterruptHandler. Drop this commit when the base moves to a quickjs-ng release that contains quickjs-ng#1808 or an equivalent fix. Cherry-picked from quickjs-ng PR quickjs-ng#1808, commit ae41179. Amp-Thread-ID: https://ampcode.com/threads/T-01a1d0c9-7061-75b3-8128-9621b38ec400 Co-authored-by: Amp <[email protected]>
With a promise hook installed, js_async_function_resume creates a throwaway continuation capability for each await, so the hook sees a promise whose parent is the awaited promise, and BEFORE/AFTER fire with that promise around the resumption. js_async_generator_await (used by await, yield, yield* and for await in async generators) and js_async_generator_completed_return still elided the capability. Their reactions then reported the awaited promise itself, so two generators awaiting one shared promise were indistinguishable, and an embedder that keys async context by promise resumed the generator in the context of whoever created the awaited promise. Factor the await continuation into js_await_continuation_capability() and use it at all three sites. Without a hook the allocation-free path is unchanged. Amp-Thread-ID: https://ampcode.com/threads/T-01a1d0c9-7061-75b3-8128-9621b38ec400 Co-authored-by: Amp <[email protected]>
noise64
approved these changes
Nov 13, 2026
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.
This adds two commits on top of
v0.14.0-patched. They make the QuickJS promise hook fire for every continuation, which wasm-rquickjs needs to keep custom durability scopes apart acrossawait(Linear GOL-925). Each commit stays separate from the other fixes on this branch, so we can drop it when upstream ships an equivalent fix.BEFORE/AFTERfire around every promise reaction job with the continuation promise. When a hook is installed, eachawaitin an async function gets its own continuation promise whose parent is the awaited promise. The engine changes are the same as in Fix promise hooks for reactions and await continuations quickjs-ng/quickjs#1808. Onlyapi-test.cchanges: the interrupt handler in the test takes aJSRuntime, because this branch predates quickjs-ng Pass JSContext to JSInterruptHandler quickjs-ng/quickjs#1802.js_async_generator_awaitandjs_async_generator_completed_return. Their reactions then report the awaited promise itself, so a generator resumes in the context of whoever created that promise. The commit moves Fix promise hooks for reactions and await continuations quickjs-ng/quickjs#1808's continuation block intojs_await_continuation_capability()and calls it from all three sites. With no hook installed, the allocation-free path does not change.Upstreaming: an upstream-ready version of commit 2, on top of quickjs-ng master with quickjs-ng#1808, is on the branch
async-generator-promise-hooks. Its engine diff is the same as here.Please merge with a merge commit or a fast-forward, not a squash or a rebase. The golemcloud/rquickjs PR points
sys/quickjsat commit970fe9d.Checks:
api-testpasses. The new async-generator cases abort when only commit 1 is applied.tests.conf: 0/115.run-test262 -m -c test262.conf -a: 52/82220 errors, the same as onv0.14.0-patchedand astest262_errors.txt.cargo test --tests --workspace --no-default-features --features full-async,bindgen).