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 = {};
|
2020-01-08 02:53:33 -06:00
|
|
|
let nexports = 0;
|
|
|
|
|
2018-10-02 15:49:51 -05:00
|
|
|
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;
|
2018-10-02 15:49:51 -05:00
|
|
|
}
|
|
|
|
|
2020-01-08 03:05:44 -06:00
|
|
|
if (my_exports.foo != "function")
|
2018-10-02 15:49:51 -05:00
|
|
|
throw new Error("`foo` wasn't defined");
|
2019-05-03 15:59:50 -05:00
|
|
|
|
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");
|
|
|
|
|
2019-05-03 15:59:50 -05:00
|
|
|
if (my_exports.main === undefined) {
|
2020-01-08 02:53:33 -06:00
|
|
|
if (nexports != 1)
|
2019-05-03 15:59:50 -05:00
|
|
|
throw new Error("should only have one function export");
|
|
|
|
} else {
|
2020-01-08 02:53:33 -06:00
|
|
|
if (nexports != 2)
|
2019-05-03 15:59:50 -05:00
|
|
|
throw new Error("should only have two function exports");
|
|
|
|
}
|