From bfdc704e2aa9b9dff074ed73afc89a9a871775be Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 13 Jun 2013 13:14:59 +0200 Subject: [PATCH] Revert "Ported RegExp object to class generator" This reverts commit 551282c220a554f269ada23bf842d8d023c7395c. Conflicts: src/qml/qml/v4/qv4regexpobject.cpp src/qml/qml/v4/v4.pri Change-Id: Ib853de8427fff3c75feb11d1b4d1db91acb26b8a Reviewed-by: Lars Knoll --- src/qml/qml/v4/qv4engine.cpp | 4 ++-- src/qml/qml/v4/qv4regexpobject.cpp | 26 ++++++++++++++++++++++---- src/qml/qml/v4/qv4regexpobject_p.h | 27 +++++++++++++++++---------- src/qml/qml/v4/v4.pri | 1 - 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/qml/qml/v4/qv4engine.cpp b/src/qml/qml/v4/qv4engine.cpp index 1fa0260..62f7206 100644 --- a/src/qml/qml/v4/qv4engine.cpp +++ b/src/qml/qml/v4/qv4engine.cpp @@ -183,7 +183,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) arrayCtor = Value::fromObject(new (memoryManager) ArrayCtor(rootContext)); functionCtor = Value::fromObject(new (memoryManager) FunctionCtor(rootContext)); dateCtor = Value::fromObject(DatePrototype::newConstructor(rootContext)); - regExpCtor = Value::fromObject(RegExpPrototype::newConstructor(rootContext)); + regExpCtor = Value::fromObject(new (memoryManager) RegExpCtor(rootContext)); errorCtor = Value::fromObject(new (memoryManager) ErrorCtor(rootContext)); evalErrorCtor = Value::fromObject(new (memoryManager) EvalErrorCtor(rootContext)); rangeErrorCtor = Value::fromObject(new (memoryManager) RangeErrorCtor(rootContext)); @@ -215,7 +215,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory) arrayPrototype->init(rootContext, arrayCtor); datePrototype->init(rootContext, dateCtor); functionPrototype->init(rootContext, functionCtor); - regExpPrototype->initClass(this, regExpCtor); + regExpPrototype->init(rootContext, regExpCtor); errorPrototype->init(this, errorCtor); evalErrorPrototype->init(this, evalErrorCtor); rangeErrorPrototype->init(this, rangeErrorCtor); diff --git a/src/qml/qml/v4/qv4regexpobject.cpp b/src/qml/qml/v4/qv4regexpobject.cpp index 09ebe70..fc6ffd2 100644 --- a/src/qml/qml/v4/qv4regexpobject.cpp +++ b/src/qml/qml/v4/qv4regexpobject.cpp @@ -210,7 +210,15 @@ uint RegExpObject::flags() const return f; } -Value RegExpPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, Value *argv, int argc) +DEFINE_MANAGED_VTABLE(RegExpCtor); + +RegExpCtor::RegExpCtor(ExecutionContext *scope) + : FunctionObject(scope, scope->engine->newIdentifier(QStringLiteral("RegExp"))) +{ + vtbl = &static_vtbl; +} + +Value RegExpCtor::construct(Managed *, ExecutionContext *ctx, Value *argv, int argc) { Value r = argc > 0 ? argv[0] : Value::undefinedValue(); Value f = argc > 1 ? argv[1] : Value::undefinedValue(); @@ -253,14 +261,25 @@ Value RegExpPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, V return Value::fromObject(o); } -Value RegExpPrototype::ctor_method_call(Managed *that, ExecutionContext *ctx, const Value &thisObject, Value *argv, int argc) +Value RegExpCtor::call(Managed *that, ExecutionContext *ctx, const Value &thisObject, Value *argv, int argc) { if (argc > 0 && argv[0].as()) { if (argc == 1 || argv[1].isUndefined()) return argv[0]; } - return ctor_method_construct(that, ctx, argv, argc); + return construct(that, ctx, argv, argc); +} + +void RegExpPrototype::init(ExecutionContext *ctx, const Value &ctor) +{ + ctor.objectValue()->defineReadonlyProperty(ctx->engine->id_prototype, Value::fromObject(this)); + ctor.objectValue()->defineReadonlyProperty(ctx->engine->id_length, Value::fromInt32(2)); + defineDefaultProperty(ctx, QStringLiteral("constructor"), ctor); + defineDefaultProperty(ctx, QStringLiteral("exec"), method_exec, 1); + defineDefaultProperty(ctx, QStringLiteral("test"), method_test, 1); + defineDefaultProperty(ctx, QStringLiteral("toString"), method_toString, 0); + defineDefaultProperty(ctx, QStringLiteral("compile"), method_compile, 2); } Value RegExpPrototype::method_exec(SimpleCallContext *ctx) @@ -334,4 +353,3 @@ Value RegExpPrototype::method_compile(SimpleCallContext *ctx) return Value::undefinedValue(); } -#include "qv4regexpobject_p_jsclass.cpp" diff --git a/src/qml/qml/v4/qv4regexpobject_p.h b/src/qml/qml/v4/qv4regexpobject_p.h index 1628f87..8589d1e 100644 --- a/src/qml/qml/v4/qv4regexpobject_p.h +++ b/src/qml/qml/v4/qv4regexpobject_p.h @@ -93,20 +93,27 @@ protected: static void markObjects(Managed *that); }; -struct QV4_JS_CLASS(RegExpPrototype): RegExpObject + +struct RegExpCtor: FunctionObject { - QV4_ANNOTATE(argc 2) - RegExpPrototype(ExecutionEngine* engine): RegExpObject(engine, RegExp::create(engine, QString()), false) {} - void initClass(ExecutionEngine *engine, const Value &ctor); - static Object *newConstructor(ExecutionContext *scope); + RegExpCtor(ExecutionContext *scope); + + 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; +}; - 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); +struct RegExpPrototype: RegExpObject +{ + RegExpPrototype(ExecutionEngine* engine): RegExpObject(engine, RegExp::create(engine, QString()), false) {} + void init(ExecutionContext *ctx, const Value &ctor); - static Value method_exec(SimpleCallContext *ctx) QV4_ARGC(1); - static Value method_test(SimpleCallContext *ctx) QV4_ARGC(1); + static Value method_exec(SimpleCallContext *ctx); + static Value method_test(SimpleCallContext *ctx); static Value method_toString(SimpleCallContext *ctx); - static Value method_compile(SimpleCallContext *ctx) QV4_ARGC(2); + static Value method_compile(SimpleCallContext *ctx); }; } diff --git a/src/qml/qml/v4/v4.pri b/src/qml/qml/v4/v4.pri index 0b840d3..e5bdc45 100644 --- a/src/qml/qml/v4/v4.pri +++ b/src/qml/qml/v4/v4.pri @@ -113,7 +113,6 @@ OTHER_FILES += \ JS_CLASS_SOURCES += $$PWD/qv4dateobject_p.h \ $$PWD/qv4stringobject_p.h \ $$PWD/qv4booleanobject_p.h \ - $$PWD/qv4regexpobject_p.h \ $$PWD/qv4variantobject_p.h \ $$PWD/qv4sequenceobject_p.h \ $$PWD/qv4errorobject_p.h -- 2.7.4