Sha256: c1ebb2b34dd330c598d3ad5c1f509fcb8a33d835f1ac707fefabfd2f240b66b5

Contents?: true

Size: 1.46 KB

Versions: 27

Compression:

Stored size: 1.46 KB

Contents

import { traverse, shiftSection } from "@webassemblyjs/ast";
import { encodeU32 } from "@webassemblyjs/wasm-gen/lib/encoder";
import { overrideBytesInBuffer } from "@webassemblyjs/helper-buffer";

function shiftFollowingSections(ast, _ref, deltaInSizeEncoding) {
  var section = _ref.section;
  // Once we hit our section every that is after needs to be shifted by the delta
  var encounteredSection = false;
  traverse(ast, {
    SectionMetadata: function SectionMetadata(path) {
      if (path.node.section === section) {
        encounteredSection = true;
        return;
      }

      if (encounteredSection === true) {
        shiftSection(ast, path.node, deltaInSizeEncoding);
      }
    }
  });
}

export function shrinkPaddedLEB128(ast, uint8Buffer) {
  traverse(ast, {
    SectionMetadata: function SectionMetadata(_ref2) {
      var node = _ref2.node;

      /**
       * Section size
       */
      {
        var newu32Encoded = encodeU32(node.size.value);
        var newu32EncodedLen = newu32Encoded.length;
        var start = node.size.loc.start.column;
        var end = node.size.loc.end.column;
        var oldu32EncodedLen = end - start;

        if (newu32EncodedLen !== oldu32EncodedLen) {
          var deltaInSizeEncoding = oldu32EncodedLen - newu32EncodedLen;
          uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newu32Encoded);
          shiftFollowingSections(ast, node, -deltaInSizeEncoding);
        }
      }
    }
  });
  return uint8Buffer;
}

Version data entries

27 entries across 26 versions & 9 rubygems

Version Path
ezii-os-5.2.1 node_modules/@webassemblyjs/wasm-opt/esm/leb128.js
ezii-os-2.0.1 node_modules/@webassemblyjs/wasm-opt/esm/leb128.js
ezii-os-1.1.0 node_modules/@webassemblyjs/wasm-opt/esm/leb128.js
ezii-os-1.0.0 node_modules/@webassemblyjs/wasm-opt/esm/leb128.js
ezii-os-0.0.0.1.0 node_modules/@webassemblyjs/wasm-opt/esm/leb128.js
ezii-os-0.0.0.0.1 node_modules/@webassemblyjs/wasm-opt/esm/leb128.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/@webassemblyjs/wasm-opt/esm/leb128.js