• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

naver / billboard.js / 5829678459

pending completion
5829678459

push

github

web-flow
chore(build): Rename plugin packaged file name (#3335)

- Set plugin dist files name to contain 'pkgd' as postfix.
- Remove '@babel/plugin-transform-block-scoping' plugin wich transpiles incorrectly

Fix #3334

5739 of 6614 branches covered (86.77%)

Branch coverage included in aggregate %.

7566 of 7934 relevant lines covered (95.36%)

20583.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/src/module/worker.ts
1
/**
2
 * Copyright (c) 2017 ~ present NAVER Corp.
3
 * billboard.js project is licensed under the MIT license
4
 */
5
import {window} from "./browser";
6

7
// Store blob in memory
8
const blob = {};
3✔
9

10
/**
11
 * Get Object URL
12
 * @param {Function} fn Function to be executed in worker
13
 * @param {Array} depsFn Dependency functions to run given function(fn).
14
 * @returns {string}
15
 * @private
16
 */
17
function getObjectURL(fn: Function, depsFn?: Function[]): string {
18
        const fnString = fn.toString();
3✔
19
        const key = fnString.replace(/(function|[\s\W\n])/g, "").substring(0, 15);
3✔
20

21
        if (!(key in blob)) {
3!
22
                // Web Worker body
23
                blob[key] = new window.Blob([
3✔
24
                        `${depsFn?.map(String).join(";") ?? ""}
6!
25

26
                        self.onmessage=function({data}) {
27
                                const result = (${fnString}).apply(null, data);
28
                                self.postMessage(result);
29
                        };`
30
                ], {
31
                        type: "text/javascript"
32
                });
33
        }
34

35
        return window.URL.createObjectURL(blob[key]);
3✔
36
}
37

38
/**
39
 * Create and run on Web Worker
40
 * @param {boolean} useWorker Use Web Worker
41
 * @param {Function} fn Function to be executed in worker
42
 * @param {Function} callback Callback function to receive result from worker
43
 * @param {Array} depsFn Dependency functions to run given function(fn).
44
 * @returns {object}
45
 * @example
46
 *         const worker = runWorker(function(arg) {
47
 *                  // do some tasks...
48
 *                  console.log("param:", A(arg));
49
 *
50
 *                  return 1234;
51
 *           }, function(data) {
52
 *                  // callback after worker is done
53
 *                   console.log("result:", data);
54
 *           },
55
 *           [function A(){}]
56
 *        );
57
 *
58
 *        worker(11111);
59
 * @private
60
 */
61
export function runWorker(
62
        useWorker = true, fn: Function, callback: Function, depsFn?: Function[]
×
63
): Function {
4,866!
64
        let runFn;
65

66
        if (window.Worker && useWorker) {
4,866✔
67
                const src = getObjectURL(fn, depsFn);
3✔
68
                const worker = new window.Worker(src);
3✔
69

70
                runFn = function(...args) {
3✔
71
                        // trigger worker
72
                        worker.postMessage(args);
3✔
73

74
                        // listen worker
75
                        worker.onmessage = function(e) {
3✔
76
                                // release object URL from memory
77
                                window.URL.revokeObjectURL(src);
3✔
78

79
                                return callback(e.data);
3✔
80
                        };
81

82
                        // handle error
83
                        worker.onerror = function(e) {
3✔
84
                                console.error(e);
×
85
                        };
86

87
                        // return new Promise((resolve, reject) => {
88
                        //         worker.onmessage = ({data}) => resolve(data);
89
                        //         worker.onerror = reject;
90
                        // });
91
                };
92
        } else {
93
                runFn = function(...args) {
4,863✔
94
                        const res = fn(...args);
4,863✔
95

96
                        callback(res);
4,863✔
97
                };
98
        }
99

100
        return runFn;
4,866✔
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc