[gjs] GObject: add pseudo-classes for fundamental types
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] GObject: add pseudo-classes for fundamental types
- Date: Sun, 2 Mar 2014 13:36:40 +0000 (UTC)
commit 0d49d2aa26166d3666c4f9afa804c212e9851dc5
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Jan 19 14:48:20 2014 +0100
GObject: add pseudo-classes for fundamental types
Add GObject.Int, GObject.Char, etc. that look like the JS fundamental
types but hold the correct $gtype property. This way, one can use
"GObject.Int" instead of "GObject.TYPE_INT" for GType arguments,
which is more consistent with GObject and GBoxed classes.
Also, attach a $gtype to String, Number and Boolean.
https://bugzilla.gnome.org/show_bug.cgi?id=722544
installed-tests/js/testGIMarshalling.js | 7 +++
modules/overrides/GObject.js | 70 ++++++++++++++++++++-----------
2 files changed, 52 insertions(+), 25 deletions(-)
---
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index c63a6d5..6f444a1 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -265,7 +265,10 @@ function testGType() {
assertEquals(GObject.TYPE_STRING, GIMarshallingTests.gtype_string_return());
GIMarshallingTests.gtype_in(GObject.TYPE_NONE);
+ GIMarshallingTests.gtype_in(GObject.VoidType);
GIMarshallingTests.gtype_string_in(GObject.TYPE_STRING);
+ GIMarshallingTests.gtype_string_in(GObject.String);
+ GIMarshallingTests.gtype_string_in(String);
assertEquals(GObject.TYPE_NONE, GIMarshallingTests.gtype_out());
assertEquals(GObject.TYPE_STRING, GIMarshallingTests.gtype_string_out());
@@ -287,6 +290,10 @@ function testGValueGType() {
GIMarshallingTests.gvalue_in_with_type('42', GObject.TYPE_STRING);
GIMarshallingTests.gvalue_in_with_type(GObject.TYPE_GTYPE, GObject.TYPE_GTYPE)
+ GIMarshallingTests.gvalue_in_with_type(42, GObject.Int);
+ GIMarshallingTests.gvalue_in_with_type(42.5, GObject.Double);
+ GIMarshallingTests.gvalue_in_with_type(42.5, Number);
+
// Object and interface
GIMarshallingTests.gvalue_in_with_type(new Gio.SimpleAction, Gio.SimpleAction);
GIMarshallingTests.gvalue_in_with_type(new Gio.SimpleAction, GObject.Object);
diff --git a/modules/overrides/GObject.js b/modules/overrides/GObject.js
index 99f5b63..2be22c2 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -144,77 +144,97 @@ function _init() {
GObject = this;
- this.TYPE_NONE = GObject.type_from_name('void');
- this.TYPE_INTERFACE = GObject.type_from_name('GInterface');
- this.TYPE_CHAR = GObject.type_from_name('gchar');
- this.TYPE_UCHAR = GObject.type_from_name('guchar');
+ function _makeDummyClass(obj, name, upperName, gtypeName, actual) {
+ let gtype = GObject.type_from_name(gtypeName);
+ obj['TYPE_' + upperName] = gtype;
+ obj[name] = function(v) { return new actual(v); }
+ obj[name].$gtype = gtype;
+ }
+
+ _makeDummyClass(this, 'VoidType', 'NONE', 'void', function() {});
+ _makeDummyClass(this, 'Char', 'CHAR', 'gchar', String);
+ _makeDummyClass(this, 'UChar', 'UCHAR', 'guchar', String);
+ _makeDummyClass(this, 'Unichar', 'UNICHAR', 'gint', String);
+
this.TYPE_BOOLEAN = GObject.type_from_name('gboolean');
- this.TYPE_INT = GObject.type_from_name('gint');
- this.TYPE_UINT = GObject.type_from_name('guint');
- this.TYPE_LONG = GObject.type_from_name('glong');
- this.TYPE_ULONG = GObject.type_from_name('gulong');
- this.TYPE_INT64 = GObject.type_from_name('gint64');
- this.TYPE_UINT64 = GObject.type_from_name('guint64');
+ this.Boolean = Boolean;
+ Boolean.$gtype = this.TYPE_BOOLEAN;
+
+ _makeDummyClass(this, 'Int', 'INT', 'gint', Number);
+ _makeDummyClass(this, 'UInt', 'UINT', 'guint', Number);
+ _makeDummyClass(this, 'Long', 'LONG', 'glong', Number);
+ _makeDummyClass(this, 'ULong', 'ULONG', 'gulong', Number);
+ _makeDummyClass(this, 'Int64', 'INT64', 'gint64', Number);
+ _makeDummyClass(this, 'UInt64', 'UINT64', 'guint64', Number);
+
this.TYPE_ENUM = GObject.type_from_name('GEnum');
this.TYPE_FLAGS = GObject.type_from_name('GFlags');
- this.TYPE_FLOAT = GObject.type_from_name('gfloat');
+
+ _makeDummyClass(this, 'Float', 'FLOAT', 'gfloat', Number);
this.TYPE_DOUBLE = GObject.type_from_name('gdouble');
+ this.Double = Number;
+ Number.$gtype = this.TYPE_DOUBLE;
+
this.TYPE_STRING = GObject.type_from_name('gchararray');
+ this.String = String;
+ String.$gtype = this.TYPE_STRING;
+
this.TYPE_POINTER = GObject.type_from_name('gpointer');
this.TYPE_BOXED = GObject.type_from_name('GBoxed');
this.TYPE_PARAM = GObject.type_from_name('GParam');
+ this.TYPE_INTERFACE = GObject.type_from_name('GInterface');
this.TYPE_OBJECT = GObject.type_from_name('GObject');
- this.TYPE_GTYPE = GObject.type_from_name('GType');
this.TYPE_VARIANT = GObject.type_from_name('GVariant');
- this.TYPE_UNICHAR = this.TYPE_UINT;
+
+ _makeDummyClass(this, 'Type', 'GTYPE', 'GType', GObject.type_from_name);
this.ParamSpec.char = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_CHAR,
+ return GObject.ParamSpec._new_internal(name, GObject.Char,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.uchar = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_UCHAR,
+ return GObject.ParamSpec._new_internal(name, GObject.UChar,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.int = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_INT,
+ return GObject.ParamSpec._new_internal(name, GObject.Int,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.uint = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_UINT,
+ return GObject.ParamSpec._new_internal(name, GObject.UInt,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.long = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_LONG,
+ return GObject.ParamSpec._new_internal(name, GObject.Long,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.ulong = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_ULONG,
+ return GObject.ParamSpec._new_internal(name, GObject.ULong,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.int64 = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_INT64,
+ return GObject.ParamSpec._new_internal(name, GObject.Int64,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.uint64 = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_UINT64,
+ return GObject.ParamSpec._new_internal(name, GObject.UInt64,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.float = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_FLOAT,
+ return GObject.ParamSpec._new_internal(name, GObject.Float,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.boolean = function(name, nick, blurb, flags, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_BOOLEAN,
+ return GObject.ParamSpec._new_internal(name, GObject.Boolean,
nick, blurb, flags, default_value);
};
@@ -227,12 +247,12 @@ function _init() {
};
this.ParamSpec.double = function(name, nick, blurb, flags, minimum, maximum, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_DOUBLE,
+ return GObject.ParamSpec._new_internal(name, GObject.Double,
nick, blurb, flags, minimum, maximum, default_value);
};
this.ParamSpec.string = function(name, nick, blurb, flags, default_value) {
- return GObject.ParamSpec._new_internal(name, GObject.TYPE_STRING,
+ return GObject.ParamSpec._new_internal(name, GObject.String,
nick, blurb, flags, default_value);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]