MCPcopy Create free account
hub / github.com/callstackincubator/polygen / constructor

Method constructor

packages/wasm-parser/src/module.ts:72–102  ·  view source on GitHub ↗
(buffer: ArrayBuffer)

Source from the content-addressed store, hash-verified

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));

Callers

nothing calls this directly

Calls 8

addImportsMethod · 0.95
addFunctionsMethod · 0.95
addGlobalsMethod · 0.95
addMemoriesMethod · 0.95
addTablesMethod · 0.95
addExportsMethod · 0.95
readModuleRawFunction · 0.85
mapImportFunction · 0.85

Tested by

no test coverage detected