Skip to content

Commit 0306b6f

Browse files
Add export global module
1 parent 06e0902 commit 0306b6f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/captured-globals.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Capture prototype to prevent overloading
2+
function captureGlobals (object) {
3+
const newGlobal = object
4+
for (const key in object) {
5+
const value = object[key]
6+
newGlobal[key] = value
7+
}
8+
for (const key in object.prototype) {
9+
const value = object.prototype[key]
10+
newGlobal.prototype[key] = value
11+
}
12+
return newGlobal
13+
}
14+
15+
export const Set = captureGlobals(globalThis.Set)

src/utils.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/* global cloneInto, exportFunction, mozProxies */
2+
import { Set } from './captured-globals.js'
23

34
// Only use globalThis for testing this breaks window.wrappedJSObject code in Firefox
45
// eslint-disable-next-line no-global-assign
56
let globalObj = typeof window === 'undefined' ? globalThis : window
67
let Error = globalObj.Error
78
let messageSecret
8-
const CapturedSet = globalObj.Set
9-
// Capture prototype to prevent overloading
10-
const createSet = () => hasMozProxies ? new Set() : new CapturedSet()
119

1210
// save a reference to original CustomEvent amd dispatchEvent so they can't be overriden to forge messages
1311
export const OriginalCustomEvent = typeof CustomEvent === 'undefined' ? null : CustomEvent
@@ -160,7 +158,7 @@ export function matchHostname (hostname, exceptionDomain) {
160158

161159
const lineTest = /(\()?(https?:[^)]+):[0-9]+:[0-9]+(\))?/
162160
export function getStackTraceUrls (stack) {
163-
const urls = createSet()
161+
const urls = new Set()
164162
try {
165163
const errorLines = stack.split('\n')
166164
// Should cater for Chrome and Firefox stacks, we only care about https? resources.
@@ -178,7 +176,7 @@ export function getStackTraceUrls (stack) {
178176

179177
export function getStackTraceOrigins (stack) {
180178
const urls = getStackTraceUrls(stack)
181-
const origins = createSet()
179+
const origins = new Set()
182180
for (const url of urls) {
183181
origins.add(url.hostname)
184182
}

0 commit comments

Comments
 (0)