Use faster call/construct methods
authorLars Knoll <lars.knoll@digia.com>
Thu, 14 Feb 2013 08:20:33 +0000 (09:20 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 14 Feb 2013 11:01:07 +0000 (12:01 +0100)
Change-Id: I3e3c2ab42f20d9d5f38d3f9681d05de9487d80bd
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
14 files changed:
src/v4/qv4booleanobject.cpp
src/v4/qv4booleanobject.h
src/v4/qv4dateobject.cpp
src/v4/qv4dateobject.h
src/v4/qv4errorobject.cpp
src/v4/qv4errorobject.h
src/v4/qv4functionobject.cpp
src/v4/qv4functionobject.h
src/v4/qv4globalobject.cpp
src/v4/qv4globalobject.h
src/v4/qv4numberobject.cpp
src/v4/qv4numberobject.h
src/v4/qv4objectproto.cpp
src/v4/qv4objectproto.h

index 748a695..02fab7b 100644 (file)
@@ -48,9 +48,9 @@ BooleanCtor::BooleanCtor(ExecutionContext *scope)
 {
 }
 
-Value BooleanCtor::construct(ExecutionContext *ctx)
+Value BooleanCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    const double n = ctx->argument(0).toBoolean(ctx);
+    bool n = argc ? args[0].toBoolean(ctx) : false;
     return Value::fromObject(ctx->engine->newBooleanObject(Value::fromBoolean(n)));
 }
 
index c73ae9b..da9105e 100644 (file)
@@ -54,7 +54,7 @@ struct BooleanCtor: FunctionObject
 {
     BooleanCtor(ExecutionContext *scope);
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
     virtual Value call(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc);
 };
 
index bdfc4be..77157d2 100644 (file)
@@ -664,15 +664,15 @@ DateCtor::DateCtor(ExecutionContext *scope)
 {
 }
 
-Value DateCtor::construct(ExecutionContext *ctx)
+Value DateCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
     double t = 0;
 
-    if (ctx->argumentCount == 0)
+    if (argc == 0)
         t = currentTime();
 
