source: trip-planner-front/node_modules/@webassemblyjs/wasm-opt/esm/leb128.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import { traverse, shiftSection } from "@webassemblyjs/ast";
2import { encodeU32 } from "@webassemblyjs/wasm-gen/lib/encoder";
3import { overrideBytesInBuffer } from "@webassemblyjs/helper-buffer";
4
5function shiftFollowingSections(ast, _ref, deltaInSizeEncoding) {
6 var section = _ref.section;
7 // Once we hit our section every that is after needs to be shifted by the delta
8 var encounteredSection = false;
9 traverse(ast, {
10 SectionMetadata: function SectionMetadata(path) {
11 if (path.node.section === section) {
12 encounteredSection = true;
13 return;
14 }
15
16 if (encounteredSection === true) {
17 shiftSection(ast, path.node, deltaInSizeEncoding);
18 }
19 }
20 });
21}
22
23export function shrinkPaddedLEB128(ast, uint8Buffer) {
24 traverse(ast, {
25 SectionMetadata: function SectionMetadata(_ref2) {
26 var node = _ref2.node;
27
28 /**
29 * Section size
30 */
31 {
32 var newu32Encoded = encodeU32(node.size.value);
33 var newu32EncodedLen = newu32Encoded.length;
34 var start = node.size.loc.start.column;
35 var end = node.size.loc.end.column;
36 var oldu32EncodedLen = end - start;
37
38 if (newu32EncodedLen !== oldu32EncodedLen) {
39 var deltaInSizeEncoding = oldu32EncodedLen - newu32EncodedLen;
40 uint8Buffer = overrideBytesInBuffer(uint8Buffer, start, end, newu32Encoded);
41 shiftFollowingSections(ast, node, -deltaInSizeEncoding);
42 }
43 }
44 }
45 });
46 return uint8Buffer;
47}
Note: See TracBrowser for help on using the repository browser.