From 3b87dcc61be33a2daa77f55eeda07e9427047d36 Mon Sep 17 00:00:00 2001 From: "John.Koepi" Date: Fri, 8 Jun 2018 10:28:35 +0200 Subject: [PATCH 1/3] fix module.wasm loading providing location func to the mod --- app/opengl-demo.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/opengl-demo.js b/app/opengl-demo.js index ee61c75..5b1c780 100644 --- a/app/opengl-demo.js +++ b/app/opengl-demo.js @@ -18,8 +18,11 @@ export class OpenGLDemo { loadDemoWasm() { this.module = Module({ - wasmBinaryFile: '/wasm/module.wasm', - canvas: document.getElementById('canvas') + wasmBinaryFile: 'module.wasm', + canvas: document.getElementById('canvas'), + locateFile: function(s) { + return 'wasm/' + s; + } }); console.log(this.module); } From dd7c06ec9c6c3eb92c765a7b3ee6aec74fec0737 Mon Sep 17 00:00:00 2001 From: "John.Koepi" Date: Fri, 8 Jun 2018 10:31:13 +0200 Subject: [PATCH 2/3] ignore package lock --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7286579..f7e9979 100644 --- a/.gitignore +++ b/.gitignore @@ -144,6 +144,7 @@ build/Release # Dependency directories node_modules/ jspm_packages/ +package-lock.json # Typescript v1 declaration files typings/ From 76eedddea59eb7f149d340f43c232195b30085b2 Mon Sep 17 00:00:00 2001 From: "John.Koepi" Date: Sat, 9 Jun 2018 11:03:02 +0200 Subject: [PATCH 3/3] fix import table init, fix counter instance resolving on load via promise continuation --- app/counter.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/counter.js b/app/counter.js index 06b7dcd..a58267a 100644 --- a/app/counter.js +++ b/app/counter.js @@ -2,6 +2,7 @@ import CounterWA from '../build/counter.wasm'; export class Counter { counterModule; + counterInstance; constructor() { this.insertCounterGUI(); @@ -13,7 +14,7 @@ export class Counter { document.querySelector('#app').insertAdjacentHTML('afterbegin', '
Count:
'); const count = document.getElementById('count'); count.addEventListener('click', () => { - document.getElementById('counter').innerHTML = this.counterModule.exports.__ZN7Counter5countEv(); // @TODO why does WASM do this for class methods?? + document.getElementById('counter').innerHTML = this.counterInstance.exports.__ZN7Counter5countEv(); // @TODO why does WASM do this for class methods?? }); } @@ -24,12 +25,17 @@ export class Counter { 'memoryBase': 0, 'tableBase': 0, 'memory': new WebAssembly.Memory({initial: 256}), - 'table': new WebAssembly.Table({initial: 0, element: 'anyfunc'}), + 'table': new WebAssembly.Table({initial: 4, element: 'anyfunc'}), + 'abort': function(msg) { console.error(msg); } } }; - this.counterModule = new CounterWA(importObject); - console.log('Counter Module', this.counterModule); - } + new CounterWA(importObject).then(result => { + this.counterModule = result.module; + this.counterInstance = result.instance; + console.log('Counter Module', this.counterModule); + console.log('Counter Instance', this.counterInstance); + }); + } }