I want a JavaScript interpreter written in wasm but I don't know how to convince anyone reading this that this isn't a joke
@mcc is “compilable to wasm” enough? https://bellard.org/quickjs/
QuickJS Javascript Engine

@mcc Like, from scratch in WASM? I've seen folks compiling stuff like JavaScritpCore which seemed to work pretty well.

@mcc only tangentially related but have you watched Gary Bernhardt's talk, The Birth & Death of JavaScript? (It is very funny)

https://www.destroyallsoftware.com/talks/the-birth-and-death-of-javascript

The Birth & Death of JavaScript

Ryan Reynolds Hd GIF - Find & Share on GIPHY

Discover & share this Reaction GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.

GIPHY
@mcc you can probably run an old version of spidermonkey in wasm
@mcc I wonder if something like this will run on .NET WASM https://github.com/sebastienros/jint
GitHub - sebastienros/jint: Javascript Interpreter for .NET

Javascript Interpreter for .NET. Contribute to sebastienros/jint development by creating an account on GitHub.

GitHub
wasmbo

@lambdageek Oh wowww

Just out of curiosity, how large is this, disk-space-wise

@mcc 9.8 megs without really doing anything to optimize for size. (it does run the IL trimmer with some default settings, but I don't remember if it's super-aggressive or if it just keeps any referenced assemblies)

@lambdageek That's actually not so bad. The C# web-izer has come a long way.

So what I was originally hoping to do, just so the original prompt doesn't seem weird, was the possibility of running js "sandboxed" inside of a web page, like imagine mastodon allowing user scripts within posts…

@mcc Yea that makes a lot of sense actually.

up-thread @zemlanin suggested compiling QuickJS with Emscripten by hand, and that probably makes more sense if you're doing this seriously and don't have other .NET dependencies in play.

And apparently someone already did the compiling part https://www.npmjs.com/package/quickjs-emscripten

quickjs-emscripten

Javascript/Typescript bindings for QuickJS, a modern Javascript interpreter, compiled to WebAssembly.. Latest version: 0.22.0, last published: 2 months ago. Start using quickjs-emscripten in your project by running `npm i quickjs-emscripten`. There are 14 other projects in the npm registry using quickjs-emscripten.

npm
@mcc depending on what you're trying to achieve you might be better off loading the JS into a web worker.
@mcc idk that sounds like exactly the sort of thing you'd do

@mcc The steps some people will go to avoid using eval()…

/s

@mcc I think there's a reference implementation for javascript written in javascript, so that's like half the way there right
@aeva lol what seriously
@mcc yes, if my dodgy memory is to be trusted
@mcc I'll see if I can find it after dinner
@mcc also this very real book might just say how to write one yourself
@mcc great news! to my astonishment, there are multiple javascript interpreters written in javascript, and also apparently many more written in other languages! maybe one will fit your niche? https://en.m.wikipedia.org/wiki/List_of_ECMAScript_engines
List of ECMAScript engines - Wikipedia

@mcc also SICP ~javascript edition~ does indeed walk through implementing a pretty straight forward metacircular evaluator for a suspiciously scheme-like subset of ECMAScript that lacks objects
@mcc tbh this is much less cursed than I was hoping. although maybe it's actually more cursed, because now it's making me think language projects are of a reasonable scope for side projects again...

@mcc I'd compile QuickJS to WASM & use that!

That's got a reasonable codesize...

@mcc relevant blogpost from 2021 where placing a JS interpreter (Spidermonkey here) in Wasm lets you do straight up wizardry https://bytecodealliance.org/articles/making-javascript-run-fast-on-webassembly
Making JavaScript run fast on WebAssembly

JavaScript in the browser runs many times faster than it did two decades ago. And that happened because the browser vendors spent that time working on intensive performance optimizations.

Bytecode Alliance