Skip to content

Encoding multiple sections for JavaScript to read #128

Description

@RReverser

This discussion originated in WebAssembly/binaryen#2327 and @kripken suggested to discuss with the wider audience to see if there's any consensus.

We want to add a custom tool-specific section(s) that could be easily readable by JavaScript and, in our case, would contain names of exported functions. The JavaScript wrapper would read names of these functions and instrument corresponding exports.

Currently, I'm emitting a same-named custom section (called "asyncify") per each such export. My motivation was:

  1. Same-named custom sections are already allowed.
  2. There is WebAssembly.customSections(module, "asyncify") API that already allows to easily enumerate all of such sections, which suggests that it wasn't a coincidence and that it's okay to duplicate sections when it makes sense.
  3. Gzip / Brotli will already do a great job at deduplicating identifiers, so size shouldn't be a concern either.

Other potential alternatives could be either:

  1. Using some binary encoding for identifiers, but that needs more JS code to decode it back, than the current one-liner.
  2. Using some comma-separated format, but that wouldn't work well with arbitrary characters in export names.
  3. Using some well-established format like JSON, but that requires including JSON encoder in the C++ tool, if we want to properly support arbitrary characters.

Current solution seems to be the best of both worlds in that it's both very easy to encode on C++ side and very easy to decode on JS side, but the only concern is that it might be not very idiomatic to have duplicate sections.

Would love to hear any thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions