Files
zen/bindings/nodejs/wasi-worker-browser.mjs
stefan-gorulesandIvan Miletic 922a262e98 feat: wasm support (#404)
* feat: wasm support

* add http callback

* streamline structs

* fix: wasm workflow

* fix: wasi path

* fix: wasm

* fix: wasm path

* fix: clang dev

* fix: libclang static

* fix: build

* fix: node

* fix: wasm

* fix: wasm wasi

* fix: npm dirs

* fix: node workflow

* fix: testing

* fix: test

* update version

* fix: targets

* fix: wasm fix

* fix: commit files

---------

Co-authored-by: Ivan Miletic <vnmiletic@gmail.com>
2025-11-13 12:36:59 +01:00

33 lines
840 B
JavaScript

import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
const handler = new MessageHandler({
onLoad({ wasmModule, wasmMemory }) {
const wasi = new WASI({
print: function () {
// eslint-disable-next-line no-console
console.log.apply(console, arguments)
},
printErr: function() {
// eslint-disable-next-line no-console
console.error.apply(console, arguments)
},
})
return instantiateNapiModuleSync(wasmModule, {
childThread: true,
wasi,
overwriteImports(importObject) {
importObject.env = {
...importObject.env,
...importObject.napi,
...importObject.emnapi,
memory: wasmMemory,
}
},
})
},
})
globalThis.onmessage = function (e) {
handler.handle(e)
}