-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibmain.worker.js
More file actions
executable file
·136 lines (136 loc) · 4.57 KB
/
libmain.worker.js
File metadata and controls
executable file
·136 lines (136 loc) · 4.57 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
"use strict";
var Module = {};
var ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
if (ENVIRONMENT_IS_NODE) {
var nodeWorkerThreads = require("worker_threads");
var parentPort = nodeWorkerThreads.parentPort;
parentPort.on("message", data=>onmessage({
data: data
}));
var fs = require("fs");
Object.assign(global, {
self: global,
require: require,
Module: Module,
location: {
href: __filename
},
Worker: nodeWorkerThreads.Worker,
importScripts: function(f) {
(0,
eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f)
},
postMessage: function(msg) {
parentPort.postMessage(msg)
},
performance: global.performance || {
now: function() {
return Date.now()
}
}
})
}
var initializedJS = false;
var pendingNotifiedProxyingQueues = [];
function threadPrintErr() {
var text = Array.prototype.slice.call(arguments).join(" ");
if (ENVIRONMENT_IS_NODE) {
fs.writeSync(2, text + "\n");
return
}
console.error(text)
}
function threadAlert() {
var text = Array.prototype.slice.call(arguments).join(" ");
postMessage({
cmd: "alert",
text: text,
threadId: Module["_pthread_self"]()
})
}
var err = threadPrintErr;
self.alert = threadAlert;
Module["instantiateWasm"] = (info,receiveInstance)=>{
var instance = new WebAssembly.Instance(Module["wasmModule"],info);
receiveInstance(instance);
Module["wasmModule"] = null;
return instance.exports
}
;
self.onunhandledrejection = e=>{
throw e.reason ?? e
}
;
self.onmessage = e=>{
try {
if (e.data.cmd === "load") {
Module["wasmModule"] = e.data.wasmModule;
for (const handler of e.data.handlers) {
Module[handler] = function() {
postMessage({
cmd: "callHandler",
handler: handler,
args: [...arguments]
})
}
}
Module["wasmMemory"] = e.data.wasmMemory;
Module["buffer"] = Module["wasmMemory"].buffer;
Module["ENVIRONMENT_IS_PTHREAD"] = true;
if (typeof e.data.urlOrBlob == "string") {
importScripts(e.data.urlOrBlob)
} else {
var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
importScripts(objectUrl);
URL.revokeObjectURL(objectUrl)
}
} else if (e.data.cmd === "run") {
Module["__performance_now_clock_drift"] = performance.now() - e.data.time;
Module["__emscripten_thread_init"](e.data.pthread_ptr, 0, 0, 1);
Module["establishStackSpace"]();
Module["PThread"].receiveObjectTransfer(e.data);
Module["PThread"].threadInitTLS();
if (!initializedJS) {
Module["__embind_initialize_bindings"]();
pendingNotifiedProxyingQueues.forEach(queue=>{
Module["executeNotifiedProxyingQueue"](queue)
}
);
pendingNotifiedProxyingQueues = [];
initializedJS = true
}
try {
Module["invokeEntryPoint"](e.data.start_routine, e.data.arg)
} catch (ex) {
if (ex != "unwind") {
if (ex instanceof Module["ExitStatus"]) {
if (Module["keepRuntimeAlive"]()) {} else {
Module["__emscripten_thread_exit"](ex.status)
}
} else {
throw ex
}
}
}
} else if (e.data.cmd === "cancel") {
if (Module["_pthread_self"]()) {
Module["__emscripten_thread_exit"](-1)
}
} else if (e.data.target === "setimmediate") {} else if (e.data.cmd === "processProxyingQueue") {
if (initializedJS) {
Module["executeNotifiedProxyingQueue"](e.data.queue)
} else {
pendingNotifiedProxyingQueues.push(e.data.queue)
}
} else if (e.data.cmd) {
err("worker.js received unknown command " + e.data.cmd);
err(e.data)
}
} catch (ex) {
if (Module["__emscripten_thread_crashed"]) {
Module["__emscripten_thread_crashed"]()
}
throw ex
}
}
;