From 678417bd473b68834747684edb6fd2b9628050b9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 6 May 2013 12:52:25 +0200 Subject: [PATCH] Ported string object over to the class generator Change-Id: I1b718f4963ade13e8d9a660785070c566d5872b0 Reviewed-by: Lars Knoll --- src/qml/qml/v4/qv4engine.cpp | 4 ++-- src/qml/qml/v4/qv4stringobject.cpp | 45 ++++------------------------------ src/qml/qml/v4/qv4stringobject_p.h | 49 +++++++++++++++++--------------------- src/qml/qml/v4/v4.pri | 3 ++- 4 files changed, 31 insertions(+), 70 deletions(-) diff --git a/src/qml/qml/v4/qv4engine.cpp b/src/qml/qml/v4/qv4engine.cpp index c2c14ef..6a5a2a6 100644 --- a/src/qml/qml/v4/qv4engine.cpp +++ b/src/qml/qml/v4/qv4engine.cpp @@ -146,7 +146,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) uRIErrorPrototype->prototype = objectPrototype; objectCtor = Value::fromObject(new (memoryManager) ObjectCtor(rootContext)); - stringCtor = Value::fromObject(new (memoryManager) StringCtor(rootContext)); + stringCtor = Value::fromObject(StringPrototype::newConstructor(rootContext)); numberCtor = Value::fromObject(new (memoryManager) NumberCtor(rootContext)); booleanCtor = Value::fromObject(new (memoryManager) BooleanCtor(rootContext)); arrayCtor = Value::fromObject(new (memoryManager) ArrayCtor(rootContext)); @@ -178,7 +178,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) uRIErrorCtor.objectValue()->prototype = functionPrototype; objectPrototype->init(rootContext, objectCtor); - stringPrototype->init(this, stringCtor); + stringPrototype->initClass(this, stringCtor); numberPrototype->init(rootContext, numberCtor); booleanPrototype->init(rootContext, booleanCtor); arrayPrototype->init(rootContext, arrayCtor); diff --git a/src/qml/qml/v4/qv4stringobject.cpp b/src/qml/qml/v4/qv4stringobject.cpp index b9e8c9a..512e035 100644 --- a/src/qml/qml/v4/qv4stringobject.cpp +++ b/src/qml/qml/v4/qv4stringobject.cpp @@ -106,15 +106,7 @@ void StringObject::markObjects(Managed *that) Object::markObjects(that); } -DEFINE_MANAGED_VTABLE(StringCtor); - -StringCtor::StringCtor(ExecutionContext *scope) - : FunctionObject(scope, scope->engine->newIdentifier(QStringLiteral("String"))) -{ - vtbl = &static_vtbl; -} - -Value StringCtor::construct(Managed *, ExecutionContext *ctx, Value *argv, int argc) +Value StringPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, Value *argv, int argc) { Value value; if (argc) @@ -124,7 +116,7 @@ Value StringCtor::construct(Managed *, ExecutionContext *ctx, Value *argv, int a return Value::fromObject(ctx->engine->newStringObject(value)); } -Value StringCtor::call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc) +Value StringPrototype::ctor_method_call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc) { Value value; if (argc) @@ -134,35 +126,6 @@ Value StringCtor::call(Managed *, ExecutionContext *parentCtx, const Value &this return value; } -void StringPrototype::init(ExecutionEngine *engine, const Value &ctor) -{ - ctor.objectValue()->defineReadonlyProperty(engine->id_prototype, Value::fromObject(this)); - ctor.objectValue()->defineReadonlyProperty(engine->id_length, Value::fromInt32(1)); - ctor.objectValue()->defineDefaultProperty(engine, QStringLiteral("fromCharCode"), method_fromCharCode, 1); - - defineDefaultProperty(engine, QStringLiteral("constructor"), ctor); - defineDefaultProperty(engine, QStringLiteral("toString"), method_toString); - defineDefaultProperty(engine, QStringLiteral("valueOf"), method_toString); // valueOf and toString are identical - defineDefaultProperty(engine, QStringLiteral("charAt"), method_charAt, 1); - defineDefaultProperty(engine, QStringLiteral("charCodeAt"), method_charCodeAt, 1); - defineDefaultProperty(engine, QStringLiteral("concat"), method_concat, 1); - defineDefaultProperty(engine, QStringLiteral("indexOf"), method_indexOf, 1); - defineDefaultProperty(engine, QStringLiteral("lastIndexOf"), method_lastIndexOf, 1); - defineDefaultProperty(engine, QStringLiteral("localeCompare"), method_localeCompare, 1); - defineDefaultProperty(engine, QStringLiteral("match"), method_match, 1); - defineDefaultProperty(engine, QStringLiteral("replace"), method_replace, 2); - defineDefaultProperty(engine, QStringLiteral("search"), method_search, 1); - defineDefaultProperty(engine, QStringLiteral("slice"), method_slice, 2); - defineDefaultProperty(engine, QStringLiteral("split"), method_split, 2); - defineDefaultProperty(engine, QStringLiteral("substr"), method_substr, 2); - defineDefaultProperty(engine, QStringLiteral("substring"), method_substring, 2); - defineDefaultProperty(engine, QStringLiteral("toLowerCase"), method_toLowerCase); - defineDefaultProperty(engine, QStringLiteral("toLocaleLowerCase"), method_toLocaleLowerCase); - defineDefaultProperty(engine, QStringLiteral("toUpperCase"), method_toUpperCase); - defineDefaultProperty(engine, QStringLiteral("toLocaleUpperCase"), method_toLocaleUpperCase); - defineDefaultProperty(engine, QStringLiteral("trim"), method_trim); -} - static QString getThisString(ExecutionContext *ctx) { String* str = 0; @@ -694,7 +657,7 @@ Value StringPrototype::method_toLocaleUpperCase(SimpleCallContext *ctx) return method_toUpperCase(ctx); } -Value StringPrototype::method_fromCharCode(SimpleCallContext *context) +Value StringPrototype::ctor_method_fromCharCode(SimpleCallContext *context) { QString str(context->argumentCount, Qt::Uninitialized); QChar *ch = str.data(); @@ -724,3 +687,5 @@ Value StringPrototype::method_trim(SimpleCallContext *ctx) return Value::fromString(ctx, QString(chars + start, end - start + 1)); } + +#include "qv4stringobject_p_jsclass.cpp" diff --git a/src/qml/qml/v4/qv4stringobject_p.h b/src/qml/qml/v4/qv4stringobject_p.h index 8b4e9f6..7bd08fa 100644 --- a/src/qml/qml/v4/qv4stringobject_p.h +++ b/src/qml/qml/v4/qv4stringobject_p.h @@ -61,41 +61,36 @@ protected: static void markObjects(Managed *that); }; -struct StringCtor: FunctionObject +struct QV4_JS_CLASS(StringPrototype): StringObject { - StringCtor(ExecutionContext *scope); + QV4_ANNOTATE(argc 1) - static Value construct(Managed *that, ExecutionContext *context, Value *args, int argc); - static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int); - -protected: - static const ManagedVTable static_vtbl; -}; - -struct StringPrototype: StringObject -{ StringPrototype(ExecutionEngine *engine): StringObject(engine, Value::fromString(engine, QString())) {} - void init(ExecutionEngine *engine, const Value &ctor); + void initClass(ExecutionEngine *engine, const Value &ctor); + static Object *newConstructor(ExecutionContext *scope); + + static Value ctor_method_construct(Managed *that, ExecutionContext *context, Value *args, int argc); + static Value ctor_method_call(Managed *that, ExecutionContext *, const Value &, Value *, int); - static Value method_toString(SimpleCallContext *context); - static Value method_charAt(SimpleCallContext *context); - static Value method_charCodeAt(SimpleCallContext *context); - static Value method_concat(SimpleCallContext *context); - static Value method_indexOf(SimpleCallContext *context); - static Value method_lastIndexOf(SimpleCallContext *context); - static Value method_localeCompare(SimpleCallContext *context); - static Value method_match(SimpleCallContext *context); - static Value method_replace(SimpleCallContext *ctx); - static Value method_search(SimpleCallContext *ctx); - static Value method_slice(SimpleCallContext *ctx); - static Value method_split(SimpleCallContext *ctx); - static Value method_substr(SimpleCallContext *context); - static Value method_substring(SimpleCallContext *context); + static Value method_toString(SimpleCallContext *context) QV4_ANNOTATE(alias valueOf); + static Value method_charAt(SimpleCallContext *context) QV4_ARGC(1); + static Value method_charCodeAt(SimpleCallContext *context) QV4_ARGC(1); + static Value method_concat(SimpleCallContext *context) QV4_ARGC(1); + static Value method_indexOf(SimpleCallContext *context) QV4_ARGC(1); + static Value method_lastIndexOf(SimpleCallContext *context) QV4_ARGC(1); + static Value method_localeCompare(SimpleCallContext *context) QV4_ARGC(1); + static Value method_match(SimpleCallContext *context) QV4_ARGC(1); + static Value method_replace(SimpleCallContext *ctx) QV4_ARGC(2); + static Value method_search(SimpleCallContext *ctx) QV4_ARGC(1); + static Value method_slice(SimpleCallContext *ctx) QV4_ARGC(2); + static Value method_split(SimpleCallContext *ctx) QV4_ARGC(2); + static Value method_substr(SimpleCallContext *context) QV4_ARGC(2); + static Value method_substring(SimpleCallContext *context) QV4_ARGC(2); static Value method_toLowerCase(SimpleCallContext *ctx); static Value method_toLocaleLowerCase(SimpleCallContext *ctx); static Value method_toUpperCase(SimpleCallContext *ctx); static Value method_toLocaleUpperCase(SimpleCallContext *ctx); - static Value method_fromCharCode(SimpleCallContext *context); + static Value ctor_method_fromCharCode(SimpleCallContext *context) QV4_ARGC(1); static Value method_trim(SimpleCallContext *ctx); }; diff --git a/src/qml/qml/v4/v4.pri b/src/qml/qml/v4/v4.pri index b50602b..c0b6286 100644 --- a/src/qml/qml/v4/v4.pri +++ b/src/qml/qml/v4/v4.pri @@ -94,7 +94,8 @@ HEADERS += \ $$PWD/qv4util_p.h \ $$PWD/qv4executableallocator_p.h -JS_CLASS_SOURCES = $$PWD/qv4dateobject_p.h +JS_CLASS_SOURCES = $$PWD/qv4dateobject_p.h \ + $$PWD/qv4stringobject_p.h js_class_bindings.output = ${QMAKE_FILE_BASE}_jsclass.cpp js_class_bindings.input = JS_CLASS_SOURCES -- 2.7.4