[gjs: 1/3] add override GLib.VariantDict.lookup
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/3] add override GLib.VariantDict.lookup
- Date: Sat, 3 Aug 2019 00:02:41 +0000 (UTC)
commit 448847782431d0e8a21891b203d63153b80d9955
Author: Sonny Piers <sonny fastmail net>
Date: Fri Aug 2 12:19:20 2019 +0200
add override GLib.VariantDict.lookup
installed-tests/js/testGLib.js | 11 +++++++++++
modules/overrides/GLib.js | 9 +++++++++
2 files changed, 20 insertions(+)
---
diff --git a/installed-tests/js/testGLib.js b/installed-tests/js/testGLib.js
index b162eee9..1645815b 100644
--- a/installed-tests/js/testGLib.js
+++ b/installed-tests/js/testGLib.js
@@ -70,3 +70,14 @@ describe('GVariant constructor', function () {
expect(a[ix]).toEqual(val));
});
});
+
+describe('GVariantDict lookup', function () {
+ it('returns the unpacked variant', function () {
+ const variantDict = new GLib.VariantDict(null);
+ variantDict.insert_value('foo', GLib.Variant.new_string('bar'));
+ expect(variantDict.lookup('foo')).toEqual('bar');
+ expect(variantDict.lookup('foo', null)).toEqual('bar');
+ expect(variantDict.lookup('foo', 's')).toEqual('bar');
+ expect(variantDict.lookup('foo', new GLib.VariantType('s'))).toEqual('bar');
+ });
+});
diff --git a/modules/overrides/GLib.js b/modules/overrides/GLib.js
index 75b2d9d2..e57555da 100644
--- a/modules/overrides/GLib.js
+++ b/modules/overrides/GLib.js
@@ -301,4 +301,13 @@ function _init() {
GLib.log_variant(logDomain, logLevel, new GLib.Variant('a{sv}', fields));
};
+ this.VariantDict.prototype.lookup = function(key, variantType = null, deep = false) {
+ if (typeof variantType === 'string')
+ variantType = new GLib.VariantType(variantType);
+
+ const variant = this.lookup_value(key, variantType);
+ if (variant === null)
+ return null;
+ return _unpack_variant(variant, deep);
+ };
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]