@datadog/browser-core
Advanced tools
Comparing version 1.9.2 to 1.9.3
@@ -82,2 +82,5 @@ export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | ||
export declare function isEmptyObject(object: object): boolean; | ||
/** | ||
* inspired by https://mathiasbynens.be/notes/globalthis | ||
*/ | ||
export declare function getGlobalObject<T>(): T; | ||
@@ -84,0 +87,0 @@ export declare function getLocationOrigin(): string; |
@@ -227,5 +227,33 @@ "use strict"; | ||
exports.isEmptyObject = isEmptyObject; | ||
/** | ||
* inspired by https://mathiasbynens.be/notes/globalthis | ||
*/ | ||
function getGlobalObject() { | ||
// tslint:disable-next-line: function-constructor no-function-constructor-with-string-args | ||
return (typeof globalThis === 'object' ? globalThis : Function('return this')()); | ||
if (typeof globalThis === 'object') { | ||
return globalThis; | ||
} | ||
Object.defineProperty(Object.prototype, '_dd_temp_', { | ||
get: function () { | ||
return this; | ||
}, | ||
configurable: true, | ||
}); | ||
// @ts-ignore | ||
var globalObject = _dd_temp_; | ||
// @ts-ignore | ||
delete Object.prototype._dd_temp_; | ||
if (typeof globalObject !== 'object') { | ||
// on safari _dd_temp_ is available on window but not globally | ||
// fallback on other browser globals check | ||
if (typeof self === 'object') { | ||
globalObject = self; | ||
} | ||
else if (typeof window === 'object') { | ||
globalObject = window; | ||
} | ||
else { | ||
globalObject = {}; | ||
} | ||
} | ||
return globalObject; | ||
} | ||
@@ -232,0 +260,0 @@ exports.getGlobalObject = getGlobalObject; |
@@ -82,2 +82,5 @@ export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; | ||
export declare function isEmptyObject(object: object): boolean; | ||
/** | ||
* inspired by https://mathiasbynens.be/notes/globalthis | ||
*/ | ||
export declare function getGlobalObject<T>(): T; | ||
@@ -84,0 +87,0 @@ export declare function getLocationOrigin(): string; |
@@ -205,5 +205,33 @@ export var ONE_SECOND = 1000; | ||
} | ||
/** | ||
* inspired by https://mathiasbynens.be/notes/globalthis | ||
*/ | ||
export function getGlobalObject() { | ||
// tslint:disable-next-line: function-constructor no-function-constructor-with-string-args | ||
return (typeof globalThis === 'object' ? globalThis : Function('return this')()); | ||
if (typeof globalThis === 'object') { | ||
return globalThis; | ||
} | ||
Object.defineProperty(Object.prototype, '_dd_temp_', { | ||
get: function () { | ||
return this; | ||
}, | ||
configurable: true, | ||
}); | ||
// @ts-ignore | ||
var globalObject = _dd_temp_; | ||
// @ts-ignore | ||
delete Object.prototype._dd_temp_; | ||
if (typeof globalObject !== 'object') { | ||
// on safari _dd_temp_ is available on window but not globally | ||
// fallback on other browser globals check | ||
if (typeof self === 'object') { | ||
globalObject = self; | ||
} | ||
else if (typeof window === 'object') { | ||
globalObject = window; | ||
} | ||
else { | ||
globalObject = {}; | ||
} | ||
} | ||
return globalObject; | ||
} | ||
@@ -210,0 +238,0 @@ export function getLocationOrigin() { |
{ | ||
"name": "@datadog/browser-core", | ||
"version": "1.9.2", | ||
"version": "1.9.3", | ||
"license": "Apache-2.0", | ||
@@ -29,3 +29,3 @@ "main": "cjs/index.js", | ||
}, | ||
"gitHead": "0cd09ed4844930c19084b9ac9c24635e108678ee" | ||
"gitHead": "bc358020a4d7e933f4c71c7e00d48cb66a7ab2fb" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355388
5861