index.html 550 B

12345678910111213141516171819202122232425262728293031
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>WASM Demo</title>
  5. </head>
  6. <body>
  7. <div id="result"></div>
  8. <script>
  9. var div = document.getElementById('result');
  10. function test1(ex){
  11. div.innerText = 'add_two(1, 2) = ' + ex.add_two(1, 2);
  12. }
  13. window.addEventListener("load", function(){
  14. var env = { env: {} };
  15. WebAssembly.instantiateStreaming( fetch('add_two.wasm'), env).then( result => {
  16. console.log('WASM loaded!');
  17. var ex = result.instance.exports;
  18. console.log('ex = ', ex);
  19. test1(ex);
  20. });
  21. }, false);
  22. </script>
  23. </body>
  24. </html>