|
| 1 | +///////////////////////////// |
| 2 | +/// WebAssembly APIs |
| 3 | +///////////////////////////// |
| 4 | + |
| 5 | +declare namespace WebAssembly { |
| 6 | + interface CompileError extends Error { |
| 7 | + } |
| 8 | + |
| 9 | + var CompileError: { |
| 10 | + prototype: CompileError; |
| 11 | + new(message?: string): CompileError; |
| 12 | + (message?: string): CompileError; |
| 13 | + }; |
| 14 | + |
| 15 | + interface Global { |
| 16 | + value: any; |
| 17 | + valueOf(): any; |
| 18 | + } |
| 19 | + |
| 20 | + var Global: { |
| 21 | + prototype: Global; |
| 22 | + new(descriptor: GlobalDescriptor, v?: any): Global; |
| 23 | + }; |
| 24 | + |
| 25 | + interface Instance { |
| 26 | + readonly exports: Exports; |
| 27 | + } |
| 28 | + |
| 29 | + var Instance: { |
| 30 | + prototype: Instance; |
| 31 | + new(module: Module, importObject?: Imports): Instance; |
| 32 | + }; |
| 33 | + |
| 34 | + interface LinkError extends Error { |
| 35 | + } |
| 36 | + |
| 37 | + var LinkError: { |
| 38 | + prototype: LinkError; |
| 39 | + new(message?: string): LinkError; |
| 40 | + (message?: string): LinkError; |
| 41 | + }; |
| 42 | + |
| 43 | + interface Memory { |
| 44 | + readonly buffer: ArrayBuffer; |
| 45 | + grow(delta: number): number; |
| 46 | + } |
| 47 | + |
| 48 | + var Memory: { |
| 49 | + prototype: Memory; |
| 50 | + new(descriptor: MemoryDescriptor): Memory; |
| 51 | + }; |
| 52 | + |
| 53 | + interface Module { |
| 54 | + } |
| 55 | + |
| 56 | + var Module: { |
| 57 | + prototype: Module; |
| 58 | + new(bytes: BufferSource): Module; |
| 59 | + customSections(moduleObject: Module, sectionName: string): ArrayBuffer[]; |
| 60 | + exports(moduleObject: Module): ModuleExportDescriptor[]; |
| 61 | + imports(moduleObject: Module): ModuleImportDescriptor[]; |
| 62 | + }; |
| 63 | + |
| 64 | + interface RuntimeError extends Error { |
| 65 | + } |
| 66 | + |
| 67 | + var RuntimeError: { |
| 68 | + prototype: RuntimeError; |
| 69 | + new(message?: string): RuntimeError; |
| 70 | + (message?: string): RuntimeError; |
| 71 | + }; |
| 72 | + |
| 73 | + interface Table { |
| 74 | + readonly length: number; |
| 75 | + get(index: number): any; |
| 76 | + grow(delta: number, value?: any): number; |
| 77 | + set(index: number, value?: any): void; |
| 78 | + } |
| 79 | + |
| 80 | + var Table: { |
| 81 | + prototype: Table; |
| 82 | + new(descriptor: TableDescriptor, value?: any): Table; |
| 83 | + }; |
| 84 | + |
| 85 | + interface GlobalDescriptor { |
| 86 | + mutable?: boolean; |
| 87 | + value: ValueType; |
| 88 | + } |
| 89 | + |
| 90 | + interface MemoryDescriptor { |
| 91 | + initial: number; |
| 92 | + maximum?: number; |
| 93 | + shared?: boolean; |
| 94 | + } |
| 95 | + |
| 96 | + interface ModuleExportDescriptor { |
| 97 | + kind: ImportExportKind; |
| 98 | + name: string; |
| 99 | + } |
| 100 | + |
| 101 | + interface ModuleImportDescriptor { |
| 102 | + kind: ImportExportKind; |
| 103 | + module: string; |
| 104 | + name: string; |
| 105 | + } |
| 106 | + |
| 107 | + interface TableDescriptor { |
| 108 | + element: TableKind; |
| 109 | + initial: number; |
| 110 | + maximum?: number; |
| 111 | + } |
| 112 | + |
| 113 | + interface WebAssemblyInstantiatedSource { |
| 114 | + instance: Instance; |
| 115 | + module: Module; |
| 116 | + } |
| 117 | + |
| 118 | + type ImportExportKind = "function" | "global" | "memory" | "table"; |
| 119 | + type TableKind = "anyfunc" | "externref"; |
| 120 | + type ValueType = "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64"; |
| 121 | + type ExportValue = Function | Global | Memory | Table; |
| 122 | + type Exports = Record<string, ExportValue>; |
| 123 | + type ImportValue = ExportValue | number; |
| 124 | + type Imports = Record<string, ModuleImports>; |
| 125 | + type ModuleImports = Record<string, ImportValue>; |
| 126 | + function compile(bytes: BufferSource): Promise<Module>; |
| 127 | + function instantiate(bytes: BufferSource, importObject?: Imports): Promise<WebAssemblyInstantiatedSource>; |
| 128 | + function instantiate(moduleObject: Module, importObject?: Imports): Promise<Instance>; |
| 129 | + function validate(bytes: BufferSource): boolean; |
| 130 | +} |
| 131 | + |
| 132 | +type BufferSource = ArrayBufferView | ArrayBuffer; |
0 commit comments