Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/browser_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ goog.module('Blockly.browserEvents');
goog.module.declareLegacyNamespace();

const Touch = goog.require('Blockly.Touch');
const global = goog.require('Blockly.utils.global');
const {globalThis} = goog.require('Blockly.utils.global');


/**
Expand Down Expand Up @@ -69,7 +69,7 @@ const conditionalBind = function(
};

const bindData = [];
if (global['PointerEvent'] && (name in Touch.TOUCH_MAP)) {
if (globalThis['PointerEvent'] && (name in Touch.TOUCH_MAP)) {
for (let i = 0; i < Touch.TOUCH_MAP[name].length; i++) {
const type = Touch.TOUCH_MAP[name][i];
node.addEventListener(type, wrapFunc, false);
Expand Down Expand Up @@ -124,7 +124,7 @@ const bind = function(node, name, thisObject, func) {
};

const bindData = [];
if (global['PointerEvent'] && (name in Touch.TOUCH_MAP)) {
if (globalThis['PointerEvent'] && (name in Touch.TOUCH_MAP)) {
for (let i = 0; i < Touch.TOUCH_MAP[name].length; i++) {
const type = Touch.TOUCH_MAP[name][i];
node.addEventListener(type, wrapFunc, false);
Expand Down
10 changes: 5 additions & 5 deletions core/msg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
goog.module('Blockly.Msg');
goog.module.declareLegacyNamespace();

const global = goog.require('Blockly.utils.global');
const {globalThis} = goog.require('Blockly.utils.global');


/**
* Exported so that if Blockly is compiled with ADVANCED_COMPILATION,
* the Blockly.Msg object exists for message files included in script tags.
*/
if (!global['Blockly']) {
global['Blockly'] = {};
if (!globalThis['Blockly']) {
globalThis['Blockly'] = {};
}
if (!global['Blockly']['Msg']) {
global['Blockly']['Msg'] = exports;
if (!globalThis['Blockly']['Msg']) {
globalThis['Blockly']['Msg'] = exports;
}
14 changes: 7 additions & 7 deletions core/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ goog.module.declareLegacyNamespace();
/* eslint-disable-next-line no-unused-vars */
const Gesture = goog.requireType('Blockly.Gesture');
const internalConstants = goog.require('Blockly.internalConstants');
const utilsGlobal = goog.require('Blockly.utils.global');
const {globalThis} = goog.require('Blockly.utils.global');
const utilsString = goog.require('Blockly.utils.string');


Expand All @@ -26,13 +26,13 @@ const utilsString = goog.require('Blockly.utils.string');
* @const
*/
const TOUCH_ENABLED =
('ontouchstart' in utilsGlobal ||
!!(utilsGlobal['document'] && document.documentElement &&
('ontouchstart' in globalThis ||
!!(globalThis['document'] && document.documentElement &&
'ontouchstart' in document.documentElement) ||
// IE10 uses non-standard touch events, so it has a different check.
!!(utilsGlobal['navigator'] &&
(utilsGlobal['navigator']['maxTouchPoints'] ||
utilsGlobal['navigator']['msMaxTouchPoints'])));
!!(globalThis['navigator'] &&
(globalThis['navigator']['maxTouchPoints'] ||
globalThis['navigator']['msMaxTouchPoints'])));
exports.TOUCH_ENABLED = TOUCH_ENABLED;

/**
Expand All @@ -47,7 +47,7 @@ let touchIdentifier_ = null;
* @type {Object}
*/
let TOUCH_MAP = {};
if (utilsGlobal['PointerEvent']) {
if (globalThis['PointerEvent']) {
TOUCH_MAP = {
'mousedown': ['pointerdown'],
'mouseenter': ['pointerenter'],
Expand Down
6 changes: 3 additions & 3 deletions core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Rect = goog.require('Blockly.utils.Rect');
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
const colourUtils = goog.require('Blockly.utils.colour');
const deprecation = goog.require('Blockly.utils.deprecation');
const global = goog.require('Blockly.utils.global');
const {globalThis} = goog.require('Blockly.utils.global');
const idGenerator = goog.require('Blockly.utils.idGenerator');
const internalConstants = goog.require('Blockly.internalConstants');
const stringUtils = goog.require('Blockly.utils.string');
Expand Down Expand Up @@ -433,7 +433,7 @@ const is3dSupported = function() {
}
// CC-BY-SA Lorenzo Polidori
// stackoverflow.com/questions/5661671/detecting-transform-translate3d-support
if (!global['getComputedStyle']) {
if (!globalThis['getComputedStyle']) {
return false;
}

Expand All @@ -453,7 +453,7 @@ const is3dSupported = function() {
for (let t in transforms) {
if (el.style[t] !== undefined) {
el.style[t] = 'translate3d(1px,1px,1px)';
const computedStyle = global['getComputedStyle'](el);
const computedStyle = globalThis['getComputedStyle'](el);
if (!computedStyle) {
// getComputedStyle in Firefox returns null when Blockly is loaded
// inside an iframe with display: none. Returning false and not
Expand Down
9 changes: 5 additions & 4 deletions core/utils/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ goog.module.declareLegacyNamespace();
* More info on this implementation here:
* https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI
*/
const utilsGlobal = function() {
exports.globalThis = (function() { // Not "let globalThis" to avoid shadowing.
if (typeof globalThis === 'object') {
return globalThis;
}
if (typeof self === 'object') {
return self;
}
Expand All @@ -31,6 +34,4 @@ const utilsGlobal = function() {
return global;
}
return this;
}();

exports = utilsGlobal;
})();
6 changes: 3 additions & 3 deletions core/utils/useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
goog.module('Blockly.utils.userAgent');
goog.module.declareLegacyNamespace();

const global = goog.require('Blockly.utils.global');
const {globalThis} = goog.require('Blockly.utils.global');


/**
Expand Down Expand Up @@ -100,7 +100,7 @@ isGecko = has('Gecko') && !isWebKit && !isIe && !isEdge;
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/extra.js
isAndroid = has('Android');
const maxTouchPoints =
global['navigator'] && global['navigator']['maxTouchPoints'];
globalThis['navigator'] && globalThis['navigator']['maxTouchPoints'];
isIPad = has('iPad') || has('Macintosh') && maxTouchPoints > 0;
isIPod = has('iPod');
isIPhone = has('iPhone') && !isIPad && !isIPod;
Expand All @@ -110,7 +110,7 @@ isMac = has('Macintosh');
// https://github.com/google/closure-library/blob/master/closure/goog/labs/useragent/device.js
isTablet = isIPad || (isAndroid && !has('Mobile')) || has('Silk');
isMobile = !isTablet && (isIPod || isIPhone || isAndroid || has('IEMobile'));
})((global['navigator'] && global['navigator']['userAgent']) || '');
})((globalThis['navigator'] && globalThis['navigator']['userAgent']) || '');

/** @const {string} */
exports.raw = rawUserAgent;
Expand Down
6 changes: 3 additions & 3 deletions core/workspace_audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ goog.module.declareLegacyNamespace();

/* eslint-disable-next-line no-unused-vars */
const WorkspaceSvg = goog.requireType('Blockly.WorkspaceSvg');
const global = goog.require('Blockly.utils.global');
const {globalThis} = goog.require('Blockly.utils.global');
const internalConstants = goog.require('Blockly.internalConstants');
const userAgent = goog.require('Blockly.utils.userAgent');

Expand Down Expand Up @@ -72,7 +72,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) {
}
let audioTest;
try {
audioTest = new global['Audio']();
audioTest = new globalThis['Audio']();
} catch (e) {
// No browser support for Audio.
// IE can throw an error even if the Audio object exists.
Expand All @@ -84,7 +84,7 @@ WorkspaceAudio.prototype.load = function(filenames, name) {
const ext = filename.match(/\.(\w+)$/);
if (ext && audioTest.canPlayType('audio/' + ext[1])) {
// Found an audio format we can play.
sound = new global['Audio'](filename);
sound = new globalThis['Audio'](filename);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Blockly.JavaScript.addReservedWords(
// Magic variable.
'arguments,' +
// Everything in the current environment (835 items in Chrome, 104 in Node).
Object.getOwnPropertyNames(Blockly.utils.global).join(','));
Object.getOwnPropertyNames(Blockly.utils.global.globalThis).join(','));

/**
* Order of operation ENUMs.
Expand Down
3 changes: 3 additions & 0 deletions scripts/migration/renamings.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const renamings = {
genUid: {module: 'Blockly.utils.idGenerator'},
}
},
'Blockly.utils.global': {
export: 'globalThis', // Previous default export now named.
},
'Blockly.utils.IdGenerator': {
module: 'Blockly.utils.idGenerator',
}
Expand Down
7 changes: 4 additions & 3 deletions scripts/package/node/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Blockly.setLocale = function (locale) {

// Override textToDomDocument and provide Node.js alternatives to DOMParser and
// XMLSerializer.
if (typeof Blockly.utils.global.document !== 'object') {
Blockly.utils.global.DOMParser = require('jsdom/lib/jsdom/living').DOMParser;
Blockly.utils.global.XMLSerializer = require('jsdom/lib/jsdom/living').XMLSerializer;
const globalThis = Blockly.utils.global.globalThis;
if (typeof globalThis.document !== 'object') {
globalThis.DOMParser = require('jsdom/lib/jsdom/living').DOMParser;
globalThis.XMLSerializer = require('jsdom/lib/jsdom/living').XMLSerializer;
var doc = Blockly.utils.xml.textToDomDocument(
'<xml xmlns="https://developers.google.com/blockly/xml"></xml>');
Blockly.utils.xml.document = function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.