beam-wasm-client 6.2.12511 → 6.2.12512
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/wasm-client.js +1 -13401
- package/wasm-client.wasm +0 -0
- package/wasm-client.worker.js +1 -216
package/wasm-client.wasm
CHANGED
Binary file
|
package/wasm-client.worker.js
CHANGED
@@ -1,216 +1 @@
|
|
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
|
-
// Node.js support
|
16
|
-
if (typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string') {
|
17
|
-
// Create as web-worker-like an environment as we can.
|
18
|
-
|
19
|
-
var nodeWorkerThreads = require('worker_threads');
|
20
|
-
|
21
|
-
var parentPort = nodeWorkerThreads.parentPort;
|
22
|
-
|
23
|
-
parentPort.on('message', function(data) {
|
24
|
-
onmessage({ data: data });
|
25
|
-
});
|
26
|
-
|
27
|
-
var nodeFS = require('fs');
|
28
|
-
|
29
|
-
Object.assign(global, {
|
30
|
-
self: global,
|
31
|
-
require: require,
|
32
|
-
Module: Module,
|
33
|
-
location: {
|
34
|
-
href: __filename
|
35
|
-
},
|
36
|
-
Worker: nodeWorkerThreads.Worker,
|
37
|
-
importScripts: function(f) {
|
38
|
-
(0, eval)(nodeFS.readFileSync(f, 'utf8'));
|
39
|
-
},
|
40
|
-
postMessage: function(msg) {
|
41
|
-
parentPort.postMessage(msg);
|
42
|
-
},
|
43
|
-
performance: global.performance || {
|
44
|
-
now: function() {
|
45
|
-
return Date.now();
|
46
|
-
}
|
47
|
-
},
|
48
|
-
});
|
49
|
-
}
|
50
|
-
|
51
|
-
// Thread-local:
|
52
|
-
var initializedJS = false; // Guard variable for one-time init of the JS state (currently only embind types registration)
|
53
|
-
|
54
|
-
function assert(condition, text) {
|
55
|
-
if (!condition) abort('Assertion failed: ' + text);
|
56
|
-
}
|
57
|
-
|
58
|
-
function threadPrintErr() {
|
59
|
-
var text = Array.prototype.slice.call(arguments).join(' ');
|
60
|
-
console.error(text);
|
61
|
-
}
|
62
|
-
function threadAlert() {
|
63
|
-
var text = Array.prototype.slice.call(arguments).join(' ');
|
64
|
-
postMessage({cmd: 'alert', text: text, threadId: Module['_pthread_self']()});
|
65
|
-
}
|
66
|
-
// We don't need out() for now, but may need to add it if we want to use it
|
67
|
-
// here. Or, if this code all moves into the main JS, that problem will go
|
68
|
-
// away. (For now, adding it here increases code size for no benefit.)
|
69
|
-
var out = function() {
|
70
|
-
throw 'out() is not defined in worker.js.';
|
71
|
-
}
|
72
|
-
var err = threadPrintErr;
|
73
|
-
self.alert = threadAlert;
|
74
|
-
|
75
|
-
Module['instantiateWasm'] = function(info, receiveInstance) {
|
76
|
-
// Instantiate from the module posted from the main thread.
|
77
|
-
// We can just use sync instantiation in the worker.
|
78
|
-
var instance = new WebAssembly.Instance(Module['wasmModule'], info);
|
79
|
-
// TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193,
|
80
|
-
// the above line no longer optimizes out down to the following line.
|
81
|
-
// When the regression is fixed, we can remove this if/else.
|
82
|
-
receiveInstance(instance);
|
83
|
-
// We don't need the module anymore; new threads will be spawned from the main thread.
|
84
|
-
Module['wasmModule'] = null;
|
85
|
-
return instance.exports;
|
86
|
-
};
|
87
|
-
|
88
|
-
self.onmessage = function(e) {
|
89
|
-
try {
|
90
|
-
if (e.data.cmd === 'load') { // Preload command that is called once per worker to parse and load the Emscripten code.
|
91
|
-
|
92
|
-
// Module and memory were sent from main thread
|
93
|
-
Module['wasmModule'] = e.data.wasmModule;
|
94
|
-
|
95
|
-
Module['wasmMemory'] = e.data.wasmMemory;
|
96
|
-
|
97
|
-
Module['buffer'] = Module['wasmMemory'].buffer;
|
98
|
-
|
99
|
-
Module['ENVIRONMENT_IS_PTHREAD'] = true;
|
100
|
-
|
101
|
-
if (typeof e.data.urlOrBlob === 'string') {
|
102
|
-
importScripts(e.data.urlOrBlob);
|
103
|
-
} else {
|
104
|
-
var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
|
105
|
-
importScripts(objectUrl);
|
106
|
-
URL.revokeObjectURL(objectUrl);
|
107
|
-
}
|
108
|
-
BeamModule(Module).then(function (instance) {
|
109
|
-
Module = instance;
|
110
|
-
});
|
111
|
-
} else if (e.data.cmd === 'run') {
|
112
|
-
// This worker was idle, and now should start executing its pthread entry
|
113
|
-
// point.
|
114
|
-
// performance.now() is specced to return a wallclock time in msecs since
|
115
|
-
// that Web Worker/main thread launched. However for pthreads this can
|
116
|
-
// cause subtle problems in emscripten_get_now() as this essentially
|
117
|
-
// would measure time from pthread_create(), meaning that the clocks
|
118
|
-
// between each threads would be wildly out of sync. Therefore sync all
|
119
|
-
// pthreads to the clock on the main browser thread, so that different
|
120
|
-
// threads see a somewhat coherent clock across each of them
|
121
|
-
// (+/- 0.1msecs in testing).
|
122
|
-
Module['__performance_now_clock_drift'] = performance.now() - e.data.time;
|
123
|
-
|
124
|
-
// Pass the thread address inside the asm.js scope to store it for fast access that avoids the need for a FFI out.
|
125
|
-
Module['__emscripten_thread_init'](e.data.threadInfoStruct, /*isMainBrowserThread=*/0, /*isMainRuntimeThread=*/0);
|
126
|
-
|
127
|
-
// Establish the stack frame for this thread in global scope
|
128
|
-
// The stack grows downwards
|
129
|
-
var max = e.data.stackBase;
|
130
|
-
var top = e.data.stackBase + e.data.stackSize;
|
131
|
-
assert(e.data.threadInfoStruct);
|
132
|
-
assert(top != 0);
|
133
|
-
assert(max != 0);
|
134
|
-
assert(top > max);
|
135
|
-
// Also call inside JS module to set up the stack frame for this pthread in JS module scope
|
136
|
-
Module['establishStackSpace'](top, max);
|
137
|
-
Module['PThread'].receiveObjectTransfer(e.data);
|
138
|
-
Module['PThread'].threadInit();
|
139
|
-
|
140
|
-
// Embind must initialize itself on all threads, as it generates support JS.
|
141
|
-
// We only do this once per worker since they get reused
|
142
|
-
if (!initializedJS) {
|
143
|
-
Module['___embind_register_native_and_builtin_types']();
|
144
|
-
initializedJS = true;
|
145
|
-
}
|
146
|
-
|
147
|
-
try {
|
148
|
-
// pthread entry points are always of signature 'void *ThreadMain(void *arg)'
|
149
|
-
// Native codebases sometimes spawn threads with other thread entry point signatures,
|
150
|
-
// such as void ThreadMain(void *arg), void *ThreadMain(), or void ThreadMain().
|
151
|
-
// That is not acceptable per C/C++ specification, but x86 compiler ABI extensions
|
152
|
-
// enable that to work. If you find the following line to crash, either change the signature
|
153
|
-
// to "proper" void *ThreadMain(void *arg) form, or try linking with the Emscripten linker
|
154
|
-
// flag -s EMULATE_FUNCTION_POINTER_CASTS=1 to add in emulation for this x86 ABI extension.
|
155
|
-
var result = Module['invokeEntryPoint'](e.data.start_routine, e.data.arg);
|
156
|
-
|
157
|
-
Module['checkStackCookie']();
|
158
|
-
if (Module['keepRuntimeAlive']()) {
|
159
|
-
Module['PThread'].setExitStatus(result);
|
160
|
-
} else {
|
161
|
-
Module['__emscripten_thread_exit'](result);
|
162
|
-
}
|
163
|
-
} catch(ex) {
|
164
|
-
if (ex != 'unwind') {
|
165
|
-
// FIXME(sbc): Figure out if this is still needed or useful. Its not
|
166
|
-
// clear to me how this check could ever fail. In order to get into
|
167
|
-
// this try/catch block at all we have already called bunch of
|
168
|
-
// functions on `Module`.. why is this one special?
|
169
|
-
if (typeof(Module['_emscripten_futex_wake']) !== 'function') {
|
170
|
-
err("Thread Initialisation failed.");
|
171
|
-
throw ex;
|
172
|
-
}
|
173
|
-
// ExitStatus not present in MINIMAL_RUNTIME
|
174
|
-
if (ex instanceof Module['ExitStatus']) {
|
175
|
-
if (Module['keepRuntimeAlive']()) {
|
176
|
-
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), staying alive due to noExitRuntime.');
|
177
|
-
} else {
|
178
|
-
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' called exit(), calling _emscripten_thread_exit.');
|
179
|
-
Module['__emscripten_thread_exit'](ex.status);
|
180
|
-
}
|
181
|
-
}
|
182
|
-
else
|
183
|
-
{
|
184
|
-
// The pthread "crashed". Do not call `_emscripten_thread_exit` (which
|
185
|
-
// would make this thread joinable. Instead, re-throw the exception
|
186
|
-
// and let the top level handler propagate it back to the main thread.
|
187
|
-
throw ex;
|
188
|
-
}
|
189
|
-
} else {
|
190
|
-
// else e == 'unwind', and we should fall through here and keep the pthread alive for asynchronous events.
|
191
|
-
err('Pthread 0x' + Module['_pthread_self']().toString(16) + ' completed its main entry point with an `unwind`, keeping the worker alive for asynchronous operation.');
|
192
|
-
}
|
193
|
-
}
|
194
|
-
} else if (e.data.cmd === 'cancel') { // Main thread is asking for a pthread_cancel() on this thread.
|
195
|
-
if (Module['_pthread_self']()) {
|
196
|
-
Module['__emscripten_thread_exit'](-1/*PTHREAD_CANCELED*/);
|
197
|
-
}
|
198
|
-
postMessage({ 'cmd': 'cancelDone' });
|
199
|
-
} else if (e.data.target === 'setimmediate') {
|
200
|
-
// no-op
|
201
|
-
} else if (e.data.cmd === 'processThreadQueue') {
|
202
|
-
if (Module['_pthread_self']()) { // If this thread is actually running?
|
203
|
-
Module['_emscripten_current_thread_process_queued_calls']();
|
204
|
-
}
|
205
|
-
} else {
|
206
|
-
err('worker.js received unknown command ' + e.data.cmd);
|
207
|
-
err(e.data);
|
208
|
-
}
|
209
|
-
} catch(ex) {
|
210
|
-
err('worker.js onmessage() captured an uncaught exception: ' + ex);
|
211
|
-
if (ex && ex.stack) err(ex.stack);
|
212
|
-
throw ex;
|
213
|
-
}
|
214
|
-
};
|
215
|
-
|
216
|
-
|
1
|
+
"use strict";var Module={};if(typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string"){var nodeWorkerThreads=require("worker_threads");var parentPort=nodeWorkerThreads.parentPort;parentPort.on("message",function(data){onmessage({data:data})});var nodeFS=require("fs");Object.assign(global,{self:global,require:require,Module:Module,location:{href:__filename},Worker:nodeWorkerThreads.Worker,importScripts:function(f){(0,eval)(nodeFS.readFileSync(f,"utf8"))},postMessage:function(msg){parentPort.postMessage(msg)},performance:global.performance||{now:function(){return Date.now()}}})}var initializedJS=false;function assert(condition,text){if(!condition)abort("Assertion failed: "+text)}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 out=function(){throw"out() is not defined in worker.js."};var err=threadPrintErr;self.alert=threadAlert;Module["instantiateWasm"]=function(info,receiveInstance){var instance=new WebAssembly.Instance(Module["wasmModule"],info);receiveInstance(instance);Module["wasmModule"]=null;return instance.exports};self.onmessage=function(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)}BeamModule(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);var max=e.data.stackBase;var top=e.data.stackBase+e.data.stackSize;assert(e.data.threadInfoStruct);assert(top!=0);assert(max!=0);assert(top>max);Module["establishStackSpace"](top,max);Module["PThread"].receiveObjectTransfer(e.data);Module["PThread"].threadInit();if(!initializedJS){Module["___embind_register_native_and_builtin_types"]();initializedJS=true}try{var result=Module["invokeEntryPoint"](e.data.start_routine,e.data.arg);Module["checkStackCookie"]();if(Module["keepRuntimeAlive"]()){Module["PThread"].setExitStatus(result)}else{Module["__emscripten_thread_exit"](result)}}catch(ex){if(ex!="unwind"){if(typeof Module["_emscripten_futex_wake"]!=="function"){err("Thread Initialisation failed.");throw ex}if(ex instanceof Module["ExitStatus"]){if(Module["keepRuntimeAlive"]()){err("Pthread 0x"+Module["_pthread_self"]().toString(16)+" called exit(), staying alive due to noExitRuntime.")}else{err("Pthread 0x"+Module["_pthread_self"]().toString(16)+" called exit(), calling _emscripten_thread_exit.");Module["__emscripten_thread_exit"](ex.status)}}else{throw ex}}else{err("Pthread 0x"+Module["_pthread_self"]().toString(16)+" completed its main entry point with an `unwind`, keeping the worker alive for asynchronous operation.")}}}else if(e.data.cmd==="cancel"){if(Module["_pthread_self"]()){Module["__emscripten_thread_exit"](-1)}postMessage({"cmd":"cancelDone"})}else if(e.data.target==="setimmediate"){}else if(e.data.cmd==="processThreadQueue"){if(Module["_pthread_self"]()){Module["_emscripten_current_thread_process_queued_calls"]()}}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);throw ex}};
|