Skip to content

feat: host-callback budget, realm reset, and native async/await - #3

Merged
ximing merged 1 commit into
masterfrom
feat/embed-runtime-host
Aug 16, 2026
Merged

ximing merged 1 commit into
masterfrom
feat/embed-runtime-host

Conversation

@ximing

@ximing ximing commented Aug 16, 2026

Copy link
Copy Markdown
Owner

Summary

Four runtime holes that show up when embedding jsvm3 in a long-lived host (MV3 service worker, content script, and similar):

  1. Published null.foo crashed the host. Cannot / property were only imported under @ifdef COMPILER, so the minified runtime threw ReferenceError: Cannot is not defined. Error strings are now literals; guest try/catch works.
  2. Host-invoked guest callbacks ignored the instruction budget. chrome.* / later(cb) created new Fiber(realm) with timeout = -1. Fibers now inherit JSVM defaultTimeout / maxDepth.
  3. VM state leaked across execs. Same JSVM reused for the next message kept guest vars and module.exports. Added vm.reset() and new JSVM(host, { resetOnExec: true }).
  4. Default async/await was a Babel accident. convertES5 inlined _asyncToGenerator / _regenerator. Compiler now leaves async/await; runtime has a fiber-native AWAIT opcode (ISA 2). Old format 0 / opcode 1 artifacts still load.

Test plan

  • npx jest — 330 passed
  • npm run typecheck
  • scripts/check-runtime-bundle.mjs after rebuild (16 KB raw / 6 KB gzip)
  • dist/runtime smoke: null.foo, resetOnExec, callback timeout, await host Promise

Fix four embed holes that show up in MV3 and other long-lived hosts:

- Inline null/undefined property errors so the published runtime
  throws JSVMTypeError instead of ReferenceError: Cannot is not defined
- Give host-invoked guest callbacks the JSVM timeout and maxDepth
- Add JSVM.reset() and resetOnExec so sequential execs do not leak vars
- Compile async/await as a fiber AWAIT opcode (ISA 2) instead of
  inlined regenerator helpers
@ximing
ximing merged commit a40ec7d into master Aug 16, 2026
2 of 3 checks passed
@ximing
ximing deleted the feat/embed-runtime-host branch August 16, 2026 12:27
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 31947083295

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+1.4%) to 81.71%

Details

  • Coverage increased (+1.4%) from the base build.
  • Patch coverage: 14 uncovered changes across 3 files (96 of 110 lines covered, 87.27%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
src/opcodes/ins.ts 20 13 65.0%
src/opcodes/utils.ts 52 47 90.38%
src/compiler/visitor.ts 3 1 33.33%
Total (8 files) 110 96 87.27%

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/opcodes/contants.ts 2 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 2314
Covered Lines: 1936
Line Coverage: 83.66%
Relevant Branches: 715
Covered Branches: 539
Branch Coverage: 75.38%
Branches in Coverage %: Yes
Coverage Strength: 17652.41 hits per line

💛 - Coveralls

ximing added a commit that referenced this pull request Aug 20, 2026
feat: host-callback budget, realm reset, and native async/await
ximing added a commit that referenced this pull request Aug 25, 2026
feat: host-callback budget, realm reset, and native async/await
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.

2 participants