verify-wasmgen-dummy-output.js 934 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env node
  2. "use strict";
  3. process.on("unhandledRejection", exn => { throw exn; });
  4. const fs = require("fs");
  5. const path = require("path");
  6. const DUMMY_MODULE_PATH = path.resolve(__dirname, "../../build/dummy_output.wasm");
  7. const dummy_module = fs.readFileSync(DUMMY_MODULE_PATH);
  8. const wm = new WebAssembly.Module(dummy_module);
  9. const mem = new WebAssembly.Memory({ initial: 256 });
  10. // These tests have to be kept in sync with src/rust/wasmgen/module_init.rs' tests
  11. // XXX: make the test more complex, involving locals, conditionals and stuff
  12. let baz_recd_arg;
  13. function baz(arg) {
  14. baz_recd_arg = arg;
  15. return 456;
  16. }
  17. let foo_recd_arg;
  18. function foo(arg) {
  19. foo_recd_arg = arg;
  20. }
  21. const i = new WebAssembly.Instance(wm, { "e": { m: mem, baz, foo } });
  22. i.exports.f();
  23. console.assert(baz_recd_arg === 2, `baz returned: "${baz_recd_arg}"`);
  24. console.assert(foo_recd_arg === 456, `foo returned: "${foo_recd_arg}"`);