[gjs] GObject: fix accessor properties on GObject classes



commit 48b6933a517e9a56dd27332cc13997856d3d8eba
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Fri Sep 27 14:30:43 2013 +0200

    GObject: fix accessor properties on GObject classes
    
    We must not access this.prototype blindly, because a property
    there might be an accessor that relies on some external state
    we don't have on prototypes. Instead, access the property descriptor,
    like Lang.Class does.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=708920

 modules/overrides/GObject.js |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/modules/overrides/GObject.js b/modules/overrides/GObject.js
index f8f74da..d4ec6bc 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -51,24 +51,31 @@ const GObjectMeta = new Lang.Class({
             }
         }
 
-        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);
+       let propertyObj = { };
+       Object.getOwnPropertyNames(params).forEach(function(name) {
+            if (name == 'Name' || name == 'Extends' || name == 'Abstract')
+               return;
+
+            let descriptor = Object.getOwnPropertyDescriptor(params, name);
+
+            if (typeof descriptor.value === 'function') {
+               let wrapped = this.prototype[name];
+
+                if (name.slice(0, 6) == 'vfunc_') {
+                    Gi.hook_up_vfunc(this.prototype, name.slice(6), wrapped);
+                } 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);
+                            wrapped.apply(emitter, argArray);
                         });
                     }
                 }
-            }
-        }
+           }
+       }.bind(this));
     },
 
     _isValidClass: function(klass) {


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