-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
45 lines (35 loc) · 973 Bytes
/
worker.js
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
export default () => {
self.addEventListener('message', e => { // eslint-disable-line no-restricted-globals
if (!e) return;
// if (e && e.fn && typeof e.fn === 'function') {
// const tmp = e.fn();
// postMessage(e.fn);
// }
// postMessage(window.eval(e)())
const fn = Function(e.data)();
postMessage(fn());
// const users = [];
// const userDetails = {
// name: 'Jane Doe',
// email: '[email protected]',
// id: 1
// };
// for (let i = 0; i < 10000000; i++) {
// userDetails.id = i++
// userDetails.dateJoined = Date.now()
// users.push(userDetails);
// }
// postMessage(users);
})
}
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}