question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add JavaScript evaluation support

See original GitHub issue

I 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

image

How to Implement

  1. Create a JavaScriptClient
  2. Create a <RunJSCode /> component which comes with an <iframe />
  3. Use safe sandbox technique to safely evaluate code
  4. Display output in <Editor />

Resources

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:open
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
jsjoeiocommented, Sep 26, 2021

Talking to @dwwoelfel and @sgrove about JS evaluation and they said they use quickjs-emscripten. Reasons why they chose this:

  • There’s no way for it to escape the sandbox
  • There aren’t a ton of other options with the same level of sandboxing
2reactions
Dhaiwat10commented, Sep 25, 2021

Thanks for putting this together @jsjoeio!

(Though there may be a desire to compile it to WASM though and use the WasmClient)

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found