add2.html 532 B

1234567891011121314151617181920212223242526272829303132333435
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>WASM test</title>
  6. </head>
  7. <body>
  8. <script>
  9. var importObject = {
  10. imports: {
  11. add: function(arg) {
  12. console.log(arg);
  13. }
  14. }
  15. };
  16. fetch('add.wasm').then(response =>
  17. response.arrayBuffer()
  18. ).then(bytes =>
  19. WebAssembly.instantiate(bytes, importObject)
  20. ).then(result =>
  21. console.log(result.instance.exports.add(1,2))
  22. );
  23. </script>
  24. </body>
  25. </html>