summaryrefslogtreecommitdiff
path: root/demo/demo.js
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2016-04-18 00:47:14 -0700
committerBen Smith <binji@chromium.org>2016-04-18 00:47:14 -0700
commit36a1f6a90c854523b80fa3166facb08e65dcfdbd (patch)
tree97527f91120a95c3ec46d38c3e98d42cb91efa54 /demo/demo.js
parent187be92a30fe1e409d019de0dac7954428e64f5f (diff)
downloadwabt-36a1f6a90c854523b80fa3166facb08e65dcfdbd.tar.gz
wabt-36a1f6a90c854523b80fa3166facb08e65dcfdbd.tar.bz2
wabt-36a1f6a90c854523b80fa3166facb08e65dcfdbd.zip
fix emscripten release build
The emscripten release build loads the module memory asynchronously, which means you can't call any of the module functions until it has loaded.
Diffstat (limited to 'demo/demo.js')
-rw-r--r--demo/demo.js71
1 files changed, 37 insertions, 34 deletions
diff --git a/demo/demo.js b/demo/demo.js
index 069927d7..16bd66a6 100644
--- a/demo/demo.js
+++ b/demo/demo.js
@@ -104,40 +104,43 @@ function onError(loc, error, sourceLine, sourceLineColumnOffset) {
output.textContent += lines.join('\n') + '\n';
}
-var allocator = wasm.LibcAllocator;
-var eh = new wasm.SourceErrorHandler(onError, 80);
-
function compile(text) {
- output.textContent = '';
- try {
- var buf = wasm.Buffer.fromString(text);
- var lexer = wasm.Lexer.fromBuffer(allocator, 'test.wast', buf);
- var script = wasm.parse(lexer, eh);
- wasm.checkAst(lexer, script, eh);
- var memoryWriter = new wasm.MemoryWriter(allocator);
- var jsWriter = new wasm.JSStringWriter();
- var logStream = new wasm.Stream(jsWriter.writer);
- var options = new wasm.WriteBinaryOptions({logStream: logStream});
- wasm.writeBinaryScript(allocator, memoryWriter.base, script, options);
- output.textContent = jsWriter.string;
- } catch (e) {
- output.textContent += e.toString();
- } finally {
- if (options)
- options.$destroy();
- if (logStream)
- logStream.$destroy();
- if (script)
- script.$destroy();
- if (jsWriter)
- jsWriter.$destroy();
- if (memoryWriter)
- memoryWriter.$destroy();
- if (lexer)
- lexer.$destroy();
- if (buf)
- buf.$destroy();
- }
+ wasm.ready.then(function() {
+ output.textContent = '';
+ try {
+ var allocator = wasm.LibcAllocator;
+ var eh = new wasm.SourceErrorHandler(onError, 80);
+ var buf = wasm.Buffer.fromString(text);
+ var lexer = wasm.Lexer.fromBuffer(allocator, 'test.wast', buf);
+ var script = wasm.parse(lexer, eh);
+ wasm.checkAst(lexer, script, eh);
+ var memoryWriter = new wasm.MemoryWriter(allocator);
+ var jsWriter = new wasm.JSStringWriter();
+ var logStream = new wasm.Stream(jsWriter.writer);
+ var options = new wasm.WriteBinaryOptions({logStream: logStream});
+ wasm.writeBinaryScript(allocator, memoryWriter.base, script, options);
+ output.textContent = jsWriter.string;
+ } catch (e) {
+ output.textContent += e.toString();
+ } finally {
+ if (options)
+ options.$destroy();
+ if (logStream)
+ logStream.$destroy();
+ if (script)
+ script.$destroy();
+ if (jsWriter)
+ jsWriter.$destroy();
+ if (memoryWriter)
+ memoryWriter.$destroy();
+ if (lexer)
+ lexer.$destroy();
+ if (buf)
+ buf.$destroy();
+ if (eh)
+ eh.$destroy();
+ }
+ });
}
var compileInput = debounce(function() { compile(input.value); }, 100);
@@ -168,7 +171,7 @@ var examples = [
contents:
'(module\n' +
' (func $fac (param i64) (result i64)\n' +
- ' (if (i64.lt_s (get_local 0) (i64.const 0))\n' +
+ ' (if (i64.lt_s (get_local 0) (i64.const 1))\n' +
' (then (i64.const 1))\n' +
' (else\n' +
' (i64.mul\n' +