2018-10-02 15:49:51 -05:00
|
|
|
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')
|
|
|
|
continue;
|
|
|
|
my_exports[entry.name] = true;
|
|
|
|
nexports += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (my_exports.foo === undefined)
|
|
|
|
throw new Error("`foo` wasn't defined");
|
2019-05-03 15:59:50 -05:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|