@@ -436,34 +436,67 @@ The expectation is that, when a binary WebAssembly module is viewed in a browser
436436environment, the data in this section will be used as the names of functions
437437and locals in the [ text format] ( TextFormat.md ) .
438438
439+ The name section contains a sequence of name subsections:
440+
439441| Field | Type | Description |
440442| ----- | ---- | ----------- |
441- | count | ` varuint32 ` | count of entries to follow |
442- | entries | ` function_names* ` | sequence of names |
443+ | name_type | ` varuint7 ` | code identifying type of name contained in this subsection |
444+ | name_payload_len | ` varuint32 ` | size of this subsection in bytes |
445+ | name_payload_data | ` bytes ` | content of this section, of length ` name_payload_len ` |
443446
444- The sequence of ` function_names ` assigns names to the corresponding
445- [ function index] ( Modules.md#function-index-space ) . (Note: this assigns names to both
446- imported and module-defined functions.) The count may differ from the actual number of functions.
447+ Since name subsections have a given length, unknown or unwanted names types can
448+ be skipped over by an engine. The current list of valid ` name_type ` codes are:
447449
448- #### Function names
450+ | Name Type | Code | Description |
451+ | --------- | ---- | ----------- |
452+ | [ Function] ( #function-names ) | ` 1 ` | Assigns names to functions |
453+ | [ Local] ( #local-names ) | ` 2 ` | Assigns names to locals in functions |
454+
455+ When present, name subsections must appear in this order and at most once. The
456+ end of the last subsection must coincide with the last byte of the name
457+ section to be a well-formed name section.
458+
459+ #### Name Map
460+
461+ In the following subsections, a ` name_map ` is encoded as:
449462
450463| Field | Type | Description |
451464| ----- | ---- | ----------- |
452- | fun_name_len | ` varuint32 ` | string length, in bytes |
453- | fun_name_str | ` bytes ` | valid utf8 encoding |
454- | local_count | ` varuint32 ` | count of local names to follow |
455- | local_names | ` local_name* ` | sequence of local names |
465+ | count | ` varuint32 ` | number of ` naming ` in names |
466+ | names | ` naming* ` | sequence of ` naming ` sorted by index |
456467
457- The sequence of ` local_name ` assigns names to the corresponding local index. The
458- count may differ from the actual number of locals.
468+ where a ` naming ` is encoded as:
459469
460- #### Local name
470+ | Field | Type | Description |
471+ | ----- | ---- | ----------- |
472+ | index | ` varuint32 ` | the index which is being named |
473+ | name_len | ` varuint32 ` | number of bytes in name_str |
474+ | name_str | ` bytes ` | binary encoding of the name |
475+
476+ #### Function names
477+
478+ The function names subsection is a ` name_map ` which assigns names to
479+ a subset of the [ function index space] ( Modules.md#function-index-space )
480+ (both imports and module-defined).
481+
482+ #### Local names
483+
484+ The local names subsection assigns ` name_map ` s to a subset of functions in the
485+ [ function index space] ( Modules.md#function-index-space ) (both imports and
486+ module-defined). The ` name_map ` for a given function assigns names to a
487+ subset of local variable indices.
461488
462489| Field | Type | Description |
463490| ----- | ---- | ----------- |
464- | local_name_len | ` varuint32 ` | string length, in bytes |
465- | local_name_str | ` bytes ` | valid utf8 encoding |
491+ | count | ` varuint32 ` | count of ` local_names ` in funcs |
492+ | funcs | ` local_names* ` | sequence of ` local_names ` sorted by index |
466493
494+ where a ` local_name ` is encoded as:
495+
496+ | Field | Type | Description |
497+ | ----- | ---- | ----------- |
498+ | index | ` varuint32 ` | the index of the function whose locals are being named |
499+ | local_map | ` name_map ` | assignment of names to local indices |
467500
468501# Function Bodies
469502
0 commit comments