Fix qqmlvaluetypewrapper auto-tests
authorSimon Hausmann <simon.hausmann@digia.com>
Thu, 20 Jun 2013 09:32:45 +0000 (11:32 +0200)
committerLars Knoll <lars.knoll@digia.com>
Thu, 20 Jun 2013 19:57:28 +0000 (21:57 +0200)
QQmlValueTypeWrapper stores its prototype in a global variable
(PersistentValue), which doesn't work when using multiple engines. Instead
this patch introduces the QML extensions structure to hold things like
prototypes for type extensions to JS that are specific to QML.

Change-Id: I41a71029edb6ce895eb80db7aa0809aab86b31db
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/qqmlvaluetypewrapper.cpp
src/qml/qml/qqmlvaluetypewrapper_p.h
src/qml/qml/v4/qv4engine.cpp
src/qml/qml/v4/qv4engine_p.h
src/qml/qml/v4/qv4qmlextensions.cpp [new file with mode: 0644]
src/qml/qml/v4/qv4qmlextensions_p.h [new file with mode: 0644]
src/qml/qml/v4/v4.pri

index ae3934f..aaa7db2 100644 (file)
@@ -50,6 +50,7 @@
 #include <private/qv4engine_p.h>
 #include <private/qv4functionobject_p.h>
 #include <private/qv4variantobject_p.h>
+#include <private/qv4qmlextensions_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -57,9 +58,6 @@ using namespace QV4;
 
 DEFINE_MANAGED_VTABLE(QmlValueTypeWrapper);
 
-PersistentValue QmlValueTypeWrapper::proto;
-
-
 class QmlValueTypeReference : public QmlValueTypeWrapper
 {
 public:
@@ -133,12 +131,12 @@ static bool readReferenceValue(const QmlValueTypeReference *reference)
 
 void QmlValueTypeWrapper::initProto(ExecutionEngine *v4)
 {
-    if (!proto.isEmpty())
+    if (v4->qmlExtensions()->valueTypeWrapperPrototype)
         return;
 
     Object *o = v4->newObject();
     o->defineDefaultProperty(v4, QStringLiteral("toString"), method_toString, 1);
-    proto = Value::fromObject(o);
+    v4->qmlExtensions()->valueTypeWrapperPrototype = o;
 }
 
 Value QmlValueTypeWrapper::create(QV8Engine *v8, QObject *object, int property, QQmlValueType *type)
@@ -147,7 +145,7 @@ Value QmlValueTypeWrapper::create(QV8Engine *v8, QObject *object, int property,
     initProto(v4);
 
     QmlValueTypeReference *r = new (v4->memoryManager) QmlValueTypeReference(v8);
-    r->prototype = proto.value().objectValue();
+    r->prototype = v4->qmlExtensions()->valueTypeWrapperPrototype;
     r->type = type; r->object = object; r->property = property;
     return Value::fromObject(r);
 }
@@ -158,7 +156,7 @@ Value QmlValueTypeWrapper::create(QV8Engine *v8, const QVariant &value, QQmlValu
     initProto(v4);
 
     QmlValueTypeCopy *r = new (v4->memoryManager) QmlValueTypeCopy(v8);
-    r->prototype = proto.value().objectValue();
+    r->prototype = v4->qmlExtensions()->valueTypeWrapperPrototype;
     r->type = type; r->value = value;
     return Value::fromObject(r);
 }
index 4841bcc..ccf4fd3 100644 (file)
@@ -95,7 +95,6 @@ public:
     mutable QQmlValueType *type;
 
     static void initProto(ExecutionEngine *v4);
-    static PersistentValue proto;
 };
 
 }
index ad5bcaf..d7064a1 100644 (file)
@@ -64,6 +64,7 @@
 #include "qv4executableallocator_p.h"
 #include "qv4sequenceobject_p.h"
 #include "qv4qobjectwrapper_p.h"
+#include "qv4qmlextensions_p.h"
 
 #if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
 #include <execinfo.h>
@@ -95,6 +96,7 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
     , m_engineId(engineSerial.fetchAndAddOrdered(1))
     , regExpCache(0)
     , m_multiplyWrappedQObjects(0)
