Skip to content

js: let a page end the settle loop early by posting "done" (M6, engine#346) - #347

Merged
tannevaled merged 1 commit into
mainfrom
js-done-signal
Nov 3, 2026
Merged

tannevaled merged 1 commit into
mainfrom
js-done-signal

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

M6 of the go-wasmcontainers WebGPU-readiness roadmap (M1 shipped as #341). The peer's own ask: "Fetch + RenderDocument + JSLog + the DOM... provided a render can wait for the page to post 'done', meaning async completion with a timeout." No WebDriver/CDP protocol needed, and no new goroutine — this rides entirely on the existing settle loop and JSTimeout/deadman budget.

  • New Engine.EnableDoneSignal bool (default false, no behaviour change for any existing caller — not even an extra global name exists).
  • When set, js/window.go's install() installs a global __webengineDone(value) a page's own script can call once its async work is finished (first call wins; later calls are no-ops).
  • settle_scripts.go's settle() pass loop now breaks as soon as sess.Done() reports the signal fired, instead of running out maxSettlePasses/JSTimeout.
  • New Session.Done() (value interface{}, ok bool) (js/session.go) reports the signal and the page's own value, exported via goja the same way Eval's return value is.

Closes #346.

Test plan

  • go build ./..., go vet ./... clean
  • enginejs_test.go's new TestEnableDoneSignalStopsSettleEarly reuses TestSettleFixpointCap's own self-replicating script chain: with the option on, the loop stops right after __webengineDone() fires (data-d="2"); with it left off, the identical page still reaches data-d="4" — proving the feature is a true no-op for existing callers.
  • js/js_test.go's new TestSessionDoneSignal covers Session.Done() directly: a call with a value, no call at all, a call with no argument (goja's Undefined(), not Go nil), and — with the option off — the same call throwing ReferenceError.
  • Full suite green, no coverage-gate regression (engine 95.8%, js 94.6%→94.9%).

🤖 Generated with Claude Code

…e#346)

go-wasmcontainers' own automation-interface ask, part of the WebGPU-readiness
roadmap: "Fetch + RenderDocument + JSLog + the DOM... provided a render can
wait for the page to post 'done', meaning async completion with a timeout."

Adds Engine.EnableDoneSignal (default false, no behaviour change for any
existing caller). When set, a page can call __webengineDone(value); the
settle loop breaks out as soon as it fires instead of running out the full
pass/JSTimeout budget, and Session.Done() reports the value back.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 04275b5 into main Nov 3, 2026
13 checks passed
@tannevaled
tannevaled deleted the js-done-signal branch November 3, 2026 18:28
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.

WebGPU roadmap M6: wait-for-page-signalled-done render mode (automation)

1 participant