I don't see any way to use WebAssembly in snippets; just HTML, JavaScript and CSS. Allowing WebAssembly would let any compilable language be indirectly used for snippets. It's not complicated to let WebAssembly run.
Can we have WebAssembly support?
I don't see any way to use WebAssembly in snippets; just HTML, JavaScript and CSS. Allowing WebAssembly would let any compilable language be indirectly used for snippets. It's not complicated to let WebAssembly run.
Can we have WebAssembly support?
Nobody keeps you from running WebAssembly in a snippet:
(module
(import "env" "memory" (memory 1))
(import "env" "log" (func $log (param i32 i32)))
(data (i32.const 0) "Hello, World!")
(func (export "hello")
i32.const 0
i32.const 13
call $log
)
)
(async function runner() {
const memory = new WebAssembly.Memory({ initial: 1 });
function dereferenceString(offset, length) {
return new TextDecoder().decode(new Uint8Array(memory.buffer, offset, length));
}
function log(messageOffset, messageLength) {
console.log(dereferenceString(messageOffset, messageLength));
}
const code = (new TextEncoder()).encode('\x00asm\x01\x00\x00\x00\x01\t\x02`\x02\x7F\x7F\x00`\x00\x00\x02\x19\x02\x03env\x06memory\x02\x00\x01\x03env\x03log\x00\x00\x03\x02\x01\x01\x07\t\x01\x05hello\x00\x01\n\n\x01\b\x00A\x00A\r\x10\x00\x0B\x0B\x13\x01\x00A\x00\x0B\rHello, World!\x00\x18\x04name\x01\x06\x01\x00\x03log\x02\t\x02\x00\x02\x00\x00\x01\x00\x01\x00');
const { instance } = await WebAssembly.instantiate(code, { env: { memory, log } });
instance.exports.hello();
})();
It just doesn't make sense (except the question is about WebAssembly). WebAssembly itself is pretty much useless without Modules being imported / exported. Now for sure one could create a "snippet library" with some utility function for logging and debugging, however this will only be useful for a very limited set of questions in the compiled languages as:
For questions about WebAssembly itself it might be quite useful to create the above in a more elegant fashion (e.g. directly compile and embed the WAT into the snippet), however as webassembly is currently a niche tag (there are 1000x more questions for JavaScript), I doubt that investing into this would be justified.
code
becomes 200B), and allows the I believe more current fetch(url)
pattern instead of using the TextEncoder.
console.log(require("fs").readFileSync("hello-world.wasm")
into the snippet ...)
Dec 22, 2021 at 9:22