fix deleteProperty on a string objects
authorLars Knoll <lars.knoll@digia.com>
Thu, 13 Jun 2013 16:27:06 +0000 (18:27 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 13 Jun 2013 16:52:21 +0000 (18:52 +0200)
For array indices that are part of the string,
deleteProperty should fail.

Change-Id: Ib253ddd5b3b04d2edc9b744a9407451c2a9778fd
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v4/qv4stringobject.cpp
src/qml/qml/v4/qv4stringobject_p.h
src/qml/qml/v8/qjsvalue.cpp

index 7e309ca..0dbd052 100644 (file)
@@ -99,6 +99,20 @@ Property *StringObject::getIndex(uint index) const
     return &tmpProperty;
 }
 
+bool StringObject::deleteIndexedProperty(Managed *m, ExecutionContext *ctx, uint index)
+{
+    StringObject *o = m->asStringObject();
+    if (!o)
+        ctx->throwTypeError();
+
+    if (index < o->value.stringValue()->toQString().length()) {
+        if (ctx->strictMode)
+            ctx->throwTypeError();
+        return false;
+    }
+    return true;
+}
+
 Property *StringObject::advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attrs)
 {
     StringObject *s = static_cast<StringObject *>(m);
index a5a64c1..a4786d8 100644 (file)
@@ -50,15 +50,18 @@ QT_BEGIN_NAMESPACE
 namespace QV4 {
 
 struct StringObject: Object {
+    Q_MANAGED
+
     Value value;
     mutable Property tmpProperty;
     StringObject(ExecutionEngine *engine, const Value &value);
 
     Property *getIndex(uint index) const;
 
+    static bool deleteIndexedProperty(Managed *m, ExecutionContext *ctx, uint index);
+
 protected:
     static Property *advanceIterator(Managed *m, ObjectIterator *it, String **name, uint *index, PropertyAttributes *attrs);
-    static const ManagedVTable static_vtbl;
     static void markObjects(Managed *that);
 };
 
index ffb4a0b..5e0c087 100644 (file)
@@ -919,7 +919,7 @@ bool QJSValue::deleteProperty(const QString &name)
         return false;
 
     ExecutionEngine *engine = d->engine();
-    String *s = engine->newIdentifier(name);
+    String *s = engine->newString(name);
     return o->deleteProperty(engine->current, s);
 }