diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-05-31 14:02:15 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-31 15:51:00 +0200 |
commit | d412840ec6b2e29053d6dc09a6066188c7d27477 (patch) | |
tree | 186ae1bfbb1f3be85044d26f942466725b4c5a97 /src/qml/qml | |
parent | 976051c491c9a79e5c34b97a0e3a37350a7c557c (diff) |
Convert more subclasses of Managed to the new casting scheme
Change-Id: I4105f61d8b1d32b59281eb28fc31002a0ac4e4eb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmllistwrapper.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmllocale.cpp | 15 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmlvaluetypewrapper.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4managed_p.h | 33 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4object_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4regexp_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4regexpobject.cpp | 12 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4regexpobject_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4runtime.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4serialize.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4stringobject.cpp | 14 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4v8.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4value_p.h | 6 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4variantobject.cpp | 1 | ||||
-rw-r--r-- | src/qml/qml/v8/qjsvalue.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 6 |
18 files changed, 31 insertions, 75 deletions
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index c7ac48902d..a4b8349aa8 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -65,7 +65,6 @@ QmlContextWrapper::QmlContextWrapper(QV8Engine *engine, QQmlContextData *context v8(engine), readOnly(true), ownsContext(ownsContext), context(context), scopeObject(scopeObject) { - type = Type_QmlContext; vtbl = &static_vtbl; } diff --git a/src/qml/qml/qqmllistwrapper.cpp b/src/qml/qml/qqmllistwrapper.cpp index e8bc053ec1..6d49b54cf4 100644 --- a/src/qml/qml/qqmllistwrapper.cpp +++ b/src/qml/qml/qqmllistwrapper.cpp @@ -55,7 +55,6 @@ QmlListWrapper::QmlListWrapper(QV8Engine *engine) : Object(QV8Engine::getV4(engine)), v8(engine) { - type = Type_QmlListWrapper; vtbl = &static_vtbl; } diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index 5db82c9e96..69ce4031d4 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -56,19 +56,20 @@ QT_BEGIN_NAMESPACE class QV4_JS_CLASS(QQmlLocaleData) : public QV4::Object { + Q_MANAGED QV4_ANNOTATE(managedTypeName QmlLocale staticInitClass true) public: QQmlLocaleData(QV4::ExecutionEngine *engine) : QV4::Object(engine) { vtbl = &static_vtbl; - type = Type_QmlLocale; + type = Type_Object; } QLocale locale; static QLocale &getThisLocale(QV4::SimpleCallContext *ctx) { - QQmlLocaleData *thisObject = ctx->thisObject.asObject()->asQmlLocale(); + QQmlLocaleData *thisObject = ctx->thisObject.asObject()->as<QQmlLocaleData>(); if (!thisObject) ctx->throwTypeError(); return thisObject->locale; @@ -109,24 +110,18 @@ private: { static_cast<QQmlLocaleData *>(that)->~QQmlLocaleData(); } - - static const QV4::ManagedVTable static_vtbl; }; DEFINE_MANAGED_VTABLE(QQmlLocaleData); #define GET_LOCALE_DATA_RESOURCE(OBJECT) \ - QQmlLocaleData *r = OBJECT.isObject() ? (OBJECT.asManaged()->asQmlLocale()) : 0; \ + QQmlLocaleData *r = OBJECT.as<QQmlLocaleData>(); \ if (!r) \ V4THROW_ERROR("Not a valid Locale object") static bool isLocaleObject(const QV4::Value &val) { - QV4::Object *obj = val.asObject(); - if (!obj) - return false; - - return obj->asQmlLocale(); + return val.as<QQmlLocaleData>(); } //-------------- diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 1c2fd1f479..8cabebf5c4 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -60,7 +60,6 @@ QmlTypeWrapper::QmlTypeWrapper(QV8Engine *engine) : Object(QV8Engine::getV4(engine)), v8(engine), mode(IncludeEnums), type(0), typeNamespace(0), importNamespace(0) { - Managed::type = Type_QmlTypeWrapper; vtbl = &static_vtbl; } diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index 8248e479ec..d17b50c1f3 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -80,7 +80,6 @@ QmlValueTypeWrapper::QmlValueTypeWrapper(QV8Engine *engine, ObjectType objectTyp : Object(QV8Engine::getV4(engine)), objectType(objectType) { v8 = engine; - Managed::type = Type_QmlValueTypeWrapper; vtbl = &static_vtbl; } diff --git a/src/qml/qml/v4/qv4managed_p.h b/src/qml/qml/v4/qv4managed_p.h index 702e620ff7..9efc253273 100644 --- a/src/qml/qml/v4/qv4managed_p.h +++ b/src/qml/qml/v4/qv4managed_p.h @@ -48,9 +48,6 @@ QT_BEGIN_NAMESPACE -class QQmlLocaleData; -class QQuickJSContext2D; - namespace QV4 { class MemoryManager; @@ -67,14 +64,11 @@ struct StringObject; struct ArrayObject; struct DateObject; struct FunctionObject; -struct RegExpObject; struct ErrorObject; struct ArgumentsObject; struct JSONObject; -struct ForeachIteratorObject; struct Managed; struct Value; -class RegExp; struct Lookup; struct ExecutionEngine; struct QObjectWrapper; @@ -92,7 +86,7 @@ inline void qYouForgotTheQ_MANAGED_Macro(T1, T2) {} #define Q_MANAGED \ public: \ Q_MANAGED_CHECK \ - static const ManagedVTable static_vtbl; + static const QV4::ManagedVTable static_vtbl; struct ManagedVTable @@ -183,28 +177,11 @@ public: Type_RegExp, Type_QObject, - // QML bindings - Type_QmlLocale, - Type_QQuickJSContext2D, - - Type_QmlSequence, - - // Wrapped QVariant - Type_QVariant, - - // Qt Object - Type_QtObject, - Type_QmlContext, - Type_QmlTypeWrapper, - Type_QmlValueTypeWrapper, - Type_QmlListWrapper + Type_QmlSequence }; ExecutionEngine *engine() const; - String *asString() { return reinterpret_cast<String *>(this); } - Object *asObject() { return reinterpret_cast<Object *>(this); } - template <typename T> T *as() { #if !defined(QT_NO_QOBJECT_CHECK) @@ -226,18 +203,12 @@ public: NumberObject *asNumberObject() { return type == Type_NumberObject ? reinterpret_cast<NumberObject *>(this) : 0; } StringObject *asStringObject() { return type == Type_StringObject ? reinterpret_cast<StringObject *>(this) : 0; } DateObject *asDateObject() { return type == Type_DateObject ? reinterpret_cast<DateObject *>(this) : 0; } - RegExpObject *asRegExpObject() { return type == Type_RegExpObject ? reinterpret_cast<RegExpObject *>(this) : 0; } ErrorObject *asErrorObject() { return type == Type_ErrorObject ? reinterpret_cast<ErrorObject *>(this) : 0; } ArgumentsObject *asArgumentsObject() { return type == Type_ArgumentsObject ? reinterpret_cast<ArgumentsObject *>(this) : 0; } JSONObject *asJSONObject() { return type == Type_JSONObject ? reinterpret_cast<JSONObject *>(this) : 0; } - ForeachIteratorObject *asForeachIteratorObject() { return type == Type_ForeachIteratorObject ? reinterpret_cast<ForeachIteratorObject *>(this) : 0; } - RegExp *asRegExp() { return type == Type_RegExp ? reinterpret_cast<RegExp *>(this) : 0; } QObjectWrapper *asQObjectWrapper() { return type == Type_QObject ? reinterpret_cast<QObjectWrapper*>(this) : 0; } - QQmlLocaleData *asQmlLocale() { return type == Type_QmlLocale ? reinterpret_cast<QQmlLocaleData *>(this) : 0; } - QQuickJSContext2D *asQQuickJSContext2D() { return type == Type_QQuickJSContext2D ? reinterpret_cast<QQuickJSContext2D *>(this) : 0; } - bool isListType() const { return type == Type_QmlSequence; } bool isArrayObject() const { return type == Type_ArrayObject; } diff --git a/src/qml/qml/v4/qv4object_p.h b/src/qml/qml/v4/qv4object_p.h index 7371f448cd..d091a518e1 100644 --- a/src/qml/qml/v4/qv4object_p.h +++ b/src/qml/qml/v4/qv4object_p.h @@ -372,6 +372,7 @@ private: }; struct ForEachIteratorObject: Object { + Q_MANAGED ObjectIterator it; ForEachIteratorObject(ExecutionContext *ctx, Object *o) : Object(ctx->engine), it(o, ObjectIterator::EnumerableOnly|ObjectIterator::WithProtoChain) { @@ -382,7 +383,6 @@ struct ForEachIteratorObject: Object { Value nextPropertyName() { return it.nextPropertyNameAsString(); } protected: - static const ManagedVTable static_vtbl; static void markObjects(Managed *that); }; diff --git a/src/qml/qml/v4/qv4regexp_p.h b/src/qml/qml/v4/qv4regexp_p.h index 0ae46e7278..48cccebaeb 100644 --- a/src/qml/qml/v4/qv4regexp_p.h +++ b/src/qml/qml/v4/qv4regexp_p.h @@ -93,6 +93,7 @@ public: class RegExp : public Managed { + Q_MANAGED public: static RegExp* create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase = false, bool multiline = false); ~RegExp(); @@ -108,7 +109,6 @@ public: int captureCount() const { return m_subPatternCount + 1; } protected: - static const ManagedVTable static_vtbl; static void destroy(Managed *that); static void markObjects(Managed *that); static Value get(Managed *m, ExecutionContext *ctx, String *name, bool *hasProperty); diff --git a/src/qml/qml/v4/qv4regexpobject.cpp b/src/qml/qml/v4/qv4regexpobject.cpp index 32def6f6dd..09ebe7097e 100644 --- a/src/qml/qml/v4/qv4regexpobject.cpp +++ b/src/qml/qml/v4/qv4regexpobject.cpp @@ -214,7 +214,7 @@ Value RegExpPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, V { Value r = argc > 0 ? argv[0] : Value::undefinedValue(); Value f = argc > 1 ? argv[1] : Value::undefinedValue(); - if (RegExpObject *re = r.asRegExpObject()) { + if (RegExpObject *re = r.as<RegExpObject>()) { if (!f.isUndefined()) ctx->throwTypeError(); @@ -255,7 +255,7 @@ Value RegExpPrototype::ctor_method_construct(Managed *, ExecutionContext *ctx, V Value RegExpPrototype::ctor_method_call(Managed *that, ExecutionContext *ctx, const Value &thisObject, Value *argv, int argc) { - if (argc > 0 && argv[0].asRegExpObject()) { + if (argc > 0 && argv[0].as<RegExpObject>()) { if (argc == 1 || argv[1].isUndefined()) return argv[0]; } @@ -265,7 +265,7 @@ Value RegExpPrototype::ctor_method_call(Managed *that, ExecutionContext *ctx, co Value RegExpPrototype::method_exec(SimpleCallContext *ctx) { - RegExpObject *r = ctx->thisObject.asRegExpObject(); + RegExpObject *r = ctx->thisObject.as<RegExpObject>(); if (!r) ctx->throwTypeError(); @@ -314,7 +314,7 @@ Value RegExpPrototype::method_test(SimpleCallContext *ctx) Value RegExpPrototype::method_toString(SimpleCallContext *ctx) { - RegExpObject *r = ctx->thisObject.asRegExpObject(); + RegExpObject *r = ctx->thisObject.as<RegExpObject>(); if (!r) ctx->throwTypeError(); @@ -323,11 +323,11 @@ Value RegExpPrototype::method_toString(SimpleCallContext *ctx) Value RegExpPrototype::method_compile(SimpleCallContext *ctx) { - RegExpObject *r = ctx->thisObject.asRegExpObject(); + RegExpObject *r = ctx->thisObject.as<RegExpObject>(); if (!r) ctx->throwTypeError(); - RegExpObject *re = ctx->engine->regExpCtor.asFunctionObject()->construct(ctx, ctx->arguments, ctx->argumentCount).asRegExpObject(); + RegExpObject *re = ctx->engine->regExpCtor.asFunctionObject()->construct(ctx, ctx->arguments, ctx->argumentCount).as<RegExpObject>(); r->value = re->value; r->global = re->global; diff --git a/src/qml/qml/v4/qv4regexpobject_p.h b/src/qml/qml/v4/qv4regexpobject_p.h index 00a4032262..1628f870d8 100644 --- a/src/qml/qml/v4/qv4regexpobject_p.h +++ b/src/qml/qml/v4/qv4regexpobject_p.h @@ -66,6 +66,7 @@ namespace QV4 { struct RegExp; struct RegExpObject: Object { + Q_MANAGED // needs to be compatible with the flags in qv4jsir_p.h enum Flags { RegExp_Global = 0x01, @@ -88,7 +89,6 @@ struct RegExpObject: Object { uint flags() const; protected: - static const ManagedVTable static_vtbl; static void destroy(Managed *that); static void markObjects(Managed *that); }; diff --git a/src/qml/qml/v4/qv4runtime.cpp b/src/qml/qml/v4/qv4runtime.cpp index 26363df309..e559d6894b 100644 --- a/src/qml/qml/v4/qv4runtime.cpp +++ b/src/qml/qml/v4/qv4runtime.cpp @@ -648,7 +648,7 @@ void __qmljs_foreach_next_property_name(Value *result, const Value &foreach_iter assert(foreach_iterator.isObject()); ForEachIteratorObject *it = static_cast<ForEachIteratorObject *>(foreach_iterator.objectValue()); - assert(it->asForeachIteratorObject()); + assert(it->as<ForEachIteratorObject>()); *result = it->nextPropertyName(); } diff --git a/src/qml/qml/v4/qv4serialize.cpp b/src/qml/qml/v4/qv4serialize.cpp index f222e4d578..e25321865d 100644 --- a/src/qml/qml/v4/qv4serialize.cpp +++ b/src/qml/qml/v4/qv4serialize.cpp @@ -202,7 +202,7 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, QV8Engine *engi reserve(data, sizeof(quint32) + sizeof(double)); push(data, valueheader(WorkerDate)); push(data, d->value.asDouble()); - } else if (QV4::RegExpObject *re = v.asRegExpObject()) { + } else if (QV4::RegExpObject *re = v.as<RegExpObject>()) { quint32 flags = re->flags(); QString pattern = re->source(); int length = pattern.length() + 1; diff --git a/src/qml/qml/v4/qv4stringobject.cpp b/src/qml/qml/v4/qv4stringobject.cpp index 512e0356ae..0b8598fdb1 100644 --- a/src/qml/qml/v4/qv4stringobject.cpp +++ b/src/qml/qml/v4/qv4stringobject.cpp @@ -268,9 +268,9 @@ Value StringPrototype::method_match(SimpleCallContext *context) String *s = context->thisObject.toString(context); Value regexp = context->argumentCount ? context->arguments[0] : Value::undefinedValue(); - RegExpObject *rx = regexp.asRegExpObject(); + RegExpObject *rx = regexp.as<RegExpObject>(); if (!rx) - rx = context->engine->regExpCtor.asFunctionObject()->construct(context, ®exp, 1).asRegExpObject(); + rx = context->engine->regExpCtor.asFunctionObject()->construct(context, ®exp, 1).as<RegExpObject>(); if (!rx) // ### CHECK @@ -372,7 +372,7 @@ Value StringPrototype::method_replace(SimpleCallContext *ctx) int numStringMatches = 0; Value searchValue = ctx->argument(0); - RegExpObject *regExp = searchValue.asRegExpObject(); + RegExpObject *regExp = searchValue.as<RegExpObject>(); if (regExp) { uint offset = 0; while (true) { @@ -456,10 +456,10 @@ Value StringPrototype::method_search(SimpleCallContext *ctx) string = ctx->thisObject.toString(ctx)->toQString(); Value regExpValue = ctx->argument(0); - RegExpObject *regExp = regExpValue.asRegExpObject(); + RegExpObject *regExp = regExpValue.as<RegExpObject>(); if (!regExp) { regExpValue = ctx->engine->regExpCtor.asFunctionObject()->construct(ctx, ®ExpValue, 1); - regExp = regExpValue.asRegExpObject(); + regExp = regExpValue.as<RegExpObject>(); } uint* matchOffsets = (uint*)alloca(regExp->value->captureCount() * 2 * sizeof(uint)); uint result = regExp->value->match(string, /*offset*/0, matchOffsets); @@ -521,14 +521,14 @@ Value StringPrototype::method_split(SimpleCallContext *ctx) if (limit == 0) return result; - if (RegExpObject* re = separatorValue.asRegExpObject()) { + if (RegExpObject* re = separatorValue.as<RegExpObject>()) { if (re->value->pattern().isEmpty()) { re = 0; separatorValue = Value::fromString(ctx, QString()); } } - if (RegExpObject* re = separatorValue.asRegExpObject()) { + if (RegExpObject* re = separatorValue.as<RegExpObject>()) { uint offset = 0; uint* matchOffsets = (uint*)alloca(re->value->captureCount() * 2 * sizeof(uint)); while (true) { diff --git a/src/qml/qml/v4/qv4v8.cpp b/src/qml/qml/v4/qv4v8.cpp index 3db0b36cf0..2956ce65ac 100644 --- a/src/qml/qml/v4/qv4v8.cpp +++ b/src/qml/qml/v4/qv4v8.cpp @@ -261,7 +261,7 @@ bool Value::IsStringObject() const bool Value::IsRegExp() const { - return ConstValuePtr(this)->asRegExpObject(); + return ConstValuePtr(this)->as<RegExpObject>(); } bool Value::IsError() const diff --git a/src/qml/qml/v4/qv4value_p.h b/src/qml/qml/v4/qv4value_p.h index ea97229958..53e1c1de05 100644 --- a/src/qml/qml/v4/qv4value_p.h +++ b/src/qml/qml/v4/qv4value_p.h @@ -266,7 +266,6 @@ struct Q_QML_EXPORT Value NumberObject *asNumberObject() const; StringObject *asStringObject() const; DateObject *asDateObject() const; - RegExpObject *asRegExpObject() const; ArrayObject *asArrayObject() const; ErrorObject *asErrorObject() const; QObjectWrapper *asQObjectWrapper() const; @@ -531,11 +530,6 @@ inline DateObject *Value::asDateObject() const return isObject() ? managed()->asDateObject() : 0; } -inline RegExpObject *Value::asRegExpObject() const -{ - return isObject() ? managed()->asRegExpObject() : 0; -} - inline ArrayObject *Value::asArrayObject() const { return isObject() ? managed()->asArrayObject() : 0; diff --git a/src/qml/qml/v4/qv4variantobject.cpp b/src/qml/qml/v4/qv4variantobject.cpp index badc49c98b..6b7deedbb2 100644 --- a/src/qml/qml/v4/qv4variantobject.cpp +++ b/src/qml/qml/v4/qv4variantobject.cpp @@ -55,7 +55,6 @@ VariantObject::VariantObject(ExecutionEngine *engine, const QVariant &value) , ExecutionEngine::ScarceResourceData(value) , m_vmePropertyReferenceCount(0) { - type = Type_QVariant; vtbl = &static_vtbl; prototype = engine->variantPrototype; if (isScarce()) diff --git a/src/qml/qml/v8/qjsvalue.cpp b/src/qml/qml/v8/qjsvalue.cpp index c2e2f6e37d..7a1b794737 100644 --- a/src/qml/qml/v8/qjsvalue.cpp +++ b/src/qml/qml/v8/qjsvalue.cpp @@ -52,6 +52,7 @@ #include "qv4runtime_p.h" #include "qv4v8_p.h" #include "qv4variantobject_p.h" +#include "qv4regexpobject_p.h" /*! \since 5.0 @@ -959,7 +960,7 @@ bool QJSValue::isDate() const */ bool QJSValue::isRegExp() const { - return d->value.asRegExpObject(); + return d->value.as<RegExpObject>(); } /*! diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 2b4f4ce05b..0f04ed997e 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -418,7 +418,7 @@ QVariant QV8Engine::toBasicVariant(const QV4::Value &value) Q_ASSERT(value.isObject()); - if (QV4::RegExpObject *re = value.asRegExpObject()) + if (QV4::RegExpObject *re = value.as<QV4::RegExpObject>()) return re->toQRegExp(); if (QV4::ArrayObject *a = value.asArrayObject()) { QVariantList rv; @@ -921,7 +921,7 @@ bool QV8Engine::metaTypeFromJS(const QV4::Value &value, int type, void *data) { return true; } break; case QMetaType::QRegExp: - if (QV4::RegExpObject *r = value.asRegExpObject()) { + if (QV4::RegExpObject *r = value.as<QV4::RegExpObject>()) { *reinterpret_cast<QRegExp *>(data) = r->toQRegExp(); return true; } break; @@ -1066,7 +1066,7 @@ QVariant QV8Engine::variantFromJS(const QV4::Value &value, return variantListFromJS(a, visitedObjects); if (QV4::DateObject *d = value.asDateObject()) return d->toQDateTime(); - if (QV4::RegExpObject *re = value.asRegExpObject()) + if (QV4::RegExpObject *re = value.as<QV4::RegExpObject>()) return re->toQRegExp(); if (QV4::VariantObject *v = value.as<QV4::VariantObject>()) return v->data; |