Fix for..in with duplicated properties
authorLars Knoll <lars.knoll@digia.com>
Thu, 13 Jun 2013 15:15:57 +0000 (17:15 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 13 Jun 2013 15:42:23 +0000 (17:42 +0200)
Properties that already appeared earlier in the
proto chain should get skipped by for..in (as they
are inaccessible from JS).

Change-Id: Ia0d9cc8582f96df4b2aaaa409d884f206456fe89
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v4/qv4objectiterator.cpp

index 9c48ec7..984d470 100644 (file)
@@ -65,9 +65,21 @@ Property *ObjectIterator::next(String **name, uint *index, PropertyAttributes *a
         if (!current)
             break;
 
-        p = current->advanceIterator(this, name, index, attrs);
-        if (p)
+        while (p = current->advanceIterator(this, name, index, attrs)) {
+            // check the property is not already defined earlier in the proto chain
+            if (current != object) {
+                Property *pp;
+                if (*name) {
+                    pp = object->__getPropertyDescriptor__(*name);
+                } else {
+                    assert (*index != UINT_MAX);
+                    pp = object->__getPropertyDescriptor__(*index);
+                }
+                if (pp != p)
+                    continue;
+            }
             return p;
+        }
 
         if (flags & WithProtoChain)
             current = current->prototype;