[gjs] function: Fix Function.length for GI functions



commit d59dad5747628c467d486d2d29afeab43fc74af1
Author: Philip Chimento <philip chimento gmail com>
Date:   Thu Jan 12 23:52:57 2017 -0800

    function: Fix Function.length for GI functions
    
    The "length" property of a function is supposed to contain the number of
    arguments in its signature. This was implemented for GI functions, but
    due to a missing ++ it always returned 0.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777205

 gi/function.cpp                                  |    2 +
 installed-tests/js/testEverythingEncapsulated.js |   31 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index dc14281..0c564c4 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -1395,6 +1395,8 @@ get_num_arguments (JSContext *context,
 
         if (g_arg_info_get_direction(&arg_info) == GI_DIRECTION_OUT)
             continue;
+
+        n_jsargs++;
     }
 
     rec.rval().setInt32(n_jsargs);
diff --git a/installed-tests/js/testEverythingEncapsulated.js 
b/installed-tests/js/testEverythingEncapsulated.js
index c627c5e..e985546 100644
--- a/installed-tests/js/testEverythingEncapsulated.js
+++ b/installed-tests/js/testEverythingEncapsulated.js
@@ -230,3 +230,34 @@ describe('Introspected GObject', function () {
         expect(obj.hasOwnProperty('ownprop')).toBeTruthy();
     });
 });
+
+describe('Introspected function length', function () {
+    let obj;
+    beforeEach(function () {
+        obj = new Regress.TestObj();
+    });
+
+    it('skips over instance parameters of methods', function () {
+        expect(obj.set_bare.length).toEqual(1);
+    });
+
+    it('skips over out and GError parameters', function () {
+        expect(obj.torture_signature_1.length).toEqual(3);
+    });
+
+    it('does not skip over inout parameters', function () {
+        expect(obj.skip_return_val.length).toEqual(5);
+    });
+
+    xit('skips over parameters annotated with skip', function () {
+        expect(obj.skip_param.length).toEqual(4);
+    }).pend('Not implemented yet');
+
+    it('gives number of arguments for static methods', function () {
+        expect(Regress.TestObj.new_from_file.length).toEqual(1);
+    });
+
+    it('skips over destroy-notify and user-data parameters', function () {
+        expect(Regress.TestObj.new_callback.length).toEqual(1);
+    });
+});


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