How to use the @webassemblyjs/wasm-gen.encodeU32 function in @webassemblyjs/wasm-gen

To help you get started, we’ve selected a few @webassemblyjs/wasm-gen 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 zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / helper-wasm-section / esm / resize.js View on Github external
}

  if (typeof sectionMetadata.vectorOfSize.loc === "undefined") {
    throw new Error("SectionMetadata " + section + " has no loc");
  } // Section has no vector


  if (sectionMetadata.vectorOfSize.value === -1) {
    return uint8Buffer;
  } // keep old node location to be overriden


  var start = sectionMetadata.vectorOfSize.loc.start.column;
  var end = sectionMetadata.vectorOfSize.loc.end.column;
  var newValue = sectionMetadata.vectorOfSize.value + deltaElements;
  var newBytes = encodeU32(newValue); // Update AST

  sectionMetadata.vectorOfSize.value = newValue;
  sectionMetadata.vectorOfSize.loc.end.column = start + newBytes.length;
  return overrideBytesInBuffer(uint8Buffer, start, end, newBytes);
}
github xtuc / webassemblyjs / packages / helper-wasm-section / src / resize.js View on Github external
if (typeof sectionMetadata.vectorOfSize.loc === "undefined") {
    throw new Error("SectionMetadata " + section + " has no loc");
  }

  // Section has no vector
  if (sectionMetadata.vectorOfSize.value === -1) {
    return uint8Buffer;
  }

  // keep old node location to be overriden
  const start = sectionMetadata.vectorOfSize.loc.start.column;
  const end = sectionMetadata.vectorOfSize.loc.end.column;

  const newValue = sectionMetadata.vectorOfSize.value + deltaElements;
  const newBytes = encodeU32(newValue);

  // Update AST
  sectionMetadata.vectorOfSize.value = newValue;
  sectionMetadata.vectorOfSize.loc.end.column = start + newBytes.length;

  debug(
    "resize vec size section=%s detla=%d newValue=%s",
    section,
    deltaElements,
    newValue
  );

  return overrideBytesInBuffer(uint8Buffer, start, end, newBytes);
}
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / helper-wasm-section / esm / resize.js View on Github external
export function resizeSectionByteSize(ast, uint8Buffer, section, deltaBytes) {
  var sectionMetadata = getSectionMetadata(ast, section);

  if (typeof sectionMetadata === "undefined") {
    throw new Error("Section metadata not found");
  }

  if (typeof sectionMetadata.size.loc === "undefined") {
    throw new Error("SectionMetadata " + section + " has no loc");
  } // keep old node location to be overriden


  var start = sectionMetadata.size.loc.start.column;
  var end = sectionMetadata.size.loc.end.column;
  var newSectionSize = sectionMetadata.size.value + deltaBytes;
  var newBytes = encodeU32(newSectionSize);
  /**
   * update AST
   */

  sectionMetadata.size.value = newSectionSize;
  var oldu32EncodedLen = end - start;
  var newu32EncodedLen = newBytes.length; // the new u32 has a different encoded length

  if (newu32EncodedLen !== oldu32EncodedLen) {
    var deltaInSizeEncoding = newu32EncodedLen - oldu32EncodedLen;
    sectionMetadata.size.loc.end.column = start + newu32EncodedLen;
    deltaBytes += deltaInSizeEncoding; // move the vec size pointer size the section size is now smaller

    sectionMetadata.vectorOfSize.loc.start.column += deltaInSizeEncoding;
    sectionMetadata.vectorOfSize.loc.end.column += deltaInSizeEncoding;
  } // Once we hit our section every that is after needs to be shifted by the delta
github xtuc / webassemblyjs / packages / helper-wasm-section / src / resize.js View on Github external
const sectionMetadata = getSectionMetadata(ast, section);

  if (typeof sectionMetadata === "undefined") {
    throw new Error("Section metadata not found");
  }

  if (typeof sectionMetadata.size.loc === "undefined") {
    throw new Error("SectionMetadata " + section + " has no loc");
  }

  // keep old node location to be overriden
  const start = sectionMetadata.size.loc.start.column;
  const end = sectionMetadata.size.loc.end.column;

  const newSectionSize = sectionMetadata.size.value + deltaBytes;
  const newBytes = encodeU32(newSectionSize);

  /**
   * update AST
   */
  sectionMetadata.size.value = newSectionSize;

  const oldu32EncodedLen = end - start;
  const newu32EncodedLen = newBytes.length;

  // the new u32 has a different encoded length
  if (newu32EncodedLen !== oldu32EncodedLen) {
    const deltaInSizeEncoding = newu32EncodedLen - oldu32EncodedLen;

    sectionMetadata.size.loc.end.column = start + newu32EncodedLen;

    deltaBytes += deltaInSizeEncoding;

@webassemblyjs/wasm-gen

WebAssembly binary format printer

MIT
Latest version published 2 months ago

Package Health Score

88 / 100
Full package analysis