[gjs/wip/ptomato/classes: 12/12] FIXME: class: Move to ES6 GObject classes in internal code



commit be6a11190fd3c07d674cba05f8d31ae1d66e299d
Author: Philip Chimento <philip endlessm com>
Date:   Thu Aug 3 02:43:46 2017 +0100

    FIXME: class: Move to ES6 GObject classes in internal code
    
    Need commit message.

 installed-tests/js/testExceptions.js    |   15 +++------
 installed-tests/js/testGIMarshalling.js |   54 +++++++-----------------------
 installed-tests/js/testGObjectClass.js  |   22 ++++--------
 installed-tests/js/testGio.js           |    9 ++---
 test/gjs-tests.cpp                      |    7 +---
 5 files changed, 30 insertions(+), 77 deletions(-)
---
diff --git a/installed-tests/js/testExceptions.js b/installed-tests/js/testExceptions.js
index 595682e..5c5e05f 100644
--- a/installed-tests/js/testExceptions.js
+++ b/installed-tests/js/testExceptions.js
@@ -1,32 +1,27 @@
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
-const Lang = imports.lang;
 
-const Foo = new Lang.Class({
-    Name: 'Foo',
-    Extends: GObject.Object,
+const Foo = GObject.registerClass({
     Properties: {
         'prop': GObject.ParamSpec.string('prop', '', '', GObject.ParamFlags.READWRITE, '')
     },
-
+}, class Foo extends GObject.Object {
     set prop(v) {
        throw new Error('set');
-    },
+    }
 
     get prop() {
        throw new Error('get');
     }
 });
 
-const Bar = new Lang.Class({
-    Name: 'Bar',
-    Extends: GObject.Object,
+const Bar = GObject.registerClass({
     Properties: {
         'prop': GObject.ParamSpec.string('prop', '', '',
             GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT, ''),
     }
-});
+}, class Bar extends GObject.Object {});
 
 describe('Exceptions', function () {
     it('are thrown from property setter', function () {
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index bf144d9..4a7d438 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -5,7 +5,6 @@ const GIMarshallingTests = imports.gi.GIMarshallingTests;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
-const Lang = imports.lang;
 
 describe('C array', function () {
     function createStructArray() {
@@ -536,72 +535,45 @@ describe('GType', function () {
     });
 });
 
-function callback_return_value_only() {
-    return 42;
-}
-
-function callback_one_out_parameter() {
-    return 43;
-}
-
-function callback_multiple_out_parameters() {
-    return [44, 45];
-}
-
-function callback_return_value_and_one_out_parameter() {
-    return [46, 47];
-}
-
-function callback_return_value_and_multiple_out_parameters() {
-    return [48, 49, 50];
-}
-
-function callback_array_out_parameter() {
-    return [50, 51];
-}
-
 describe('Callback', function () {
     it('marshals a return value', function () {
-        expect(GIMarshallingTests.callback_return_value_only(callback_return_value_only))
+        expect(GIMarshallingTests.callback_return_value_only(() => 42))
             .toEqual(42);
     });
 
     it('marshals one out parameter', function () {
-        expect(GIMarshallingTests.callback_one_out_parameter(callback_one_out_parameter))
+        expect(GIMarshallingTests.callback_one_out_parameter(() => 43))
             .toEqual(43);
     });
 
     it('marshals multiple out parameters', function () {
-        expect(GIMarshallingTests.callback_multiple_out_parameters(callback_multiple_out_parameters))
+        expect(GIMarshallingTests.callback_multiple_out_parameters(() => [44, 45]))
             .toEqual([44, 45]);
     });
 
     it('marshals a return value and one out parameter', function () {
-        
expect(GIMarshallingTests.callback_return_value_and_one_out_parameter(callback_return_value_and_one_out_parameter))
+        expect(GIMarshallingTests.callback_return_value_and_one_out_parameter(() => [46, 47]))
             .toEqual([46, 47]);
     });
 
     it('marshals a return value and multiple out parameters', function () {
-        
expect(GIMarshallingTests.callback_return_value_and_multiple_out_parameters(callback_return_value_and_multiple_out_parameters))
+        expect(GIMarshallingTests.callback_return_value_and_multiple_out_parameters(() => [48, 49, 50]))
             .toEqual([48, 49, 50]);
     });
 
     xit('marshals an array out parameter', function () {
-        expect(GIMarshallingTests.callback_array_out_parameter(callback_array_out_parameter))
+        expect(GIMarshallingTests.callback_array_out_parameter(() => [50, 51]))
             .toEqual([50, 51]);
     }).pend('Function not added to gobject-introspection test suite yet');
 });
 
-const VFuncTester = new Lang.Class({
-    Name: 'VFuncTester',
-    Extends: GIMarshallingTests.Object,
-
-    vfunc_vfunc_return_value_only: callback_return_value_only,
-    vfunc_vfunc_one_out_parameter: callback_one_out_parameter,
-    vfunc_vfunc_multiple_out_parameters: callback_multiple_out_parameters,
-    vfunc_vfunc_return_value_and_one_out_parameter: callback_return_value_and_one_out_parameter,
-    vfunc_vfunc_return_value_and_multiple_out_parameters: callback_return_value_and_multiple_out_parameters,
-    vfunc_vfunc_array_out_parameter: callback_array_out_parameter,
+const VFuncTester = GObject.registerClass(class VFuncTester extends GIMarshallingTests.Object {
+    vfunc_vfunc_return_value_only() { return 42; }
+    vfunc_vfunc_one_out_parameter() { return 43; }
+    vfunc_vfunc_multiple_out_parameters() { return [44, 45]; }
+    vfunc_vfunc_return_value_and_one_out_parameter() { return [46, 47]; }
+    vfunc_vfunc_return_value_and_multiple_out_parameters() { return [48, 49, 50]; }
+    vfunc_vfunc_array_out_parameter() { return [50, 51]; }
 });
 
 describe('Virtual function', function () {
diff --git a/installed-tests/js/testGObjectClass.js b/installed-tests/js/testGObjectClass.js
index 32684a1..9f302ad 100644
--- a/installed-tests/js/testGObjectClass.js
+++ b/installed-tests/js/testGObjectClass.js
@@ -4,7 +4,6 @@ imports.gi.versions.Gtk = '3.0';
 const Gio = imports.gi.Gio;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
-const Lang = imports.lang;
 
 const MyObject = GObject.registerClass({
     Properties: {
@@ -314,32 +313,29 @@ describe('GObject class with decorator', function () {
     });
 
     it('can have an interface-valued property', function () {
-        const InterfacePropObject = new Lang.Class({
-            Name: 'InterfacePropObject',
-            Extends: GObject.Object,
+        const InterfacePropObject = GObject.registerClass({
             Properties: {
                 'file': GObject.ParamSpec.object('file', 'File', 'File',
                     GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
                     Gio.File.$gtype)
             },
-        });
+        }, class InterfacePropObject extends GObject.Object {});
         let file = Gio.File.new_for_path('dummy');
         expect(() => new InterfacePropObject({ file: file })).not.toThrow();
     });
 
     it('can override a property from the parent class', function () {
-        const OverrideObject = new Lang.Class({
-            Name: 'OverrideObject',
-            Extends: MyObject,
+        const OverrideObject = GObject.registerClass({
             Properties: {
                 'readwrite': GObject.ParamSpec.override('readwrite', MyObject),
             },
+        }, class OverrideObject extends MyObject {
             get readwrite() {
                 return this._subclass_readwrite;
-            },
+            }
             set readwrite(val) {
                 this._subclass_readwrite = 'subclass' + val;
-            },
+            }
         });
         let obj = new OverrideObject();
         obj.readwrite = 'foo';
@@ -347,12 +343,10 @@ describe('GObject class with decorator', function () {
     });
 
     it('cannot override a non-existent property', function () {
-        expect(() => new Lang.Class({
-            Name: 'BadOverride',
-            Extends: GObject.Object,
+        expect(() => GObject.registerClass({
             Properties: {
                 'nonexistent': GObject.ParamSpec.override('nonexistent', GObject.Object),
             },
-        })).toThrow();
+        }, class BadOverride extends GObject.Object {})).toThrow();
     });
 });
diff --git a/installed-tests/js/testGio.js b/installed-tests/js/testGio.js
index 107221d..7feeb79 100644
--- a/installed-tests/js/testGio.js
+++ b/installed-tests/js/testGio.js
@@ -1,12 +1,9 @@
 const Gio = imports.gi.Gio;
 const GObject = imports.gi.GObject;
-const Lang = imports.lang;
 
-const Foo = new Lang.Class({
-    Name: 'Foo',
-    Extends: GObject.Object,
-    _init: function (value) {
-        this.parent();
+const Foo = GObject.registerClass(class Foo extends GObject.Object {
+    _init(value) {
+        super._init();
         this.value = value;
     }
 });
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index fefc2ef..4e2dd1c 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -91,13 +91,8 @@ gjstest_test_func_gjs_context_exit(void)
 }
 
 #define JS_CLASS "\
-const Lang    = imports.lang; \
 const GObject = imports.gi.GObject; \
-\
-const FooBar = new Lang.Class({ \
-    Name: 'FooBar', \
-    Extends: GObject.Object, \
-}); \
+const FooBar = GObject.registerClass(class FooBar extends GObject.Object {}); \
 "
 
 static void


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