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/ 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', '<button id="count">Click me</button><div>Count: <span id="counter"></span></div>'); 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); + }); + } } 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); }