Experimental FFI wrappers around the WebAssembly-related API in Node.js.
I'm creating a new web service using WebAssembly on the server side.
It should work. But I don't publish it because:
- Tested only in Node.js v15.2 (the latest version as of writing this document).
- Should be compatible with the browsers' API. But some of the browsers' features are not implemented yet (e.g.
compileStreaming
).
- Should be compatible with the browsers' API. But some of the browsers' features are not implemented yet (e.g.
- Requires
--experimental-wasi-unstable-preview1
option to thenode
command.- See the "Running the Tests" section below when testing.
spago test
doesn't work because you have to pass --experimental-wasi-unstable-preview1
to node to run the tests:
spago build --then "node --experimental-wasi-unstable-preview1 runTest.js"
And to get a coverage report with nyc
during the test:
spago build --purs-args="-g sourcemaps" --then "nyc node --experimental-wasi-unstable-preview1 runTest.js"
To avoid name conflicts, this package contains exacly one module per one class (or object). So most of the wrapper methods have the same name with the wrapped methods in JavaScript. But there are some exceptions:
- Wrapped methods which return a
Promise
areforeign import
-ed by a name prefixed withImpl
.- E.g.
WebAssembly.compileImpl :: ArrayBuffer -> Effect (Promise Module)
- Then their
Aff
version is named withoutImpl
.- E.g.
WebAssembly.compile :: ArrayBuffer -> Aff Module
- E.g.
- E.g.
- Constructors are named with
new
.- E.g.
new WebAssembly.Module()
is wrapped byWebAssembly.Module.new
.
- E.g.
- Wrapped method which accepts various types of arguments are named with several different prefixes by their arguments' types.
- E.g.
new WebAssembly.Module({ initial })
is named asWebAssembly.Module.new
- E.g.
new WebAssembly.Module({ initial, maximum })
is named asWebAssembly.Module.newWithMaximum
- E.g.
- Types which can be refined and the wrapped methods returning them and/or accepting them as the arguments are named prefixed with
Raw
.- E.g.
WebAssembly.Module.exportsRaw :: Module -> Array ModuleExportDescriptorRaw
- And
WebAssembly.Module.exports :: Module -> Array ModuleExportDescriptor
- Where
ModuleExportDescriptorRaw
haskind
asString
- While
ModuleExportDescriptor
haskind
asImportExportKind
- E.g.
Some wrapped methods' order of arguments are swapped for more useful partial application of them.
For example, WebAssembly.instantiate(buf, imports)
is wrapped by instantiateRaw :: ImportObjectRaw -> ArrayBuffer -> Aff ResultObject
.