Saner handling of property deleting with internal classes
authorLars Knoll <lars.knoll@digia.com>
Tue, 12 Feb 2013 12:14:19 +0000 (13:14 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 12 Feb 2013 15:27:01 +0000 (16:27 +0100)
Build up a new internal class from the empty class with the
deleted member removed. The add a transition for removal from
the current class to the new one.

This avoids bad behavior in pathological cases where someone
would remove a member, then add it again etc.

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

index d062e8d..b192459 100644 (file)
@@ -99,17 +99,14 @@ void InternalClass::removeMember(Object *object, uint id)
     }
 
     // create a new class and add it to the tree
-    InternalClass *newClass = new InternalClass(*this);
-    newClass->propertyTable.remove(id);
-    newClass->nameMap.remove(propIdx);
-    --newClass->size;
-    for (QHash<uint, uint>::iterator it = newClass->propertyTable.begin(); it != newClass->propertyTable.end(); ++it) {
-        if ((*it) > propIdx)
-            --(*it);
+    object->internalClass = engine->emptyClass;
+    for (int i = 0; i < nameMap.size(); ++i) {
+        if (i == propIdx)
+            continue;
+        object->internalClass->getOrAddMember(object, nameMap.at(i));
     }
 
-    transitions.insert(toRemove, newClass);
-    object->internalClass = newClass;
+    transitions.insert(toRemove, object->internalClass);
 }
 
 uint InternalClass::find(String *string)