Implement Object.defineProperties and fix Object.create
authorLars Knoll <lars.knoll@digia.com>
Tue, 11 Dec 2012 19:27:17 +0000 (20:27 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 11 Dec 2012 14:06:07 +0000 (15:06 +0100)
Change-Id: I5a55b8d9b3c8e34018defcbe8ee97bde43a714c6
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qv4ecmaobjects.cpp

index b7d2e88..64c56bb 100644 (file)
@@ -618,8 +618,10 @@ Value ObjectPrototype::method_create(ExecutionContext *ctx)
     newObject->prototype = O.objectValue();
 
     Value objValue = Value::fromObject(newObject);
-    ctx->arguments[0] = objValue;
-    method_defineProperties(ctx);
+    if (ctx->argumentCount > 1) {
+        ctx->arguments[0] = objValue;
+        method_defineProperties(ctx);
+    }
 
     return objValue;
 }
@@ -650,8 +652,22 @@ Value ObjectPrototype::method_defineProperties(ExecutionContext *ctx)
     if (!O.isObject())
         ctx->throwTypeError();
 
-    ctx->throwUnimplemented(QStringLiteral("Object.defineProperties"));
-    return Value::undefinedValue();
+    Object *o = ctx->argument(1).toObject(ctx).objectValue();
+
+    if (o->members) {
+        PropertyTable::iterator it = o->members->begin();
+        while (it != o->members->end()) {
+            if ((*it)->descriptor.isEnumerable()) {
+                String *name = (*it)->name;
+                PropertyDescriptor pd;
+                toPropertyDescriptor(ctx, o->__get__(ctx, name), &pd);
+                O.objectValue()->__defineOwnProperty__(ctx, name, &pd);
+            }
+            ++it;
+        }
+    }
+
+    return O;
 }
 
 Value ObjectPrototype::method_seal(ExecutionContext *ctx)