1
0

verify-wasmgen-dummy-output.js 959 B

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