-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathloader.ts
42 lines (38 loc) · 881 Bytes
/
loader.ts
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
import shims from "./shims";
import { compileModule } from "./compiler";
import { EelVersion } from "./types";
type LoadModuleOptions = {
pools: {
[name: string]: {
[name: string]: WebAssembly.Global;
};
};
functions: {
[name: string]: {
pool: string;
code: string;
};
};
eelVersion?: EelVersion;
};
export async function loadModule({
pools,
functions,
eelVersion = 2,
}: LoadModuleOptions) {
let compilerPools: { [name: string]: Set<string> } = {};
Object.entries(pools).forEach(([key, globals]) => {
compilerPools[key] = new Set(Object.keys(globals));
});
const buffer = compileModule({
pools: compilerPools,
functions,
eelVersion,
});
const mod = await WebAssembly.compile(buffer);
var importObject = {
...pools,
shims,
};
return await WebAssembly.instantiate(mod, importObject);
}