[gjs] lang: No need to set prototype for Lang.Interface



commit e0fd6b6079187d41394d30e68d45f5b038214832
Author: Philip Chimento <philip endlessm com>
Date:   Tue Nov 22 12:26:33 2016 -0500

    lang: No need to set prototype for Lang.Interface
    
    Since we are removing any direct alterations of objects' prototypes, we
    can remove this one altogether as it turns out that it isn't necessary.
    
    The normal way to create an object with a custom prototype is
    Object.create(), and since it's not necessary for the interface object to
    be callable, we don't have to do the trick where we give a function a
    custom prototype.
    
    We still need to do the trick for GObject interfaces, because the
    interface object needs to be the object returned from
    Gi.register_interface().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751252

 modules/lang.js |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
---
diff --git a/modules/lang.js b/modules/lang.js
index 437d8bb..9583a79 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -385,19 +385,13 @@ Interface.prototype.__name__ = 'Interface';
 Interface.prototype._construct = function (params) {
     if (!params.Name)
         throw new TypeError("Interfaces require an explicit 'Name' parameter.");
-    let name = params.Name;
-
-    let newInterface = function () {
-        throw new TypeError('Cannot instantiate interface ' + name);
-    };
 
-    // See note in Class._construct(); this makes "newInterface instanceof
-    // Interface" work, and allows inheritance.
-    newInterface.__proto__ = this.constructor.prototype;
+    let newInterface = Object.create(this.constructor.prototype);
 
     newInterface.__super__ = Interface;
     newInterface.prototype = Object.create(Interface.prototype);
     newInterface.prototype.constructor = newInterface;
+    newInterface.prototype.__name__ = params.Name;
 
     newInterface._init.apply(newInterface, arguments);
 


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