Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { traverse } = require("@webassemblyjs/ast");
const template = require("@babel/template").default;
const generate = require("@babel/generator").default;
const t = require("@babel/types");
const globalInstanceIdentifier = t.identifier("instance");
const globalMemoryIdentifier = t.identifier("_memory0");
const globalTableIdentifier = t.identifier("_table0");
const exportFuncTemplate = template.program(`
export function NAME(ARGS) {
if (typeof INSTANCE === "undefined") {
throw new Error("Can not call function " + NAME.name + ", module not initialized.");
}
return INSTANCE.exports.NAME(ARGS);
}
`);
const headerTemplate = template.program(`
if (typeof WebAssembly === "undefined") {
throw new Error("WebAssembly not supported");
}
let INSTANCE;
const globalInstanceIdentifier = t.identifier("instance");
const globalMemoryIdentifier = t.identifier("_memory0");
const globalTableIdentifier = t.identifier("_table0");
const exportFuncTemplate = template.program(`
export function NAME(ARGS) {
if (typeof INSTANCE === "undefined") {
throw new Error("Can not call function " + NAME.name + ", module not initialized.");
}
return INSTANCE.exports.NAME(ARGS);
}
`);
const headerTemplate = template.program(`
if (typeof WebAssembly === "undefined") {
throw new Error("WebAssembly not supported");
}
let INSTANCE;
const MEMORY = new WebAssembly.Memory({initial: 100, limit: 1000});
const TABLE = new WebAssembly.Table({initial: 0, element: 'anyfunc'});
`);
const initFuncTemplate = template.program(`
export const memory = MEMORY;
export const table = TABLE;
export default function(opts = {env:{}}) {
return INSTANCE.exports.NAME(ARGS);
}
`);
const headerTemplate = template.program(`
if (typeof WebAssembly === "undefined") {
throw new Error("WebAssembly not supported");
}
let INSTANCE;
const MEMORY = new WebAssembly.Memory({initial: 100, limit: 1000});
const TABLE = new WebAssembly.Table({initial: 0, element: 'anyfunc'});
`);
const initFuncTemplate = template.program(`
export const memory = MEMORY;
export const table = TABLE;
export default function(opts = {env:{}}) {
if (typeof opts.env.memory === "undefined") {
opts.env.memory = MEMORY;
}
if (typeof opts.env.table === "undefined") {
opts.env.table = TABLE;
}
const importObject = opts;
const getArrayBuffer = response => response.arrayBuffer();