Skip to content

fix(eval): return compiled modules before namespace conversion - #273

Open
cp-20 wants to merge 2 commits into
justjake:mainfrom
cp-20:codex/fix-module-compile-only
Open

cp-20 wants to merge 2 commits into
justjake:mainfrom
cp-20:codex/fix-module-compile-only

Conversation

@cp-20

@cp-20 cp-20 commented Oct 9, 2026 •

Copy link
Copy Markdown

Why

evalCode(src, file, { type: "module", compileOnly: true }) reads an uninitialized pointer in QTS_Eval.

module is only assigned on the evaluate path. With compileOnly, JS_Eval returns the compiled module (JS_TAG_MODULE), which is not an exception and has the module flag set, so it falls through to the namespace conversion: the result is freed and JS_GetModuleNamespace(ctx, module) is called with garbage.

const h = vm.unwrapResult(
  vm.evalCode("export const x = 1", "m.js", { type: "module", compileOnly: true }),
)
vm.typeof(h) // "number" on 0.32.0; "unknown" (compiled code) for type: "global"

What

Return compile-only results before the module namespace/promise handling, the same way global compile-only code is already returned. The caller owns and disposes the handle.

Notes

Ran quickjs.test.ts for quickjs release/debug (sync + asyncify) and quickjs-ng release (sync + asyncify). quickjs-ng debug and the packaging/browser/example jobs were not run locally.

@cp-20
cp-20 marked this pull request as ready for review October 9, 2026 09:52
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.

1 participant