v141 · webassembly

WebAssembly Custom Descriptors

Allows WebAssembly to store data associated with source-level types more efficiently in new "custom descriptor" objects. These custom descriptors can be configured with prototypes for the WebAssembly objects of that source-level type. This allows methods to be installed on a WebAssembly object's prototype chain and called directly from JS using normal method

concepts

  1. Custom Descriptors

    Wasm Custom Descriptors standardise the way modules attach typed metadata to their interface. Tools no longer need to parse each toolchain's custom section format.

  2. JS Prototype Bridge

    Wasm objects expose JS-class-shaped APIs: player.takeDamage(20) instead of module.takeDamage(player, 20). Side-by-side with the pre-141 awkward syntax.

  3. Object Size

    Calculator showing the per-instance bytes saved when the type metadata pointer moves out of each object. Plug in your runtime's scale to see the memory win.

  4. Wasm Type Explorer

    Live WebAssembly GC type browser: instantiate a WAT snippet with struct and array types, then explore the custom-descriptor objects the engine creates — prototype chain, field layout, descriptor reference. A diff panel compares object sizes with and without custom descriptors at various instance counts.

why it shipped

Without custom descriptors, WebAssembly objects must contain an explicit reference to separate objects containing the data associated with their source-level types, increasing the size of most objects. Furthermore, without the ability to associate JS prototypes with WebAssembly objects via their custom descriptors, it is impossible to call methods on the WebAssembly objects from JS using normal method call syntax. Allowing method calls to work with WebAssembly objects makes it easier and more ergonomic to consume WebAssembly libraries from JS.

references