wasmcctxmodule.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. const buf = WebAssembly.wabt.convertWast2Wasm(`(module
  6. (import "test" "foo" (func $foo (param i32)))
  7. (func $a (export "a") (param i32)
  8. (call $foo (get_local 0))
  9. )
  10. (func $c (export "c") (param i32)
  11. (call $d (get_local 0))
  12. )
  13. (func $d (param i32)
  14. (call $a (get_local 0))
  15. )
  16. )`);
  17. var testValue;
  18. class MyException extends Error {}
  19. var MyExceptionExport = MyException;
  20. var lastModule;
  21. var lastInstance;
  22. var mem = new WebAssembly.Memory({initial: 1});
  23. var table = new WebAssembly.Table({element: "anyfunc", initial: 15});
  24. function createModule() {
  25. lastModule = new WebAssembly.Module(buf);
  26. lastInstance = new WebAssembly.Instance(lastModule, {test: {
  27. foo: function(val) {
  28. testValue = val;
  29. throw new MyException();
  30. }
  31. }});
  32. return lastInstance.exports;
  33. }