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+
13/**
24 * Check if the current document origin is on the tracker list, using the provided lookup trie.
35 * @param {object } trackerLookup Trie lookup of tracker domains
46 * @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.
510 */
6- export function isTrackerOrigin ( trackerLookup , originHostname = document . location . hostname ) {
11+ export function isTrackerOrigin ( trackerLookup , originHostname = getGlobal ( ) . document . location . hostname ) {
712 const parts = originHostname . split ( '.' ) . reverse ( ) ;
813 let node = trackerLookup ;
914 for ( const sub of parts ) {
Original file line number Diff line number Diff line change @@ -49,6 +49,14 @@ export function setGlobal(globalObjIn) {
4949 Error = globalObj . Error ;
5050}
5151
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+
5260// linear feedback shift register to find a random approximation
5361export function nextRandom ( v ) {
5462 return Math . abs ( ( v >> 1 ) | ( ( ( v << 62 ) ^ ( v << 61 ) ) & ( ~ ( ~ 0 << 63 ) << 62 ) ) ) ;
You can’t perform that action at this time.
0 commit comments