From 5e7bf4ca2b4ffa55539cc3b01ba7477e7ac88bbb Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 13 Jun 2013 13:17:45 +0200 Subject: [PATCH] Revert "Ported string object over to the class generator" This reverts commit 678417bd473b68834747684edb6fd2b9628050b9. Conflicts: src/qml/qml/v4/v4.pri Change-Id: I927514f20ec5417dd0280a3868f3a0b71b752eca 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 | 1 - 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/src/qml/qml/v4/qv4engine.cpp b/src/qml/qml/v4/qv4engine.cpp index 91fcdbb..b659ced 100644 --- a/src/qml/qml/v4/qv4engine.cpp +++ b/src/qml/qml/v4/qv4engine.cpp @@ -177,7 +177,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) uRIErrorPrototype->prototype = objectPrototype; objectCtor = Value::fromObject(new (memoryManager) ObjectCtor(rootContext)); - stringCtor = Value::fromObject(StringPrototype::newConstructor(rootContext)); + stringCtor = Value::fromObject(new (memoryManager) StringCtor(rootContext)); numberCtor = Value::fromObject(new (memoryManager) NumberCtor(rootContext)); booleanCtor = Value::fromObject(new (memoryManager) BooleanCtor(rootContext)); arrayCtor = Value::fromObject(new (memoryManager) ArrayCtor(rootContext)); @@ -209,7 +209,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) uRIErrorCtor.objectValue()->prototype = functionPrototype; objectPrototype->init(rootContext, objectCtor); - stringPrototype->initClass(this, stringCtor); + stringPrototype->init(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 912db7d..7e309ca 100644 --- a/src/qml/qml/v4/qv4stringobject.cpp +++ b/src/qml/qml/v4/qv4stringobject.cpp @@ -127,7 +127,15 @@ void StringObject::markObjects(Managed *that) Object::markObjects(that); } -Value StringPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, Value *argv, int argc) +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 value; if (argc) @@ -137,7 +145,7 @@ Value StringPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, V return Value::fromObject(ctx->engine->newStringObject(value)); } -Value StringPrototype::ctor_method_call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc) +Value StringCtor::call(Managed *, ExecutionContext *parentCtx, const Value &thisObject, Value *argv, int argc) { Value value; if (argc) @@ -147,6 +155,35 @@ Value StringPrototype::ctor_method_call(Managed *, ExecutionContext *parentCtx, 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; @@ -678,7 +715,7 @@ Value StringPrototype::method_toLocaleUpperCase(SimpleCallContext *ctx) return method_toUpperCase(ctx); } -Value StringPrototype::ctor_method_fromCharCode(SimpleCallContext *context) +Value StringPrototype::method_fromCharCode(SimpleCallContext *context) { QString str(context->argumentCount, Qt::Uninitialized); QChar *ch = str.data(); @@ -708,5 +745,3 @@ 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 cbd7fef..a5a64c1 100644 --- a/src/qml/qml/v4/qv4stringobject_p.h +++ b/src/qml/qml/v4/qv4stringobject_p.h @@ -62,36 +62,41 @@ protected: static void markObjects(Managed *that); }; -struct QV4_JS_CLASS(StringPrototype): StringObject +struct StringCtor: FunctionObject { - QV4_ANNOTATE(argc 1) + StringCtor(ExecutionContext *scope); - StringPrototype(ExecutionEngine *engine): StringObject(engine, Value::fromString(engine, QString())) {} - void initClass(ExecutionEngine *engine, const Value &ctor); - static Object *newConstructor(ExecutionContext *scope); + static Value construct(Managed *that, ExecutionContext *context, Value *args, int argc); + static Value call(Managed *that, ExecutionContext *, const Value &, Value *, int); - 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); +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); - 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_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_toLowerCase(SimpleCallContext *ctx); static Value method_toLocaleLowerCase(SimpleCallContext *ctx); static Value method_toUpperCase(SimpleCallContext *ctx); static Value method_toLocaleUpperCase(SimpleCallContext *ctx); - static Value ctor_method_fromCharCode(SimpleCallContext *context) QV4_ARGC(1); + static Value method_fromCharCode(SimpleCallContext *context); static Value method_trim(SimpleCallContext *ctx); }; diff --git a/src/qml/qml/v4/v4.pri b/src/qml/qml/v4/v4.pri index 670f436..5edcfd5 100644 --- a/src/qml/qml/v4/v4.pri +++ b/src/qml/qml/v4/v4.pri @@ -111,7 +111,6 @@ OTHER_FILES += \ $$PWD/v4classgen JS_CLASS_SOURCES += $$PWD/qv4dateobject_p.h \ - $$PWD/qv4stringobject_p.h \ $$PWD/qv4variantobject_p.h \ $$PWD/qv4sequenceobject_p.h \ $$PWD/qv4errorobject_p.h -- 2.7.4