How to use the @webassemblyjs/wasm-gen.encodeNode 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 xtuc / webassemblyjs / packages / wasm-edit / src / apply.js View on Github external
Func({ node }) {
        const funcHasThisIntr =
          node.body.find(n => n === newNode) !== undefined;

        // Update func's body size if needed
        if (funcHasThisIntr === true) {
          // These are the old functions locations informations
          assertHasLoc(node);

          const oldNodeSize = encodeNode(oldNode).length;
          const bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;

          if (bodySizeDeltaBytes !== 0) {
            const newValue = node.metadata.bodySize + bodySizeDeltaBytes;
            const newByteArray = encodeU32(newValue);

            // function body size byte
            // FIXME(sven): only handles one byte u32
            const start = node.loc.start.column;
            const end = start + 1;

            uint8Buffer = overrideBytesInBuffer(
              uint8Buffer,
              start,
              end,
              newByteArray
github xtuc / webassemblyjs / packages / wasm-edit / src / apply.js View on Github external
Func({ node }) {
        const funcHasThisIntr =
          node.body.find(n => n === newNode) !== undefined;

        // Update func's body size if needed
        if (funcHasThisIntr === true) {
          // These are the old functions locations informations
          assertHasLoc(node);

          const oldNodeSize = encodeNode(oldNode).length;
          const bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;

          if (bodySizeDeltaBytes !== 0) {
            const newValue = node.metadata.bodySize + bodySizeDeltaBytes;
            const newByteArray = encodeU32(newValue);

            debug("resize func body newValue=%d", newValue);

            // function body size byte
            // FIXME(sven): only handles one byte u32
            const start = node.loc.start.column;
            const end = start + 1;

            uint8Buffer = overrideBytesInBuffer(
              uint8Buffer,
              start,
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / wasm-edit / esm / apply.js View on Github external
Func: function Func(_ref3) {
        var node = _ref3.node;
        var funcHasThisIntr = node.body.find(function (n) {
          return n === newNode;
        }) !== undefined; // Update func's body size if needed

        if (funcHasThisIntr === true) {
          // These are the old functions locations informations
          assertHasLoc(node);
          var oldNodeSize = encodeNode(oldNode).length;
          var bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;

          if (bodySizeDeltaBytes !== 0) {
            var newValue = node.metadata.bodySize + bodySizeDeltaBytes;
            var newByteArray = encodeU32(newValue); // function body size byte
            // FIXME(sven): only handles one byte u32

            var start = node.loc.start.column;
            var end = start + 1;
            uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newByteArray);
          }
        }
      }
    });
github xtuc / webassemblyjs / packages / wasm-edit / src / apply.js View on Github external
* check that the expressions were ended
   */
  if (isFunc(node)) {
    // $FlowIgnore
    CHECK_END(node.body);
  }

  if (isGlobal(node)) {
    // $FlowIgnore
    CHECK_END(node.init);
  }

  /**
   * Add nodes
   */
  const newByteArray = encodeNode(node);

  // The size of the section doesn't include the storage of the size itself
  // we need to manually add it here
  const start = getEndOfSection(sectionMetadata);

  const end = start;

  /**
   * Update section
   */
  const deltaBytes = newByteArray.length;

  uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newByteArray);

  node.loc = {
    start: { line: -1, column: start },
github xtuc / webassemblyjs / packages / wasm-edit / src / apply.js View on Github external
const sectionName = getSectionForNode(node);

  let sectionMetadata = getSectionMetadata(ast, sectionName);

  // Section doesn't exists, we create an empty one
  if (typeof sectionMetadata === "undefined") {
    const res = createEmptySection(ast, uint8Buffer, sectionName);

    uint8Buffer = res.uint8Buffer;
    sectionMetadata = res.sectionMetadata;
  }

  /**
   * Add nodes
   */
  const newByteArray = encodeNode(node);

  // The size of the section doesn't include the storage of the size itself
  // we need to manually add it here
  const start = getEndOfSection(sectionMetadata);

  const end = start;

  /**
   * Update section
   */
  const deltaBytes = newByteArray.length;

  debug(
    "add node=%s section=%s after=%d deltaBytes=%s deltaElements=%s",
    node.type,
    sectionName,
github flaviuse / mern-authentication / client / node_modules / @webassemblyjs / wasm-edit / esm / apply.js View on Github external
Func: function Func(_ref3) {
        var node = _ref3.node;
        var funcHasThisIntr = node.body.find(function (n) {
          return n === newNode;
        }) !== undefined; // Update func's body size if needed

        if (funcHasThisIntr === true) {
          // These are the old functions locations informations
          assertHasLoc(node);
          var oldNodeSize = encodeNode(oldNode).length;
          var bodySizeDeltaBytes = replacementByteArray.length - oldNodeSize;

          if (bodySizeDeltaBytes !== 0) {
            var newValue = node.metadata.bodySize + bodySizeDeltaBytes;
            var newByteArray = encodeU32(newValue); // function body size byte
            // FIXME(sven): only handles one byte u32

            var start = node.loc.start.column;
            var end = start + 1;
            uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newByteArray);
          }
        }
      }
    });
github xtuc / webassemblyjs / packages / wasm-edit / src / apply.js View on Github external
function applyUpdate(
  ast: Program,
  uint8Buffer: Uint8Array,
  [oldNode, newNode]: [Node, Node]
): State {
  const deltaElements = 0;

  assertHasLoc(oldNode);

  const sectionName = getSectionForNode(newNode);
  const replacementByteArray = encodeNode(newNode);

  /**
   * Replace new node as bytes
   */
  uint8Buffer = overrideBytesInBuffer(
    uint8Buffer,
    // $FlowIgnore: assertHasLoc ensures that
    oldNode.loc.start.column,
    // $FlowIgnore: assertHasLoc ensures that
    oldNode.loc.end.column,
    replacementByteArray
  );

  /**
   * Update function body size if needed
   */
github zc910704 / Vue.js-personal-note / www / day6.1.webpack的url-loader与babel / node_modules / @webassemblyjs / wasm-edit / esm / apply.js View on Github external
function applyUpdate(ast, uint8Buffer, _ref) {
  var _ref2 = _slicedToArray(_ref, 2),
      oldNode = _ref2[0],
      newNode = _ref2[1];

  var deltaElements = 0;
  assertHasLoc(oldNode);
  var sectionName = getSectionForNode(newNode);
  var replacementByteArray = encodeNode(newNode);
  /**
   * Replace new node as bytes
   */

  uint8Buffer = overrideBytesInBuffer(uint8Buffer, // $FlowIgnore: assertHasLoc ensures that
  oldNode.loc.start.column, // $FlowIgnore: assertHasLoc ensures that
  oldNode.loc.end.column, replacementByteArray);
  /**
   * Update function body size if needed
   */

  if (sectionName === "code") {
    // Find the parent func
    traverse(ast, {
      Func: function Func(_ref3) {
        var node = _ref3.node;

@webassemblyjs/wasm-gen

WebAssembly binary format printer

MIT
Latest version published 3 months ago

Package Health Score

85 / 100
Full package analysis