[gnome-shell] cleanup: Replace non-standard ByteArray module



commit ef70364e8102caf9d91c48881fc6361c4f344a44
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 12 16:38:57 2021 +0200

    cleanup: Replace non-standard ByteArray module
    
    gjs landed support for TextDecoder/TextEncoder. Use those instead
    of gjs' own ByteArray module.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1946>

 .gitlab-ci.yml                        |  2 +-
 js/misc/fileUtils.js                  |  2 +-
 js/ui/components/networkAgent.js      |  6 +++---
 js/ui/environment.js                  |  4 +---
 js/ui/extensionDownloader.js          | 10 ++++------
 js/ui/extensionSystem.js              |  3 +--
 js/ui/keyboard.js                     |  9 +++------
 js/ui/padOsd.js                       |  4 +---
 js/ui/sessionMode.js                  |  5 ++---
 meson.build                           |  2 +-
 subprojects/extensions-app/js/main.js |  2 +-
 11 files changed, 19 insertions(+), 30 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5f97c3312a..97aff40271 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -31,7 +31,7 @@ variables:
     LINT_LOG: "eslint-report.xml"
     LINT_MR_LOG: "eslint-mr-report.xml"
 
-image: registry.gitlab.gnome.org/gnome/mutter/fedora/34:x86_64-2021-08-01.0
+image: registry.gitlab.gnome.org/gnome/mutter/fedora/34:x86_64-2021-08-25.0
 
 workflow:
     rules:
