Skip to content

Commit 8a9325a

Browse files
authored
Make use of arrow functions in worker.js. NFC (#19533)
1 parent b1ac027 commit 8a9325a

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/worker.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,15 @@ if (ENVIRONMENT_IS_NODE) {
2828

2929
Object.assign(global, {
3030
self: global,
31-
require: require,
32-
Module: Module,
31+
require,
32+
Module,
3333
location: {
3434
href: __filename
3535
},
3636
Worker: nodeWorkerThreads.Worker,
37-
importScripts: function(f) {
38-
(0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f);
39-
},
40-
postMessage: function(msg) {
41-
parentPort.postMessage(msg);
42-
},
43-
performance: global.performance || {
44-
now: function() {
45-
return Date.now();
46-
}
47-
},
37+
importScripts: (f) => (0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f),
38+
postMessage: (msg) => parentPort.postMessage(msg),
39+
performance: global.performance || { now: Date.now },
4840
});
4941
}
5042
#endif // ENVIRONMENT_MAY_BE_NODE
@@ -160,8 +152,11 @@ function handleMessage(e) {
160152
// Use `const` here to ensure that the variable is scoped only to
161153
// that iteration, allowing safe reference from a closure.
162154
for (const handler of e.data.handlers) {
163-
Module[handler] = function() {
164-
postMessage({ cmd: 'callHandler', handler, args: [...arguments] });
155+
Module[handler] = (...args) => {
156+
#if RUNTIME_DEBUG
157+
dbg(`calling handler on main thread: ${handler}`);
158+
#endif
159+
postMessage({ cmd: 'callHandler', handler, args: args });
165160
}
166161
}
167162

@@ -191,7 +186,7 @@ function handleMessage(e) {
191186
if (typeof e.data.urlOrBlob == 'string') {
192187
#if TRUSTED_TYPES
193188
if (typeof self.trustedTypes != 'undefined' && self.trustedTypes.createPolicy) {
194-
var p = self.trustedTypes.createPolicy('emscripten#workerPolicy3', { createScriptURL: function(ignored) { return e.data.urlOrBlob } });
189+
var p = self.trustedTypes.createPolicy('emscripten#workerPolicy3', { createScriptURL: (ignored) => e.data.urlOrBlob });
195190
importScripts(p.createScriptURL('ignored'));
196191
} else
197192
#endif
@@ -200,7 +195,7 @@ function handleMessage(e) {
200195
var objectUrl = URL.createObjectURL(e.data.urlOrBlob);
201196
#if TRUSTED_TYPES
202197
if (typeof self.trustedTypes != 'undefined' && self.trustedTypes.createPolicy) {
203-
var p = self.trustedTypes.createPolicy('emscripten#workerPolicy3', { createScriptURL: function(ignored) { return objectUrl } });
198+
var p = self.trustedTypes.createPolicy('emscripten#workerPolicy3', { createScriptURL: (ignored) => objectUrl });
204199
importScripts(p.createScriptURL('ignored'));
205200
} else
206201
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15455
1+
15405

0 commit comments

Comments
 (0)