index.html 614 B

123456789101112131415161718192021222324252627282930313233
  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. print: (result) => { console.log('result = ', result); }
  16. } };
  17. WebAssembly.instantiateStreaming( fetch('add_two.wasm'), env).then( result => {
  18. console.log('WASM loaded!');
  19. var ex = result.instance.exports;
  20. console.log('ex = ', ex);
  21. test1(ex);
  22. });
  23. }, false);
  24. </script>
  25. </body>
  26. </html>