diff --git a/js/misc/fileUtils.js b/js/misc/fileUtils.js
index 2f1798b84b..88f043a79a 100644
--- a/js/misc/fileUtils.js
+++ b/js/misc/fileUtils.js
@@ -86,7 +86,7 @@ function loadInterfaceXML(iface) {
 
     try {
         let [ok_, bytes] = f.load_contents(null);
-        return imports.byteArray.toString(bytes);
+        return new TextDecoder().decode(bytes);
     } catch (e) {
         log(`Failed to load D-Bus interface ${iface}`);
     }
diff --git a/js/ui/components/networkAgent.js b/js/ui/components/networkAgent.js
index 9a1885a038..92e499302a 100644
--- a/js/ui/components/networkAgent.js
+++ b/js/ui/components/networkAgent.js
@@ -2,7 +2,6 @@
 /* exported Component */
 
 const { Clutter, Gio, GLib, GObject, NM, Pango, Shell, St } = imports.gi;
-const ByteArray = imports.byteArray;
 const Signals = imports.signals;
 
 const Dialog = imports.ui.dialog;
@@ -498,7 +497,8 @@ var VPNRequestHandler = class {
             return;
         }
 
-        this._vpnChildProcessLineOldStyle(ByteArray.toString(line));
+        const decoder = new TextDecoder();
+        this._vpnChildProcessLineOldStyle(decoder.decode(line));
 
         // try to read more!
         this._readStdoutOldStyle();
@@ -527,7 +527,7 @@ var VPNRequestHandler = class {
         let contentOverride;
 
         try {
-            data = ByteArray.toGBytes(this._dataStdout.peek_buffer());
+            data = new GLib.Bytes(this._dataStdout.peek_buffer());
             keyfile.load_from_bytes(data, GLib.KeyFileFlags.NONE);
 
             if (keyfile.get_integer(VPN_UI_GROUP, 'Version') != 2)
diff --git a/js/ui/environment.js b/js/ui/environment.js
index 89ff701c70..ccd7dcdaa6 100644
--- a/js/ui/environment.js
+++ b/js/ui/environment.js
@@ -86,8 +86,6 @@ function _patchLayoutClass(layoutClass, styleProps) {
  * @returns {void}
  */
 function _injectSoup3Compat(Soup) {
-    const ByteArray = imports.byteArray;
-
     Soup.StatusCode = Soup.KnownStatusCode;
 
     Soup.Message.new_from_encoded_form =
@@ -101,7 +99,7 @@ function _injectSoup3Compat(Soup) {
             this.set_request(
                 contentType,
                 Soup.MemoryUse.COPY,
-                ByteArray.toString(bytes.get_data()));
+                new TextDecoder().decode(bytes.get_data()));
         };
 
     Soup.Session.prototype.send_and_read_async =
diff --git a/js/ui/extensionDownloader.js b/js/ui/extensionDownloader.js
index d1c899fa00..8bf4646a6a 100644
--- a/js/ui/extensionDownloader.js
+++ b/js/ui/extensionDownloader.js
@@ -3,8 +3,6 @@
 
 const { Clutter, Gio, GLib, GObject, Soup } = imports.gi;
 
-const ByteArray = imports.byteArray;
-
 const Config = imports.misc.config;
 const Dialog = imports.ui.dialog;
 const ExtensionUtils = imports.misc.extensionUtils;
@@ -49,7 +47,8 @@ async function installExtension(uuid, invocation) {
             GLib.PRIORITY_DEFAULT,
             null);
         checkResponse(message);
-        info = JSON.parse(ByteArray.toString(bytes.get_data()));
+        const decoder = new TextDecoder();
+        info = JSON.parse(decoder.decode(bytes.get_data()));
     } catch (e) {
         Main.extensionManager.logExtensionError(uuid, e);
         invocation.return_dbus_error(
@@ -181,8 +180,7 @@ async function checkForUpdates() {
         shell_version: Config.PACKAGE_VERSION,
         disable_version_validation: versionCheck.toString(),
     };
-    const requestBody = new GLib.Bytes(
-        ByteArray.fromString(JSON.stringify(metadatas)));
+    const requestBody = new GLib.Bytes(JSON.stringify(metadatas));
 
     const message = Soup.Message.new('POST',
         '%s?%s'.format(REPOSITORY_URL_UPDATE, Soup.form_encode_hash(params)));
@@ -195,7 +193,7 @@ async function checkForUpdates() {
             GLib.PRIORITY_DEFAULT,
             null);
         checkResponse(message);
-        json = ByteArray.toString(bytes.get_data());
+        json = new TextDecoder().decode(bytes.get_data());
     } catch (e) {
         log('Update check failed: %s'.format(e.message));
         return;
diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js
index 6b624fca09..cc61cab403 100644
--- a/js/ui/extensionSystem.js
+++ b/js/ui/extensionSystem.js
@@ -2,7 +2,6 @@
 /* exported init connect disconnect */
 
 const { GLib, Gio, GObject, Shell, St } = imports.gi;
-const ByteArray = imports.byteArray;
 const Signals = imports.signals;
 
 const ExtensionDownloader = imports.ui.extensionDownloader;
@@ -285,7 +284,7 @@ var ExtensionManager = class {
         let metadataContents, success_;
         try {
             [success_, metadataContents] = metadataFile.load_contents(null);
-            metadataContents = ByteArray.toString(metadataContents);
+            metadataContents = new TextDecoder().decode(metadataContents);
         } catch (e) {
             throw new Error('Failed to load metadata.json: %s'.format(e.toString()));
         }
diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js
index d0dde5b23a..0597e82e4a 100644
--- a/js/ui/keyboard.js
+++ b/js/ui/keyboard.js
@@ -2,7 +2,6 @@
 /* exported KeyboardManager */
 
 const { Clutter, Gio, GLib, GObject, Graphene, Meta, Shell, St } = imports.gi;
-const ByteArray = imports.byteArray;
 const Signals = imports.signals;
 
 const EdgeDragAction = imports.ui.edgeDragAction;
@@ -536,9 +535,9 @@ var KeyboardModel = class {
     _loadModel(groupName) {
         let file = Gio.File.new_for_uri('resource:///org/gnome/shell/osk-layouts/%s.json'.format(groupName));
         let [success_, contents] = file.load_contents(null);
-        contents = ByteArray.toString(contents);
 
-        return JSON.parse(contents);
+        const decoder = new TextDecoder();
+        return JSON.parse(decoder.decode(contents));
     }
 
     getLevels() {
@@ -1039,9 +1038,7 @@ var EmojiSelection = GObject.registerClass({
         let file = Gio.File.new_for_uri('resource:///org/gnome/shell/osk-layouts/emoji.json');
         let [success_, contents] = file.load_contents(null);
 
-        if (contents instanceof Uint8Array)
-            contents = imports.byteArray.toString(contents);
-        let emoji = JSON.parse(contents);
+        let emoji = JSON.parse(new TextDecoder().decode(contents));
 
         let variants = [];
         let currentKey = 0;
diff --git a/js/ui/padOsd.js b/js/ui/padOsd.js
index ed207415ad..9804f9e305 100644
--- a/js/ui/padOsd.js
+++ b/js/ui/padOsd.js
@@ -3,7 +3,6 @@
 
 const { Atk, Clutter, GDesktopEnums, Gio,
         GLib, GObject, Gtk, Meta, Pango, Rsvg, St } = imports.gi;
-const ByteArray = imports.byteArray;
 const Signals = imports.signals;
 
 const Main = imports.ui.main;
@@ -298,10 +297,9 @@ var PadDiagram = GObject.registerClass({
     _init(params) {
         let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/pad-osd.css');
         let [success_, css] = file.load_contents(null);
-        css = ByteArray.toString(css);
         this._curEdited = null;
         this._prevEdited = null;
-        this._css = css;
+        this._css = new TextDecoder().decode(css);
         this._labels = [];
         this._activeButtons = [];
         super._init(params);
diff --git a/js/ui/sessionMode.js b/js/ui/sessionMode.js
index 4d4fb2444c..afcd67cfd2 100644
--- a/js/ui/sessionMode.js
+++ b/js/ui/sessionMode.js
@@ -1,7 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported SessionMode, listModes */
 
-const ByteArray = imports.byteArray;
 const GLib = imports.gi.GLib;
 const Signals = imports.signals;
 
@@ -110,8 +109,8 @@ function _loadMode(file, info) {
     let fileContent, success_, newMode;
     try {
         [success_, fileContent] = file.load_contents(null);
-        fileContent = ByteArray.toString(fileContent);
-        newMode = JSON.parse(fileContent);
+        const decoder = new TextDecoder();
+        newMode = JSON.parse(decoder.decode(fileContent));
     } catch (e) {
         return;
     }
diff --git a/meson.build b/meson.build
index 5847500513..41f5b02a34 100644
--- a/meson.build
+++ b/meson.build
@@ -24,7 +24,7 @@ eds_req = '>= 3.33.1'
 gcr_req = '>= 3.7.5'
 gio_req = '>= 2.56.0'
 gi_req = '>= 1.49.1'
-gjs_req = '>= 1.68.1'
+gjs_req = '>= 1.69.2'
 gtk_req = '>= 3.15.0'
 mutter_req = '>= 41.beta'
 polkit_req = '>= 0.100'
diff --git a/subprojects/extensions-app/js/main.js b/subprojects/extensions-app/js/main.js
index d4b6ec79fd..48d382f3f6 100644
--- a/subprojects/extensions-app/js/main.js
+++ b/subprojects/extensions-app/js/main.js
@@ -24,7 +24,7 @@ function loadInterfaceXML(iface) {
 
     try {
         let [ok_, bytes] = f.load_contents(null);
-        return imports.byteArray.toString(bytes);
+        return new TextDecoder().decode(bytes);
     } catch (e) {
         log('Failed to load D-Bus interface %s'.format(iface));
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]