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



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

    class: Move to ES6 GObject classes in internal code
    
    This moves all remaining uses of Lang.Class (except for where the legacy
    class framework is explicitly tested) from the codebase, in favour of
    GObject.registerClass().

 installed-tests/js/testExceptions.js    |   15 +++------
 installed-tests/js/testGIMarshalling.js |   54 +++++++-----------------------
 installed-tests/js/testGio.js           |    9 ++---
 test/gjs-tests.cpp                      |    7 +---
 4 files changed, 22 insertions(+), 63 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/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]