Fix builtin_define_property
authorLars Knoll <lars.knoll@digia.com>
Sat, 2 Mar 2013 23:50:33 +0000 (00:50 +0100)
committerLars Knoll <lars.knoll@digia.com>
Sun, 3 Mar 2013 10:13:04 +0000 (11:13 +0100)
Commit 72c1fe5822aa65f4a3f70f78e058fb7e3154a4b6 broke
object literals that uses numbers as keys (e.g.
{ "2": "bla" }. This fixes it while keeping the faster
code path.

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

index b511cf3..76361c0 100644 (file)
@@ -1237,8 +1237,8 @@ void __qmljs_builtin_define_property(ExecutionContext *ctx, const Value &object,
     Object *o = object.asObject();
     assert(o);
 
-
-    PropertyDescriptor *pd = o->insertMember(name);
+    uint idx = name->asArrayIndex();
+    PropertyDescriptor *pd = (idx != UINT_MAX) ? o->arrayInsert(idx) : o->insertMember(name);
     pd->value = val ? *val : Value::undefinedValue();
     pd->type = PropertyDescriptor::Data;
     pd->writable = PropertyDescriptor::Enabled;
@@ -1282,14 +1282,14 @@ void __qmljs_builtin_define_getter_setter(ExecutionContext *ctx, const Value &ob
     Object *o = object.asObject();
     assert(o);
 
-    PropertyDescriptor pd;
-    pd.get = getter ? getter->asFunctionObject() : 0;
-    pd.set = setter ? setter->asFunctionObject() : 0;
-    pd.type = PropertyDescriptor::Accessor;
-    pd.writable = PropertyDescriptor::Undefined;
-    pd.enumberable = PropertyDescriptor::Enabled;
-    pd.configurable = PropertyDescriptor::Enabled;
-    o->__defineOwnProperty__(ctx, name, &pd);
+    uint idx = name->asArrayIndex();
+    PropertyDescriptor *pd = (idx != UINT_MAX) ? o->arrayInsert(idx) : o->insertMember(name);
+    pd->get = getter ? getter->asFunctionObject() : 0;
+    pd->set = setter ? setter->asFunctionObject() : 0;
+    pd->type = PropertyDescriptor::Accessor;
+    pd->writable = PropertyDescriptor::Undefined;
+    pd->enumberable = PropertyDescriptor::Enabled;
+    pd->configurable = PropertyDescriptor::Enabled;
 }
 
 void __qmljs_increment(ExecutionContext *ctx, Value *result, const Value &value)