rust/tests/run-make/wasm-export-all-symbols/verify.js

33 lines
794 B
JavaScript
Raw Normal View History

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 = {};
2020-01-08 02:53:33 -06:00
let nexports = 0;
for (const entry of list) {
2020-01-07 12:37:24 -06:00
if (entry.kind == 'function'){
2020-01-08 02:53:33 -06:00
nexports += 1;
2020-01-07 12:37:24 -06:00
}
2020-01-08 03:05:44 -06:00
my_exports[entry.name] = entry.kind;
}
2020-01-08 03:05:44 -06:00
if (my_exports.foo != "function")
throw new Error("`foo` wasn't defined");
2020-01-08 03:05:44 -06:00
if (my_exports.FOO != "global")
2020-01-07 12:37:24 -06:00
throw new Error("`FOO` wasn't defined");
if (my_exports.main === undefined) {
2020-01-08 02:53:33 -06:00
if (nexports != 1)
throw new Error("should only have one function export");
} else {
2020-01-08 02:53:33 -06:00
if (nexports != 2)
throw new Error("should only have two function exports");
}