summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2023-02-26 19:47:53 -0800
committerPhilip Chimento <philip.chimento@gmail.com>2023-03-04 23:40:32 -0800
commit9633f54961f83dbe06871eb9b9c11b997cc9d577 (patch)
tree11bf4fdc89e9d6e6218b486b162a6504ae45624a
parent296934af365ea347aa94bdc88cf9e12b5e5031e8 (diff)
downloadgjs-9633f54961f83dbe06871eb9b9c11b997cc9d577.tar.gz
GLib: Remove circular dependency between GLib and ByteArray
ByteArray.fromString() is already defined by _byteArrayNative and re-exported; while ByteArray.toGBytes() just calls new GLib.Bytes anyway.
-rw-r--r--modules/core/overrides/GLib.js13
1 files changed, 5 insertions, 8 deletions
diff --git a/modules/core/overrides/GLib.js b/modules/core/overrides/GLib.js
index 023cf795..2d51b575 100644
--- a/modules/core/overrides/GLib.js
+++ b/modules/core/overrides/GLib.js
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
// SPDX-FileCopyrightText: 2011 Giovanni Campagna
-const ByteArray = imports.byteArray;
+const ByteArray = imports._byteArrayNative;
const {setMainLoopHook} = imports._promiseNative;
let GLib;
@@ -100,15 +100,12 @@ function _packVariant(signature, value) {
}
if (arrayType[0] === 'y') {
// special case for array of bytes
- let bytes;
if (typeof value === 'string') {
- let byteArray = ByteArray.fromString(value);
- if (byteArray[byteArray.length - 1] !== 0)
- byteArray = Uint8Array.of(...byteArray, 0);
- bytes = ByteArray.toGBytes(byteArray);
- } else {
- bytes = new GLib.Bytes(value);
+ value = ByteArray.fromString(value);
+ if (value[value.length - 1] !== 0)
+ value = Uint8Array.of(...value, 0);
}
+ const bytes = new GLib.Bytes(value);
return GLib.Variant.new_from_bytes(new GLib.VariantType('ay'),
bytes, true);
}