Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadModule(type: string, filename: string): Instance {
const internalInstanceOptions = {
checkForI64InSignature: false,
returnStackLocal: true
};
const importObject = {
_internalInstanceOptions: internalInstanceOptions
};
if (type === "text") {
const content = readFileSync(join(WASM_TEST_DIR, filename), "utf8");
// we need a module in order to be compiled
const ast = parse("(module " + content + ")");
// TODO(sven): pass fakeCompiler here?
const module = createCompiledModule(ast);
return new Instance(module, importObject);
} else if (type === "binary") {
// $FlowIgnore
const buff = readFileSync(join(WASM_TEST_DIR, filename), null);
const ast = decode(buff, decoderOpts);
const module = createCompiledModule(ast);
return new Instance(module, importObject);
} else {
throw new Error("unsupported module type: " + type);
}
}
// @flow
const wastIdentifierToIndex = require("@webassemblyjs/ast/lib/transform/wast-identifier-to-index");
const denormalizeTypeReferences = require("@webassemblyjs/ast/lib/transform/denormalize-type-references");
const { parse } = require("@webassemblyjs/wast-parser");
const { print } = require("@webassemblyjs/wast-printer");
const { readFileSync } = require("fs");
const filename = process.argv[2];
if (typeof filename === "undefined") {
throw new Error("Missing file");
}
const content = readFileSync(filename, "utf8");
const ast = parse(content);
denormalizeTypeReferences.transform(ast);
wastIdentifierToIndex.transform(ast);
console.log(print(ast));
function replEval(input) {
if (isVerbose === true) {
console.log(input);
}
const ast = parse(input);
const [node] = ast.body;
// Empty input, skip this iteration
if (node === undefined) {
return;
}
if (node.type === "Instr") {
if (node.id === "assert_invalid") {
return assert_invalid(node);
}
if (node.id === "assert_return") {
return assert_return(node);
}
function replEval(input) {
if (isVerbose === true) {
onLog(input);
}
const ast = parse(input);
const [node] = ast.body;
// Empty input, skip this iteration
if (node === undefined) {
return;
}
if (node.type === "Instr") {
if (node.id === "assert_invalid") {
return assert_invalid(node);
}
if (node.id === "assert_return") {
return assert_return(node);
}
instantiateFromSource(
content: string,
importObject: ImportObject = {}
): Instance {
const ast = parse(content);
const module = createCompiledModule(ast);
console.warn("using deprecated instantiateFromSource");
return new Instance(module, importObject);
},
function parseQuoteModule(node /*: QuoteModule */) {
const raw = node.string.join("");
parse(raw);
}