-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworker.js
50 lines (47 loc) · 1.7 KB
/
worker.js
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
// Maybe we'll treat this like a promise
// This is where we will set up our worker thread, this will just emit the completed json document
const compilerReady = new Promise((resolve, reject) => {
self.Module = {};
self.Module.onRuntimeInitialized = () => {
try {
const config = {
vfsPrefix: "dlls",
deployPrefix: "dlls",
enableDebugging: 0
};
// TODO: fix assembly format for some of the different types
const assemblies = [
'ink_compiler.dll',
'ink-engine-runtime.dll',
'wasm-target.dll',
'mscorlib.dll',
'WebAssembly.Bindings.dll',
'netstandard.dll',
'System.dll',
'System.Core.dll'
];
MONO.mono_load_runtime_and_bcl(
config.vfsPrefix,
config.deployPrefix,
config.enableDebugging,
assemblies,
() => {
Module.mono_bindings_init("[WebAssembly.Bindings]WebAssembly.Runtime");
resolve(Module.mono_bind_static_method("[wasm-target] CompileHelper:JSON"));
}
)
} catch(ex){
reject(ex);
}
};
})
// message back the main section when we are done, at worst we can treat this like a fun global in a react app, that handles all of that part for us
importScripts("mono.js");
compilerReady.then(compile => {
postMessage("ready");
self.onmessage = function(e){
const compiled = compile(e.data);
const json = JSON.parse(compiled);
postMessage(json);
}
});