Akjava commited on
Commit
ced275e
·
verified ·
1 Parent(s): f0639da

Upload 9 files

Browse files
Godot-simple-groq-api.apple-touch-icon.png ADDED
Godot-simple-groq-api.audio.worklet.js ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**************************************************************************/
2
+ /* audio.worklet.js */
3
+ /**************************************************************************/
4
+ /* This file is part of: */
5
+ /* GODOT ENGINE */
6
+ /* https://godotengine.org */
7
+ /**************************************************************************/
8
+ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
+ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
+ /* */
11
+ /* Permission is hereby granted, free of charge, to any person obtaining */
12
+ /* a copy of this software and associated documentation files (the */
13
+ /* "Software"), to deal in the Software without restriction, including */
14
+ /* without limitation the rights to use, copy, modify, merge, publish, */
15
+ /* distribute, sublicense, and/or sell copies of the Software, and to */
16
+ /* permit persons to whom the Software is furnished to do so, subject to */
17
+ /* the following conditions: */
18
+ /* */
19
+ /* The above copyright notice and this permission notice shall be */
20
+ /* included in all copies or substantial portions of the Software. */
21
+ /* */
22
+ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
+ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
+ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
+ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
+ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
+ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
+ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
+ /**************************************************************************/
30
+
31
+ class RingBuffer {
32
+ constructor(p_buffer, p_state, p_threads) {
33
+ this.buffer = p_buffer;
34
+ this.avail = p_state;
35
+ this.threads = p_threads;
36
+ this.rpos = 0;
37
+ this.wpos = 0;
38
+ }
39
+
40
+ data_left() {
41
+ return this.threads ? Atomics.load(this.avail, 0) : this.avail;
42
+ }
43
+
44
+ space_left() {
45
+ return this.buffer.length - this.data_left();
46
+ }
47
+
48
+ read(output) {
49
+ const size = this.buffer.length;
50
+ let from = 0;
51
+ let to_write = output.length;
52
+ if (this.rpos + to_write > size) {
53
+ const high = size - this.rpos;
54
+ output.set(this.buffer.subarray(this.rpos, size));
55
+ from = high;
56
+ to_write -= high;
57
+ this.rpos = 0;
58
+ }
59
+ if (to_write) {
60
+ output.set(this.buffer.subarray(this.rpos, this.rpos + to_write), from);
61
+ }
62
+ this.rpos += to_write;
63
+ if (this.threads) {
64
+ Atomics.add(this.avail, 0, -output.length);
65
+ Atomics.notify(this.avail, 0);
66
+ } else {
67
+ this.avail -= output.length;
68
+ }
69
+ }
70
+
71
+ write(p_buffer) {
72
+ const to_write = p_buffer.length;
73
+ const mw = this.buffer.length - this.wpos;
74
+ if (mw >= to_write) {
75
+ this.buffer.set(p_buffer, this.wpos);
76
+ this.wpos += to_write;
77
+ if (mw === to_write) {
78
+ this.wpos = 0;
79
+ }
80
+ } else {
81
+ const high = p_buffer.subarray(0, mw);
82
+ const low = p_buffer.subarray(mw);
83
+ this.buffer.set(high, this.wpos);
84
+ this.buffer.set(low);
85
+ this.wpos = low.length;
86
+ }
87
+ if (this.threads) {
88
+ Atomics.add(this.avail, 0, to_write);
89
+ Atomics.notify(this.avail, 0);
90
+ } else {
91
+ this.avail += to_write;
92
+ }
93
+ }
94
+ }
95
+
96
+ class GodotProcessor extends AudioWorkletProcessor {
97
+ constructor() {
98
+ super();
99
+ this.threads = false;
100
+ this.running = true;
101
+ this.lock = null;
102
+ this.notifier = null;
103
+ this.output = null;
104
+ this.output_buffer = new Float32Array();
105
+ this.input = null;
106
+ this.input_buffer = new Float32Array();
107
+ this.port.onmessage = (event) => {
108
+ const cmd = event.data['cmd'];
109
+ const data = event.data['data'];
110
+ this.parse_message(cmd, data);
111
+ };
112
+ }
113
+
114
+ process_notify() {
115
+ if (this.notifier) {
116
+ Atomics.add(this.notifier, 0, 1);
117
+ Atomics.notify(this.notifier, 0);
118
+ }
119
+ }
120
+
121
+ parse_message(p_cmd, p_data) {
122
+ if (p_cmd === 'start' && p_data) {
123
+ const state = p_data[0];
124
+ let idx = 0;
125
+ this.threads = true;
126
+ this.lock = state.subarray(idx, ++idx);
127
+ this.notifier = state.subarray(idx, ++idx);
128
+ const avail_in = state.subarray(idx, ++idx);
129
+ const avail_out = state.subarray(idx, ++idx);
130
+ this.input = new RingBuffer(p_data[1], avail_in, true);
131
+ this.output = new RingBuffer(p_data[2], avail_out, true);
132
+ } else if (p_cmd === 'stop') {
133
+ this.running = false;
134
+ this.output = null;
135
+ this.input = null;
136
+ this.lock = null;
137
+ this.notifier = null;
138
+ } else if (p_cmd === 'start_nothreads') {
139
+ this.output = new RingBuffer(p_data[0], p_data[0].length, false);
140
+ } else if (p_cmd === 'chunk') {
141
+ this.output.write(p_data);
142
+ }
143
+ }
144
+
145
+ static array_has_data(arr) {
146
+ return arr.length && arr[0].length && arr[0][0].length;
147
+ }
148
+
149
+ process(inputs, outputs, parameters) {
150
+ if (!this.running) {
151
+ return false; // Stop processing.
152
+ }
153
+ if (this.output === null) {
154
+ return true; // Not ready yet, keep processing.
155
+ }
156
+ const process_input = GodotProcessor.array_has_data(inputs);
157
+ if (process_input) {
158
+ const input = inputs[0];
159
+ const chunk = input[0].length * input.length;
160
+ if (this.input_buffer.length !== chunk) {
161
+ this.input_buffer = new Float32Array(chunk);
162
+ }
163
+ if (!this.threads) {
164
+ GodotProcessor.write_input(this.input_buffer, input);
165
+ this.port.postMessage({ 'cmd': 'input', 'data': this.input_buffer });
166
+ } else if (this.input.space_left() >= chunk) {
167
+ GodotProcessor.write_input(this.input_buffer, input);
168
+ this.input.write(this.input_buffer);
169
+ } else {
170
+ // this.port.postMessage('Input buffer is full! Skipping input frame.'); // Uncomment this line to debug input buffer.
171
+ }
172
+ }
173
+ const process_output = GodotProcessor.array_has_data(outputs);
174
+ if (process_output) {
175
+ const output = outputs[0];
176
+ const chunk = output[0].length * output.length;
177
+ if (this.output_buffer.length !== chunk) {
178
+ this.output_buffer = new Float32Array(chunk);
179
+ }
180
+ if (this.output.data_left() >= chunk) {
181
+ this.output.read(this.output_buffer);
182
+ GodotProcessor.write_output(output, this.output_buffer);
183
+ if (!this.threads) {
184
+ this.port.postMessage({ 'cmd': 'read', 'data': chunk });
185
+ }
186
+ } else {
187
+ // this.port.postMessage('Output buffer has not enough frames! Skipping output frame.'); // Uncomment this line to debug output buffer.
188
+ }
189
+ }
190
+ this.process_notify();
191
+ return true;
192
+ }
193
+
194
+ static write_output(dest, source) {
195
+ const channels = dest.length;
196
+ for (let ch = 0; ch < channels; ch++) {
197
+ for (let sample = 0; sample < dest[ch].length; sample++) {
198
+ dest[ch][sample] = source[sample * channels + ch];
199
+ }
200
+ }
201
+ }
202
+
203
+ static write_input(dest, source) {
204
+ const channels = source.length;
205
+ for (let ch = 0; ch < channels; ch++) {
206
+ for (let sample = 0; sample < source[ch].length; sample++) {
207
+ dest[sample * channels + ch] = source[ch][sample];
208
+ }
209
+ }
210
+ }
211
+ }
212
+
213
+ registerProcessor('godot-processor', GodotProcessor);
Godot-simple-groq-api.html ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
6
+ <title>Godot-groq-moa</title>
7
+ <style>
8
+ html, body, #canvas {
9
+ margin: 0;
10
+ padding: 0;
11
+ border: 0;
12
+ }
13
+
14
+ body {
15
+ color: white;
16
+ background-color: black;
17
+ overflow: hidden;
18
+ touch-action: none;
19
+ }
20
+
21
+ #canvas {
22
+ display: block;
23
+ }
24
+
25
+ #canvas:focus {
26
+ outline: none;
27
+ }
28
+
29
+ #status, #status-splash, #status-progress {
30
+ position: absolute;
31
+ left: 0;
32
+ right: 0;
33
+ }
34
+
35
+ #status, #status-splash {
36
+ top: 0;
37
+ bottom: 0;
38
+ }
39
+
40
+ #status {
41
+ background-color: #242424;
42
+ display: flex;
43
+ flex-direction: column;
44
+ justify-content: center;
45
+ align-items: center;
46
+ visibility: hidden;
47
+ }
48
+
49
+ #status-splash {
50
+ max-height: 100%;
51
+ max-width: 100%;
52
+ margin: auto;
53
+ }
54
+
55
+ #status-progress, #status-notice {
56
+ display: none;
57
+ }
58
+
59
+ #status-progress {
60
+ bottom: 10%;
61
+ width: 50%;
62
+ margin: 0 auto;
63
+ }
64
+
65
+ #status-notice {
66
+ background-color: #5b3943;
67
+ border-radius: 0.5rem;
68
+ border: 1px solid #9b3943;
69
+ color: #e0e0e0;
70
+ font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
71
+ line-height: 1.3;
72
+ margin: 0 2rem;
73
+ overflow: hidden;
74
+ padding: 1rem;
75
+ text-align: center;
76
+ z-index: 1;
77
+ }
78
+ </style>
79
+ <link id="-gd-engine-icon" rel="icon" type="image/png" href="Godot-simple-groq-api.icon.png" />
80
+ <link rel="apple-touch-icon" href="Godot-simple-groq-api.apple-touch-icon.png"/>
81
+
82
+ </head>
83
+ <body>
84
+ <canvas id="canvas">
85
+ Your browser does not support the canvas tag.
86
+ </canvas>
87
+
88
+ <noscript>
89
+ Your browser does not support JavaScript.
90
+ </noscript>
91
+
92
+ <div id="status">
93
+ <img id="status-splash" src="Godot-simple-groq-api.png" alt="">
94
+ <progress id="status-progress"></progress>
95
+ <div id="status-notice"></div>
96
+ </div>
97
+
98
+ <script src="Godot-simple-groq-api.js"></script>
99
+ <script>
100
+ const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":true,"executable":"Godot-simple-groq-api","experimentalVK":false,"fileSizes":{"Godot-simple-groq-api.pck":4365936,"Godot-simple-groq-api.wasm":35372023},"focusCanvas":true,"gdextensionLibs":[]};
101
+ const GODOT_THREADS_ENABLED = false;
102
+ const engine = new Engine(GODOT_CONFIG);
103
+
104
+ (function () {
105
+ const statusOverlay = document.getElementById('status');
106
+ const statusProgress = document.getElementById('status-progress');
107
+ const statusNotice = document.getElementById('status-notice');
108
+
109
+ let initializing = true;
110
+ let statusMode = '';
111
+
112
+ function setStatusMode(mode) {
113
+ if (statusMode === mode || !initializing) {
114
+ return;
115
+ }
116
+ if (mode === 'hidden') {
117
+ statusOverlay.remove();
118
+ initializing = false;
119
+ return;
120
+ }
121
+ statusOverlay.style.visibility = 'visible';
122
+ statusProgress.style.display = mode === 'progress' ? 'block' : 'none';
123
+ statusNotice.style.display = mode === 'notice' ? 'block' : 'none';
124
+ statusMode = mode;
125
+ }
126
+
127
+ function setStatusNotice(text) {
128
+ while (statusNotice.lastChild) {
129
+ statusNotice.removeChild(statusNotice.lastChild);
130
+ }
131
+ const lines = text.split('\n');
132
+ lines.forEach((line) => {
133
+ statusNotice.appendChild(document.createTextNode(line));
134
+ statusNotice.appendChild(document.createElement('br'));
135
+ });
136
+ }
137
+
138
+ function displayFailureNotice(err) {
139
+ console.error(err);
140
+ if (err instanceof Error) {
141
+ setStatusNotice(err.message);
142
+ } else if (typeof err === 'string') {
143
+ setStatusNotice(err);
144
+ } else {
145
+ setStatusNotice('An unknown error occured');
146
+ }
147
+ setStatusMode('notice');
148
+ initializing = false;
149
+ }
150
+
151
+ const missing = Engine.getMissingFeatures({
152
+ threads: GODOT_THREADS_ENABLED,
153
+ });
154
+
155
+ if (missing.length !== 0) {
156
+ if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) {
157
+ // There's a chance that installing the service worker would fix the issue
158
+ Promise.race([
159
+ navigator.serviceWorker.getRegistration().then((registration) => {
160
+ if (registration != null) {
161
+ return Promise.reject(new Error('Service worker already exists.'));
162
+ }
163
+ return registration;
164
+ }).then(() => engine.installServiceWorker()),
165
+ // For some reason, `getRegistration()` can stall
166
+ new Promise((resolve) => {
167
+ setTimeout(() => resolve(), 2000);
168
+ }),
169
+ ]).catch((err) => {
170
+ console.error('Error while registering service worker:', err);
171
+ }).then(() => {
172
+ window.location.reload();
173
+ });
174
+ } else {
175
+ // Display the message as usual
176
+ const missingMsg = 'Error\nThe following features required to run Godot projects on the Web are missing:\n';
177
+ displayFailureNotice(missingMsg + missing.join('\n'));
178
+ }
179
+ } else {
180
+ setStatusMode('progress');
181
+ engine.startGame({
182
+ 'onProgress': function (current, total) {
183
+ if (current > 0 && total > 0) {
184
+ statusProgress.value = current;
185
+ statusProgress.max = total;
186
+ } else {
187
+ statusProgress.removeAttribute('value');
188
+ statusProgress.removeAttribute('max');
189
+ }
190
+ },
191
+ }).then(() => {
192
+ setStatusMode('hidden');
193
+ }, displayFailureNotice);
194
+ }
195
+ }());
196
+ </script>
197
+ </body>
198
+ </html>
199
+
Godot-simple-groq-api.icon.png ADDED
Godot-simple-groq-api.js ADDED
The diff for this file is too large to render. See raw diff
 
