[gjs: 1/2] Replace remaining mentions of window with globalThis
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] Replace remaining mentions of window with globalThis
- Date: Sat, 23 Jan 2021 18:37:38 +0000 (UTC)
commit b48b24ea878ec76d1a443e61d9ea5209bef7eb95
Author: Sonny Piers <sonny fastmail net>
Date: Thu Jan 21 11:44:11 2021 +0100
Replace remaining mentions of window with globalThis
.eslintrc.yml | 2 ++
doc/Logging.md | 13 ++++++-------
doc/Modules.md | 4 ++--
doc/Package/Specification.md | 4 ++--
doc/Style_Guide.md | 2 +-
tools/heapgraph.md | 4 ++--
tools/heapgraph.py | 2 +-
7 files changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 9edb5641..0a07f205 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -121,6 +121,7 @@ rules:
no-octal-escape: error
no-proto: error
no-prototype-builtins: 'off'
+ no-restricted-globals: [error, window]
no-restricted-properties:
- error
- object: Lang
@@ -244,5 +245,6 @@ globals:
logError: readonly
print: readonly
printerr: readonly
+ window: readonly
parserOptions:
ecmaVersion: 2020
diff --git a/doc/Logging.md b/doc/Logging.md
index 6a01defc..e2f127f4 100644
--- a/doc/Logging.md
+++ b/doc/Logging.md
@@ -98,13 +98,12 @@ function _makeLogFunction(level) {
};
}
-// `window` is the global object in GJS, for historical reasons
-window.log = _makeLogFunction(GLib.LogLevelFlags.LEVEL_MESSAGE);
-window.debug = _makeLogFunction(GLib.LogLevelFlags.LEVEL_DEBUG);
-window.info = _makeLogFunction(GLib.LogLevelFlags.LEVEL_INFO);
-window.warning = _makeLogFunction(GLib.LogLevelFlags.LEVEL_WARNING);
-window.critical = _makeLogFunction(GLib.LogLevelFlags.LEVEL_CRITICAL);
-window.error = _makeLogFunction(GLib.LogLevelFlags.LEVEL_ERROR);
+globalThis.log = _makeLogFunction(GLib.LogLevelFlags.LEVEL_MESSAGE);
+globalThis.debug = _makeLogFunction(GLib.LogLevelFlags.LEVEL_DEBUG);
+globalThis.info = _makeLogFunction(GLib.LogLevelFlags.LEVEL_INFO);
+globalThis.warning = _makeLogFunction(GLib.LogLevelFlags.LEVEL_WARNING);
+globalThis.critical = _makeLogFunction(GLib.LogLevelFlags.LEVEL_CRITICAL);
+globalThis.error = _makeLogFunction(GLib.LogLevelFlags.LEVEL_ERROR);
// Log all messages when connected to the journal
if (GLib.log_writer_is_journald(2))
diff --git a/doc/Modules.md b/doc/Modules.md
index dbc2b91a..cd944922 100644
--- a/doc/Modules.md
+++ b/doc/Modules.md
@@ -193,7 +193,7 @@ Infrastructure and utilities for [standalone applications](Home#standalone-appli
A GObject-like signal framework for native Javascript objects.
-**NOTE:** Unlike [GObject signals](Mapping#signals), `this` within a signal callback will refer to the
global object (ie. `window`).
+**NOTE:** Unlike [GObject signals](Mapping#signals), `this` within a signal callback will refer to the
global object (ie. `globalThis`).
```js
const Signals = imports.signals;
@@ -209,7 +209,7 @@ let obj = new MyJSObject();
// Connect and disconnect like standard GObject signals
let handlerId = obj.connect("exampleSignal", (obj, stringArg, intArg) => {
- // Remember 'this' === 'window'
+ // Remember 'this' === 'globalThis'
});
obj.disconnect(handlerId);
diff --git a/doc/Package/Specification.md b/doc/Package/Specification.md
index 39c92dd3..41aac732 100644
--- a/doc/Package/Specification.md
+++ b/doc/Package/Specification.md
@@ -91,11 +91,11 @@ This `main()` function should initialize a GApplication whose id is **${entry-po
The following API will be available to applications, through the
[`package.js`](https://gitlab.gnome.org/GNOME/gjs/blob/master/modules/script/package.js) module.
-* `window.pkg` (ie `pkg` on the global object) will provide access to the package module
+* `globalThis.pkg` (ie `pkg` on the global object) will provide access to the package module
* `pkg.name` and `pkg.version` will return the package name and version, as passed to `pkg.init()`
* `pkg.prefix`, `pkg.datadir`, `pkg.libdir` will return the installed locations of those folders
* `pkg.pkgdatadir`, `pkg.moduledir`, `pkg.pkglibdir`, `pkg.localedir` will return the respective
directories, or the appropriate subdirectory of the current directory if running uninstalled
-* `pkg.initGettext()` will initialize gettext. After calling `window._`, `window.C_` and `window.N_` will be
available
+* `pkg.initGettext()` will initialize gettext. After calling `globalThis._`, `globalThis.C_` and
`globalThis.N_` will be available
* `pkg.initFormat()` will initialize the format module. After calling, String.prototype.format will be
available
* `pkg.initSubmodule(name)` will initialize a submodule named @name. It must be called before accessing the
typelibs installed by that submodule
* `pkg.loadResource(name)` will load and register a GResource named @name. @name is optional and defaults to
${package-name}
diff --git a/doc/Style_Guide.md b/doc/Style_Guide.md
index 908fefc3..e2a53764 100644
--- a/doc/Style_Guide.md
+++ b/doc/Style_Guide.md
@@ -114,7 +114,7 @@ If your usage of an object is like a hash table (and thus conceptually the keys
- We use javaStyle variable names, with CamelCase for type names and lowerCamelCase for variable and method
names. However, when calling a C method with underscore-based names via introspection, we just keep them
looking as they do in C for simplicity.
- Private variables, whether object member variables or module-scoped variables, should begin with `_`.
-- True global variables (in the global or 'window' object) should be avoided whenever possible. If you do
create them, the variable name should have a namespace in it, like `BigFoo`
+- True global variables should be avoided whenever possible. If you do create them, the variable name should
have a namespace in it, like `BigFoo`
- When you assign a module to an alias to avoid typing `imports.foo.bar` all the time, the alias should be
`const TitleCase` so `const Bar = imports.foo.bar;`
- If you need to name a variable something weird to avoid a namespace collision, add a trailing `_` (not
leading, leading `_` means private).
diff --git a/tools/heapgraph.md b/tools/heapgraph.md
index c0193a13..441a8979 100644
--- a/tools/heapgraph.md
+++ b/tools/heapgraph.md
@@ -105,7 +105,7 @@ You can also exclude Gray Roots, WeakMaps, nodes with a heap address or nodes
with labels containing a string. Because GObject addresses are part of the node
label, these can be excluded with `--hide-node` as well.
-By default the global object (GjsGlobal aka `window`), imports (GjsModule,
+By default the global object (GjsGlobal aka `globalThis`), imports (GjsModule,
GjsFileImporter), and namespaces (GIRepositoryNamespace) aren't shown in the
graph since these are less useful and can't be garbage collected anyways.
@@ -167,7 +167,7 @@ Node/Root Filtering:
Don't show roots common to the heap FILE
--no-gray-roots, -ng Don't show gray roots (marked to be collected)
--no-weak-maps, -nwm Don't show WeakMaps
- --show-global, -g Show the global object (eg. window/GjsGlobal)
+ --show-global, -g Show the global object (eg. globalThis/GjsGlobal)
--show-imports, -i Show import and module nodes (eg. imports.foo)
--hide-addr ADDR, -ha ADDR
Don't show roots with the heap address ADDR
diff --git a/tools/heapgraph.py b/tools/heapgraph.py
index d62e449f..365e965b 100755
--- a/tools/heapgraph.py
+++ b/tools/heapgraph.py
@@ -84,7 +84,7 @@ filt_opts.add_argument('--no-weak-maps', '-nwm', dest='no_weak_maps',
filt_opts.add_argument('--show-global', '-g', dest='show_global',
action='store_true', default=False,
- help='Show the global object (eg. window/GjsGlobal)')
+ help='Show the global object (eg. globalThis/GjsGlobal)')
filt_opts.add_argument('--show-imports', '-i', dest='show_imports',
action='store_true', default=False,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]