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] Upgrade to v2024-01-13 #150

Closed niedzielski closed 4 months ago

niedzielski commented 4 months ago

This is a request to upgrade to the latest and greatest version of QuickJS, v2024-01-13. I've attempted this locally but some recent packaging changes and environmental differences have made this challenging to compare to the prior release. I've appended my notes in case they're helpful.

Thank you for this package!


update-quickjs is missing so it's from the website:

wget https://bellard.org/quickjs/quickjs-2024-01-13.tar.xz
tar xf ./quickjs-2024-01-13.tar.xz
rm -rf vendor/quickjs
mv quickjs-2024-01-13 vendor/quickjs

Many shell scripts and makefiles use bashisms like [[ ]]-style conditionals and assume sh is bash. A workaround was tried:

mkdir bin
cd bin
ln -s /bin/bash sh
PATH="$PWD/bin:$PATH" yarn build

Errors still crept in. Ultimately, the following from a clean slate appeared to build:

yarn
find . -not \( \( -name node_modules -o -name .git \) -prune \) -type f|
xargs -rd\\n sed -ri 's%/bin/sh%/bin/bash%g; s%\[\[ %[ %g; s% \]\]% ]%g'
PATH="$PWD/bin:$PATH" yarn check

However, the unit tests failed:

[quickjs-emscripten]: stderr | src/quickjs.test.ts > QuickJSAsyncContext > DEBUG async module > async API > ASYNCIFY_STACK_SIZE > is enough to support at least 20 levels of function nesting
[quickjs-emscripten]: quickjs-emscripten: new_function(name: asyncFn, magic: -32767)
[quickjs-emscripten]: quickjs-emscripten: QTS_Eval: Detected module = false
[quickjs-emscripten]: 
[quickjs-emscripten]: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 6 ⎯⎯⎯⎯⎯⎯⎯
[quickjs-emscripten]: 
[quickjs-emscripten]:  FAIL  src/quickjs.test.ts > QuickJSAsyncContext > newQuickJSAsyncWASMModule > async API > module loading > supports async module loading
[quickjs-emscripten]:  FAIL  src/quickjs.test.ts > QuickJSAsyncContext > DEBUG async module > async API > module loading > supports async module loading
[quickjs-emscripten]: AssertionError: Expected values to be strictly equal:
[quickjs-emscripten]: + actual - expected
[quickjs-emscripten]: 
[quickjs-emscripten]: + {}
[quickjs-emscripten]: - undefined
[quickjs-emscripten]:  ❯ testBody src/quickjs.test.ts:976:16
[quickjs-emscripten]:     974|         debugLog("consumed result")
[quickjs-emscripten]:     975| 
[quickjs-emscripten]:     976|         assert.strictEqual(dumped, undefined)
[quickjs-emscripten]:        |                ^
[quickjs-emscripten]:     977|         debugLog("asserted result")
[quickjs-emscripten]:     978| 
[quickjs-emscripten]:  ❯ src/quickjs.test.ts:984:9
[quickjs-emscripten]: 
[quickjs-emscripten]: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/6]⎯
[quickjs-emscripten]: 
[quickjs-emscripten]:  FAIL  src/quickjs.test.ts > QuickJSAsyncContext > newQuickJSAsyncWASMModule > async API > module loading > passes through the module name
[quickjs-emscripten]:  FAIL  src/quickjs.test.ts > QuickJSAsyncContext > DEBUG async module > async API > module loading > passes through the module name
[quickjs-emscripten]: AssertionError: Expected values to be strictly equal:
[quickjs-emscripten]: + actual - expected
[quickjs-emscripten]: 
[quickjs-emscripten]: + {}
[quickjs-emscripten]: - undefined
[quickjs-emscripten]:  ❯ src/quickjs.test.ts:1004:14
[quickjs-emscripten]:     1002|       // Asserts that the eval worked without incident
[quickjs-emscripten]:     1003|       const unwrapped = vm.unwrapResult(result).consume(vm.dump)
[quickjs-emscripten]:     1004|       assert.strictEqual(unwrapped, undefined)
[quickjs-emscripten]:        |              ^
[quickjs-emscripten]:     1005| 
[quickjs-emscripten]:     1006|       assert.strictEqual(callCtx!, vm, "expected VM")
[quickjs-emscripten]: 
[quickjs-emscripten]: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/6]⎯
[quickjs-emscripten]: 
[quickjs-emscripten]:  FAIL  src/quickjs.test.ts > QuickJSAsyncContext > newQuickJSAsyncWASMModule > async API > module loading > calls the module loader with the name returned from the module normalizer
[quickjs-emscripten]:  FAIL  src/quickjs.test.ts > QuickJSAsyncContext > DEBUG async module > async API > module loading > calls the module loader with the name returned from the module normalizer
[quickjs-emscripten]: AssertionError: Expected values to be strictly equal:
[quickjs-emscripten]: + actual - expected
[quickjs-emscripten]: 
[quickjs-emscripten]: + {}
[quickjs-emscripten]: - undefined
[quickjs-emscripten]:  ❯ src/quickjs.test.ts:1042:14
[quickjs-emscripten]:     1040|       const result = vm.evalCode(`import otherModule from '${IMPORT_PA…
[quickjs-emscripten]:     1041|       const unwrapped = vm.unwrapResult(result).consume(vm.dump)
[quickjs-emscripten]:     1042|       assert.strictEqual(unwrapped, undefined)
[quickjs-emscripten]:        |              ^
[quickjs-emscripten]:     1043| 
[quickjs-emscripten]:     1044|       // Check our request
[quickjs-emscripten]: 
[quickjs-emscripten]: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/6]⎯
[quickjs-emscripten]: 
[quickjs-emscripten]: npm ERR! Lifecycle script `test:vi` failed with error: 
[quickjs-emscripten]: npm ERR! Error: command failed 
[quickjs-emscripten]: npm ERR!   in workspace: quickjs-emscripten@0.27.0 
[quickjs-emscripten]: npm ERR!   at location: /home/user/desk/quickjs-emscripten/packages/quickjs-emscripten 
[quickjs-emscripten]: Process exited (exit code 1), completed in 55s 580ms
The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph
Failed with errors in 56s 971ms
justjake commented 4 months ago

Oops, the upgrade script went missing when I restructured the repo. I wonder if the new return value is related to upstream trying to expose module exports?

justjake commented 4 months ago

Published to NPM

niedzielski commented 4 months ago

Wow! Thank you, @justjake!!