diff options
Diffstat (limited to 'test/binaryen.js/browser.html')
-rw-r--r-- | test/binaryen.js/browser.html | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/binaryen.js/browser.html b/test/binaryen.js/browser.html new file mode 100644 index 000000000..fcb0fe082 --- /dev/null +++ b/test/binaryen.js/browser.html @@ -0,0 +1,80 @@ +<!DOCTYPE HTML> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>Binaryen</title> + <style type="text/css"> + +* { margin:0; padding:0; font-family:inherit; } +body { + margin:2em; + background:white; + color:black; + font:14px monospace; + white-space: pre; +} +p { + white-space: normal; + font-family:sans-serif; +} + + </style> + <script type="text/javascript" src="../../bin/binaryen.js"></script> + </head> + <body><script type="text/javascript"> +// Separate javascript tag to support <=ES3 browser (the other block uses ES5 and ES6 features) +if (!window.Wasm) { + var e = document.createElement('p'); + e.innerHTML = 'No WASM support detected.<br>Please see <a href="https://github.com/kripken/emscripten/wiki/WebAssembly#testing-native-webassembly-in-browsers">https://github.com/kripken/emscripten/wiki/WebAssembly#testing-native-webassembly-in-browsers</a> for instructions on how to enable it.'; + document.body.appendChild(e); +} +</script><script type="text/javascript"> +if (window.Wasm) { + try { + let startTime = new Date; + document.write("Start at "+startTime.toLocaleTimeString()+"\n"); + + Binaryen = Binaryen(); + + var input1 =` + (module + (export "add" $add) + (import $add2 "env" "add" (param f64 f64) (result f64)) + (func $add (param $x f64) (param $y f64) (result f64) + (f64.add + (call_import $add2 (get_local $x) (get_local $y)) + (f64.add (get_local $x) (get_local $y)) + ) + ) + )`; + + document.write("let buf = Binaryen.compileWast('"+input1+"')\n"); + let buf = Binaryen.compileWast(input1); + + document.write("Wasm.verifyModule(buf) ..."); + Wasm.verifyModule(buf); + document.write(" OK\n"); + + document.write("let m = Wasm.instantiateModule(buf, {env:{add: function(a, b){...}}})\n"); + let m = Wasm.instantiateModule(buf, { + env: { + add: function(a, b) { return a + b; } + } + }); + + let res = m.exports.add(10.0, 20) + document.write("m.exports.add(10.0, 20) => "+res+"\n"); + + let endTime = new Date; + document.write("Completed at "+endTime.toLocaleTimeString()+ + " (total of "+(endTime - startTime)+" ms)\n"); + + } catch (err) { + document.write("Error: " + (err.stack || String(err))); + throw err; + } +} + +</script> +</body> +</html>
\ No newline at end of file |