summaryrefslogtreecommitdiffstats
path: root/tests/run-make/wasm-export-all-symbols/verify.js
blob: 72db3356f5635146259f438b8019973eda1c906c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const process = require('process');
const assert = require('assert');
const buffer = fs.readFileSync(process.argv[2]);

let m = new WebAssembly.Module(buffer);
let list = WebAssembly.Module.exports(m);
console.log('exports', list);

const my_exports = {};
let nexports = 0;

for (const entry of list) {
  if (entry.kind == 'function'){
    nexports += 1;
  }
  my_exports[entry.name] = entry.kind;
}

if (my_exports.foo != "function")
  throw new Error("`foo` wasn't defined");

if (my_exports.FOO != "global")
  throw new Error("`FOO` wasn't defined");

if (my_exports.main === undefined) {
  if (nexports != 1)
    throw new Error("should only have one function export");
} else {
  if (nexports != 2)
    throw new Error("should only have two function exports");
}