diff options
author | Giovanni Campagna <gcampagna@src.gnome.org> | 2014-01-19 14:48:20 +0100 |
---|---|---|
committer | Giovanni Campagna <gcampagna@src.gnome.org> | 2014-03-02 14:36:51 +0100 |
commit | 0d49d2aa26166d3666c4f9afa804c212e9851dc5 (patch) | |
tree | 89ea75257cc3d99ecd8afebb8745667395ddf3c7 | |
parent | 1c027e7ed0a5ed5b02fe78a82e725815a79ac4ce (diff) | |
download | gjs-0d49d2aa26166d3666c4f9afa804c212e9851dc5.tar.gz |
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
-rw-r--r-- | installed-tests/js/testGIMarshalling.js | 7 | ||||
-rw-r--r-- | 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 c63a6d5e..6f444a11 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 99f5b63a..2be22c2a 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); }; |