How to use the webassemblyjs/lib/interpreter/partial-evaluation.evaluate function in webassemblyjs

To help you get started, we’ve selected a few webassemblyjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xtuc / webassemblyjs / packages / ast / src / traverse.js View on Github external
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);
  }
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
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();
      }
    });
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
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(
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
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();
      }
    });
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
function assert_return(node) {
    const [action, ...args] = node.args;

    let expectedRes;

    const expectedEvaluation = partialEvaluation.evaluate(allocator, args);

    if (expectedEvaluation !== undefined) {
      expectedRes = expectedEvaluation.value.toString();
    }

    if (action.type === "Instr" && action.id === "invoke") {
      const actualRes = invoke(action);

      assert(
        actualRes == expectedRes,
        `expected "${expectedRes}", "${actualRes}" given`
      );
    } else if (action.type === "Instr" && action.id === "get") {
      let id;

      if (action.args.length === 2) {