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.27k stars 95 forks source link

evalCode(type=module) throws instead of returning rejected promise #161

Closed justjake closed 6 months ago

justjake commented 7 months ago

Fixes #160

New versions of quickjs library return Promise<void> when evaluating a module.

Our wrapper code unwrapped this implicit promise if it's resolved and return the module exports, and replace a pending promise with pending Promise<ModuleExports>.

However, our code passed through the rejected promise value as a success result back to the caller, who probably isn't expecting a promise.

With this PR, we consider the sync rejected module evaluation promise as an error, restoring the behavior of errors thrown during evaluation.

Also: context.dump(val) now inspects promises