Files
blockly/core/utils/global.js
Christopher Allen f9d0caa112 Migrate core.global.js to named exports (#5451)
This is part of #5153 but is being prioritised because we want remove
the declareLegacyNamespace calls from the core/utils/*.js modules and
then reexport them explicitly via utils.js, and it turns out that
doing so results in the exports object of this module being passed to
Object.freeze - which fails on the global object, which can't be made
non-extensible!

The new name chosen for the former default export is globalThis, since
it is intended to have the same value as the global variable of that
name; see:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
2021-09-14 14:39:29 +01:00

38 lines
808 B
JavaScript

/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Provides a reference to the global object.
* @author samelh@google.com (Sam El-Husseini)
*/
'use strict';
goog.module('Blockly.utils.global');
goog.module.declareLegacyNamespace();
/**
* Reference to the global object.
*
* More info on this implementation here:
* https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI
*/
exports.globalThis = (function() { // Not "let globalThis" to avoid shadowing.
if (typeof globalThis === 'object') {
return globalThis;
}
if (typeof self === 'object') {
return self;
}
if (typeof window === 'object') {
return window;
}
if (typeof global === 'object') {
return global;
}
return this;
})();