-    else if (ctx->argumentCount == 1) {
-        Value arg = ctx->argument(0);
+    else if (argc == 1) {
+        Value arg = args[0];
         if (DateObject *d = arg.asDateObject())
             arg = d->value;
         else
@@ -684,14 +684,14 @@ Value DateCtor::construct(ExecutionContext *ctx)
             t = TimeClip(arg.toNumber(ctx));
     }
 
-    else { // ctx->argumentCount > 1
-        double year  = ctx->argument(0).toNumber(ctx);
-        double month = ctx->argument(1).toNumber(ctx);
-        double day  = ctx->argumentCount >= 3 ? ctx->argument(2).toNumber(ctx) : 1;
-        double hours = ctx->argumentCount >= 4 ? ctx->argument(3).toNumber(ctx) : 0;
-        double mins = ctx->argumentCount >= 5 ? ctx->argument(4).toNumber(ctx) : 0;
-        double secs = ctx->argumentCount >= 6 ? ctx->argument(5).toNumber(ctx) : 0;
-        double ms    = ctx->argumentCount >= 7 ? ctx->argument(6).toNumber(ctx) : 0;
+    else { // argc > 1
+        double year  = args[0].toNumber(ctx);
+        double month = args[1].toNumber(ctx);
+        double day  = argc >= 3 ? args[2].toNumber(ctx) : 1;
+        double hours = argc >= 4 ? args[3].toNumber(ctx) : 0;
+        double mins = argc >= 5 ? args[4].toNumber(ctx) : 0;
+        double secs = argc >= 6 ? args[5].toNumber(ctx) : 0;
+        double ms    = argc >= 7 ? args[6].toNumber(ctx) : 0;
         if (year >= 0 && year <= 99)
             year += 1900;
         t = MakeDate(MakeDay(year, month, day), MakeTime(hours, mins, secs, ms));
index 15bd99f..56f96aa 100644 (file)
@@ -59,7 +59,7 @@ struct DateCtor: FunctionObject
 {
     DateCtor(ExecutionContext *scope);
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
     virtual Value call(ExecutionContext *ctx);
 };
 
index c6b0a12..50797b7 100644 (file)
@@ -79,7 +79,7 @@ ErrorObject::ErrorObject(ExecutionEngine* engine, const Value &message)
     type = Type_ErrorObject;
     subtype = Error;
 
-    if (message.type() != Value::Undefined_Type)
+    if (!message.isUndefined())
         defineDefaultProperty(engine->newString(QStringLiteral("message")), message);
 }
 
@@ -99,72 +99,64 @@ SyntaxErrorObject::SyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *m
 
 
 
-EvalErrorObject::EvalErrorObject(ExecutionContext *ctx)
-    : ErrorObject(ctx->engine, ctx->argument(0))
+EvalErrorObject::EvalErrorObject(ExecutionContext *ctx, const Value &message)
+    : ErrorObject(ctx->engine, message)
 {
     subtype = EvalError;
     setNameProperty(ctx);
     prototype = ctx->engine->evalErrorPrototype;
 }
 
-RangeErrorObject::RangeErrorObject(ExecutionContext *ctx)
-    : ErrorObject(ctx->engine, ctx->argument(0))
+RangeErrorObject::RangeErrorObject(ExecutionContext *ctx, const Value &message)
+    : ErrorObject(ctx->engine, message)
 {
     subtype = RangeError;
     setNameProperty(ctx);
     prototype = ctx->engine->rangeErrorPrototype;
 }
 
-RangeErrorObject::RangeErrorObject(ExecutionContext *ctx, const QString &msg)
-    : ErrorObject(ctx->engine, Value::fromString(ctx,msg))
+RangeErrorObject::RangeErrorObject(ExecutionContext *ctx, const QString &message)
+    : ErrorObject(ctx->engine, Value::fromString(ctx,message))
 {
     subtype = RangeError;
     setNameProperty(ctx);
     prototype = ctx->engine->rangeErrorPrototype;
 }
 
-ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx)
-    : ErrorObject(ctx->engine, ctx->argument(0))
+ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx, const Value &message)
+    : ErrorObject(ctx->engine, message)
 {
     subtype = ReferenceError;
     setNameProperty(ctx);
     prototype = ctx->engine->referenceErrorPrototype;
 }
 
-ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx, const QString &msg)
-    : ErrorObject(ctx->engine, Value::fromString(ctx,msg))
+ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx, const QString &message)
+    : ErrorObject(ctx->engine, Value::fromString(ctx,message))
 {
     subtype = ReferenceError;
     setNameProperty(ctx);
     prototype = ctx->engine->referenceErrorPrototype;
 }
 
-TypeErrorObject::TypeErrorObject(ExecutionContext *ctx)
-    : ErrorObject(ctx->engine, ctx->argument(0))
+TypeErrorObject::TypeErrorObject(ExecutionContext *ctx, const Value &message)
+    : ErrorObject(ctx->engine, message)
 {
     subtype = TypeError;
     setNameProperty(ctx);
     prototype = ctx->engine->typeErrorPrototype;
 }
 
-TypeErrorObject::TypeErrorObject(ExecutionContext *ctx, const QString &msg)
-    : ErrorObject(ctx->engine, Value::fromString(ctx,msg))
+TypeErrorObject::TypeErrorObject(ExecutionContext *ctx, const QString &message)
+    : ErrorObject(ctx->engine, Value::fromString(ctx,message))
 {
     subtype = TypeError;
     setNameProperty(ctx);
     prototype = ctx->engine->typeErrorPrototype;
 }
 
