How to use the @webassemblyjs/validation.getType function in @webassemblyjs/validation

To help you get started, we’ve selected a few @webassemblyjs/validation 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 / webassemblyjs / src / interpreter / runtime / values / global.js View on Github external
export function createInstance(
  allocator: Allocator,
  node: Global
): GlobalInstance {
  let value;
  const { valtype, mutability } = node.globalType;

  // None or multiple constant expressions in the initializer seems not possible
  // TODO(sven): find a specification reference for that
  // FIXME(sven): +1 because of the implicit end, change the order of validations
  if (node.init.length > 2 || node.init.length === 1) {
    throw new CompileError("type mismatch");
  }

  // Validate the type
  const resultInferedType = getType(node.init);

  if (
    resultInferedType != null &&
    typeEq([node.globalType.valtype], resultInferedType) === false
  ) {
    throw new CompileError("type mismatch");
  }

  const res = evaluate(allocator, node.init);

  if (res != null) {
    value = res.value;
  }

  return {
    type: valtype,

@webassemblyjs/validation

Module AST validations

MIT
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis