Does anyone have a working example of evaluating JavaScript via WASM?
(This is a spin-off from this thread, which ultimately asks a different question and has become quite lengthy.)
I need to evaluate some JavaScript, but understand that
eval()
/ new Function()
is blocked on workers. I understand my only route to evalulation is via WASM.
But I'm struggling to implement a working example of JS evaluation via WASM in Workers. I'm completely new to WASM and am focusing on packages that do the heavy lifting for you. Here's what I've tried, using quickjs-emscripten:
This throws no error but simply never gets into the callback.
I've also tried wasm-jseval, via:
But this errors - it seems the package seems to think I'm working in the browser, as the error pertains to it trying to access location.href
.
So does anyone have a working cut-and-paste version of evaluating JS via a package like this I could use?
I'd be most grateful!2 Replies
You was able to fix this ?
No - I found a workaround. But I did get some responses which may help:
- Package author response to my GH issue
- SO answer
GitHub
getQuickJS()
callback never resolves? · Issue #142 · justjake/qui...Not sure what I'm doing wrong here. I'm trying to use this within a CloudFlare Worker. My code is taken from the demo: import { getQuickJS, shouldInterruptAfterDeadline } from "quickjs...
Stack Overflow
WASM/QuickJS - callback from getQuickJS() is never entered?
I'm using quickjs-emscripten to try to evaluate some JS within a Cloudflare Worker (i.e. serverless). I know the pitfalls of JS evaluation and don't need to debate that here.
The docs say this should