[gjs/wip/gdbus-2: 13/13] GObject: fix building a class with non trivial accessor properties



commit 64894f50b96c0e4859e5246e4e8bec5fceed3779
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Fri Oct 26 19:30:39 2012 +0200

    GObject: fix building a class with non trivial accessor properties
    
    The accessors would be invoked while traversing the prototype for vfuncs.

 modules/lang.js              |    2 +-
 modules/overrides/GObject.js |   19 ++++++++++---------
 2 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/modules/lang.js b/modules/lang.js
index 84748b0..d5aeeec 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -287,7 +287,7 @@ Class.prototype._init = function(params) {
         descriptor.configurable = false;
 
         propertyObj[name] = descriptor;
-    }.bind(this));
+    }, this);
 
     Object.defineProperties(this.prototype, propertyObj);
     Object.defineProperties(this.prototype, {
diff --git a/modules/overrides/GObject.js b/modules/overrides/GObject.js
index 7765b31..9cd5886 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -68,24 +68,25 @@ const GObjectMeta = new Lang.Class({
                 Gi.add_interface(this.prototype, ifaces[i]);
         }
 
-        for (let prop in params) {
-            let value = this.prototype[prop];
-            if (typeof value === 'function') {
-                if (prop.slice(0, 6) == 'vfunc_') {
-                    Gi.hook_up_vfunc(this.prototype, prop.slice(6), value);
-                } else if (prop.slice(0, 3) == 'on_') {
-                    let id = GObject.signal_lookup(prop.slice(3).replace('_', '-'), this.$gtype);
+        Object.getOwnPropertyNames(this.prototype).forEach(function (name) {
+            let descriptor = Object.getOwnPropertyDescriptor(this.prototype, name);
+
+            if (typeof descriptor.value === 'function') {
+                if (name.slice(0, 6) == 'vfunc_') {
+                    Gi.hook_up_vfunc(this.prototype, name.slice(6), descriptor.value);
+                } else if (name.slice(0, 3) == 'on_') {
+                    let id = GObject.signal_lookup(name.slice(3).replace('_', '-'), this.$gtype);
                     if (id != 0) {
                         GObject.signal_override_class_closure(id, this.$gtype, function() {
                             let argArray = Array.prototype.slice.call(arguments);
                             let emitter = argArray.shift();
 
-                            value.apply(emitter, argArray);
+                            descriptor.value.apply(emitter, argArray);
                         });
                     }
                 }
             }
-        }
+        }, this);
     },
 
     _isValidClass: function(klass) {



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