|
| 1 | +WebAssembly Parser |
| 2 | +================== |
| 3 | + |
| 4 | +An [AssemblyScript](http://assemblyscript.org) example. A WebAssembly binary parser in WebAssembly. Small, fast, with TypeScript support. |
| 5 | + |
| 6 | +API |
| 7 | +--- |
| 8 | + |
| 9 | +* **parse**(binary: `Uint8Array`, options?: `ParseOptions`): `void`<br /> |
| 10 | + Parses the contents of a WebAssembly binary according to the specified options. |
| 11 | + |
| 12 | +* **ParseOptions**<br /> |
| 13 | + Options specified to the parser. The `onSection` callback determines the sections being evaluated in detail. |
| 14 | + |
| 15 | + * **onSection**?(id: `SectionId`, payloadOff: `number`, payloadLen: `number`, nameOff: `number`, nameLen: `number`): `boolean`<br /> |
| 16 | + Called with each section in the binary. Returning `true` evaluates the section. |
| 17 | + |
| 18 | + * **onType**?(index: `number`, form: `number`): `void`<br /> |
| 19 | + Called with each function type if the type section is evaluated. |
| 20 | + |
| 21 | + * **onTypeParam**?(index: `number`, paramIndex: `number`, paramType: `Type`): `void`<br /> |
| 22 | + Called with each function parameter if the type section is evaluated. |
| 23 | + |
| 24 | + * **onTypeReturn**?(index: `number`, returnIndex: `number`, returnType: `Type`): `void`<br /> |
| 25 | + Called with each function return type if the type section is evaluated. |
| 26 | + |
| 27 | + * **onImport**?(index: `number`, kind: `ExternalKind`, moduleOff: `number`, moduleLen: `number`, fieldOff: `number`, fieldLen: `number`): `void`<br /> |
| 28 | + Called with each import if the import section is evaluated. |
| 29 | + |
| 30 | + * **onFunctionImport**?(index: `number`, type: `number`): `void`<br /> |
| 31 | + Called with each function import if the import section is evaluated. |
| 32 | + |
| 33 | + * **onTableImport**?(index: `number`, type: `Type`, initial: `number`, maximum: `number`, flags: `number`): `void`<br /> |
| 34 | + Called with each table import if the import section is evaluated. |
| 35 | + |
| 36 | + * **onMemoryImport**?(index: `number`, initial: `number`, maximum: `number`, flags: `number`): `void`<br /> |
| 37 | + Called with each memory import if the import section is evaluated. |
| 38 | + |
| 39 | + * **onGlobalImport**?(index: `number`, type: `Type`, mutability: `number`): `void`<br /> |
| 40 | + Called with each global import if the import section is evaluated. |
| 41 | + |
| 42 | + * **onMemory**?(index: `number`, initial: `number`, maximum: `number`, flags: `number`): `void`<br /> |
| 43 | + Called with each memory if the memory section is evaluated. |
| 44 | + |
| 45 | + * **onFunction**?(index: `number`, typeIndex: `number`): `void`<br /> |
| 46 | + Called with each function if the function section is evaluated. |
| 47 | + |
| 48 | + * **onGlobal**?(index: `number`, type: `Type`, mutability: `number`): `void`<br /> |
| 49 | + Called with each global if the global section is evaluated. |
| 50 | + |
| 51 | + * **onStart**?(index: `number`): `void`<br /> |
| 52 | + Called with the start function index if the start section is evaluated. |
| 53 | + |
| 54 | + * **onExport**?(index: `number`, kind: `ExternalKind`, kindIndex: `number`, nameOff: `number`, nameLen: `number`): `void`<br /> |
| 55 | + Called with each export if the export section is evaluated. |
| 56 | + |
| 57 | + * **onSourceMappingURL**?(offset: `number`, length: `number`): `void`<br /> |
| 58 | + Called with the source map URL if the 'sourceMappingURL' section is evaluated. |
| 59 | + |
| 60 | + * **onModuleName**?(offset: `number`, length: `number`): `void`<br /> |
| 61 | + Called with the module name if present and the 'name' section is evaluated. |
| 62 | + |
| 63 | + * **onFunctionName**?(index: `number`, offset: `number`, length: `number`): `void`<br /> |
| 64 | + Called with each function name if present and the 'name' section is evaluated. |
| 65 | + |
| 66 | + * **onLocalName**?(funcIndex: `number`, index: `number`, offset: `number`, length: `number`): `void`<br /> |
| 67 | + Called with each local name if present and the 'name' section is evaluated. |
| 68 | + |
| 69 | +* **Type**<br /> |
| 70 | + A value or element type, depending on context. |
| 71 | + |
| 72 | + | Name | Value |
| 73 | + |---------|------- |
| 74 | + | i32 | 0x7f |
| 75 | + | i64 | 0x7e |
| 76 | + | f32 | 0x7d |
| 77 | + | f64 | 0x7c |
| 78 | + | anyfunc | 0x70 |
| 79 | + | func | 0x60 |
| 80 | + | none | 0x40 |
| 81 | + |
| 82 | +* **SectionId**<br /> |
| 83 | + Numerical id of the current section. |
| 84 | + |
| 85 | + | Name | Value |
| 86 | + |----------|------- |
| 87 | + | Custom | 0 |
| 88 | + | Type | 1 |
| 89 | + | Import | 2 |
| 90 | + | Function | 3 |
| 91 | + | Table | 4 |
| 92 | + | Memory | 5 |
| 93 | + | Global | 6 |
| 94 | + | Export | 7 |
| 95 | + | Start | 8 |
| 96 | + | Element | 9 |
| 97 | + | Code | 10 |
| 98 | + | Data | 11 |
| 99 | + |
| 100 | +* **ExternalKind**<br /> |
| 101 | + Kind of an export or import. |
| 102 | + |
| 103 | + | Name | Value |
| 104 | + |----------|------- |
| 105 | + | Function | 0 |
| 106 | + | Table | 1 |
| 107 | + | Memory | 2 |
| 108 | + | Global | 3 |
0 commit comments