(buffer: ArrayBuffer)
| 70 | public exports: ModuleExport[] = []; |
| 71 | |
| 72 | constructor(buffer: ArrayBuffer) { |
| 73 | const sections = Object.groupBy( |
| 74 | readModuleRaw(buffer), |
| 75 | (section) => section.type |
| 76 | ); |
| 77 | |
| 78 | function getSection<T extends Section>(type: T['type']): T | undefined { |
| 79 | return sections[type]?.[0] as T | undefined; |
| 80 | } |
| 81 | |
| 82 | const types = getSection<TypeSection>('type')?.types ?? []; |
| 83 | const processedImports = getSection<ImportSection>('import')?.imports?.map( |
| 84 | (i) => mapImport(i, types) |
| 85 | ); |
| 86 | this.addImports(processedImports ?? []); |
| 87 | |
| 88 | const indices = getSection<FunctionSection>('function')?.indices ?? []; |
| 89 | const functions = indices |
| 90 | .map((i) => types?.[i]) |
| 91 | .filter(Boolean) as FunctionType[]; |
| 92 | this.addFunctions(functions); |
| 93 | |
| 94 | const globals = getSection<GlobalSection>('global')?.globals?.map( |
| 95 | (g) => g.type |
| 96 | ); |
| 97 | this.addGlobals(globals ?? []); |
| 98 | this.addMemories(getSection<MemorySection>('memory')?.memories ?? []); |
| 99 | this.addTables(getSection<TableSection>('table')?.tables ?? []); |
| 100 | |
| 101 | this.addExports(getSection<ExportSection>('export')?.exports ?? []); |
| 102 | } |
| 103 | |
| 104 | public addFunction(funcType: FunctionType) { |
| 105 | this.functions.push(mapFunction(funcType)); |
nothing calls this directly
no test coverage detected