Skip to content

Commit c8e532e

Browse files
authored
(#8676) - browser.worker test: dereference globals safely
Co-authored-by: alxndrsn <alxndrsn>
1 parent 4751ebd commit c8e532e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

tests/integration/browser.worker.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
'use strict';
22

3-
var sourceFile = window.location.search.match(/[?&]sourceFile=([^&]+)/);
4-
5-
if (!sourceFile) {
6-
sourceFile = '../../packages/node_modules/pouchdb/dist/pouchdb.js';
7-
} else {
8-
sourceFile = '../../packages/node_modules/pouchdb/dist/' + sourceFile[1];
9-
}
10-
113
// only running in Chrome and Firefox due to various bugs.
124
// IE: https://connect.microsoft.com/IE/feedback/details/866495
135
// Safari: doesn't have IndexedDB or WebSQL in a WW
@@ -16,9 +8,9 @@ if (!sourceFile) {
168
var isNodeWebkit = typeof window !== 'undefined' &&
179
typeof process !== 'undefined';
1810

19-
if (typeof window.Worker === 'function' &&
11+
if ((window && typeof window.Worker === 'function') &&
2012
!isNodeWebkit && !testUtils.isIE() &&
21-
(window.chrome || /Firefox/.test(navigator.userAgent))) {
13+
((window && window.chrome) || (navigator && /Firefox/.test(navigator.userAgent)))) {
2214
runTests();
2315
}
2416

@@ -28,6 +20,15 @@ function runTests() {
2820

2921
before(function () {
3022
worker = new Worker('worker.js');
23+
24+
var sourceFile = window && window.location.search.match(/[?&]sourceFile=([^&]+)/);
25+
26+
if (!sourceFile) {
27+
sourceFile = '../../packages/node_modules/pouchdb/dist/pouchdb.js';
28+
} else {
29+
sourceFile = '../../packages/node_modules/pouchdb/dist/' + sourceFile[1];
30+
}
31+
3132
worker.postMessage(['source', sourceFile]);
3233
});
3334

0 commit comments

Comments
 (0)