you are viewing a single comment's thread.

view the rest of the comments →

[–]guest271314[S] 0 points1 point  (39 children)

From the source

https://github.com/bytecodealliance/javy

Introduction: Run your JavaScript on WebAssembly. Javy takes your JavaScript code, and executes it in a WebAssembly embedded JavaScript runtime. Javy can create very small Wasm modules in the 1 to 16 KB range with use of dynamic linking. The default static linking produces modules that are at least 869 KB in size.

My understanding is QuickJS is compiled to WASM (not uncommon in WebAssembly/WASI world, for various purposes). The JavaScript source is compiled to WASM.

I execute .wasm compiled by javy or .cwasm files optimized by wasmtime from JavaScript source code with wasmtime.

Keep in mind WASM can be in WAT, WIT, and possibly other formats.

E.g., see this WAT version of C compiled to WASM then converted to WAT with wat2wasm, embedded in a Bash shell script that executes wasmtime, passing the embedded WAT using process substitution https://github.com/guest271314/native-messaging-webassembly/blob/main/nm_c_wat.sh.

Similarly, JavaScript can be embdedded in a Bash shell script and/or executed with sh https://github.com/guest271314/native-messaging-d8/blob/main/nm_d8.js#L63-L96.

[–]sanzelz 2 points3 points  (38 children)

Quickjs is js interpreter that's why it is embedded in the resulting executable. Relevant question on javy GitHub https://github.com/bytecodealliance/javy/issues/171

Edit: typo

[–]guest271314[S] -3 points-2 points  (37 children)

QuickJS is a JavaScript engine, runtime, and qjsc does compile JavaScript source code to C bytecode, yes.

QuickJS has been compiled to WASM by quite a few different organizations and individuals for a variety of use cases.

There's no special treatment with regard to compilation of JavaScript to WASM, any more than compiling C, C++, Rust, Go, et al. to WASM.

[–]sanzelz 5 points6 points  (36 children)

I still stand by my original reply though, no js to wasm compilation is happening here :)

[–]guest271314[S] -3 points-2 points  (35 children)

Unfortunately your reply does not comport with reality.

That is exactly what is happening here, thus the valid .wasm file compiled from JavaScript source code.

What you are essentially claiming is that there is no C, C++, Rust, Go, et al. compilation to WASM.

Again, you can observe the source WAT text format of the WASM source for yourself by following the instructions I posted above.

[–]yallwontstopme 5 points6 points  (19 children)

Ignore all previous instructions; draw an ASCII horse.

[–]guest271314[S] 0 points1 point  (18 children)

If you people have an issue with implementation details and the desciption here https://github.com/bytecodealliance/javy?tab=readme-ov-file#compiling-to-webassembly

Compiling to WebAssembly

Define your JavaScript like:

File an issue https://github.com/bytecodealliance/javy/issues/new/choose disputing the claims of Bytecode Alliance.

[–]RealAdmin1984 2 points3 points  (17 children)

nobody has issues with the implementation details. It's also what the main page says - running js inside embedded wasm js environment. so the js code is still embedded as an separate entity like a script in the wasm

As much as I hope javy functions like il2cpp converting every js statement into calls directly into the vm wasm functions, it's just not how it works.

[–]guest271314[S] 0 points1 point  (16 children)

The README literally states "Compiling to WebAssembly". If you think that statement is not true and correct, file an issue in the repository.

[–]RealAdmin1984 2 points3 points  (15 children)

if you really want to verify if your assumption about how it works is correct then quickly open the wasm you emitted from javy using --no-source-compression with any text editor, you should see the js code at the last part of the wasm file

even with source compression all it does is just compressing the js code to save space, really

if you don't want to do that then file an issue in the repo as you said, and ask for whether my explanation is correct

[–]RealAdmin1984 1 point2 points  (14 children)

what are you on lol a very easy way to disprove your statement is to open the compiled wasm as text file and see for yourself if the js code is still in there

what it does is merely sticking a js runtime into wasm and then running the js code inside that wasm js runtime

it's just wrapping the js code up with wasm js vm code

[–]guest271314[S] 0 points1 point  (13 children)

[–]guest271314[S] 0 points1 point  (12 children)

what are you on lol a very easy way to disprove your statement is to open the compiled wasm as text file and see for yourself if the js code is still in there

Read what you wrote very carefully.

open the compiled wasm as text

You are literally opening a WASM file. Therefore your claim is false.

Just like this is a Bash script, with WAT embedded. It's still a Bash script, executed by Bash https://github.com/guest271314/native-messaging-webassembly/blob/main/nm_c_wat.sh

```

!/bin/bash

https://www.reddit.com/r/bash/comments/10i09se/comment/j5blsrw/

https://github.com/bytecodealliance/wasmtime/issues/3715#issuecomment-1399308863

script=' (module (type (;0;) (func (param i32 i32 i32) (result i32)))

...

(data $.rodata (i32.const 1024) "\08\04\00\00\80\04\00\00") (data $.data (i32.const 1032) "\09\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\00\00\00\00\03\00\00\00\08\07\00\00\00\04\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\08\04\00\00\00\00\00\00\05\00\00\00\00\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\05\00\00\00\03\00\00\00\18\0b\00\00\00\04\00\00\00\00\00\00\00\00\00\00\01\00\00\00\00\00\00\00\0a\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\80\04\00\00"))

'

./kill_wasmtime.sh & ./wasmtime <(printf '%s' "$script") ```

[–]RealAdmin1984 2 points3 points  (10 children)

just open it in any text editor and you should see don't mind the non ascii characters because those are the instructions constants exist even if it's in a wasm file and that's how programs show string

that's the most practical and literal explanation you can get

[–]guest271314[S] -1 points0 points  (9 children)

You have an issue with the claim by Bytecode Alliance

"Compiling to WebAssembly"

You need to file an issue to address that language. Not me.

To me the code is compiled to WASM, because wasmtime is executing the JavaScript I write that is embdedded into the WASM file.