[gjs/mozjs31] lang: Interfaces shouldn't clobber inherited props



commit f1d06ab6f0df2106709bfc0dbac3754f37f31547
Author: Philip Chimento <philip endlessm com>
Date:   Thu Nov 17 17:52:22 2016 -0800

    lang: Interfaces shouldn't clobber inherited props
    
    Working on the __proto__ stuff exposed a bug in interfaces: when an
    object implements an interface, all properties from the interface will be
    copied over to the object. However, this would hide any properties from
    the object's prototype chain with the same name, for example from a
    parent class which also implemented the interface.
    
    We had a test which purported to test this exact situation, but there was
    also a check that assumed if a parent class implemented an interface,
    then we didn't need to check if the derived class did so correctly too.
    This fixes both the test and the bug.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751252

 installed-tests/js/testInterface.js |    1 +
 modules/lang.js                     |    3 ++-
 2 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/installed-tests/js/testInterface.js b/installed-tests/js/testInterface.js
index d634e76..2af1171 100644
--- a/installed-tests/js/testInterface.js
+++ b/installed-tests/js/testInterface.js
@@ -329,6 +329,7 @@ function testSubclassCanReimplementTheSameInterfaceAsItsParent() {
     });
     let obj = new SubImplementer();
     JSUnit.assertTrue(obj.constructor.implements(AnInterface));
+    obj.required();  // should not throw NotImplemented
 }
 
 function testToString() {
diff --git a/modules/lang.js b/modules/lang.js
index 1852dbe..437d8bb 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -272,6 +272,7 @@ Class.prototype._init = function(params) {
     interfaces.forEach((iface) => {
         Object.getOwnPropertyNames(iface.prototype)
         .filter((name) => !name.startsWith('__') && name !== 'constructor')
+        .filter((name) => !(name in this.prototype))
         .forEach((name) => {
             let descriptor = Object.getOwnPropertyDescriptor(iface.prototype,
                 name);
@@ -372,7 +373,7 @@ Class.MetaInterface = Interface;
  * of the interface. Creating a class that doesn't override the function will
  * throw an error.
  */
-Interface.UNIMPLEMENTED = function () {
+Interface.UNIMPLEMENTED = function UNIMPLEMENTED () {
     throw new Error('Not implemented');
 };
 


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