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

Brightspace / react-valence-ui-fileviewer / 7111280825

06 Dec 2023 07:04AM UTC coverage: 56.35% (-32.8%) from 89.198%
7111280825

push

github

web-flow
Merge pull request #114 from Brightspace/venkata/node-sass-update-2

adding npm i in release.yml

604 of 1444 branches covered (0.0%)

1624 of 2882 relevant lines covered (56.35%)

11.45 hits per line

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

63.97
/src/plugins/pdf/alternate/pdfjsWorkerSrcInit.js
1
'use strict';
2

3
// inspired by http://colonelpanic.net/2014/08/using-pdf-js-web-worker-cross-domain-cors/
4

5
var pdfjs = require('./pdfjs-lib'),
26!
6
        isCrossDomain = require('./isCrossDomain'),
7
        cache = require('./pdfjsWorkerSrcInitCache');
2✔
8

2✔
9
function loadWorkerSrcFromUrl(url) {
2✔
10
        return new Promise(function(resolve, reject) {
11
                var request = new XMLHttpRequest();
12

6✔
13
                request.onreadystatechange = function() {
6✔
14
                        if (request.readyState === 4) {
15
                                if (request.status === 200) {
6✔
16
                                        var workerSrcBlob = getBlob(request);
34✔
17
                                        resolve(window.URL.createObjectURL(workerSrcBlob));
6✔
18
                                } else {
4✔
19
                                        reject();
4✔
20
                                }
21
                        }
2✔
22
                };
23
                request.open('GET', url, true);
24
                request.send();
25
        });
6✔
26
}
6✔
27

28
function getBlob(request) {
29
        return new Blob([request.responseText], {
30
                type: 'text/javascript'
31
        });
×
32
}
33

34
function initialize() {
35
        return new Promise(function(resolve) {
36
                if (!isCrossDomain(pdfjs.workerSrc)) {
37
                        // if we're not making a cross-domain call then there's nothing to do.
8✔
38
                        resolve();
8✔
39
                } else {
40
                        loadWorkerSrcFromUrl(pdfjs.workerSrc)
2✔
41
                                .then(function(workerSrcBlobUrl) {
42
                                        pdfjs.workerSrc = workerSrcBlobUrl;
6✔
43
                                        resolve();
4✔
44
                                }).catch(function() {
4✔
45
                                        // If loading the worker source via XHR did not work it's OK because pdf.js
46
                                        // will just fall back to using a fake worker which while less performant
47
                                        // should still work just fine.
48
                                        resolve();
49
                                });
2✔
50
                }
51
        });
52
}
53

54
function ensureInitialized() {
55
        var cachedResult = cache.get();
56
        if (!cachedResult) {
10✔
57
                cachedResult = initialize();
10✔
58
                cache.set(cachedResult);
8✔
59
        }
8✔
60
        return cachedResult;
61
}
10✔
62

63
module.exports = ensureInitialized;
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

© 2025 Coveralls, Inc