JS: migrate from the global window
to globalThis
As of mozjs68 (gjs-1.64) `globalThis` is recommended over `window` and it makes more sense in this context anyways. Migrate the few instances of `window` we use and adjust the eslint configuration. `window` will continue to resolve to `globalThis`, so this won't affect extensions or other downstream users. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2322 closes #2322
This commit is contained in:
parent
d94d0f60c8
commit
3dc4f01113
@ -245,16 +245,15 @@ function _loggingFunc(...args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
// Add some bindings to the global JS namespace; (gjs keeps the web
|
// Add some bindings to the global JS namespace
|
||||||
// browser convention of having that namespace be called 'window'.)
|
globalThis.global = Shell.Global.get();
|
||||||
window.global = Shell.Global.get();
|
|
||||||
|
|
||||||
window.log = _loggingFunc;
|
globalThis.log = _loggingFunc;
|
||||||
|
|
||||||
window._ = Gettext.gettext;
|
globalThis._ = Gettext.gettext;
|
||||||
window.C_ = Gettext.pgettext;
|
globalThis.C_ = Gettext.pgettext;
|
||||||
window.ngettext = Gettext.ngettext;
|
globalThis.ngettext = Gettext.ngettext;
|
||||||
window.N_ = s => s;
|
globalThis.N_ = s => s;
|
||||||
|
|
||||||
GObject.gtypeNameBasedOnJSPath = true;
|
GObject.gtypeNameBasedOnJSPath = true;
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ const LG_ANIMATION_TIME = 500;
|
|||||||
|
|
||||||
function _getAutoCompleteGlobalKeywords() {
|
function _getAutoCompleteGlobalKeywords() {
|
||||||
const keywords = ['true', 'false', 'null', 'new'];
|
const keywords = ['true', 'false', 'null', 'new'];
|
||||||
// Don't add the private properties of window (i.e., ones starting with '_')
|
// Don't add the private properties of globalThis (i.e., ones starting with '_')
|
||||||
const windowProperties = Object.getOwnPropertyNames(window).filter(
|
const windowProperties = Object.getOwnPropertyNames(globalThis).filter(
|
||||||
a => a.charAt(0) != '_'
|
a => a.charAt(0) != '_'
|
||||||
);
|
);
|
||||||
const headerProperties = JsParse.getDeclaredConstants(commandHeader);
|
const headerProperties = JsParse.getDeclaredConstants(commandHeader);
|
||||||
|
@ -125,8 +125,8 @@ function _sessionUpdated() {
|
|||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
// These are here so we don't break compatibility.
|
// These are here so we don't break compatibility.
|
||||||
global.logError = window.log;
|
global.logError = globalThis.log;
|
||||||
global.log = window.log;
|
global.log = globalThis.log;
|
||||||
|
|
||||||
// Chain up async errors reported from C
|
// Chain up async errors reported from C
|
||||||
global.connect('notify-error', (global, msg, detail) => {
|
global.connect('notify-error', (global, msg, detail) => {
|
||||||
|
@ -218,12 +218,12 @@ globals:
|
|||||||
ARGV: readonly
|
ARGV: readonly
|
||||||
Debugger: readonly
|
Debugger: readonly
|
||||||
GIRepositoryGType: readonly
|
GIRepositoryGType: readonly
|
||||||
|
globalThis: readonly
|
||||||
imports: readonly
|
imports: readonly
|
||||||
Intl: readonly
|
Intl: readonly
|
||||||
log: readonly
|
log: readonly
|
||||||
logError: readonly
|
logError: readonly
|
||||||
print: readonly
|
print: readonly
|
||||||
printerr: readonly
|
printerr: readonly
|
||||||
window: readonly
|
|
||||||
parserOptions:
|
parserOptions:
|
||||||
ecmaVersion: 2019
|
ecmaVersion: 2019
|
||||||
|
@ -476,7 +476,7 @@ var ExtensionRow = GObject.registerClass({
|
|||||||
function initEnvironment() {
|
function initEnvironment() {
|
||||||
// Monkey-patch in a "global" object that fakes some Shell utilities
|
// Monkey-patch in a "global" object that fakes some Shell utilities
|
||||||
// that ExtensionUtils depends on.
|
// that ExtensionUtils depends on.
|
||||||
window.global = {
|
globalThis.global = {
|
||||||
log(...args) {
|
log(...args) {
|
||||||
print(args.join(', '));
|
print(args.join(', '));
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user