Add JavaScript evaluation support
See original GitHub issueI think a solid first step, before https://github.com/slipHQ/run-wasm/issues/13 (at least the way I’m thinking about it), is to add support for JavaScript since it’s relatively straightforward since JS <-> Browser === ❤️
How it works
At a high-level, it works similarly to the current implementation for Python:
- user provides input
- user hits run button
- input -> client to run code -> saves output
- output is displayed in browser for user
How to Implement
- Create a
JavaScriptClient
- Create a
<RunJSCode />
component which comes with an<iframe />
- Use safe sandbox technique to safely evaluate code
- Display output in
<Editor />
Resources
- Play safely in sandboxed iFrames (thank you @hatemhosny for sharing that here)
- direct link to example: https://github.com/html5rocks/www.html5rocks.com/blob/master/static/demos/evalbox/index.html
- MDN eval
- Wasmer JS tutorial
Additional Notes
Once we have this implemented, I think adding TypeScript support would be relatively straightforward. All we would need to do is add an extra step to compile the TS -> JS using swc.
(Though there may be a desire to compile it to WASM though and use the WasmClient
)
Contributors
We figured this out as a team on a livestream, thanks to:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:7 (5 by maintainers)
Top Results From Across the Web
eval() - JavaScript - MDN Web Docs - Mozilla
The eval() function evaluates JavaScript code represented as a string and returns its completion value. The source is parsed as a script.
Read more >Add JavaScript - Qualtrics
Click the question you'd like to add JavaScript to. · In the Question behavior section, select JavaScript. · Place your JavaScript in the...
Read more >JavaScript Evaluation - Internal.io
JavaScript Evaluation. Internal allows for JavaScript evaluation (JS Eval) in various parts of the application. Where to Use JS Eval in Internal.
Read more >Lazy Evaluation and Javascript | Codementor
Brief explanation on what is lazy evaluation and how to use it in Javascript (and Typescript).
Read more >Evaluating JavaScript code via eval() and new Function() - 2ality
Normally, it is better to use new Function() than eval() to evaluate code: The function parameters provide a clear interface to the evaluated ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Talking to @dwwoelfel and @sgrove about JS evaluation and they said they use
quickjs-emscripten
. Reasons why they chose this:Thanks for putting this together @jsjoeio!
I think we should def look into this & see what are the benefits of compiling it to Wasm. Anything we learn from there will probably help us get a clearer picture of what Wasm actually does & how it is being used in this project.