module.exports.validateBytecodeModule = function()

in packages/metro-hermes-compiler/src/index.js [151:186]


module.exports.validateBytecodeModule = function (
  bytecode: Buffer,
  offset: number,
): void {
  if ((bytecode.byteOffset + offset) % props.BYTECODE_ALIGNMENT) {
    throw new Error(
      'Bytecode is not aligned to ' + props.BYTECODE_ALIGNMENT + '.',
    );
  }

  const fileLength = bytecode.readUInt32LE(offset + props.LENGTH_OFFSET);
  if (
    bytecode.length - offset < props.HEADER_SIZE ||
    bytecode.length - offset < fileLength
  ) {
    throw new Error('Bytecode buffer is too small.');
  }

  if (
    bytecode.readUInt32LE(offset + 0) !== props.MAGIC[0] ||
    bytecode.readUInt32LE(offset + 4) !== props.MAGIC[1]
  ) {
    throw new Error('Bytecode buffer is missing magic value.');
  }

  const version = bytecode.readUInt32LE(offset + 8);
  if (version !== props.VERSION) {
    throw new Error(
      'Bytecode version is ' +
        version +
        ' but ' +
        props.VERSION +
        ' is required.',
    );
  }
};