Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
}
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);
}
}
};
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);
}
}
function evaluate(customNode: ?Array): ?StackLocal {
let n = [node];
if (typeof customNode !== "undefined") {
n = customNode;
}
const memory = new Memory({ initial: 100 });
const allocator = createAllocator(memory);
const code = n;
// $FlowIgnore
code.push(t.instruction("end"));
return partialEvaluation.evaluate(allocator, code);
}
const argValues = args.map(expr => {
const code = [expr];
addEndInstruction(code);
const evaluation = partialEvaluation.evaluate(allocator, code);
if (evaluation !== undefined) {
// Pass the raw value here since we need the LongNumber representation
// It's only meant for testing
if (expr.object === "i64") {
return evaluation.value._value;
}
return evaluation.value.toString();
}
});
function assert_return(node) {
const [action, ...args] = node.args;
addEndInstruction(args);
const expectedRes = partialEvaluation.evaluate(allocator, args);
if (action.type === "Instr" && action.id === "invoke") {
const actualRes = invoke(action);
assertSameStackLocal(actualRes, expectedRes);
} else if (action.type === "Instr" && action.id === "get") {
let id;
if (action.args.length === 2) {
id = action.args[1];
} else {
id = action.args[0];
}
// find export in instantiated module
const module = instantiatedModules.find(
const argValues = args.map(expr => {
const evaluation = partialEvaluation.evaluate(allocator, [expr]);
if (evaluation !== undefined) {
// Pass the raw value here since we need the LongNumber representation
// It's only meant for testing
if (expr.object === "i64") {
return evaluation.value._value;
}
return evaluation.value.toString();
}
});
return evaluation.value._value;
}
return evaluation.value.toString();
}
});
const res = module.exports[name.value](...argValues);
return res;
}
/**
* REPL
*/
const memory = new Memory({ initial: 100 });
const allocator = createAllocator(memory);
// Cache instanced modules
const instantiatedModules = [];
// function wrapInModule(node) {
// const name = "autogenerated";
// return t.module(name, [node]);
// }
function assert(cond, msg = "unknown") {
if (cond === false) {
error(new Error("assertion failure: " + msg));
onAssert();
}
if (isVerbose === true) {
function evaluate(customNode: ?Array): ?StackLocal {
let n = [node];
if (typeof customNode !== "undefined") {
n = customNode;
}
const memory = new Memory({ initial: 100 });
const allocator = createAllocator(memory);
const code = n;
// $FlowIgnore
code.push(t.instruction("end"));
return partialEvaluation.evaluate(allocator, code);
}
if (expr.object === "i64") {
return evaluation.value._value;
}
return evaluation.value.toString();
}
});
return module.exports[name.value](...argValues);
}
/**
* REPL
*/
const memory = new Memory({ initial: 100 });
const allocator = createAllocator(memory);
// Cache instanced modules
const instantiatedModules = [];
function wrapInModule(node) {
const name = "autogenerated";
return t.module(name, [node]);
}
function assert(cond, msg = "unknown") {
if (cond === false) {
error(new Error("assertion failure: " + msg));
onAssert();
return;
}