How to use the webassemblyjs/lib/interpreter.Instance 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 / helper-testsuite-runner / src / index.js View on Github external
};

  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);
  }
}
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
function createModuleInstanceFromAst(moduleNode) {
    const internalInstanceOptions = {
      checkForI64InSignature: false
    };

    const importObject = {
      _internalInstanceOptions: internalInstanceOptions
    };
    const module = createCompiledModule(moduleNode);

    return new Instance(module, importObject);
  }
github xtuc / webassemblyjs / packages / repl / src / index.js View on Github external
if (typeErrors.length > 0) {
        const containsImmutableGlobalViolation = typeErrors.some(
          x => x === "global is immutable"
        );

        if (containsImmutableGlobalViolation) {
          throw new Error("global is immutable");
        }

        throw new Error("type mismatch");
      }
    }

    const compiledModule = createCompiledModule(moduleNode);

    return new Instance(compiledModule, importObject);
  }