justjake / quickjs-emscripten

Safely execute untrusted Javascript in your Javascript, and execute synchronous code that uses async functions
https://www.npmjs.com/package/quickjs-emscripten
Other
1.18k stars 94 forks source link

Feature request: Expose GetModuleExport APIs #148

Closed Symbitic closed 4 months ago

Symbitic commented 5 months ago

quickjs-ng (and most forks/patches of the original quickjs) expose JS_GetModuleExport and related functions that allow accessing the value of an ESM export, which makes it great for a plugin system. Work is still ongoing in the original quickjs (see bellard/quickjs#35), so there may need to be placeholders that throw an exception when a non-quickjs-ng build is used, but I would really like to see this added.

justjake commented 5 months ago

I'd follow upstream here, which is to expose JS_GetModuleNamespace. Can you propose an interface for how it's used in Javascript code? quickjs-emscripten doesn't have any public APIs that use JSModuleDef, I'm curious what would work for your use-case.

Symbitic commented 5 months ago

The use case is for when you want to get a value from a JavaScript file instead of evaluating code. So instead of something like vm.evalCode, you'd have:

const result = vm.getExports(code);
const { name, resolveId, preconfigure } = result.default;
justjake commented 4 months ago

Work in progress here: #154

justjake commented 4 months ago

Published with v0.29.0