Fix a bug in the Object contructor
authorLars Knoll <lars.knoll@digia.com>
Fri, 14 Dec 2012 13:23:21 +0000 (14:23 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 14 Dec 2012 13:29:35 +0000 (14:29 +0100)
new Object(x) should convert x to an object and return
it if x is not null or undefined

Change-Id: Icb5547a23df83018757901bfecb5f024610e7c68
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qv4ecmaobjects.cpp

index c9e0ea6..4774c78 100644 (file)
@@ -531,7 +531,10 @@ ObjectCtor::ObjectCtor(ExecutionContext *scope)
 
 Value ObjectCtor::construct(ExecutionContext *ctx)
 {
-    ctx->thisObject = Value::fromObject(ctx->engine->newObject());
+    if (!ctx->argumentCount || ctx->argument(0).isUndefined() || ctx->argument(0).isNull())
+        ctx->thisObject = Value::fromObject(ctx->engine->newObject());
+    else
+        ctx->thisObject = __qmljs_to_object(ctx->argument(0), ctx);
     return ctx->thisObject;
 }