Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Support for cloudflare workers #240

Open
Bartek20 opened this issue Jan 11, 2023 · 4 comments
Open

Add: Support for cloudflare workers #240

Bartek20 opened this issue Jan 11, 2023 · 4 comments

Comments

@Bartek20
Copy link

I think some users will like this idea as it will help to eliminate eval() and new Function() restrictions in workers.

@NeilFraser
Copy link
Owner

What would be involved in supporting this?

@Bartek20
Copy link
Author

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.

@NeilFraser
Copy link
Owner

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.

@yorinasub17
Copy link

yorinasub17 commented Aug 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants