JS-Interpreter
JS-Interpreter copied to clipboard
Add: Support for cloudflare workers
I think some users will like this idea as it will help to eliminate eval() and new Function() restrictions in workers.
What would be involved in supporting this?
The point is that in cloudflare workers libraries are compiled into a single script and then they are executed. Unfortunately, when compiling this library, errors like Interpreter() is not a function or Interpreter() is not a class are generated. I would like to add that adding support would allow the execution of functions downloaded from an external api, which is that in workers there is a top-down restriction on the eval() and new Function() functions, therefore currently running functions downloaded from the api is not physically possible and this library is however, it does not currently work with workers properly.
We don't have any experience with Cloudflare, so you'd have to do the work. If you need assistance from the JS-Interpreter side, do let us know. Once you get something running we'd certainly be interested in seeing it. Then we can discuss whether something like this could be added to the demo directory, or as documentation, or whether there are changes that should be made to the core library.
Not sure if you are still looking for a way to do this, but I found a way to integrate JS-Interpreter
into Cloudflare Workers since I needed this as well. Here is a minimal hello world demo: https://github.com/yorinasub17/workers-js-interpreter-demo
The gist is that you need to load acorn
into globalThis
manually since it will be exported as a module instead of being loaded into the globalThis
object like the browser environment.