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:
- Same-named custom sections are already allowed.
- 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.
- 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:
- Using some binary encoding for identifiers, but that needs more JS code to decode it back, than the current one-liner.
- Using some comma-separated format, but that wouldn't work well with arbitrary characters in export names.
- 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.
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: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.Other potential alternatives could be either:
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.