+    , m_qmlExtensions(0)
 {
     MemoryManager::GCBlocker gcBlocker(memoryManager);
 
@@ -276,6 +278,7 @@ ExecutionEngine::~ExecutionEngine()
     delete m_multiplyWrappedQObjects;
     m_multiplyWrappedQObjects = 0;
     delete memoryManager;
+    delete m_qmlExtensions;
     emptyClass->destroy();
     delete identifierCache;
     delete bumperPointerAllocator;
@@ -877,6 +880,9 @@ void ExecutionEngine::markObjects()
 
     variantPrototype->mark();
     sequencePrototype->mark();
+
+    if (m_qmlExtensions)
+        m_qmlExtensions->markObjects();
 }
 
 namespace {
@@ -914,6 +920,13 @@ Function *ExecutionEngine::functionForProgramCounter(quintptr pc) const
     return 0;
 }
 
+QmlExtensions *ExecutionEngine::qmlExtensions()
+{
+    if (!m_qmlExtensions)
+        m_qmlExtensions = new QmlExtensions;
+    return m_qmlExtensions;
+}
+
 Exception::Exception(ExecutionContext *throwingContext, const Value &exceptionValue)
     : exception(exceptionValue)
 {
index 09f76ec..5b7733a 100644 (file)
@@ -106,6 +106,7 @@ struct InternalClass;
 class MultiplyWrappedQObjectMap;
 class RegExp;
 class RegExpCache;
+struct QmlExtensions;
 
 struct Q_QML_EXPORT ExecutionEngine
 {
@@ -297,6 +298,11 @@ struct Q_QML_EXPORT ExecutionEngine
     InternalClass *newClass(const InternalClass &other);
 
     Function *functionForProgramCounter(quintptr pc) const;
+
+    QmlExtensions *qmlExtensions();
+
+private:
+    QmlExtensions *m_qmlExtensions;
 };
 
 inline void ExecutionEngine::pushContext(SimpleCallContext *context)
diff --git a/src/qml/qml/v4/qv4qmlextensions.cpp b/src/qml/qml/v4/qv4qmlextensions.cpp
new file mode 100644 (file)
index 0000000..41a683d
--- /dev/null
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the V4VM module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qv4qmlextensions_p.h"
+#include "qv4object_p.h"
+
+using namespace QV4;
+
+void QmlExtensions::markObjects()
+{
+    if (valueTypeWrapperPrototype)
+        valueTypeWrapperPrototype->mark();
+}
diff --git a/src/qml/qml/v4/qv4qmlextensions_p.h b/src/qml/qml/v4/qv4qmlextensions_p.h
new file mode 100644 (file)
index 0000000..ee25a12
--- /dev/null
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the V4VM module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QV4QMLEXTENSIONS_P_H
+#define QV4QMLEXTENSIONS_P_H
+
+#include <qtqmlglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace QV4 {
+struct Object;
+
+struct Q_QML_EXPORT QmlExtensions
+{
+    QmlExtensions()
+        : valueTypeWrapperPrototype(0)
+    {}
+
+    Object *valueTypeWrapperPrototype;
+
+    void markObjects();
+};
+
+} // namespace QV4
+
+QT_END_NAMESPACE
+
+#endif
index 3538e0f..9d15992 100644 (file)
@@ -53,7 +53,8 @@ SOURCES += \
     $$PWD/qv4executableallocator.cpp \
     $$PWD/qv4sequenceobject.cpp \
     $$PWD/qv4include.cpp \
-    $$PWD/qv4qobjectwrapper.cpp
+    $$PWD/qv4qobjectwrapper.cpp \
+    $$PWD/qv4qmlextensions.cpp
 
 HEADERS += \
     $$PWD/qv4global_p.h \
@@ -105,7 +106,8 @@ HEADERS += \
     $$PWD/qv4executableallocator_p.h \
     $$PWD/qv4sequenceobject_p.h \
     $$PWD/qv4include_p.h \
-    $$PWD/qv4qobjectwrapper_p.h
+    $$PWD/qv4qobjectwrapper_p.h \
+    $$PWD/qv4qmlextensions_p.h
 
 llvm-libs {