News for hackers. Stuff that matters.
Re:QuickJS Running in WebAssembly by pyrolistical on Sunday November 20, 2022 @02:13AM (#33679006)
Running user provided js in quickjs in webassembly in a worker in an sandboxed iframe on a different domain would offer many layers of security
Re:QuickJS Running in WebAssembly by auggierose on Sunday November 20, 2022 @02:20AM (#33679034)
Re:QuickJS Running in WebAssembly by jitl on Sunday November 20, 2022 @02:57AM (#33679192)
The library was inspired by Figma’s blog posts about their plug-in system: https://github.com/justjake/quickjs-emscripten#background
Re:QuickJS Running in WebAssembly by auggierose on Sunday November 20, 2022 @03:09AM (#33679240)
Ah ok, I see.
Re:QuickJS Running in WebAssembly by nine_k on Sunday November 20, 2022 @06:28AM (#33680096)
One of the companies I worked for did exactly that to safely run customers' JS code, while also limiting / extending the API surface available.

The performance was quite adequate.

Re:QuickJS Running in WebAssembly by dang on Sunday November 20, 2022 @03:04AM (#33679221)
Related:

QuickJS JavaScript Engine - https://news.ycombinator.com/item?id=30598026 - March 2022 (67 comments)

A small but complete JavaScript engine - https://news.ycombinator.com/item?id=24867103 - Oct 2020 (146 comments)

QuickJS JavaScript Engine - https://news.ycombinator.com/item?id=20411154 - July 2019 (261 comments)

QuickJS JavaScript Engine - https://news.ycombinator.com/item?id=20404503 - July 2019 (3 comments)

Re:QuickJS Running in WebAssembly by vbezhenar on Sunday November 20, 2022 @03:24AM (#33679304)
Imagine something like "base system" with WebAssembly, bare bones HTML engine with canvas support and no CSS. So now you can just download your favourite JS engine, your favourite HTML, CSS engines. But browser does not necessarily need to sheep those. It would allow to lower the bar for entry into browser market. I think that even a single person could implement that kind of base browser.

Of course there're many hard questions. For example downloading an entire JS+HTML+CSS engine with every website is not a good approach, some caching must be done. There should not be version hell with every website asking for a different version of engine. But those questions could be approached as a more general web library issues.

Re:QuickJS Running in WebAssembly by pjmlp on Sunday November 20, 2022 @05:11AM (#33679776)
Re:QuickJS Running in WebAssembly by krapp on Sunday November 20, 2022 @05:22AM (#33679822)
Check out Geminispace https://gemini.circumlunar.space - one of the design requirements of the protocol is that it be simple enough that a single person can implement a browser for it in a weekend.
Re:QuickJS Running in WebAssembly by makapuf on Sunday November 20, 2022 @06:57AM (#33680255)
I'm not sure, just for the fact that the best browser is something that could vary quickly, there might be niches, different native versions...
Re:QuickJS Running in WebAssembly by rictic on Sunday November 20, 2022 @11:59AM (#33682721)
Cross origin caching of resources is a privacy risk

If site A can tell based on timing information that you probably visited site B recently, that's a pretty big privacy issue

This has largely killed cross-origin caching on the web, as I understand it

Re:QuickJS Running in WebAssembly by jitl on Sunday November 20, 2022 @01:09PM (#33683480)
Ah yes, Java applets.
Re:QuickJS Running in WebAssembly by jensneuse on Sunday November 20, 2022 @03:35AM (#33679357)
Is this also possible with Go as the host instead of TypeScript?
Re:QuickJS Running in WebAssembly by vijaybritto on Sunday November 20, 2022 @03:46AM (#33679404)
Yes but not this exact module. You can use wasmtime-go to run wasm modules in go programs. You just need to compile quickjs to wasm
Re:QuickJS Running in WebAssembly by paulgb on Sunday November 20, 2022 @04:26AM (#33679582)
I’m not sure if anyone has done so yet for Go, but Shopify has done this for Rust.

https://github.com/Shopify/javy/tree/main/crates/quickjs-was...

Re:QuickJS Running in WebAssembly by Arathorn on Sunday November 20, 2022 @04:15AM (#33679529)
This is very similar to how Third Room’s user generated content engine is being implemented (supporting C, Rust and Zig alongside QuickJS though): https://thenewstack.io/third-room-teases-user-generated-cont...
Re:QuickJS Running in WebAssembly by lioeters on Sunday November 20, 2022 @06:30AM (#33680106)
Another library I found recently, which has a different take (simpler API) for using QuickJS compiled to WASM:

https://github.com/taowen/define-function

Re:QuickJS Running in WebAssembly by Kiro on Sunday November 20, 2022 @07:56AM (#33680538)
Would you use this to run untrusted JS on the server?
Re:QuickJS Running in WebAssembly by gmatejka on Sunday November 20, 2022 @08:03AM (#33680587)
From what I understand, this allows you to run untrusted js anywhere, as long as there’s a wasm runtime.

This repo in particular is for JavaScript host environments

Re:QuickJS Running in WebAssembly by jansommer on Sunday November 20, 2022 @12:48PM (#33683253)
Not sure if I'd trust the wasm runtime. If someone breaks out of that it's game over. QuickJS in a unikernel in something like Firecracker VM would be the most secure approach and still provide good performance and startup time.

Another thing is resource consumption where you likely want to limit cpu- and mem-usage.

Re:QuickJS Running in WebAssembly by jitl on Sunday November 20, 2022 @01:07PM (#33683457)
I recommend Lambda as an easy way to create ephemeral Firecracker VMs and set overall limits on host + guest. For casual use, the memory and CPU limits available in the library should be enough.
Re:QuickJS Running in WebAssembly by jitl on Sunday November 20, 2022 @12:58PM (#33683355)
I use it on both client and server. A easy way to get excellent security in the server is to run inside AWS Lambda or similar FaaS that uses strong VM isolation; ideally with a lambda instance per user.
Re:QuickJS Running in WebAssembly by remram on Sunday November 20, 2022 @04:30PM (#33685565)
You can just run QuickJS (without std lib) as a separate process running as an unprivileged user with seccomp rules.

WASM probably doesn't add much there.

Re:QuickJS Running in WebAssembly by anderspitman on Sunday November 20, 2022 @12:29PM (#33683081)
Because it wouldn't be HN if someone didn't: https://www.destroyallsoftware.com/talks/the-birth-and-death...
Re:QuickJS Running in WebAssembly by jitl on Sunday November 20, 2022 @01:13PM (#33683538)
Hello, library author here. Happy to answer whatever questions you have.
Re:QuickJS Running in WebAssembly by ggzor on Monday November 21, 2022 @04:15PM (#33698026)
The npm package isn't working in the browser. I get `process is not defined`. There is a commit that fixes that issue, but no npm publish was made after that.