Skip to content

Latest commit

History

History

README.md

AS parse

A WebAssembly binary parser in WebAssembly. Super small, super fast, with TypeScript support.

API

  • parse(binary: Uint8Array, options?: ParseOptions): void
    Parses the contents of a WebAssembly binary according to the specified options.

  • ParseOptions
    Options specified to the parser. The onSection callback determines the sections being evaluated in detail.

    • onSection?(id: SectionId, payloadOff: number, payloadLen: number, nameOff: number, nameLen: number): boolean
      Called with each section in the binary. Returning true evaluates the section.

    • onType?(index: number, form: number): void
      Called with each function type if the type section is evaluated.

    • onTypeParam?(index: number, paramIndex: number, paramType: Type): void
      Called with each function parameter if the type section is evaluated.

    • onTypeReturn?(index: number, returnIndex: number, returnType: Type): void
      Called with each function return type if the type section is evaluated.

    • onImport?(index: number, kind: ExternalKind, moduleOff: number, moduleLen: number, fieldOff: number, fieldLen: number): void
      Called with each import if the import section is evaluated.

    • onFunctionImport?(index: number, type: number): void
      Called with each function import if the import section is evaluated.

    • onTableImport?(index: number, type: Type, initial: number, maximum: number, flags: number): void
      Called with each table import if the import section is evaluated.

    • onMemoryImport?(index: number, initial: number, maximum: number, flags: number): void
      Called with each memory import if the import section is evaluated.

    • onGlobalImport?(index: number, type: Type, mutability: number): void
      Called with each global import if the import section is evaluated.

    • onMemory?(index: number, initial: number, maximum: number, flags: number): void
      Called with each memory if the memory section is evaluated.

    • onFunction?(index: number, typeIndex: number): void
      Called with each function if the function section is evaluated.

    • onGlobal?(index: number, type: Type, mutability: number): void
      Called with each global if the global section is evaluated.

    • onStart?(index: number): void
      Called with the start function index if the start section is evaluated.

    • onExport?(index: number, kind: ExternalKind, kindIndex: number, nameOff: number, nameLen: number): void
      Called with each export if the export section is evaluated.

    • onSourceMappingURL?(offset: number, length: number): void
      Called with the source map URL if the 'sourceMappingURL' section is evaluated.

    • onModuleName?(offset: number, length: number): void
      Called with the module name if present and the 'name' section is evaluated.

    • onFunctionName?(index: number, offset: number, length: number): void
      Called with each function name if present and the 'name' section is evaluated.

    • onLocalName?(funcIndex: number, index: number, offset: number, length: number): void
      Called with each local name if present and the 'name' section is evaluated.

  • Type
    A value or element type, depending on context.

    NameValue
    i320x7f
    i640x7e
    f320x7d
    f640x7c
    anyfunc0x70
    func0x60
    none0x40
  • SectionId
    Numerical id of the current section.

    NameValue
    Custom0
    Type1
    Import2
    Function3
    Table4
    Memory5
    Global6
    Export7
    Start8
    Element9
    Code10
    Data11
  • ExternalKind
    Kind of an export or import.

    NameValue
    Function0
    Table1
    Memory2
    Global3