HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/nodejs/webassemblyjs/esm/interpreter/runtime/values/global.js
import { getType, typeEq } from "@webassemblyjs/validation";

var _require = require("../../partial-evaluation"),
    evaluate = _require.evaluate;

var _require2 = require("../../../errors"),
    CompileError = _require2.CompileError;

export function createInstance(allocator, node) {
  var value;
  var _node$globalType = node.globalType,
      valtype = _node$globalType.valtype,
      mutability = _node$globalType.mutability; // 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


  var resultInferedType = getType(node.init);

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

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

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

  return {
    type: valtype,
    mutability: mutability,
    value: value
  };
}