File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { getGlobal } from './utils.js' ;
2
+
1
3
/**
2
4
* Check if the current document origin is on the tracker list, using the provided lookup trie.
3
5
* @param {object } trackerLookup Trie lookup of tracker domains
4
6
* @returns {boolean } True iff the origin is a tracker.
7
+ *
8
+ * Note: getGlobal() is used in testing to get the global object,
9
+ * it's a work around for ESM modules are essentially singletons preventing overriding of global variables.
5
10
*/
6
- export function isTrackerOrigin ( trackerLookup , originHostname = document . location . hostname ) {
11
+ export function isTrackerOrigin ( trackerLookup , originHostname = getGlobal ( ) . document . location . hostname ) {
7
12
const parts = originHostname . split ( '.' ) . reverse ( ) ;
8
13
let node = trackerLookup ;
9
14
for ( const sub of parts ) {
Original file line number Diff line number Diff line change @@ -49,6 +49,14 @@ export function setGlobal(globalObjIn) {
49
49
Error = globalObj . Error ;
50
50
}
51
51
52
+ /**
53
+ * Used for testing to allow other files to override the globals used within this file.
54
+ * @returns {globalThis } the global object
55
+ */
56
+ export function getGlobal ( ) {
57
+ return globalObj ;
58
+ }
59
+
52
60
// linear feedback shift register to find a random approximation
53
61
export function nextRandom ( v ) {
54
62
return Math . abs ( ( v >> 1 ) | ( ( ( v << 62 ) ^ ( v << 61 ) ) & ( ~ ( ~ 0 << 63 ) << 62 ) ) ) ;
You can’t perform that action at this time.
0 commit comments