[gjs/ewlsh/interface-resolution: 4/6] (review and squash) No need to check if the target prototype already has the property




commit a95bb2d5738b1b33c1bd7dfb4c44e4a5f059863e
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri Oct 15 14:53:24 2021 -0700

    (review and squash) No need to check if the target prototype already has the property
    
    If the target already has the property, the resolve operation is not
    called, so this check is redundant.

 gi/object.cpp                              | 11 -----------
 installed-tests/js/testGObjectInterface.js | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index b2e6df34..4ee45384 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -709,17 +709,6 @@ static bool resolve_on_interface_prototype(JSContext* cx,
     if (!prototype)
         return false;
 
-    bool target_has_property;
-    if (!JS_HasPropertyById(cx, target_prototype, identifier,
-                            &target_has_property))
-        return false;
-
-    // Don't overwrite an existing method implementation...
-    if (target_has_property) {
-        *found = true;
-        return true;
-    }
-
     JS::Rooted<JS::PropertyDescriptor> desc(cx);
     if (!JS_GetPropertyDescriptorById(cx, prototype, identifier, &desc))
         return false;
diff --git a/installed-tests/js/testGObjectInterface.js b/installed-tests/js/testGObjectInterface.js
index d7801db7..2451de06 100644
--- a/installed-tests/js/testGObjectInterface.js
+++ b/installed-tests/js/testGObjectInterface.js
@@ -331,6 +331,22 @@ describe('GObject interface', function () {
             Gio.File.prototype._originalDup = 5;
             expect(file._originalDup).toBe(5);
         });
+
+        it('original property can be shadowed by class prototype property', function () {
+            spyOn(Gio._LocalFilePrototype, 'dup').and.returnValue(5);
+
+            expect(file.dup()).toBe(5);
+            expect(Gio._LocalFilePrototype.dup).toHaveBeenCalled();
+        });
+
+        it('overridden property can be shadowed by class prototype property', function () {
+            spyOn(Gio._LocalFilePrototype, 'dup');
+            spyOn(Gio.File.prototype, 'dup');
+
+            file.dup();
+            expect(Gio._LocalFilePrototype.dup).toHaveBeenCalled();
+            expect(Gio.File.prototype.dup).not.toHaveBeenCalled();
+        });
     });
 });
 


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