-URIErrorObject::URIErrorObject(ExecutionContext *ctx)
-    : ErrorObject(ctx->engine, ctx->argument(0))
-{
-    subtype = URIError;
-    setNameProperty(ctx);
-    prototype = ctx->engine->uRIErrorPrototype;
-}
-
-URIErrorObject::URIErrorObject(ExecutionContext *ctx, Value msg)
-    : ErrorObject(ctx->engine, msg)
+URIErrorObject::URIErrorObject(ExecutionContext *ctx, const Value &message)
+    : ErrorObject(ctx->engine, message)
 {
     subtype = URIError;
     setNameProperty(ctx);
@@ -177,44 +169,44 @@ ErrorCtor::ErrorCtor(ExecutionContext *scope)
 {
 }
 
-Value ErrorCtor::construct(ExecutionContext *ctx)
+Value ErrorCtor::construct(ExecutionContext *context, Value *args, int argc)
 {
-    return Value::fromObject(ctx->engine->newErrorObject(ctx->argument(0)));
+    return Value::fromObject(context->engine->newErrorObject(argc ? args[0] : Value::undefinedValue()));
 }
 
-Value ErrorCtor::call(ExecutionContext *ctx)
+Value ErrorCtor::call(ExecutionContext *ctx, Value thisObject, Value *args, int argc)
 {
-    return construct(ctx);
+    return construct(ctx, args, argc);
 }
 
-Value EvalErrorCtor::construct(ExecutionContext *ctx)
+Value EvalErrorCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    return Value::fromObject(new (ctx->engine->memoryManager) EvalErrorObject(ctx));
+    return Value::fromObject(new (ctx->engine->memoryManager) EvalErrorObject(ctx, argc ? args[0] : Value::undefinedValue()));
 }
 
-Value RangeErrorCtor::construct(ExecutionContext *ctx)
+Value RangeErrorCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    return Value::fromObject(new (ctx->engine->memoryManager) RangeErrorObject(ctx));
+    return Value::fromObject(new (ctx->engine->memoryManager) RangeErrorObject(ctx, argc ? args[0] : Value::undefinedValue()));
 }
 
-Value ReferenceErrorCtor::construct(ExecutionContext *ctx)
+Value ReferenceErrorCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    return Value::fromObject(new (ctx->engine->memoryManager) ReferenceErrorObject(ctx));
+    return Value::fromObject(new (ctx->engine->memoryManager) ReferenceErrorObject(ctx, argc ? args[0] : Value::undefinedValue()));
 }
 
-Value SyntaxErrorCtor::construct(ExecutionContext *ctx)
+Value SyntaxErrorCtor::construct(ExecutionContext *ctx, Value *, int)
 {
     return Value::fromObject(new (ctx->engine->memoryManager) SyntaxErrorObject(ctx, 0));
 }
 
-Value TypeErrorCtor::construct(ExecutionContext *ctx)
+Value TypeErrorCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    return Value::fromObject(new (ctx->engine->memoryManager) TypeErrorObject(ctx));
+    return Value::fromObject(new (ctx->engine->memoryManager) TypeErrorObject(ctx, argc ? args[0] : Value::undefinedValue()));
 }
 
-Value URIErrorCtor::construct(ExecutionContext *ctx)
+Value URIErrorCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    return Value::fromObject(new (ctx->engine->memoryManager) URIErrorObject(ctx));
+    return Value::fromObject(new (ctx->engine->memoryManager) URIErrorObject(ctx, argc ? args[0] : Value::undefinedValue()));
 }
 
 void ErrorPrototype::init(ExecutionContext *ctx, const Value &ctor, Object *obj)
index 452b7b3..651951c 100644 (file)
@@ -69,16 +69,16 @@ protected:
 };
 
 struct EvalErrorObject: ErrorObject {
-    EvalErrorObject(ExecutionContext *ctx);
+    EvalErrorObject(ExecutionContext *ctx, const Value &message);
 };
 
 struct RangeErrorObject: ErrorObject {
-    RangeErrorObject(ExecutionContext *ctx);
+    RangeErrorObject(ExecutionContext *ctx, const Value &message);
     RangeErrorObject(ExecutionContext *ctx, const QString &msg);
 };
 
 struct ReferenceErrorObject: ErrorObject {
-    ReferenceErrorObject(ExecutionContext *ctx);
+    ReferenceErrorObject(ExecutionContext *ctx, const Value &message);
     ReferenceErrorObject(ExecutionContext *ctx, const QString &msg);
 };
 
@@ -94,63 +94,62 @@ private:
 };
 
 struct TypeErrorObject: ErrorObject {
-    TypeErrorObject(ExecutionContext *ctx);
+    TypeErrorObject(ExecutionContext *ctx, const Value &message);
     TypeErrorObject(ExecutionContext *ctx, const QString &msg);
 };
 
 struct URIErrorObject: ErrorObject {
-    URIErrorObject(ExecutionContext *ctx);
-    URIErrorObject(ExecutionContext *ctx, Value);
+    URIErrorObject(ExecutionContext *ctx, const Value &message);
 };
 
 struct ErrorCtor: FunctionObject
 {
     ErrorCtor(ExecutionContext *scope);
 
-    virtual Value construct(ExecutionContext *ctx);
-    virtual Value call(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *context, Value *args, int argc);
+    virtual Value call(ExecutionContext *ctx, Value thisObject, Value *args, int argc);
 };
 
 struct EvalErrorCtor: ErrorCtor
 {
     EvalErrorCtor(ExecutionContext *scope): ErrorCtor(scope) {}
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *, int argc);
 };
 
 struct RangeErrorCtor: ErrorCtor
 {
     RangeErrorCtor(ExecutionContext *scope): ErrorCtor(scope) {}
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
 };
 
 struct ReferenceErrorCtor: ErrorCtor
 {
     ReferenceErrorCtor(ExecutionContext *scope): ErrorCtor(scope) {}
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
 };
 
 struct SyntaxErrorCtor: ErrorCtor
 {
     SyntaxErrorCtor(ExecutionContext *scope): ErrorCtor(scope) {}
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *, int);
 };
 
 struct TypeErrorCtor: ErrorCtor
 {
     TypeErrorCtor(ExecutionContext *scope): ErrorCtor(scope) {}
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
 };
 
 struct URIErrorCtor: ErrorCtor
 {
     URIErrorCtor(ExecutionContext *scope): ErrorCtor(scope) {}
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
 };
 
 
@@ -166,19 +165,19 @@ struct ErrorPrototype: ErrorObject
 
 struct EvalErrorPrototype: EvalErrorObject
 {
-    EvalErrorPrototype(ExecutionContext *ctx): EvalErrorObject(ctx) {}
+    EvalErrorPrototype(ExecutionContext *ctx): EvalErrorObject(ctx, Value::undefinedValue()) {}
     void init(ExecutionContext *ctx, const Value &ctor) { ErrorPrototype::init(ctx, ctor, this); }
 };
 
 struct RangeErrorPrototype: RangeErrorObject
 {
-    RangeErrorPrototype(ExecutionContext *ctx): RangeErrorObject(ctx) {}
+    RangeErrorPrototype(ExecutionContext *ctx): RangeErrorObject(ctx, Value::undefinedValue()) {}
     void init(ExecutionContext *ctx, const Value &ctor) { ErrorPrototype::init(ctx, ctor, this); }
 };
 
 struct ReferenceErrorPrototype: ReferenceErrorObject
 {
-    ReferenceErrorPrototype(ExecutionContext *ctx): ReferenceErrorObject(ctx) {}
+    ReferenceErrorPrototype(ExecutionContext *ctx): ReferenceErrorObject(ctx, Value::undefinedValue()) {}
     void init(ExecutionContext *ctx, const Value &ctor) { ErrorPrototype::init(ctx, ctor, this); }
 };
 
@@ -190,13 +189,13 @@ struct SyntaxErrorPrototype: SyntaxErrorObject
 
 struct TypeErrorPrototype: TypeErrorObject
 {
-    TypeErrorPrototype(ExecutionContext *ctx): TypeErrorObject(ctx) {}
+    TypeErrorPrototype(ExecutionContext *ctx): TypeErrorObject(ctx, Value::undefinedValue()) {}
     void init(ExecutionContext *ctx, const Value &ctor) { ErrorPrototype::init(ctx, ctor, this); }
 };
 
 struct URIErrorPrototype: URIErrorObject
 {
-    URIErrorPrototype(ExecutionContext *ctx): URIErrorObject(ctx) {}
+    URIErrorPrototype(ExecutionContext *ctx): URIErrorObject(ctx, Value::undefinedValue()) {}
     void init(ExecutionContext *ctx, const Value &ctor) { ErrorPrototype::init(ctx, ctor, this); }
 };
 
index b404ecf..0f9655c 100644 (file)
@@ -222,22 +222,22 @@ FunctionCtor::FunctionCtor(ExecutionContext *scope)
 }
 
 // 15.3.2
-Value FunctionCtor::construct(ExecutionContext *ctx)
+Value FunctionCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
     MemoryManager::GCBlocker gcBlocker(ctx->engine->memoryManager);
 
-    QString args;
+    QString arguments;
     QString body;
-    if (ctx->argumentCount > 0) {
-        for (uint i = 0; i < ctx->argumentCount - 1; ++i) {
+    if (argc > 0) {
+        for (uint i = 0; i < argc - 1; ++i) {
             if (i)
-                args += QLatin1String(", ");
-            args += ctx->argument(i).toString(ctx)->toQString();
+                arguments += QLatin1String(", ");
+            arguments += args[i].toString(ctx)->toQString();
         }
-        body = ctx->argument(ctx->argumentCount - 1).toString(ctx)->toQString();
+        body = args[argc - 1].toString(ctx)->toQString();
     }
 
-    QString function = QLatin1String("function(") + args + QLatin1String("){") + body + QLatin1String("}");
+    QString function = QLatin1String("function(") + arguments + QLatin1String("){") + body + QLatin1String("}");
 
     QQmlJS::Engine ee, *engine = &ee;
     Lexer lexer(engine);
@@ -256,7 +256,7 @@ Value FunctionCtor::construct(ExecutionContext *ctx)
 
     IR::Module module;
 
-    Codegen cg(ctx, ctx->strictMode);
+    Codegen cg(ctx, strictMode);
     IR::Function *irf = cg(QString(), fe, &module);
 
     QScopedPointer<EvalInstructionSelection> isel(ctx->engine->iselFactory->create(ctx->engine, &module));
@@ -266,9 +266,9 @@ Value FunctionCtor::construct(ExecutionContext *ctx)
 }
 
 // 15.3.1: This is equivalent to new Function(...)
-Value FunctionCtor::call(ExecutionContext *ctx)
+Value FunctionCtor::call(ExecutionContext *context, Value thisObject, Value *args, int argc)
 {
-    return construct(ctx);
+    return construct(context, args, argc);
 }
 
 void FunctionPrototype::init(ExecutionContext *ctx, const Value &ctor)
@@ -420,7 +420,7 @@ BuiltinFunctionOld::BuiltinFunctionOld(ExecutionContext *scope, String *name, Va
     isBuiltinFunction = true;
 }
 
-Value BuiltinFunctionOld::construct(ExecutionContext *ctx)
+Value BuiltinFunctionOld::construct(ExecutionContext *ctx, Value *, int)
 {
     ctx->throwTypeError();
     return Value::undefinedValue();
@@ -434,7 +434,7 @@ BuiltinFunction::BuiltinFunction(ExecutionContext *scope, String *name, Value (*
     isBuiltinFunction = true;
 }
 
-Value BuiltinFunction::construct(ExecutionContext *ctx)
+Value BuiltinFunction::construct(ExecutionContext *ctx, Value *, int)
 {
     ctx->throwTypeError();
     return Value::undefinedValue();
index 5cc0aab..c5f74de 100644 (file)
@@ -174,8 +174,8 @@ struct FunctionCtor: FunctionObject
 {
     FunctionCtor(ExecutionContext *scope);
 
-    virtual Value construct(ExecutionContext *ctx);
-    virtual Value call(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
+    virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
 };
 
 struct FunctionPrototype: FunctionObject
@@ -194,7 +194,7 @@ struct BuiltinFunctionOld: FunctionObject {
 
     BuiltinFunctionOld(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *));
     virtual Value call(ExecutionContext *ctx) { return code(ctx); }
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *, int);
 };
 
 struct BuiltinFunction: FunctionObject {
@@ -204,7 +204,7 @@ struct BuiltinFunction: FunctionObject {
     virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc) {
         return code(context, thisObject, args, argc);
     }
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *, int);
 };
 
 struct ScriptFunction: FunctionObject {
index 8a0f779..384bce5 100644 (file)
@@ -408,7 +408,7 @@ Value EvalFunction::call(ExecutionContext *context, Value thisObject, Value *arg
     return evalCall(context, thisObject, args, argc, false);
 }
 
-Value EvalFunction::construct(ExecutionContext *ctx)
+Value EvalFunction::construct(ExecutionContext *ctx, Value *, int)
 {
     ctx->throwTypeError();
     return Value::undefinedValue();
index 8399c94..e15b7b2 100644 (file)
@@ -62,7 +62,7 @@ struct Q_V4_EXPORT EvalFunction : FunctionObject
     virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc);
     Value evalCall(ExecutionContext *context, Value thisObject, Value *args, int argc, bool directCall);
 
-    Value construct(ExecutionContext *ctx);
+    Value construct(ExecutionContext *ctx, Value *, int);
 };
 
 struct GlobalFunctions
index 57cfab9..0601da6 100644 (file)
@@ -54,9 +54,9 @@ NumberCtor::NumberCtor(ExecutionContext *scope)
 {
 }
 
-Value NumberCtor::construct(ExecutionContext *ctx)
+Value NumberCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    double d = ctx->argumentCount ? ctx->argument(0).toNumber(ctx) : 0;
+    double d = argc ? args[0].toNumber(ctx) : 0.;
     return Value::fromObject(ctx->engine->newNumberObject(Value::fromDouble(d)));
 }
 
index b24e538..e9125ab 100644 (file)
@@ -54,7 +54,7 @@ struct NumberCtor: FunctionObject
 {
     NumberCtor(ExecutionContext *scope);
 
-    virtual Value construct(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
     virtual Value call(ExecutionContext *parentCtx, Value thisObject, Value *argv, int argc);
 };
 
index 09ffb6a..de8b7ff 100644 (file)
@@ -79,18 +79,23 @@ ObjectCtor::ObjectCtor(ExecutionContext *scope)
 {
 }
 
-Value ObjectCtor::construct(ExecutionContext *ctx)
+Value ObjectCtor::construct(ExecutionContext *ctx, Value *args, int argc)
 {
-    if (!ctx->argumentCount || ctx->argument(0).isUndefined() || ctx->argument(0).isNull())
-        return ctx->thisObject;
-    return __qmljs_to_object(ctx->argument(0), ctx);
+    if (!argc || args[0].isUndefined() || args[0].isNull()) {
+        Object *obj = ctx->engine->newObject();
+        Value proto = __get__(ctx, ctx->engine->id_prototype);
+        if (proto.isObject())
+            obj->prototype = proto.objectValue();
+        return Value::fromObject(obj);
+    }
+    return __qmljs_to_object(args[0], ctx);
 }
 
-Value ObjectCtor::call(ExecutionContext *ctx)
+Value ObjectCtor::call(ExecutionContext *ctx, Value /*thisObject*/, Value *args, int argc)
 {
-    if (!ctx->argumentCount || ctx->argument(0).isUndefined() || ctx->argument(0).isNull())
+    if (!argc || args[0].isUndefined() || args[0].isNull())
         return Value::fromObject(ctx->engine->newObject());
-    return __qmljs_to_object(ctx->argument(0), ctx);
+    return __qmljs_to_object(args[0], ctx);
 }
 
 void ObjectPrototype::init(ExecutionContext *ctx, const Value &ctor)
index 679c271..6341128 100644 (file)
@@ -54,8 +54,8 @@ struct ObjectCtor: FunctionObject
 {
     ObjectCtor(ExecutionContext *scope);
 
-    virtual Value construct(ExecutionContext *ctx);
-    virtual Value call(ExecutionContext *ctx);
+    virtual Value construct(ExecutionContext *ctx, Value *args, int argc);
+    virtual Value call(ExecutionContext *ctx, Value, Value *args, int argc);
 };
 
 struct ObjectPrototype: Object