Skip to content

Commit

Permalink
Uncaught ReferenceError: global is not defined #1911
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Oct 3, 2022
1 parent 06c1469 commit 308c4dc
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tools/shims/src/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@ let _cachedGlobal: Window = null;
* of the properties or functions.
*/
export function getGlobal(useCached: boolean = true): Window {
if (!_cachedGlobal || !useCached) {
let result = useCached === false ? null : _cachedGlobal;

if (typeof globalThis !== strShimUndefined && globalThis) {
_cachedGlobal = globalThis;
if (!result) {
if (typeof globalThis !== strShimUndefined) {
result = globalThis;
}

if (typeof self !== strShimUndefined && self) {
_cachedGlobal = self;
if (!result && typeof self !== strShimUndefined) {
result = self;
}

if (typeof window !== strShimUndefined && window) {
_cachedGlobal = window;
if (!result && typeof window !== strShimUndefined) {
result = window;
}

if (typeof global !== strShimUndefined && global) {
_cachedGlobal = global;
if (!result && typeof global !== strShimUndefined) {
result = global;
}

_cachedGlobal = result;
}

return _cachedGlobal;
return result;
}

export function throwTypeError(message: string): never {
Expand Down

0 comments on commit 308c4dc

Please sign in to comment.