test_godot_editor / godot.tools.worker.js
thomwolf's picture
thomwolf HF staff
test
2976aff
raw
history blame
2.81 kB
"use strict";
var Module = {};
function threadPrintErr() {
var text = Array.prototype.slice.call(arguments).join(" ");
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.onmessage = (e => {
try {
if (e.data.cmd === "load") {
Module["wasmModule"] = e.data.wasmModule;
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)
}
Godot(Module).then(function(instance) { Module = instance })
} else if (e.data.cmd === "run") {
Module["__performance_now_clock_drift"] = performance.now() - e.data.time;
Module["__emscripten_thread_init"](e.data.threadInfoStruct, 0, 0, 1);
Module["establishStackSpace"]();
Module["PThread"].receiveObjectTransfer(e.data);
Module["PThread"].threadInit();
try { var result = Module["invokeEntryPoint"](e.data.start_routine, e.data.arg); if (Module["keepRuntimeAlive"]()) { Module["PThread"].setExitStatus(result) } else { Module["__emscripten_thread_exit"](result) } } 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 === "processThreadQueue") { if (Module["_pthread_self"]()) { Module["_emscripten_current_thread_process_queued_calls"]() } } else if (e.data.cmd === "processProxyingQueue") { if (Module["_pthread_self"]()) { Module["_emscripten_proxy_execute_queue"](e.data.queue) } } else {
err("worker.js received unknown command " + e.data.cmd);
err(e.data)
}
} catch (ex) { err("worker.js onmessage() captured an uncaught exception: " + ex); if (ex && ex.stack) err(ex.stack); if (Module["__emscripten_thread_crashed"]) { Module["__emscripten_thread_crashed"]() } throw ex }
});