Following on from my
previous post
regarding passing arrays between JavaScript
and WebAssembly, I have found out how to remove the need to call back into JavaScript
Prerequisites
These examples have been tested with nodejs v12.9.1,
clang 10.0.0,
and wabt 1.0.16 on Ubuntu 18.04.
I installed clang
in /opt/clang
, wabt
in /opt/wabt
, and I use
nodenv to manage my nodejs
environment.
Update your path.
1 | export PATH=/opt/clang/bin:/opt/wabt/bin:$PATH |
What was the problem?
In order to find the size of the memory and grow it, I was having to import
functions from JavaScript. I now find there are two built in functions that
do exactly what I want:
- __builtin_wasm_memory_size(0)
- __builtin_wasm_memory_grow(0, blocks)
This means my growMoreMemory
function now looks like this.
1 |
|
The code
You can find the code here.