# All files / src/emitter/section memory.js

100% Statements 13/13
100% Branches 4/4
100% Functions 3/3
100% Lines 12/12

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23

    21x
    21x

    21x
    6x
    6x
    6x
    1x

    21x
    6x
    6x
    6x

    6x

     // @flow
    // Emits function section. For function code emitter look into code.js
    import { varuint32, varint1 } from "../numbers";
    import OutputStream from "../../utils/output-stream";

    const emitEntry = (payload, entry) => {
      payload.push(varint1, entry.max ? 1 : 0, "has no max");
      payload.push(varuint32, entry.initial, "initial memory size(PAGES)");
      if (entry.max) {
        payload.push(varuint32, entry.max, "max memory size(PAGES)");
      }
    };

    const emit = (memories: any[]) => {
      const stream = new OutputStream();
      stream.push(varuint32, memories.length, "count");
      memories.forEach(entry => emitEntry(stream, entry));

      return stream;
    };

    export default emit;