diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-05-31 16:06:42 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2013-05-31 16:32:05 +0200 |
commit | 140eb57413accb41b76a610f8fa888da9cc95b68 (patch) | |
tree | 5239424b5d14d54c4275debb09c0040def1eca95 /src/qml | |
parent | ab5631442f354125dcc7c86323507f6e40f70002 (diff) |
Clean up more stuff in qv8engine
Change-Id: Ia31d5abd4694b1c67115e75f0d0f134a65d4d775
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/v4/qv4objectproto.cpp | 27 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4objectproto_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/v4/qv4serialize.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 81 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine_p.h | 30 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8qobjectwrapper.cpp | 7 |
6 files changed, 30 insertions, 121 deletions
diff --git a/src/qml/qml/v4/qv4objectproto.cpp b/src/qml/qml/v4/qv4objectproto.cpp index ceaffbb977..5d34d331c6 100644 --- a/src/qml/qml/v4/qv4objectproto.cpp +++ b/src/qml/qml/v4/qv4objectproto.cpp @@ -156,14 +156,7 @@ Value ObjectPrototype::method_getOwnPropertyNames(SimpleCallContext *context) if (!O) context->throwTypeError(); - ArrayObject *array = context->engine->newArrayObject(); - ObjectIterator it(O, ObjectIterator::NoFlags); - while (1) { - Value v = it.nextPropertyNameAsString(); - if (v.isNull()) - break; - array->push_back(v); - } + ArrayObject *array = getOwnPropertyNames(context->engine, context->arguments[0]); return Value::fromObject(array); } @@ -563,3 +556,21 @@ Value ObjectPrototype::fromPropertyDescriptor(ExecutionContext *ctx, const Prope return Value::fromObject(o); } + + +ArrayObject *ObjectPrototype::getOwnPropertyNames(ExecutionEngine *v4, const Value &o) +{ + ArrayObject *array = v4->newArrayObject(); + Object *O = o.asObject(); + if (!O) + return array; + + ObjectIterator it(O, ObjectIterator::NoFlags); + while (1) { + Value v = it.nextPropertyNameAsString(); + if (v.isNull()) + break; + array->push_back(v); + } + return array; +} diff --git a/src/qml/qml/v4/qv4objectproto_p.h b/src/qml/qml/v4/qv4objectproto_p.h index 87f6b0095c..e266953fed 100644 --- a/src/qml/qml/v4/qv4objectproto_p.h +++ b/src/qml/qml/v4/qv4objectproto_p.h @@ -92,6 +92,8 @@ struct ObjectPrototype: Object static void toPropertyDescriptor(ExecutionContext *ctx, Value v, Property *desc, PropertyAttributes *attrs); static Value fromPropertyDescriptor(ExecutionContext *ctx, const Property *desc, PropertyAttributes attrs); + + static ArrayObject *getOwnPropertyNames(ExecutionEngine *v4, const Value &o); }; diff --git a/src/qml/qml/v4/qv4serialize.cpp b/src/qml/qml/v4/qv4serialize.cpp index e25321865d..692f478ee8 100644 --- a/src/qml/qml/v4/qv4serialize.cpp +++ b/src/qml/qml/v4/qv4serialize.cpp @@ -48,6 +48,8 @@ #include <private/qv4value_p.h> #include <private/qv4dateobject_p.h> #include <private/qv4regexpobject_p.h> +#include <private/qv4sequenceobject_p.h> +#include <private/qv4objectproto_p.h> QT_BEGIN_NAMESPACE @@ -262,7 +264,7 @@ void Serialize::serialize(QByteArray &data, const QV4::Value &v, QV8Engine *engi } // regular object - QV4::ArrayObject *properties = engine->getOwnPropertyNames(v).asArrayObject(); + QV4::ArrayObject *properties = QV4::ObjectPrototype::getOwnPropertyNames(v4, v); quint32 length = properties->arrayLength(); if (length > 0xFFFFFF) { push(data, valueheader(WorkerUndefined)); diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 55f246ed25..0506118956 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -99,10 +99,6 @@ QV8Engine::QV8Engine(QJSEngine* qq) v8::Isolate::SetEngine(m_v4Engine); m_v4Engine->publicEngine = q; - m_strongReferencer = QV4::Value::fromObject(m_v4Engine->newObject()); - - m_bindingFlagKey = QV4::Value::fromString(m_v4Engine->current, QStringLiteral("qml::binding")); - m_qobjectWrapper.init(this); m_jsonWrapper.init(m_v4Engine); @@ -367,22 +363,6 @@ const QStringHash<bool> &QV8Engine::illegalNames() const return m_illegalNames; } -// Requires a handle scope -QV4::Value QV8Engine::getOwnPropertyNames(const QV4::Value &o) -{ - if (!o.asObject()) - return QV4::Value::fromObject(m_v4Engine->newArrayObject()); - QV4::SimpleCallContext ctx; - ctx.initSimpleCallContext(m_v4Engine); - QV4::Value args = o; - ctx.arguments = &args; - ctx.argumentCount = 1; - m_v4Engine->pushContext(&ctx); - QV4::Value result = QV4::ObjectPrototype::method_getOwnPropertyNames(&ctx); - m_v4Engine->popContext(); - return result; -} - QQmlContextData *QV8Engine::callingContext() { return QV4::QmlContextWrapper::callingContext(m_v4Engine); @@ -488,43 +468,6 @@ void QV8Engine::gc() m_v4Engine->memoryManager->runGC(); } -#ifdef QML_GLOBAL_HANDLE_DEBUGGING -#include <QtCore/qthreadstorage.h> -static QThreadStorage<QSet<void *> *> QV8Engine_activeHandles; - -void QV8Engine::registerHandle(void *handle) -{ - if (!handle) { - qWarning("Attempting to register a null handle"); - return; - } - - if (!QV8Engine_activeHandles.hasLocalData()) - QV8Engine_activeHandles.setLocalData(new QSet<void *>); - - if (QV8Engine_activeHandles.localData()->contains(handle)) { - qFatal("Handle %p already alive", handle); - } else { - QV8Engine_activeHandles.localData()->insert(handle); - } -} - -void QV8Engine::releaseHandle(void *handle) -{ - if (!handle) - return; - - if (!QV8Engine_activeHandles.hasLocalData()) - QV8Engine_activeHandles.setLocalData(new QSet<void *>); - - if (QV8Engine_activeHandles.localData()->contains(handle)) { - QV8Engine_activeHandles.localData()->remove(handle); - } else { - qFatal("Handle %p already dead", handle); - } -} -#endif - struct QV8EngineRegistrationData { QV8EngineRegistrationData() : extensionCount(0) {} @@ -1015,8 +958,8 @@ QVariant QV8Engine::variantFromJS(const QV4::Value &value, return v->data; if (isQObject(value)) return qVariantFromValue(qtObjectFromJS(value)); - if (isValueType(value)) - return toValueType(value); + if (QV4::QmlValueTypeWrapper *v = value.as<QV4::QmlValueTypeWrapper>()) + return v->toVariant(); return variantMapFromJS(value.asObject(), visitedObjects); } @@ -1115,25 +1058,5 @@ QV4::Value QV8Engine::toString(const QString &string) return QV4::Value::fromString(m_v4Engine->newString(string)); } -QV4::Value QV8Engine::newValueType(QObject *object, int property, QQmlValueType *type) -{ - return QV4::QmlValueTypeWrapper::create(this, object, property, type); -} - -QV4::Value QV8Engine::newValueType(const QVariant &value, QQmlValueType *type) -{ - return QV4::QmlValueTypeWrapper::create(this, value, type); -} - -bool QV8Engine::isValueType(const QV4::Value &value) const -{ - return value.isObject() ? value.objectValue()->as<QV4::QmlValueTypeWrapper>() : 0; -} - -QVariant QV8Engine::toValueType(const QV4::Value &obj) -{ - return obj.isObject() ? obj.objectValue()->as<QV4::QmlValueTypeWrapper>()->toVariant() : QVariant(); -} - QT_END_NAMESPACE diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 26faf2271e..17a31f2f91 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -72,7 +72,6 @@ #include "qv8objectresource_p.h" #include "qv8qobjectwrapper_p.h" -#include <private/qv4sequenceobject_p.h> #include "qv4jsonwrapper_p.h" #include <private/qv4value_p.h> #include <private/qv4object_p.h> @@ -103,10 +102,6 @@ namespace QV4 { #define V4THROW_ERROR(string) \ v8::Isolate::GetEngine()->current->throwError(QString::fromUtf8(string)); -#define V8THROW_TYPE(string) { \ - v8::ThrowException(v8::Exception::TypeError(v8::String::New(string))); \ - return v8::Handle<v8::Value>(); \ -} #define V4THROW_TYPE(string) \ v8::Isolate::GetEngine()->current->throwError(QStringLiteral(string)); @@ -258,7 +253,6 @@ public: QQmlContextData *callingContext(); - QV4::Value getOwnPropertyNames(const QV4::Value &o); void freezeObject(const QV4::Value &value); QVariant toVariant(const QV4::Value &value, int typeHint); @@ -273,15 +267,6 @@ public: // Return a JS string for the given QString \a string QV4::Value toString(const QString &string); - // Create a new value type object - QV4::Value newValueType(QObject *, int coreIndex, QQmlValueType *); - QV4::Value newValueType(const QVariant &, QQmlValueType *); - bool isValueType(const QV4::Value &value) const; - QVariant toValueType(const QV4::Value &obj); - - // Create a new sequence type object - inline QV4::Value newSequence(int sequenceType, QObject *, int coreIndex, bool *succeeded); - // Return the network access manager for this engine. By default this returns the network // access manager of the QQmlEngine. It is overridden in the case of a threaded v8 // instance (like in WorkerScript). @@ -293,12 +278,6 @@ public: inline void collectGarbage() { gc(); } void gc(); -#ifdef QML_GLOBAL_HANDLE_DEBUGGING - // Used for handle debugging - static void registerHandle(void *); - static void releaseHandle(void *); -#endif - static QMutex *registrationMutex(); static int registerExtension(); @@ -340,16 +319,12 @@ public: QObject *qtObjectFromJS(const QV4::Value &value); - QV4::PersistentValue m_strongReferencer; - protected: QJSEngine* q; QQmlEngine *m_engine; QV4::ExecutionEngine *m_v4Engine; - QV4::PersistentValue m_bindingFlagKey; - QV8QObjectWrapper m_qobjectWrapper; QV4JsonWrapper m_jsonWrapper; @@ -410,11 +385,6 @@ QV4::Value QV8Engine::newQObject(QObject *object, const ObjectOwnership ownershi return result; } -QV4::Value QV8Engine::newSequence(int sequenceType, QObject *object, int property, bool *succeeded) -{ - return QV4::SequencePrototype::newSequence(m_v4Engine, sequenceType, object, property, succeeded); -} - QV8Engine::Deletable *QV8Engine::extensionData(int index) const { if (index < m_extensionData.count()) diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp index 4157f8abc6..4090e9c515 100644 --- a/src/qml/qml/v8/qv8qobjectwrapper.cpp +++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp @@ -59,6 +59,7 @@ #include <private/qv4functionobject_p.h> #include <private/qv4runtime_p.h> #include <private/qv4variantobject_p.h> +#include <private/qv4sequenceobject_p.h> #include <QtQml/qjsvalue.h> #include <QtCore/qjsonarray.h> @@ -513,7 +514,7 @@ static QV4::Value LoadProperty(QV8Engine *engine, QObject *object, if (QQmlValueTypeFactory::isValueType(v.userType())) { if (QQmlValueType *valueType = QQmlValueTypeFactory::valueType(v.userType())) - return engine->newValueType(object, property.coreIndex, valueType); // VariantReference value-type. + return QV4::QmlValueTypeWrapper::create(engine, object, property.coreIndex, valueType); // VariantReference value-type. } return engine->fromVariant(v); @@ -521,13 +522,13 @@ static QV4::Value LoadProperty(QV8Engine *engine, QObject *object, Q_ASSERT(notifier == 0); if (QQmlValueType *valueType = QQmlValueTypeFactory::valueType(property.propType)) - return engine->newValueType(object, property.coreIndex, valueType); + return QV4::QmlValueTypeWrapper::create(engine, object, property.coreIndex, valueType); } else { Q_ASSERT(notifier == 0); // see if it's a sequence type bool succeeded = false; - QV4::Value retn = engine->newSequence(property.propType, object, property.coreIndex, &succeeded); + QV4::Value retn = QV4::SequencePrototype::newSequence(QV8Engine::getV4(engine), property.propType, object, property.coreIndex, &succeeded); if (succeeded) return retn; } |