Godot-simple-groq-api.png ADDED
Godot-simple-groq-api.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0cfd538cbf628a5626cd48db5e4ec7f883dcc22e1548b06fbe01b3450db316b9
3
+ size 35372023
Godot-simple-groq-api.worker.js ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2015 The Emscripten Authors
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ // Pthread Web Worker startup routine:
8
+ // This is the entry point file that is loaded first by each Web Worker
9
+ // that executes pthreads on the Emscripten application.
10
+
11
+ 'use strict';
12
+
13
+ var Module = {};
14
+
15
+ // Thread-local guard variable for one-time init of the JS state
16
+ var initializedJS = false;
17
+
18
+ function assert(condition, text) {
19
+ if (!condition) abort('Assertion failed: ' + text);
20
+ }
21
+
22
+ function threadPrintErr() {
23
+ var text = Array.prototype.slice.call(arguments).join(' ');
24
+ console.error(text);
25
+ }
26
+ function threadAlert() {
27
+ var text = Array.prototype.slice.call(arguments).join(' ');
28
+ postMessage({cmd: 'alert', text: text, threadId: Module['_pthread_self']()});
29
+ }
30
+ // We don't need out() for now, but may need to add it if we want to use it
31
+ // here. Or, if this code all moves into the main JS, that problem will go
32
+ // away. (For now, adding it here increases code size for no benefit.)
33
+ var out = () => { throw 'out() is not defined in worker.js.'; }
34
+ var err = threadPrintErr;
35
+ self.alert = threadAlert;
36
+
37
+ Module['instantiateWasm'] = (info, receiveInstance) => {
38
+ // Instantiate from the module posted from the main thread.
39
+ // We can just use sync instantiation in the worker.
40
+ var module = Module['wasmModule'];
41
+ // We don't need the module anymore; new threads will be spawned from the main thread.
42
+ Module['wasmModule'] = null;
43
+ var instance = new WebAssembly.Instance(module, info);
44
+ // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193,
45
+ // the above line no longer optimizes out down to the following line.
46
+ // When the regression is fixed, we can remove this if/else.
47
+ return receiveInstance(instance);
48
+ }
49
+
50
+ // Turn unhandled rejected promises into errors so that the main thread will be
51
+ // notified about them.
52
+ self.onunhandledrejection = (e) => {
53
+ throw e.reason ?? e;
54
+ };
55
+
56
+ function handleMessage(e) {
57
+ try {
58
+ if (e.data.cmd === 'load') { // Preload command that is called once per worker to parse and load the Emscripten code.
59
+
60
+ // Until we initialize the runtime, queue up any further incoming messages.
61
+ let messageQueue = [];
62
+ self.onmessage = (e) => messageQueue.push(e);
63
+
64
+ // And add a callback for when the runtime is initialized.
65
+ self.startWorker = (instance) => {
66
+ Module = instance;
67
+ // Notify the main thread that this thread has loaded.
68
+ postMessage({ 'cmd': 'loaded' });
69
+ // Process any messages that were queued before the thread was ready.
70
+ for (let msg of messageQueue) {
71
+ handleMessage(msg);
72
+ }
73
+ // Restore the real message handler.
74
+ self.onmessage = handleMessage;
75
+ };
76
+
77
+ // Module and memory were sent from main thread
78
+ Module['wasmModule'] = e.data.wasmModule;
79
+
80
+ // Use `const` here to ensure that the variable is scoped only to
81
+ // that iteration, allowing safe reference from a closure.
82
+ for (const handler of e.data.handlers) {
83
+ Module[handler] = function() {
84
+ postMessage({ cmd: 'callHandler', handler, args: [...arguments] });
85
+ }
86
+ }
87
+
88
+ Module['wasmMemory'] = e.data.wasmMemory;
89
+
90
+ Module['buffer'] = Module['wasmMemory'].buffer;
91
+
92
+ Module['workerID'] = e.data.workerID;
93
+
94
+ Module['ENVIRONMENT_IS_PTHREAD'] = true;
95
+
96
+ if (typeof e.data.urlOrBlob == 'string') {
97
+ importScripts(e.data.urlOrBlob);
98
+ } else {
99
+ var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
100
+ importScripts(objectUrl);
101
+ URL.revokeObjectURL(objectUrl);
102
+ }
103
+ Godot(Module);
104
+ } else if (e.data.cmd === 'run') {
105
+ // Pass the thread address to wasm to store it for fast access.
106
+ Module['__emscripten_thread_init'](e.data.pthread_ptr, /*isMainBrowserThread=*/0, /*isMainRuntimeThread=*/0, /*canBlock=*/1);
107
+
108
+ // Await mailbox notifications with `Atomics.waitAsync` so we can start
109
+ // using the fast `Atomics.notify` notification path.
110
+ Module['__emscripten_thread_mailbox_await'](e.data.pthread_ptr);
111
+
112
+ assert(e.data.pthread_ptr);
113
+ // Also call inside JS module to set up the stack frame for this pthread in JS module scope
114
+ Module['establishStackSpace']();
115
+ Module['PThread'].receiveObjectTransfer(e.data);
116
+ Module['PThread'].threadInitTLS();
117
+
118
+ if (!initializedJS) {
119
+ initializedJS = true;
120
+ }
121
+
122
+ try {
123
+ Module['invokeEntryPoint'](e.data.start_routine, e.data.arg);
124
+ } catch(ex) {
125
+ if (ex != 'unwind') {
126
+ // The pthread "crashed". Do not call `_emscripten_thread_exit` (which
127
+ // would make this thread joinable). Instead, re-throw the exception
128
+ // and let the top level handler propagate it back to the main thread.
129
+ throw ex;
130
+ }
131
+ }
132
+ } else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.
133
+ if (Module['_pthread_self']()) {
134
+ Module['__emscripten_thread_exit'](-1);
135
+ }
136
+ } else if (e.data.target === 'setimmediate') {
137
+ // no-op
138
+ } else if (e.data.cmd === 'checkMailbox') {
139
+ if (initializedJS) {
140
+ Module['checkMailbox']();
141
+ }
142
+ } else if (e.data.cmd) {
143
+ // The received message looks like something that should be handled by this message
144
+ // handler, (since there is a e.data.cmd field present), but is not one of the
145
+ // recognized commands:
146
+ err('worker.js received unknown command ' + e.data.cmd);
147
+ err(e.data);
148
+ }
149
+ } catch(ex) {
150
+ err('worker.js onmessage() captured an uncaught exception: ' + ex);
151
+ if (ex && ex.stack) err(ex.stack);
152
+ if (Module['__emscripten_thread_crashed']) {
153
+ Module['__emscripten_thread_crashed']();
154
+ }
155
+ throw ex;
156
+ }
157
+ };
158
+
159
+ self.onmessage = handleMessage;
160
+
161
+