Skip to content

Commit

Permalink
Update the loader and the cpp example
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanks10100 committed Jun 25, 2019
1 parent 78f4fc3 commit dad3d37
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cpp/math.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <emscripten.h>

EMSCRIPTEN_KEEPALIVE
int square (int x) {
return x * x;
}
Binary file modified cpp/math.wasm
Binary file not shown.
8 changes: 5 additions & 3 deletions loader.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
function loadWebAssembly(filename, imports = {}) {
return fetch(filename)
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.compile(buffer))
.then(module => {
.then(buffer => {
imports.env = imports.env || {}
Object.assign(imports.env, {
memoryBase: 0,
tableBase: 0,
__memory_base: 0,
__table_base: 0,
memory: new WebAssembly.Memory({ initial: 256, maximum: 256 }),
table: new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' })
})
return new WebAssembly.Instance(module, imports)
return WebAssembly.instantiate(buffer, imports)
})
.then(result => result.instance )
}

function loadJS (url, imports = {}) {
Expand Down

0 comments on commit dad3d37

Please sign in to comment.