Repository: dotnet/runtime
File: src/coreclr/tools/Common/Compiler/ObjectWriter/WasmObjectWriter.cs (C#)

Code before:

            return codeSection;
        }

        private WasmSection WriteTypeSection(Span<WasmFuncType> functionSignatures, Logger logger)
        {
            WasmSection typeSection = new WasmSection(WasmSectionType.Type, new SectionData(), "type");
            SectionWriter writer = typeSection.Writer;

            // Write the number of types
            writer.WriteULEB128((ulong)functionSignatures.Length);
            foreach (WasmFuncType signature in functionSignatures)
            {
                if (logger.IsVerbose)
                {
                    logger.LogMessage($"Emitting function signature: {signature}");
                }
                writer.EmitData(signature.Encode());
            }
            return typeSection;
        }

        private WasmSection WriteFunctionSection(WasmFuncType[] allFunctionSignatures, IDictionary<WasmFuncType, int> signatureMap, Logger logger)
        {
            WasmSection functionSection = new WasmSection(WasmSectionType.Function, new SectionData(), "function");
        
            SectionWriter writer = functionSection.Writer;
            // Write the number of functions
            writer.WriteULEB128((ulong)allFunctionSignatures.Length);
            for (int i = 0; i < allFunctionSignatures.Length; i++)
            {
                var signature = allFunctionSignatures[i];
                writer.WriteULEB128((ulong)signatureMap[signature]);
            }
            return functionSection;
        }

        private void EmitSection(Func<WasmSection> writeFunc, Stream outputFileStream, Logger logger)
        {
            var section = writeFunc();

            outputFileStream.Write(section.Header);
            if (logger.IsVerbose)
            {
                logger.LogMessage($"Wrote section header of size {section.Header.Length} bytes.");
            }

            section.Data.GetReadStream().CopyTo(outputFileStream);
            if (logger.IsVerbose)
            {
                logger.LogMessage($"Emitted section: {section.Name} of type `{section.Type}` with size {section.Data.Length} bytes.");

Review comment (suggestion):
Line 212 contains trailing whitespace, which should be removed.
```suggestion

```

Code after:
        public static WasmFuncType GetSignature(MethodDesc method)
        {
            return PlaceholderValues.CreateWasmFunc_i32_i32();
        }
    }

    internal class WasmSection
    {
        public WasmSectionType Type { get; }
        public string Name { get; }
        public SectionData Data => _data;
        private SectionWriter? _writer;

        private SectionData _data;

        public int HeaderSize
        {
            get
            {
                ulong sectionSize = (ulong)_data.Length;
                uint sizeEncodeLength = DwarfHelper.SizeOfULEB128(sectionSize);
                return 1 + (int)sizeEncodeLength;
            }
        }

        public int EncodeHeader(Span<byte> headerBuffer)
        {
            ulong sectionSize = (ulong)_data.Length;
            uint encodeLength = DwarfHelper.SizeOfULEB128(sectionSize);

            // Section header consists of:
            // 1 byte: section type
            // ULEB128: size of section
            headerBuffer[0] = (byte)Type;
            DwarfHelper.WriteULEB128(headerBuffer.Slice(1), sectionSize);

            return 1 + (int)encodeLength;
        }

        public SectionWriter Writer
        {
            get
            {
                if (_writer == null)
                {
                    _writer = new SectionWriter(null, 0, _data);
                }
                return _writer.Value;
            }
        }