Skip to content

Promise hooks for await continuations - #1

Merged
vigoo merged 2 commits into
v0.14.0-patchedfrom
promise-hooks-for-await
Nov 13, 2026
Merged

vigoo merged 2 commits into
v0.14.0-patchedfrom
promise-hooks-for-await

Conversation

@vigoo

@vigoo vigoo commented Nov 12, 2026

Copy link
Copy Markdown

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 across await (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.

  1. Fix promise hooks for reactions and await continuations (author pluveto). This is a backport of the open quickjs-ng PR #1808, for issue #1740. BEFORE/AFTER fire around every promise reaction job with the continuation promise. When a hook is installed, each await in 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. Only api-test.c changes: the interrupt handler in the test takes a JSRuntime, because this branch predates quickjs-ng Pass JSContext to JSInterruptHandler quickjs-ng/quickjs#1802.
  2. Give async generator awaits their own continuation promise. Fix promise hooks for reactions and await continuations quickjs-ng/quickjs#1808 does not change the two async-generator await sites, js_async_generator_await and js_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 into js_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/quickjs at commit 970fe9d.

Checks:

  • api-test passes. 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 on v0.14.0-patched and as test262_errors.txt.
  • The golemcloud/rquickjs test suite passes on top of this branch (cargo test --tests --workspace --no-default-features --features full-async,bindgen).

pluveto and others added 2 commits November 12, 2026 18:28
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]>
@vigoo
vigoo merged commit 381e1e5 into v0.14.0-patched Nov 13, 2026
118 of 128 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants