From 5ac7bd9cb6be0977595f90fd66c3282e48f11a29 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 13 Jun 2013 13:17:20 +0200 Subject: [PATCH] Revert "Ported boolean prototype over to class generator" This reverts commit b6263687dd876959379022090eb8d43a0dbcdd08. Conflicts: src/qml/qml/v4/v4.pri Change-Id: Iebaad46adea26c788b541a111e881af3d305e46a Reviewed-by: Lars Knoll --- src/qml/qml/v4/qv4booleanobject.cpp | 23 +++++++++++++++++++---- src/qml/qml/v4/qv4booleanobject_p.h | 24 +++++++++++++++--------- src/qml/qml/v4/qv4engine.cpp | 4 ++-- src/qml/qml/v4/v4.pri | 1 - 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/qml/qml/v4/qv4booleanobject.cpp b/src/qml/qml/v4/qv4booleanobject.cpp index bee08dc..3395e79 100644 --- a/src/qml/qml/v4/qv4booleanobject.cpp +++ b/src/qml/qml/v4/qv4booleanobject.cpp @@ -43,18 +43,35 @@ using namespace QV4; -Value BooleanPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, Value *args, int argc) +DEFINE_MANAGED_VTABLE(BooleanCtor); + +BooleanCtor::BooleanCtor(ExecutionContext *scope) + : FunctionObject(scope, scope->engine->newIdentifier("Boolean")) +{ + vtbl = &static_vtbl; +} + +Value BooleanCtor::construct(Managed *, ExecutionContext *ctx, Value *args, int argc) { bool n = argc ? args[0].toBoolean() : false; return Value::fromObject(ctx->engine->newBooleanObject(Value::fromBoolean(n))); } -Value BooleanPrototype::ctor_method_call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc) +Value BooleanCtor::call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc) { bool value = argc ? argv[0].toBoolean() : 0; return Value::fromBoolean(value); } +void BooleanPrototype::init(ExecutionContext *ctx, const Value &ctor) +{ + ctor.objectValue()->defineReadonlyProperty(ctx->engine->id_length, Value::fromInt32(1)); + ctor.objectValue()->defineReadonlyProperty(ctx->engine->id_prototype, Value::fromObject(this)); + defineDefaultProperty(ctx, QStringLiteral("constructor"), ctor); + defineDefaultProperty(ctx, QStringLiteral("toString"), method_toString); + defineDefaultProperty(ctx, QStringLiteral("valueOf"), method_valueOf); +} + Value BooleanPrototype::method_toString(SimpleCallContext *ctx) { bool result; @@ -78,5 +95,3 @@ Value BooleanPrototype::method_valueOf(SimpleCallContext *ctx) return thisObject->value; } - -#include "qv4booleanobject_p_jsclass.cpp" diff --git a/src/qml/qml/v4/qv4booleanobject_p.h b/src/qml/qml/v4/qv4booleanobject_p.h index f0baa6e..79f5d4a 100644 --- a/src/qml/qml/v4/qv4booleanobject_p.h +++ b/src/qml/qml/v4/qv4booleanobject_p.h @@ -39,7 +39,7 @@ ** ****************************************************************************/ #ifndef QV4BOOLEANOBJECT_H -#define QV4BOOLEANOBJECT_H +#define QBOOLEANOBJECT_H #include "qv4object_p.h" #include "qv4functionobject_p.h" @@ -49,15 +49,21 @@ QT_BEGIN_NAMESPACE namespace QV4 { -struct QV4_JS_CLASS(BooleanPrototype): BooleanObject +struct BooleanCtor: FunctionObject { - QV4_ANNOTATE(argc 1) - BooleanPrototype(ExecutionEngine *engine): BooleanObject(engine, Value::fromBoolean(false)) {} - void initClass(ExecutionEngine *engine, const Value &ctor); - static Object *newConstructor(ExecutionContext *scope); + BooleanCtor(ExecutionContext *scope); + + static Value construct(Managed *, ExecutionContext *context, Value *args, int argc); + static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int); + +protected: + static const ManagedVTable static_vtbl; +}; - static Value ctor_method_construct(Managed *, ExecutionContext *context, Value *args, int argc); - static Value ctor_method_call(Managed *that, ExecutionContext *, const Value &, Value *, int); +struct BooleanPrototype: BooleanObject +{ + BooleanPrototype(ExecutionEngine *engine): BooleanObject(engine, Value::fromBoolean(false)) {} + void init(ExecutionContext *ctx, const Value &ctor); static Value method_toString(SimpleCallContext *ctx); static Value method_valueOf(SimpleCallContext *ctx); @@ -68,4 +74,4 @@ struct QV4_JS_CLASS(BooleanPrototype): BooleanObject QT_END_NAMESPACE -#endif // QV4BOOLEANOBJECT_H +#endif // QV4ECMAOBJECTS_P_H diff --git a/src/qml/qml/v4/qv4engine.cpp b/src/qml/qml/v4/qv4engine.cpp index 62f7206..91fcdbb 100644 --- a/src/qml/qml/v4/qv4engine.cpp +++ b/src/qml/qml/v4/qv4engine.cpp @@ -179,7 +179,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) objectCtor = Value::fromObject(new (memoryManager) ObjectCtor(rootContext)); stringCtor = Value::fromObject(StringPrototype::newConstructor(rootContext)); numberCtor = Value::fromObject(new (memoryManager) NumberCtor(rootContext)); - booleanCtor = Value::fromObject(BooleanPrototype::newConstructor(rootContext)); + booleanCtor = Value::fromObject(new (memoryManager) BooleanCtor(rootContext)); arrayCtor = Value::fromObject(new (memoryManager) ArrayCtor(rootContext)); functionCtor = Value::fromObject(new (memoryManager) FunctionCtor(rootContext)); dateCtor = Value::fromObject(DatePrototype::newConstructor(rootContext)); @@ -211,7 +211,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) objectPrototype->init(rootContext, objectCtor); stringPrototype->initClass(this, stringCtor); numberPrototype->init(rootContext, numberCtor); - booleanPrototype->initClass(this, booleanCtor); + booleanPrototype->init(rootContext, booleanCtor); arrayPrototype->init(rootContext, arrayCtor); datePrototype->init(rootContext, dateCtor); functionPrototype->init(rootContext, functionCtor); diff --git a/src/qml/qml/v4/v4.pri b/src/qml/qml/v4/v4.pri index e5bdc45..670f436 100644 --- a/src/qml/qml/v4/v4.pri +++ b/src/qml/qml/v4/v4.pri @@ -112,7 +112,6 @@ OTHER_FILES += \ JS_CLASS_SOURCES += $$PWD/qv4dateobject_p.h \ $$PWD/qv4stringobject_p.h \ - $$PWD/qv4booleanobject_p.h \ $$PWD/qv4variantobject_p.h \ $$PWD/qv4sequenceobject_p.h \ $$PWD/qv4errorobject_p.h -- 2.7.4