-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathinstantiate.d.ts
More file actions
146 lines (137 loc) · 3.99 KB
/
instantiate.d.ts
File metadata and controls
146 lines (137 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* #if USE_SHARED_MEMORY */
import type { SwiftRuntimeThreadChannel } from "./runtime.js";
/* #endif */
/* #if HAS_BRIDGE */
export type { Imports, Exports } from "./bridge-js.js";
import type { Imports, Exports } from "./bridge-js.js";
/* #else */
export type Imports = {}
export type Exports = {}
/* #endif */
/**
* The path to the WebAssembly module relative to the root of the package
*/
export declare const MODULE_PATH: string;
/* #if USE_SHARED_MEMORY */
/**
* The type of the WebAssembly memory imported by the module
*/
export declare const MEMORY_TYPE: {
initial: number,
maximum: number,
shared: boolean
}
/* #endif */
export interface WASI {
/**
* The WASI Preview 1 import object
*/
wasiImport: WebAssembly.ModuleImports
/**
* Initialize the WASI reactor instance
*
* @param instance - The instance of the WebAssembly module
*/
initialize(instance: WebAssembly.Instance): void
/**
* Set a new instance of the WebAssembly module to the WASI context
* Typically used when instantiating a WebAssembly module for a thread
*
* @param instance - The instance of the WebAssembly module
*/
setInstance(instance: WebAssembly.Instance): void
/**
* Extract a file from the WASI filesystem
*
* @param path - The path to the file to extract
* @returns The data of the file if it was extracted, undefined otherwise
*/
extractFile?(path: string): Uint8Array | undefined
}
export type SwiftRuntime = {
UnsafeEventLoopYield: { [Symbol.hasInstance]: (value: unknown) => boolean }
main(): void;
startThread(tid: number, startArg: number): void;
}
export type ModuleSource = WebAssembly.Module | ArrayBufferView | ArrayBuffer | Response | PromiseLike<Response>
/**
* The options for instantiating a WebAssembly module
*/
export type InstantiateOptions = {
/**
* The WebAssembly namespace to use for instantiation.
* Defaults to the globalThis.WebAssembly object.
*/
WebAssembly?: typeof globalThis.WebAssembly,
/**
* The WebAssembly module to instantiate
*/
module: ModuleSource,
/* #if HAS_IMPORTS */
/**
* The imports provided by the embedder
*/
imports: Imports,
/* #endif */
/* #if IS_WASI */
/**
* The WASI implementation to use
*/
wasi: WASI,
/* #endif */
/* #if USE_SHARED_MEMORY */
/**
* The WebAssembly memory to use (must be 'shared')
*/
memory: WebAssembly.Memory
/**
* The thread channel is a set of functions that are used to communicate
* between the main thread and the worker thread.
*/
threadChannel: SwiftRuntimeThreadChannel & {
spawnThread: (module: WebAssembly.Module, memory: WebAssembly.Memory, startArg: any) => number;
}
/* #endif */
/**
* Add imports to the WebAssembly import object
* @param imports - The imports to add
* @param context - The context object
*/
addToCoreImports?: (
imports: WebAssembly.Imports,
context: {
getInstance: () => WebAssembly.Instance | null,
getExports: () => Exports | null,
_swift: SwiftRuntime,
}
) => void
/**
* Instrument the WebAssembly instance
*
* @param instance - The instance of the WebAssembly module
* @param context - The context object
* @returns The instrumented instance
*/
instrumentInstance?: (
instance: WebAssembly.Instance,
context: {
_swift: SwiftRuntime
}
) => WebAssembly.Instance
}
/**
* Instantiate the given WebAssembly module
*/
export declare function instantiate(options: InstantiateOptions): Promise<{
instance: WebAssembly.Instance,
swift: SwiftRuntime,
exports: Exports
}>
/**
* Instantiate the given WebAssembly module for a thread
*/
export declare function instantiateForThread(tid: number, startArg: number, options: InstantiateOptions): Promise<{
instance: WebAssembly.Instance,
swift: SwiftRuntime,
exports: Exports
}>