aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/animations/qabstractanimationjob.cpp2
-rw-r--r--src/qml/animations/qcontinuinganimationgroupjob.cpp2
-rw-r--r--src/qml/animations/qparallelanimationgroupjob.cpp2
-rw-r--r--src/qml/animations/qpauseanimationjob.cpp2
-rw-r--r--src/qml/animations/qsequentialanimationgroupjob.cpp2
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp75
-rw-r--r--src/qml/compiler/qv4ssa.cpp4
-rw-r--r--src/qml/doc/qtqml.qdocconf5
-rw-r--r--src/qml/doc/src/examples.qdoc35
-rw-r--r--src/qml/doc/src/qmlfunctions.qdoc2
-rw-r--r--src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc87
-rw-r--r--src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc90
-rw-r--r--src/qml/doc/src/qtqml.qdoc1
-rw-r--r--src/qml/jit/qv4isel_masm.cpp62
-rw-r--r--src/qml/jsapi/qjsengine.cpp2
-rw-r--r--src/qml/jsruntime/qv4arraybuffer.cpp2
-rw-r--r--src/qml/jsruntime/qv4debugging.cpp10
-rw-r--r--src/qml/jsruntime/qv4debugging_p.h2
-rw-r--r--src/qml/jsruntime/qv4engine.cpp32
-rw-r--r--src/qml/jsruntime/qv4engine_p.h1
-rw-r--r--src/qml/jsruntime/qv4function.cpp3
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp10
-rw-r--r--src/qml/jsruntime/qv4numberobject.cpp10
-rw-r--r--src/qml/jsruntime/qv4persistent.cpp63
-rw-r--r--src/qml/jsruntime/qv4persistent_p.h8
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp25
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper_p.h6
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp12
-rw-r--r--src/qml/jsruntime/qv4script.cpp12
-rw-r--r--src/qml/jsruntime/qv4script_p.h2
-rw-r--r--src/qml/jsruntime/qv4serialize.cpp10
-rw-r--r--src/qml/jsruntime/qv4string.cpp7
-rw-r--r--src/qml/jsruntime/qv4string_p.h8
-rw-r--r--src/qml/jsruntime/qv4typedarray.cpp14
-rw-r--r--src/qml/jsruntime/qv4value_p.h30
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp8
-rw-r--r--src/qml/memory/qv4mm.cpp54
-rw-r--r--src/qml/memory/qv4mm_p.h17
-rw-r--r--src/qml/qml/ftw/qbitfield_p.h11
-rw-r--r--src/qml/qml/ftw/qhashedstring_p.h4
-rw-r--r--src/qml/qml/qqml.h10
-rw-r--r--src/qml/qml/qqmlabstracturlinterceptor.cpp2
-rw-r--r--src/qml/qml/qqmlbinding.cpp8
-rw-r--r--src/qml/qml/qqmlcontext.cpp2
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp77
-rw-r--r--src/qml/qml/qqmlcontextwrapper_p.h5
-rw-r--r--src/qml/qml/qqmlengine.cpp45
-rw-r--r--src/qml/qml/qqmlextensionplugin.cpp66
-rw-r--r--src/qml/qml/qqmlfileselector.cpp3
-rw-r--r--src/qml/qml/qqmlglobal.cpp58
-rw-r--r--src/qml/qml/qqmlglobal_p.h20
-rw-r--r--src/qml/qml/qqmlimport.cpp2
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp44
-rw-r--r--src/qml/qml/qqmljavascriptexpression_p.h2
-rw-r--r--src/qml/qml/qqmlmetatype.cpp5
-rw-r--r--src/qml/qml/qqmlnotifier.cpp56
-rw-r--r--src/qml/qml/qqmlnotifier_p.h7
-rw-r--r--src/qml/qml/qqmlopenmetaobject.cpp33
-rw-r--r--src/qml/qml/qqmlopenmetaobject_p.h3
-rw-r--r--src/qml/qml/qqmlproperty.cpp9
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp22
-rw-r--r--src/qml/qml/qqmlpropertycache_p.h8
-rw-r--r--src/qml/qml/qqmlvaluetype.cpp2
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp922
-rw-r--r--src/qml/qml/qqmlvmemetaobject_p.h52
-rw-r--r--src/qml/qml/qqmlxmlhttprequest.cpp146
-rw-r--r--src/qml/qml/v8/qv8engine_p.h13
-rw-r--r--src/qml/types/qqmlinstantiator.cpp2
-rw-r--r--src/qml/types/qqmllistmodel.cpp154
-rw-r--r--src/qml/types/qqmllistmodel_p.h5
-rw-r--r--src/qml/types/qqmllistmodel_p_p.h77
-rw-r--r--src/qml/util/qqmladaptormodel.cpp2
-rw-r--r--src/qml/util/qqmllistaccessor.cpp4
73 files changed, 1367 insertions, 1233 deletions
diff --git a/src/qml/animations/qabstractanimationjob.cpp b/src/qml/animations/qabstractanimationjob.cpp
index 7fcf383bcb..d301c43822 100644
--- a/src/qml/animations/qabstractanimationjob.cpp
+++ b/src/qml/animations/qabstractanimationjob.cpp
@@ -652,7 +652,7 @@ void QAbstractAnimationJob::removeAnimationChangeListener(QAnimationJobChangeLis
void QAbstractAnimationJob::debugAnimation(QDebug d) const
{
- d << "AbstractAnimationJob(" << hex << (void *) this << dec << ") state:"
+ d << "AbstractAnimationJob(" << hex << (const void *) this << dec << ") state:"
<< m_state << "duration:" << duration();
}
diff --git a/src/qml/animations/qcontinuinganimationgroupjob.cpp b/src/qml/animations/qcontinuinganimationgroupjob.cpp
index c77448f153..88005baf12 100644
--- a/src/qml/animations/qcontinuinganimationgroupjob.cpp
+++ b/src/qml/animations/qcontinuinganimationgroupjob.cpp
@@ -115,7 +115,7 @@ void QContinuingAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimat
void QContinuingAnimationGroupJob::debugAnimation(QDebug d) const
{
- d << "ContinuingAnimationGroupJob(" << hex << (void *) this << dec << ")";
+ d << "ContinuingAnimationGroupJob(" << hex << (const void *) this << dec << ")";
debugChildren(d);
}
diff --git a/src/qml/animations/qparallelanimationgroupjob.cpp b/src/qml/animations/qparallelanimationgroupjob.cpp
index 0153794d6f..fe56f2b1e8 100644
--- a/src/qml/animations/qparallelanimationgroupjob.cpp
+++ b/src/qml/animations/qparallelanimationgroupjob.cpp
@@ -233,7 +233,7 @@ void QParallelAnimationGroupJob::uncontrolledAnimationFinished(QAbstractAnimatio
void QParallelAnimationGroupJob::debugAnimation(QDebug d) const
{
- d << "ParallelAnimationGroupJob(" << hex << (void *) this << dec << ")";
+ d << "ParallelAnimationGroupJob(" << hex << (const void *) this << dec << ")";
debugChildren(d);
}
diff --git a/src/qml/animations/qpauseanimationjob.cpp b/src/qml/animations/qpauseanimationjob.cpp
index 8e35c58999..0e95645f41 100644
--- a/src/qml/animations/qpauseanimationjob.cpp
+++ b/src/qml/animations/qpauseanimationjob.cpp
@@ -62,7 +62,7 @@ void QPauseAnimationJob::updateCurrentTime(int)
void QPauseAnimationJob::debugAnimation(QDebug d) const
{
- d << "PauseAnimationJob(" << hex << (void *) this << dec << ")" << "duration:" << m_duration;
+ d << "PauseAnimationJob(" << hex << (const void *) this << dec << ")" << "duration:" << m_duration;
}
QT_END_NAMESPACE
diff --git a/src/qml/animations/qsequentialanimationgroupjob.cpp b/src/qml/animations/qsequentialanimationgroupjob.cpp
index 5060b7f6cd..b92caf3bc4 100644
--- a/src/qml/animations/qsequentialanimationgroupjob.cpp
+++ b/src/qml/animations/qsequentialanimationgroupjob.cpp
@@ -411,7 +411,7 @@ void QSequentialAnimationGroupJob::animationRemoved(QAbstractAnimationJob *anim,
void QSequentialAnimationGroupJob::debugAnimation(QDebug d) const
{
- d << "SequentialAnimationGroupJob(" << hex << (void *) this << dec << ")" << "currentAnimation:" << (void *)m_currentAnimation;
+ d << "SequentialAnimationGroupJob(" << hex << (const void *) this << dec << ")" << "currentAnimation:" << (void *)m_currentAnimation;
debugChildren(d);
}
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index 911be238b9..80ffafda72 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -667,17 +667,14 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob
}
// First set up notify signals for properties - first normal, then var, then alias
- enum { NSS_Normal = 0, NSS_Var = 1, NSS_Alias = 2 };
+ enum { NSS_Normal = 0, NSS_Alias = 1 };
for (int ii = NSS_Normal; ii <= NSS_Alias; ++ii) { // 0 == normal, 1 == var, 2 == alias
- if (ii == NSS_Var && varPropCount == 0) continue;
- else if (ii == NSS_Alias && aliasCount == 0) continue;
+ if (ii == NSS_Alias && aliasCount == 0) continue;
for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next) {
- if ((ii == NSS_Normal && (p->type == QV4::CompiledData::Property::Alias ||
- p->type == QV4::CompiledData::Property::Var)) ||
- ((ii == NSS_Var) && (p->type != QV4::CompiledData::Property::Var)) ||
- ((ii == NSS_Alias) && (p->type != QV4::CompiledData::Property::Alias)))
+ if ((ii == NSS_Normal && p->type == QV4::CompiledData::Property::Alias) ||
+ (ii == NSS_Alias && p->type != QV4::CompiledData::Property::Alias))
continue;
quint32 flags = QQmlPropertyData::IsSignal | QQmlPropertyData::IsFunction |
@@ -780,15 +777,18 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob
int propertyIdx = 0;
for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next, ++propertyIdx) {
- if (p->type == QV4::CompiledData::Property::Alias ||
- p->type == QV4::CompiledData::Property::Var)
+ if (p->type == QV4::CompiledData::Property::Alias)
continue;
int propertyType = 0;
int vmePropertyType = 0;
quint32 propertyFlags = 0;
- if (p->type < builtinTypeCount) {
+ if (p->type == QV4::CompiledData::Property::Var) {
+ propertyType = QMetaType::QVariant;
+ vmePropertyType = QQmlVMEMetaData::VarPropertyType;
+ propertyFlags = QQmlPropertyData::IsVarProperty;
+ } else if (p->type < builtinTypeCount) {
propertyType = builtinTypes[p->type].metaType;
vmePropertyType = propertyType;
@@ -836,7 +836,7 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob
propertyFlags |= QQmlPropertyData::IsQList;
}
- if ((!p->flags & QV4::CompiledData::Property::IsReadOnly) && p->type != QV4::CompiledData::Property::CustomList)
+ if (!(p->flags & QV4::CompiledData::Property::IsReadOnly) && p->type != QV4::CompiledData::Property::CustomList)
propertyFlags |= QQmlPropertyData::IsWritable;
@@ -852,30 +852,6 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob
vmd->propertyCount++;
}
- // Now do var properties
- propertyIdx = 0;
- for (const QmlIR::Property *p = obj->firstProperty(); p; p = p->next, ++propertyIdx) {
-
- if (p->type != QV4::CompiledData::Property::Var)
- continue;
-
- quint32 propertyFlags = QQmlPropertyData::IsVarProperty;
- if (!p->flags & QV4::CompiledData::Property::IsReadOnly)
- propertyFlags |= QQmlPropertyData::IsWritable;
-
- VMD *vmd = (QQmlVMEMetaData *)dynamicData.data();
- (vmd->propertyData() + vmd->propertyCount)->propertyType = QMetaType::QVariant;
- vmd->propertyCount++;
- ((QQmlVMEMetaData *)dynamicData.data())->varPropertyCount++;
-
- QString propertyName = stringAt(p->nameIndex);
- if (propertyIdx == obj->indexOfDefaultProperty) cache->_defaultPropertyName = propertyName;
- cache->appendProperty(propertyName, propertyFlags, effectivePropertyIndex++,
- QMetaType::QVariant, effectiveSignalIndex);
-
- effectiveSignalIndex++;
- }
-
// Alias property count. Actual data is setup in buildDynamicMetaAliases
((QQmlVMEMetaData *)dynamicData.data())->aliasCount = aliasCount;
@@ -1067,16 +1043,29 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio
paramList = paramList->finish();
QmlIR::CompiledFunctionOrExpression *foe = obj->functionsAndExpressions->slowAt(binding->value.compiledScriptIndex);
- QQmlJS::AST::Statement *statement = static_cast<QQmlJS::AST::Statement*>(foe->node);
- QQmlJS::AST::SourceElement *sourceElement = new (pool) QQmlJS::AST::StatementSourceElement(statement);
- QQmlJS::AST::SourceElements *elements = new (pool) QQmlJS::AST::SourceElements(sourceElement);
- elements = elements->finish();
-
- QQmlJS::AST::FunctionBody *body = new (pool) QQmlJS::AST::FunctionBody(elements);
+ QQmlJS::AST::FunctionDeclaration *functionDeclaration = 0;
+ if (QQmlJS::AST::ExpressionStatement *es = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement*>(foe->node)) {
+ if (QQmlJS::AST::FunctionExpression *fe = QQmlJS::AST::cast<QQmlJS::AST::FunctionExpression*>(es->expression)) {
+ functionDeclaration = new (pool) QQmlJS::AST::FunctionDeclaration(fe->name, fe->formals, fe->body);
+ functionDeclaration->functionToken = fe->functionToken;
+ functionDeclaration->identifierToken = fe->identifierToken;
+ functionDeclaration->lparenToken = fe->lparenToken;
+ functionDeclaration->rparenToken = fe->rparenToken;
+ functionDeclaration->lbraceToken = fe->lbraceToken;
+ functionDeclaration->rbraceToken = fe->rbraceToken;
+ }
+ }
+ if (!functionDeclaration) {
+ QQmlJS::AST::Statement *statement = static_cast<QQmlJS::AST::Statement*>(foe->node);
+ QQmlJS::AST::SourceElement *sourceElement = new (pool) QQmlJS::AST::StatementSourceElement(statement);
+ QQmlJS::AST::SourceElements *elements = new (pool) QQmlJS::AST::SourceElements(sourceElement);
+ elements = elements->finish();
- QQmlJS::AST::FunctionDeclaration *functionDeclaration = new (pool) QQmlJS::AST::FunctionDeclaration(compiler->newStringRef(stringAt(binding->propertyNameIndex)), paramList, body);
- functionDeclaration->functionToken = foe->node->firstSourceLocation();
+ QQmlJS::AST::FunctionBody *body = new (pool) QQmlJS::AST::FunctionBody(elements);
+ functionDeclaration = new (pool) QQmlJS::AST::FunctionDeclaration(compiler->newStringRef(stringAt(binding->propertyNameIndex)), paramList, body);
+ functionDeclaration->functionToken = foe->node->firstSourceLocation();
+ }
foe->node = functionDeclaration;
binding->propertyNameIndex = compiler->registerString(propertyName);
binding->flags |= QV4::CompiledData::Binding::IsSignalHandlerExpression;
diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp
index 62e661c98a..c150666a11 100644
--- a/src/qml/compiler/qv4ssa.cpp
+++ b/src/qml/compiler/qv4ssa.cpp
@@ -530,7 +530,7 @@ class DominatorTree
const int bbCount = function->basicBlockCount();
d->vertex = std::vector<int>(bbCount, InvalidBasicBlockIndex);
d->parent = std::vector<int>(bbCount, InvalidBasicBlockIndex);
- d->dfnum = std::vector<int>(bbCount, 0);
+ d->dfnum = std::vector<int>(size_t(bbCount), 0);
d->semi = std::vector<BasicBlockIndex>(bbCount, InvalidBasicBlockIndex);
d->ancestor = std::vector<BasicBlockIndex>(bbCount, InvalidBasicBlockIndex);
idom = std::vector<BasicBlockIndex>(bbCount, InvalidBasicBlockIndex);
@@ -873,7 +873,7 @@ private:
// - set the current node's depth to that of immediate dominator + 1
std::vector<int> calculateNodeDepths() const
{
- std::vector<int> nodeDepths(function->basicBlockCount(), -1);
+ std::vector<int> nodeDepths(size_t(function->basicBlockCount()), -1);
nodeDepths[0] = 0;
foreach (BasicBlock *bb, function->basicBlocks()) {
if (bb->isRemoved())
diff --git a/src/qml/doc/qtqml.qdocconf b/src/qml/doc/qtqml.qdocconf
index 5729a60ea3..74b61fd6e1 100644
--- a/src/qml/doc/qtqml.qdocconf
+++ b/src/qml/doc/qtqml.qdocconf
@@ -23,7 +23,7 @@ qhp.QtQml.subprojects.classes.indexTitle = Qt QML C++ Classes
qhp.QtQml.subprojects.classes.selectors = class fake:headerfile
qhp.QtQml.subprojects.classes.sortPages = true
qhp.QtQml.subprojects.examples.title = Examples
-qhp.QtQml.subprojects.examples.indexTitle = Qt Quick Examples and Tutorials
+qhp.QtQml.subprojects.examples.indexTitle = Qt QML Examples
qhp.QtQml.subprojects.examples.selectors = fake:example
qhp.QtQml.subprojects.qmltypes.title = QML Types
qhp.QtQml.subprojects.qmltypes.indexTitle = Qt QML QML Types
@@ -50,7 +50,8 @@ imagedirs += images
# Add a thumbnail for examples that do not have images
manifestmeta.thumbnail.names += "QtQml/Chapter 4*" \
- "QtQml/Chapter 6*"
+ "QtQml/Chapter 6*" \
+ "QtQml/C++ Extensions: *"
navigation.landingpage = "Qt QML"
navigation.cppclassespage = "Qt QML C++ Classes"
diff --git a/src/qml/doc/src/examples.qdoc b/src/qml/doc/src/examples.qdoc
new file mode 100644
index 0000000000..f3550ae199
--- /dev/null
+++ b/src/qml/doc/src/examples.qdoc
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: http://www.gnu.org/copyleft/fdl.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+\group qmlextendingexamples
+\title Qt QML Examples
+\brief List of Qt QML examples for reference.
+
+The list of examples demonstrating how to extend C++ to QML or the other way
+around.
+*/
diff --git a/src/qml/doc/src/qmlfunctions.qdoc b/src/qml/doc/src/qmlfunctions.qdoc
index 25bb0d6068..4203cca8b3 100644
--- a/src/qml/doc/src/qmlfunctions.qdoc
+++ b/src/qml/doc/src/qmlfunctions.qdoc
@@ -470,8 +470,8 @@
as any other item).
Usage:
- // First, define your QML singleton type which provides the functionality.
\qml
+ // First, define your QML singleton type which provides the functionality.
pragma Singleton
import QtQuick 2.0
Item {
diff --git a/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc b/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc
index 79bd3df9d9..a2397b6cfb 100644
--- a/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc
+++ b/src/qml/doc/src/qmllanguageref/modules/cppplugins.qdoc
@@ -32,96 +32,13 @@
\section1 Creating a Plugin
- The \l{QQmlEngine}{QML engine} load C++ plugins for QML.
+ The \l{QQmlEngine}{QML engine} loads C++ plugins for QML.
Such plugins are usually provided in a QML extension module, and can
provide types for use by clients in QML documents which import the module.
A module requires at least one type registered in order to be considered
valid.
- QQmlExtensionPlugin is a plugin interface that makes it possible to
- create QML extensions that can be loaded dynamically into QML applications.
- These extensions allow custom QML types to be made available to the
- QML engine.
-
- To write a QML extension plugin:
- \list 1
- \li Subclass QQmlExtensionPlugin
- \list
- \li Use the Q_PLUGIN_METADATA() macro to register the plugin with
- the Qt meta object system
- \li Override the \l{QQmlExtensionPlugin::}{registerTypes()} method
- and call qmlRegisterType() to register the types to be exported
- by the plugin
- \endlist
- \li Write a project file for the plugin
- \li Create a \l{Module Definition qmldir Files}{qmldir file} to
- describe the plugin
- \endlist
-
- QML extension plugins are for either application-specific or library-like
- plugins. Library plugins should limit themselves to registering types, as
- any manipulation of the engine's root context may cause conflicts or other
- issues in the library user's code.
-
-\section1 Plugin Example
-
- Suppose there is a new \c TimeModel C++ class that should be made available
- as a new QML type. It provides the current time through \c hour and \c minute
- properties.
-
- \snippet qmlextensionplugins/plugin.cpp 0
- \dots
-
- To make this type available, we create a plugin class named \c QExampleQmlPlugin
- which is a subclass of \l QQmlExtensionPlugin. It overrides the
- \l{QQmlExtensionPlugin::}{registerTypes()} method in order to register the \c TimeModel
- type using qmlRegisterType(). It also uses the Q_PLUGIN_METADATA() macro in the class
- definition to register the plugin with the Qt meta object system using a unique
- identifier for the plugin.
-
- \snippet qmlextensionplugins/plugin.cpp plugin
-
- The \c TimeModel class receives a \c{1.0} version of this plugin library, as
- a QML type called \c Time. The Q_ASSERT() macro can ensure the type namespace is
- imported correctly by any QML components that use this plugin. The
- \l{Defining QML Types from C++} article has more information about registering C++
- types into the runtime.
-
- For this example, the TimeExample source directory is in
- \c{imports/TimeExample}. The plugin's type namespace will mirror
- this structure, so the types are registered into the namespace
- "TimeExample".
-
- Additionally, the project file, in a \c .pro file, defines the project as a plugin library,
- specifies it should be built into the \c imports/TimeExample directory, and registers
- the plugin target name and various other details:
-
- \code
- TEMPLATE = lib
- CONFIG += qt plugin
- QT += qml
-
- DESTDIR = imports/TimeExample
- TARGET = qmlqtimeexampleplugin
- SOURCES += qexampleqmlplugin.cpp
- \endcode
-
- Finally, a \l{Module Definition qmldir Files}{qmldir file} is required
- in the \c imports/TimeExample directory to describe the plugin and the types that it
- exports. The plugin includes a \c Clock.qml file along with the \c qmlqtimeexampleplugin
- that is built by the project (as shown above in the \c .pro file) so both of these
- need to be specified in the \c qmldir file:
-
- \quotefile qmlextensionplugins/imports/TimeExample/qmldir
-
- Once the project is built and installed, the new \c Time component is
- accessible by any QML component that imports the \c TimeExample
- module
-
- \snippet qmlextensionplugins/plugins.qml 0
-
- The full source code is available in the \l {qmlextensionplugins}{plugins example}.
-
+ \include qqmlextensionplugin.qdocinc
\section1 Reference
diff --git a/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc
new file mode 100644
index 0000000000..7c1d65b095
--- /dev/null
+++ b/src/qml/doc/src/qmllanguageref/modules/qqmlextensionplugin.qdocinc
@@ -0,0 +1,90 @@
+QQmlExtensionPlugin is a plugin interface that makes it possible to
+create QML extensions that can be loaded dynamically into QML applications.
+These extensions allow custom QML types to be made available to the
+QML engine.
+
+To write a QML extension plugin:
+\list 1
+\li Subclass QQmlExtensionPlugin
+ \list
+ \li Use the Q_PLUGIN_METADATA() macro to register the plugin with
+ the Qt meta object system
+ \li Override the \l{QQmlExtensionPlugin::}{registerTypes()} method
+ and call qmlRegisterType() to register the types to be exported
+ by the plugin
+ \endlist
+\li Write a project file for the plugin
+\li Create a \l{Module Definition qmldir Files}{qmldir file} to
+ describe the plugin
+\endlist
+
+QML extension plugins are for either application-specific or library-like
+plugins. Library plugins should limit themselves to registering types, as
+any manipulation of the engine's root context may cause conflicts or other
+issues in the library user's code.
+
+\section1 Plugin Example
+
+Suppose there is a new \c TimeModel C++ class that should be made available
+as a new QML type. It provides the current time through \c hour and \c minute
+properties.
+
+\snippet qmlextensionplugins/plugin.cpp 0
+\dots
+
+To make this type available, we create a plugin class named \c QExampleQmlPlugin
+which is a subclass of \l QQmlExtensionPlugin. It overrides the
+\l{QQmlExtensionPlugin::}{registerTypes()} method in order to register the \c TimeModel
+type using qmlRegisterType(). It also uses the Q_PLUGIN_METADATA() macro in the class
+definition to register the plugin with the Qt meta object system using a unique
+identifier for the plugin.
+
+\snippet qmlextensionplugins/plugin.cpp plugin
+
+This registers the \c TimeModel class with version \c{1.0} of this plugin library, as
+a QML type called \c Time. The Q_ASSERT() macro can ensure the type namespace is
+imported correctly by any QML components that use this plugin. The
+\l{Defining QML Types from C++} article has more information about registering C++
+types into the runtime.
+
+Additionally, the project file (\c .pro) defines the project as a plugin library,
+specifies it should be built into the \c imports/TimeExample directory, and registers
+the plugin target name and various other details:
+
+\code
+TEMPLATE = lib
+CONFIG += qt plugin
+QT += qml
+
+DESTDIR = imports/TimeExample
+TARGET = qmlqtimeexampleplugin
+SOURCES += qexampleqmlplugin.cpp
+\endcode
+
+Finally, a \l{Module Definition qmldir Files}{qmldir file} is required
+in the \c imports/TimeExample directory to describe the plugin and the types that it
+exports. The plugin includes a \c Clock.qml file along with the \c qmlqtimeexampleplugin
+that is built by the project (as shown above in the \c .pro file) so both of these
+need to be specified in the \c qmldir file:
+
+\quotefile qmlextensionplugins/imports/TimeExample/qmldir
+
+To make things easier for this example, the TimeExample source directory is in
+\c{imports/TimeExample}, and we build
+\l{Source, Build, and Install Directories}{in-source}. However, the structure
+of the source directory is not so important, as the \c qmldir file can specify
+paths to installed QML files.
+
+What is important is the name of the directory that the qmldir is installed
+into. When the user imports our module, the QML engine uses the
+\l{Contents of a Module Definition qmldir File}{module identifier}
+(\c TimeExample) to find the plugin, and so the directory in which it is
+installed must match the module identifier.
+
+Once the project is built and installed, the new \c Time component is
+accessible by any QML component that imports the \c TimeExample
+module
+
+\snippet qmlextensionplugins/plugins.qml 0
+
+The full source code is available in the \l {qmlextensionplugins}{plugins example}.
diff --git a/src/qml/doc/src/qtqml.qdoc b/src/qml/doc/src/qtqml.qdoc
index 61ebbcf690..64d6bb9ac4 100644
--- a/src/qml/doc/src/qtqml.qdoc
+++ b/src/qml/doc/src/qtqml.qdoc
@@ -148,6 +148,7 @@ Further information for writing QML applications:
\list
\li \l{Qt QML C++ Classes}{C++ Classes}
\li \l{Qt QML QML Types}{QML Types}
+\li \l{Qt QML Examples}{Examples}
\endlist
*/
diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp
index acead2088b..5dfd891b80 100644
--- a/src/qml/jit/qv4isel_masm.cpp
+++ b/src/qml/jit/qv4isel_masm.cpp
@@ -45,6 +45,7 @@
#include "qv4binop_p.h"
#include <QtCore/QBuffer>
+#include <QtCore/QCoreApplication>
#include <assembler/LinkBuffer.h>
#include <WTFStubs.h>
@@ -120,6 +121,19 @@ static void printDisassembledOutputWithCalls(QByteArray processedOutput, const Q
qDebug("%s", processedOutput.constData());
}
+#if defined(Q_OS_LINUX)
+static FILE *pmap;
+
+static void qt_closePmap()
+{
+ if (pmap) {
+ fclose(pmap);
+ pmap = 0;
+ }
+}
+
+#endif
+
JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize)
{
Label endOfCode = label();
@@ -167,6 +181,8 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize)
*codeSize = linkBuffer.offsetOf(endOfCode);
+ QByteArray name;
+
JSC::MacroAssemblerCodeRef codeRef;
static bool showCode = !qgetenv("QV4_SHOW_ASM").isNull();
@@ -175,7 +191,7 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize)
buf.open(QIODevice::WriteOnly);
WTF::setDataFile(new QIODevicePrintStream(&buf));
- QByteArray name = _function->name->toUtf8();
+ name = _function->name->toUtf8();
if (name.isEmpty()) {
name = QByteArray::number(quintptr(_function), 16);
name.prepend("IR::Function(0x");
@@ -189,6 +205,50 @@ JSC::MacroAssemblerCodeRef Assembler::link(int *codeSize)
codeRef = linkBuffer.finalizeCodeWithoutDisassembly();
}
+#if defined(Q_OS_LINUX)
+ // This implements writing of JIT'd addresses so that perf can find the
+ // symbol names.
+ //
+ // Perf expects the mapping to be in a certain place and have certain
+ // content, for more information, see:
+ // https://github.com/torvalds/linux/blob/master/tools/perf/Documentation/jit-interface.txt
+ static bool doProfile = !qEnvironmentVariableIsEmpty("QV4_PROFILE_WRITE_PERF_MAP");
+ static bool profileInitialized = false;
+ if (doProfile && !profileInitialized) {
+ profileInitialized = true;
+
+ char pname[PATH_MAX];
+ snprintf(pname, PATH_MAX - 1, "/tmp/perf-%lu.map",
+ (unsigned long)QCoreApplication::applicationPid());
+
+ pmap = fopen(pname, "w");
+ if (!pmap)
+ qWarning("QV4: Can't write %s, call stacks will not contain JavaScript function names", pname);
+
+ // make sure we clean up nicely
+ std::atexit(qt_closePmap);
+ }
+
+ if (pmap) {
+ // this may have been pre-populated, if QV4_SHOW_ASM was on
+ if (name.isEmpty()) {
+ name = _function->name->toUtf8();
+ if (name.isEmpty()) {
+ name = QByteArray::number(quintptr(_function), 16);
+ name.prepend("IR::Function(0x");
+ name.append(")");
+ }
+ }
+
+ fprintf(pmap, "%llx %x %.*s\n",
+ (long long unsigned int)codeRef.code().executableAddress(),
+ *codeSize,
+ name.length(),
+ name.constData());
+ fflush(pmap);
+ }
+#endif
+
return codeRef;
}
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index d9615d496f..4910b6a1c6 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -580,7 +580,7 @@ QJSEnginePrivate::~QJSEnginePrivate()
QQmlPropertyCache *QJSEnginePrivate::createCache(const QMetaObject *mo)
{
if (!mo->superClass()) {
- QQmlPropertyCache *rv = new QQmlPropertyCache(q_func(), mo);
+ QQmlPropertyCache *rv = new QQmlPropertyCache(QV8Engine::getV4(q_func()), mo);
propertyCache.insert(mo, rv);
return rv;
} else {
diff --git a/src/qml/jsruntime/qv4arraybuffer.cpp b/src/qml/jsruntime/qv4arraybuffer.cpp
index 3106d3af23..23c9695cf4 100644
--- a/src/qml/jsruntime/qv4arraybuffer.cpp
+++ b/src/qml/jsruntime/qv4arraybuffer.cpp
@@ -79,7 +79,7 @@ ReturnedValue ArrayBufferCtor::method_isView(CallContext *ctx)
QV4::Scoped<DataView> v(scope, ctx->argument(0));
if (!!v)
return Encode(true);
- return Encode(true);
+ return Encode(false);
}
diff --git a/src/qml/jsruntime/qv4debugging.cpp b/src/qml/jsruntime/qv4debugging.cpp
index ceeef80b9f..6efc3793ce 100644
--- a/src/qml/jsruntime/qv4debugging.cpp
+++ b/src/qml/jsruntime/qv4debugging.cpp
@@ -59,6 +59,7 @@ Debugger::JavaScriptJob::JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr
: engine(engine)
, frameNr(frameNr)
, script(script)
+ , resultIsException(false)
{}
void Debugger::JavaScriptJob::run()
@@ -85,11 +86,18 @@ void Debugger::JavaScriptJob::run()
QV4::ScopedValue result(scope);
if (!scope.engine->hasException)
result = script.run();
- if (scope.engine->hasException)
+ if (scope.engine->hasException) {
result = scope.engine->catchException();
+ resultIsException = true;
+ }
handleResult(result);
}
+bool Debugger::JavaScriptJob::hasExeption() const
+{
+ return resultIsException;
+}
+
class EvalJob: public Debugger::JavaScriptJob
{
bool result;
diff --git a/src/qml/jsruntime/qv4debugging_p.h b/src/qml/jsruntime/qv4debugging_p.h
index ac0c934d42..86faba45f7 100644
--- a/src/qml/jsruntime/qv4debugging_p.h
+++ b/src/qml/jsruntime/qv4debugging_p.h
@@ -95,10 +95,12 @@ public:
QV4::ExecutionEngine *engine;
int frameNr;
const QString &script;
+ bool resultIsException;
public:
JavaScriptJob(QV4::ExecutionEngine *engine, int frameNr, const QString &script);
void run();
+ bool hasExeption() const;
protected:
virtual void handleResult(QV4::ScopedValue &result) = 0;
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 320ed59fcc..caf07e8b0b 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -107,6 +107,9 @@ static ReturnedValue throwTypeError(CallContext *ctx)
const int MinimumStackSize = 256; // in kbytes
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_MSVC(4172) // MSVC 2015: warning C4172: returning address of local variable or temporary: dummy
+
quintptr getStackLimit()
{
quintptr stackLimit;
@@ -171,6 +174,7 @@ quintptr getStackLimit()
int dummy;
// this is inexact, as part of the stack is used when being called here,
// but let's simply default to 1MB from where the stack is right now
+ // (Note: triggers warning C4172 as of MSVC 2015, returning address of local variable)
stackLimit = reinterpret_cast<qintptr>(&dummy) - 1024*1024;
#endif
@@ -178,6 +182,7 @@ quintptr getStackLimit()
return stackLimit + MinimumStackSize*1024;
}
+QT_WARNING_POP
QJSEngine *ExecutionEngine::jsEngine() const
{
@@ -540,7 +545,7 @@ Heap::Object *ExecutionEngine::newObject(InternalClass *internalClass, QV4::Obje
Heap::String *ExecutionEngine::newString(const QString &s)
{
Scope scope(this);
- return ScopedString(scope, memoryManager->alloc<String>(s))->d();
+ return ScopedString(scope, memoryManager->allocWithStringData<String>(s.length() * sizeof(QChar), s))->d();
}
Heap::String *ExecutionEngine::newIdentifier(const QString &text)
@@ -754,6 +759,27 @@ QObject *ExecutionEngine::qmlScopeObject() const
return qmlContextObject()->scopeObject;
}
+ReturnedValue ExecutionEngine::qmlSingletonWrapper(String *name)
+{
+ QQmlContextData *ctx = callingQmlContext();
+ if (!ctx->imports)
+ return Encode::undefined();
+ // Search for attached properties, enums and imported scripts
+ QQmlTypeNameCache::Result r = ctx->imports->query(name);
+
+ Q_ASSERT(r.isValid());
+ Q_ASSERT(r.type);
+ Q_ASSERT(r.type->isSingleton());
+
+ QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo();
+ QQmlEngine *e = qmlEngine();
+ siinfo->init(e);
+
+ if (QObject *qobjectSingleton = siinfo->qobjectApi(e))
+ return QV4::QObjectWrapper::wrap(this, qobjectSingleton);
+ return QJSValuePrivate::convertedToValue(this, siinfo->scriptApi(e));
+}
+
QQmlContextData *ExecutionEngine::callingQmlContext() const
{
Heap::QmlContextWrapper *w = qmlContextObject();
@@ -1373,7 +1399,7 @@ QV4::ReturnedValue QV4::ExecutionEngine::fromVariant(const QVariant &variant)
QV4::Scope scope(this);
if (type == qMetaTypeId<QQmlListReference>()) {
typedef QQmlListReferencePrivate QDLRP;
- QDLRP *p = QDLRP::get((QQmlListReference*)ptr);
+ QDLRP *p = QDLRP::get((QQmlListReference*)const_cast<void *>(ptr));
if (p->object) {
return QV4::QmlListWrapper::create(scope.engine, p->property, p->propertyType);
} else {
@@ -1385,7 +1411,7 @@ QV4::ReturnedValue QV4::ExecutionEngine::fromVariant(const QVariant &variant)
} else if (type == qMetaTypeId<QList<QObject *> >()) {
// XXX Can this be made more by using Array as a prototype and implementing
// directly against QList<QObject*>?
- const QList<QObject *> &list = *(QList<QObject *>*)ptr;
+ const QList<QObject *> &list = *(const QList<QObject *>*)ptr;
QV4::ScopedArrayObject a(scope, newArrayObject());
a->arrayReserve(list.count());
QV4::ScopedValue v(scope);
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index 9f44745e4c..90564a9652 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -390,6 +390,7 @@ public:
Heap::QmlContext *qmlContext() const;
QV4::Heap::QmlContextWrapper *qmlContextObject() const;
QObject *qmlScopeObject() const;
+ ReturnedValue qmlSingletonWrapper(String *name);
QQmlContextData *callingQmlContext() const;
diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp
index a18a2d4919..98a4490211 100644
--- a/src/qml/jsruntime/qv4function.cpp
+++ b/src/qml/jsruntime/qv4function.cpp
@@ -66,7 +66,8 @@ Function::Function(ExecutionEngine *engine, CompiledData::CompilationUnit *unit,
break;
}
// duplicate arguments, need some trick to store them
- arg = engine->memoryManager->alloc<String>(arg->d(), engine->newString(QString(0xfffe)));
+ MemoryManager *mm = engine->memoryManager;
+ arg = mm->alloc<String>(mm, arg->d(), engine->newString(QString(0xfffe)));
}
}
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index da01592c0d..6412e65fa9 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -46,7 +46,7 @@
#include <private/qqmljslexer_p.h>
#include <private/qqmljsparser_p.h>
#include <private/qqmljsast_p.h>
-#include <private/qqmlcontextwrapper_p.h>
+#include <private/qqmljavascriptexpression_p.h>
#include <private/qqmlengine_p.h>
#include <qv4codegen_p.h>
#include "private/qlocale_tools_p.h"
@@ -430,7 +430,7 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData)
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
if (f->function()->compiledFunction->hasQmlDependencies())
- QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
+ QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction);
if (v4->hasException)
return Encode::undefined();
@@ -457,7 +457,7 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData)
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
if (f->function()->compiledFunction->hasQmlDependencies())
- QmlContextWrapper::registerQmlDependencies(scope.engine, f->function()->compiledFunction);
+ QQmlPropertyCapture::registerQmlDependencies(scope.engine, f->function()->compiledFunction);
return result->asReturnedValue();
}
@@ -531,7 +531,7 @@ ReturnedValue SimpleScriptFunction::construct(const Managed *that, CallData *cal
ScopedObject result(scope, Q_V4_PROFILE(v4, f->function()));
if (f->function()->compiledFunction->hasQmlDependencies())
- QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
+ QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction);
if (!result)
return callData->thisObject.asReturnedValue();
@@ -569,7 +569,7 @@ ReturnedValue SimpleScriptFunction::call(const Managed *that, CallData *callData
ScopedValue result(scope, Q_V4_PROFILE(v4, f->function()));
if (f->function()->compiledFunction->hasQmlDependencies())
- QmlContextWrapper::registerQmlDependencies(v4, f->function()->compiledFunction);
+ QQmlPropertyCapture::registerQmlDependencies(v4, f->function()->compiledFunction);
return result->asReturnedValue();
}
diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp
index 096fe9fb4c..4ae30a7f35 100644
--- a/src/qml/jsruntime/qv4numberobject.cpp
+++ b/src/qml/jsruntime/qv4numberobject.cpp
@@ -76,14 +76,10 @@ void NumberPrototype::init(ExecutionEngine *engine, Object *ctor)
ctor->defineReadonlyProperty(QStringLiteral("POSITIVE_INFINITY"), Primitive::fromDouble(qInf()));
ctor->defineReadonlyProperty(QStringLiteral("MAX_VALUE"), Primitive::fromDouble(1.7976931348623158e+308));
-#ifdef __INTEL_COMPILER
-# pragma warning( push )
-# pragma warning(disable: 239)
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_INTEL(239)
ctor->defineReadonlyProperty(QStringLiteral("MIN_VALUE"), Primitive::fromDouble(5e-324));
-#ifdef __INTEL_COMPILER
-# pragma warning( pop )
-#endif
+QT_WARNING_POP
defineDefaultProperty(QStringLiteral("constructor"), (o = ctor));
defineDefaultProperty(engine->id_toString(), method_toString);
diff --git a/src/qml/jsruntime/qv4persistent.cpp b/src/qml/jsruntime/qv4persistent.cpp
index 4ec7103644..4a0f84b685 100644
--- a/src/qml/jsruntime/qv4persistent.cpp
+++ b/src/qml/jsruntime/qv4persistent.cpp
@@ -93,6 +93,43 @@ Page *allocatePage(PersistentValueStorage *storage)
}
+PersistentValueStorage::Iterator::Iterator(void *p, int idx)
+ : p(p), index(idx)
+{
+ Page *page = static_cast<Page *>(p);
+ if (page)
+ ++page->header.refCount;
+}
+
+PersistentValueStorage::Iterator::Iterator(const PersistentValueStorage::Iterator &o)
+ : p(o.p), index(o.index)
+{
+ Page *page = static_cast<Page *>(p);
+ if (page)
+ ++page->header.refCount;
+}
+
+PersistentValueStorage::Iterator &PersistentValueStorage::Iterator::operator=(const PersistentValueStorage::Iterator &o)
+{
+ Page *page = static_cast<Page *>(p);
+ if (page && !--page->header.refCount)
+ freePage(p);
+ p = o.p;
+ index = o.index;
+ page = static_cast<Page *>(p);
+ if (page)
+ ++page->header.refCount;
+
+ return *this;
+}
+
+PersistentValueStorage::Iterator::~Iterator()
+{
+ Page *page = static_cast<Page *>(p);
+ if (page && !--page->header.refCount)
+ freePage(page);
+}
+
PersistentValueStorage::Iterator &PersistentValueStorage::Iterator::operator++() {
while (p) {
while (index < kEntriesPerPage - 1) {
@@ -101,7 +138,12 @@ PersistentValueStorage::Iterator &PersistentValueStorage::Iterator::operator++()
return *this;
}
index = -1;
- p = static_cast<Page *>(p)->header.next;
+ Page *next = static_cast<Page *>(p)->header.next;
+ if (!--static_cast<Page *>(p)->header.refCount)
+ freePage(p);
+ p = next;
+ if (next)
+ ++next->header.refCount;
}
index = 0;
return *this;
@@ -165,13 +207,8 @@ void PersistentValueStorage::free(Value *v)
v->setTag(QV4::Value::Empty_Type);
v->setInt_32(p->header.freeList);
p->header.freeList = v - p->values;
- if (!--p->header.refCount) {
- if (p->header.prev)
- *p->header.prev = p->header.next;
- if (p->header.next)
- p->header.next->header.prev = p->header.prev;
- p->header.alloc.deallocate();
- }
+ if (!--p->header.refCount)
+ freePage(p);
}
static void drainMarkStack(QV4::ExecutionEngine *engine, Value *markBase)
@@ -204,6 +241,16 @@ ExecutionEngine *PersistentValueStorage::getEngine(Value *v)
return getPage(v)->header.engine;
}
+void PersistentValueStorage::freePage(void *page)
+{
+ Page *p = static_cast<Page *>(page);
+ if (p->header.prev)
+ *p->header.prev = p->header.next;
+ if (p->header.next)
+ p->header.next->header.prev = p->header.prev;
+ p->header.alloc.deallocate();
+}
+
PersistentValue::PersistentValue(const PersistentValue &other)
: val(0)
diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h
index 858734e9ed..67a76742d1 100644
--- a/src/qml/jsruntime/qv4persistent_p.h
+++ b/src/qml/jsruntime/qv4persistent_p.h
@@ -51,8 +51,10 @@ struct Q_QML_EXPORT PersistentValueStorage
void mark(ExecutionEngine *e);
struct Iterator {
- Q_DECL_CONSTEXPR Iterator(void *p, int idx)
- : p(p), index(idx) {}
+ Iterator(void *p, int idx);
+ Iterator(const Iterator &o);
+ Iterator & operator=(const Iterator &o);
+ ~Iterator();
void *p;
int index;
Iterator &operator++();
@@ -68,6 +70,8 @@ struct Q_QML_EXPORT PersistentValueStorage
ExecutionEngine *engine;
void *firstPage;
+private:
+ static void freePage(void *page);
};
class Q_QML_EXPORT PersistentValue
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 529703bda4..d1796f5fd4 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -71,14 +71,9 @@
QT_BEGIN_NAMESPACE
-#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
-# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
// The code in this file does not violate strict aliasing, but GCC thinks it does
// so turn off the warnings for us to have a clean build
-# pragma GCC diagnostic ignored "-Wstrict-aliasing"
-# endif
-#endif
-
+QT_WARNING_DISABLE_GCC("-Wstrict-aliasing")
using namespace QV4;
@@ -338,9 +333,8 @@ ReturnedValue QObjectWrapper::getProperty(ExecutionEngine *engine, QObject *obje
Q_ASSERT(vmemo);
return vmemo->vmeMethod(property->coreIndex);
} else if (property->isV4Function()) {
- QV4::ScopedObject qmlcontextobject(scope, engine->qmlContextObject());
- ScopedContext global(scope, scope.engine->rootContext());
- return QV4::QObjectMethod::create(global, object, property->coreIndex, qmlcontextobject);
+ ScopedContext global(scope, scope.engine->qmlContext());
+ return QV4::QObjectMethod::create(global, object, property->coreIndex);
} else if (property->isSignalHandler()) {
QV4::Scoped<QV4::QmlSignalHandler> handler(scope, scope.engine->memoryManager->alloc<QV4::QmlSignalHandler>(engine, object, property->coreIndex));
@@ -1731,7 +1725,7 @@ QV4::ReturnedValue CallArgument::toValue(QV4::ExecutionEngine *engine)
}
}
-ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal)
+ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, int index)
{
Scope valueScope(scope);
Scoped<QObjectMethod> method(valueScope, scope->d()->engine->memoryManager->alloc<QObjectMethod>(scope));
@@ -1741,18 +1735,16 @@ ReturnedValue QObjectMethod::create(ExecutionContext *scope, QObject *object, in
method->d()->propertyCache = ddata->propertyCache;
method->d()->index = index;
- method->d()->qmlGlobal = qmlGlobal;
method->d()->valueTypeWrapper = Primitive::undefinedValue();
return method.asReturnedValue();
}
-ReturnedValue QObjectMethod::create(ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index, const Value &qmlGlobal)
+ReturnedValue QObjectMethod::create(ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index)
{
Scope valueScope(scope);
Scoped<QObjectMethod> method(valueScope, scope->d()->engine->memoryManager->alloc<QObjectMethod>(scope));
method->d()->propertyCache = valueType->d()->propertyCache;
method->d()->index = index;
- method->d()->qmlGlobal = qmlGlobal;
method->d()->valueTypeWrapper = *valueType;
return method.asReturnedValue();
}
@@ -1868,11 +1860,7 @@ ReturnedValue QObjectMethod::callInternal(CallData *callData) const
if (method.isV4Function()) {
QV4::ScopedValue rv(scope, QV4::Primitive::undefinedValue());
-
- QV4::ScopedValue qmlGlobal(scope, d()->qmlGlobal);
- QQmlV4Function func(callData, rv, qmlGlobal,
- QmlContextWrapper::getContext(qmlGlobal),
- scope.engine);
+ QQmlV4Function func(callData, rv, scope.engine);
QQmlV4Function *funcptr = &func;
void *args[] = { 0, &funcptr };
@@ -1891,7 +1879,6 @@ ReturnedValue QObjectMethod::callInternal(CallData *callData) const
void QObjectMethod::markObjects(Heap::Base *that, ExecutionEngine *e)
{
QObjectMethod::Data *This = static_cast<QObjectMethod::Data*>(that);
- This->qmlGlobal.mark(e);
This->valueTypeWrapper.mark(e);
FunctionObject::markObjects(that, e);
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h
index 2d10006d97..da24c81f40 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper_p.h
+++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h
@@ -79,7 +79,6 @@ struct QObjectMethod : FunctionObject {
QPointer<QObject> object;
QQmlRefPointer<QQmlPropertyCache> propertyCache;
int index;
- Value qmlGlobal;
Value valueTypeWrapper;
@@ -123,7 +122,6 @@ struct Q_QML_EXPORT QObjectWrapper : public Object
protected:
static bool isEqualTo(Managed *that, Managed *o);
-private:
static ReturnedValue getProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, bool captureRequired = true);
static void setProperty(ExecutionEngine *engine, QObject *object, QQmlPropertyData *property, const Value &value);
@@ -150,8 +148,8 @@ struct Q_QML_EXPORT QObjectMethod : public QV4::FunctionObject
enum { DestroyMethod = -1, ToStringMethod = -2 };
- static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index, const Value &qmlGlobal = Primitive::undefinedValue());
- static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index, const Value &qmlGlobal = Primitive::undefinedValue());
+ static ReturnedValue create(QV4::ExecutionContext *scope, QObject *object, int index);
+ static ReturnedValue create(QV4::ExecutionContext *scope, const QQmlValueTypeWrapper *valueType, int index);
int methodIndex() const { return d()->index; }
QObject *object() const { return d()->object.data(); }
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 089922d03e..9316223696 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -524,7 +524,8 @@ QV4::ReturnedValue RuntimeHelpers::addHelper(ExecutionEngine *engine, const Valu
return pright->asReturnedValue();
if (!pright->stringValue()->d()->length())
return pleft->asReturnedValue();
- return (engine->memoryManager->alloc<String>(pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue();
+ MemoryManager *mm = engine->memoryManager;
+ return (mm->alloc<String>(mm, pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue();
}
double x = RuntimeHelpers::toNumber(pleft);
double y = RuntimeHelpers::toNumber(pright);
@@ -540,7 +541,8 @@ QV4::ReturnedValue Runtime::addString(ExecutionEngine *engine, const Value &left
return right.asReturnedValue();
if (!right.stringValue()->d()->length())
return left.asReturnedValue();
- return (engine->memoryManager->alloc<String>(left.stringValue()->d(), right.stringValue()->d()))->asReturnedValue();
+ MemoryManager *mm = engine->memoryManager;
+ return (mm->alloc<String>(mm, left.stringValue()->d(), right.stringValue()->d()))->asReturnedValue();
}
Scope scope(engine);
@@ -557,7 +559,8 @@ QV4::ReturnedValue Runtime::addString(ExecutionEngine *engine, const Value &left
return pright->asReturnedValue();
if (!pright->stringValue()->d()->length())
return pleft->asReturnedValue();
- return (engine->memoryManager->alloc<String>(pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue();
+ MemoryManager *mm = engine->memoryManager;
+ return (mm->alloc<String>(mm, pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue();
}
void Runtime::setProperty(ExecutionEngine *engine, const Value &object, int nameIndex, const Value &value)
@@ -1457,8 +1460,7 @@ QV4::ReturnedValue Runtime::getQmlSingleton(QV4::NoThrowEngine *engine, int name
{
Scope scope(engine);
ScopedString name(scope, engine->currentContext()->compilationUnit->runtimeStrings[nameIndex]);
- Scoped<QmlContextWrapper> wrapper(scope, engine->qmlContextObject());
- return wrapper->qmlSingletonWrapper(engine, name);
+ return engine->qmlSingletonWrapper(name);
}
void Runtime::convertThisToObject(ExecutionEngine *engine)
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index 0bf4f21acb..14b8b878bd 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -90,7 +90,6 @@ DEFINE_OBJECT_VTABLE(CompilationUnitHolder);
Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::QmlContextWrapper *qml)
: Heap::FunctionObject(scope, scope->d()->engine->id_eval(), /*createProto = */ false)
- , qml(qml->d())
{
Q_ASSERT(scope->inUse());
@@ -107,7 +106,6 @@ Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, Functio
Heap::QmlBindingWrapper::QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::QmlContextWrapper *qml)
: Heap::FunctionObject(scope, scope->d()->engine->id_eval(), /*createProto = */ false)
- , qml(qml->d())
{
Q_ASSERT(scope->inUse());
@@ -140,14 +138,6 @@ ReturnedValue QmlBindingWrapper::call(const Managed *that, CallData *callData)
return result->asReturnedValue();
}
-void QmlBindingWrapper::markObjects(Heap::Base *m, ExecutionEngine *e)
-{
- QmlBindingWrapper::Data *wrapper = static_cast<QmlBindingWrapper::Data *>(m);
- if (wrapper->qml)
- wrapper->qml->mark(e);
- FunctionObject::markObjects(m, e);
-}
-
static ReturnedValue signalParameterGetter(QV4::CallContext *ctx, uint parameterIndex)
{
QV4::Scope scope(ctx);
@@ -379,7 +369,7 @@ ReturnedValue Script::qmlBinding()
return v.asReturnedValue();
}
-QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject)
+QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, Object *scopeObject)
{
QV4::Scope scope(engine);
QV4::Script qmlScript(engine, scopeObject, script, QString());
diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h
index 77784dfc4f..22714496f8 100644
--- a/src/qml/jsruntime/qv4script_p.h
+++ b/src/qml/jsruntime/qv4script_p.h
@@ -90,7 +90,6 @@ struct QmlBindingWrapper : Heap::FunctionObject {
QmlBindingWrapper(QV4::ExecutionContext *scope, Function *f, QV4::QmlContextWrapper *qml);
// Constructor for QML functions and signal handlers, resulting binding wrapper is not callable!
QmlBindingWrapper(QV4::ExecutionContext *scope, QV4::QmlContextWrapper *qml);
- Pointer<Object> qml;
};
}
@@ -99,7 +98,6 @@ struct Q_QML_EXPORT QmlBindingWrapper : FunctionObject {
V4_OBJECT2(QmlBindingWrapper, FunctionObject)
static ReturnedValue call(const Managed *that, CallData *callData);
- static void markObjects(Heap::Base *m, ExecutionEngine *e);
Heap::QmlContext *context() const { return static_cast<Heap::QmlContext *>(d()->scope.ptr); }
diff --git a/src/qml/jsruntime/qv4serialize.cpp b/src/qml/jsruntime/qv4serialize.cpp
index 090e9c7e6a..33b40796a4 100644
--- a/src/qml/jsruntime/qv4serialize.cpp
+++ b/src/qml/jsruntime/qv4serialize.cpp
@@ -116,21 +116,21 @@ static inline void reserve(QByteArray &data, int extra)
static inline quint32 popUint32(const char *&data)
{
- quint32 rv = *((quint32 *)data);
+ quint32 rv = *((const quint32 *)data);
data += sizeof(quint32);
return rv;
}
static inline double popDouble(const char *&data)
{
- double rv = *((double *)data);
+ double rv = *((const double *)data);
data += sizeof(double);
return rv;
}
static inline void *popPtr(const char *&data)
{
- void *rv = *((void **)data);
+ void *rv = *((void *const *)data);
data += sizeof(void *);
return rv;
}
@@ -297,7 +297,7 @@ ReturnedValue Serialize::deserialize(const char *&data, ExecutionEngine *engine)
case WorkerString:
{
quint32 size = headersize(header);
- QString qstr((QChar *)data, size);
+ QString qstr((const QChar *)data, size);
data += ALIGN(size * sizeof(quint16));
return QV4::Encode(engine->newString(qstr));
}
@@ -342,7 +342,7 @@ ReturnedValue Serialize::deserialize(const char *&data, ExecutionEngine *engine)
{
quint32 flags = headersize(header);
quint32 length = popUint32(data);
- QString pattern = QString((QChar *)data, length - 1);
+ QString pattern = QString((const QChar *)data, length - 1);
data += ALIGN(length * sizeof(quint16));
return Encode(engine->newRegExpObject(pattern, flags));
}
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp
index 2ab608e64e..24a13ddd10 100644
--- a/src/qml/jsruntime/qv4string.cpp
+++ b/src/qml/jsruntime/qv4string.cpp
@@ -117,7 +117,8 @@ bool String::isEqualTo(Managed *t, Managed *o)
}
-Heap::String::String(const QString &t)
+Heap::String::String(MemoryManager *mm, const QString &t)
+ : mm(mm)
{
subtype = String::StringType_Unknown;
@@ -129,7 +130,8 @@ Heap::String::String(const QString &t)
len = text->size;
}
-Heap::String::String(String *l, String *r)
+Heap::String::String(MemoryManager *mm, String *l, String *r)
+ : mm(mm)
{
subtype = String::StringType_Unknown;
@@ -187,6 +189,7 @@ void Heap::String::simplifyString() const
text->ref.ref();
identifier = 0;
largestSubLength = 0;
+ mm->growUnmanagedHeapSizeUsage(size_t(text->size) * sizeof(QChar));
}
void Heap::String::createHashValue() const
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h
index 568c11261a..93a25d7ed5 100644
--- a/src/qml/jsruntime/qv4string_p.h
+++ b/src/qml/jsruntime/qv4string_p.h
@@ -53,8 +53,8 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
StringType_ArrayIndex
};
- String(const QString &text);
- String(String *l, String *n);
+ String(MemoryManager *mm, const QString &text);
+ String(MemoryManager *mm, String *l, String *n);
~String() {
if (!largestSubLength && !text->ref.deref())
QStringData::deallocate(text);
@@ -66,6 +66,9 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
len == (uint)text->size);
return len;
}
+ std::size_t retainedTextSize() const {
+ return largestSubLength ? 0 : (std::size_t(text->size) * sizeof(QChar));
+ }
void createHashValue() const;
inline unsigned hashValue() const {
if (subtype == StringType_Unknown)
@@ -107,6 +110,7 @@ struct Q_QML_PRIVATE_EXPORT String : Base {
mutable uint stringHash;
mutable uint largestSubLength;
uint len;
+ MemoryManager *mm;
private:
static void append(const String *data, QChar *ch);
};
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp
index fcc6f3dc5d..f06eeb08b9 100644
--- a/src/qml/jsruntime/qv4typedarray.cpp
+++ b/src/qml/jsruntime/qv4typedarray.cpp
@@ -85,7 +85,7 @@ void UInt8ClampedArrayWrite(ExecutionEngine *e, char *data, int index, const Val
return;
}
if (d >= 255) {
- data[index] = (unsigned char)(255);
+ data[index] = (char)(255);
return;
}
double f = std::floor(d);
@@ -107,7 +107,7 @@ void UInt8ClampedArrayWrite(ExecutionEngine *e, char *data, int index, const Val
ReturnedValue Int16ArrayRead(const char *data, int index)
{
- return Encode((int)*(short *)(data + index));
+ return Encode((int)*(const short *)(data + index));
}
void Int16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value)
@@ -120,7 +120,7 @@ void Int16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &val
ReturnedValue UInt16ArrayRead(const char *data, int index)
{
- return Encode((int)*(unsigned short *)(data + index));
+ return Encode((int)*(const unsigned short *)(data + index));
}
void UInt16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value)
@@ -133,7 +133,7 @@ void UInt16ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &va
ReturnedValue Int32ArrayRead(const char *data, int index)
{
- return Encode(*(int *)(data + index));
+ return Encode(*(const int *)(data + index));
}
void Int32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value)
@@ -146,7 +146,7 @@ void Int32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &val
ReturnedValue UInt32ArrayRead(const char *data, int index)
{
- return Encode(*(unsigned int *)(data + index));
+ return Encode(*(const unsigned int *)(data + index));
}
void UInt32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value)
@@ -159,7 +159,7 @@ void UInt32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &va
ReturnedValue Float32ArrayRead(const char *data, int index)
{
- return Encode(*(float *)(data + index));
+ return Encode(*(const float *)(data + index));
}
void Float32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value)
@@ -172,7 +172,7 @@ void Float32ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &v
ReturnedValue Float64ArrayRead(const char *data, int index)
{
- return Encode(*(double *)(data + index));
+ return Encode(*(const double *)(data + index));
}
void Float64ArrayWrite(ExecutionEngine *e, char *data, int index, const Value &value)
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h
index c0420a38db..6305e6dfbb 100644
--- a/src/qml/jsruntime/qv4value_p.h
+++ b/src/qml/jsruntime/qv4value_p.h
@@ -39,6 +39,14 @@
#include "qv4global_p.h"
#include <private/qv4heap_p.h>
+/* We cannot rely on QT_POINTER_SIZE to be set correctly on host builds. In qmldevtools the Value objects
+ are only used to store primitives, never object pointers. So we can use the 64-bit encoding. */
+#ifdef V4_BOOTSTRAP
+#define QV4_USE_64_BIT_VALUE_ENCODING
+#elif QT_POINTER_SIZE == 8
+#define QV4_USE_64_BIT_VALUE_ENCODING
+#endif
+
QT_BEGIN_NAMESPACE
namespace QV4 {
@@ -94,10 +102,10 @@ struct Q_QML_PRIVATE_EXPORT Value
Q_ALWAYS_INLINE quint32 value() const { return _val >> 32; }
#endif
-#if QT_POINTER_SIZE == 8
+#ifdef QV4_USE_64_BIT_VALUE_ENCODING
Q_ALWAYS_INLINE Heap::Base *m() const { Heap::Base *b; memcpy(&b, &_val, 8); return b; }
Q_ALWAYS_INLINE void setM(Heap::Base *b) { memcpy(&_val, &b, 8); }
-#else // QT_POINTER_SIZE == 4
+#else // !QV4_USE_64_BIT_VALUE_ENCODING
Q_ALWAYS_INLINE Heap::Base *m() const { Heap::Base *b; quint32 v = value(); memcpy(&b, &v, 4); return b; }
Q_ALWAYS_INLINE void setM(Heap::Base *b) { quint32 v; memcpy(&v, &b, 4); setValue(v); }
#endif
@@ -106,7 +114,7 @@ struct Q_QML_PRIVATE_EXPORT Value
Q_ALWAYS_INLINE void setInt_32(int i) { quint32 u; memcpy(&u, &i, 4); setValue(u); }
Q_ALWAYS_INLINE uint uint_32() const { return value(); }
-#if QT_POINTER_SIZE == 4
+#ifndef QV4_USE_64_BIT_VALUE_ENCODING
enum Masks {
SilentNaNBit = 0x00040000,
NaN_Mask = 0x7ff80000,
@@ -186,7 +194,7 @@ struct Q_QML_PRIVATE_EXPORT Value
inline bool isUndefined() const { return tag() == Undefined_Type; }
inline bool isNull() const { return tag() == _Null_Type; }
inline bool isBoolean() const { return tag ()== _Boolean_Type; }
-#if QT_POINTER_SIZE == 8
+#ifdef QV4_USE_64_BIT_VALUE_ENCODING
inline bool isInteger() const { return (_val >> IsNumber_Shift) == 1; }
inline bool isDouble() const { return (_val >> IsDouble_Shift); }
inline bool isNumber() const { return (_val >> IsNumber_Shift); }
@@ -219,7 +227,7 @@ struct Q_QML_PRIVATE_EXPORT Value
Q_ASSERT(isDouble());
double d;
quint64 v = _val;
-#if QT_POINTER_SIZE == 8
+#ifdef QV4_USE_64_BIT_VALUE_ENCODING
v ^= NaNEncodeMask;
#endif
memcpy(&d, &v, 8);
@@ -227,7 +235,7 @@ struct Q_QML_PRIVATE_EXPORT Value
}
Q_ALWAYS_INLINE void setDouble(double d) {
memcpy(&_val, &d, 8);
-#if QT_POINTER_SIZE == 8
+#ifdef QV4_USE_64_BIT_VALUE_ENCODING
_val ^= NaNEncodeMask;
#endif
Q_ASSERT(isDouble());
@@ -287,7 +295,7 @@ struct Q_QML_PRIVATE_EXPORT Value
Value v;
v.setRawValue(0);
v.setM(m);
-#if QT_POINTER_SIZE == 4
+#ifndef QV4_USE_64_BIT_VALUE_ENCODING
v.setTag(Managed_Type);
#endif
return v;
@@ -368,7 +376,7 @@ struct Q_QML_PRIVATE_EXPORT Value
}
Value &operator=(Heap::Base *o) {
setM(o);
-#if QT_POINTER_SIZE == 4
+#ifndef QV4_USE_64_BIT_VALUE_ENCODING
setTag(Managed_Type);
#endif
return *this;
@@ -413,7 +421,7 @@ inline double Value::toNumber() const
#ifndef V4_BOOTSTRAP
inline uint Value::asArrayIndex() const
{
-#if QT_POINTER_SIZE == 8
+#ifdef QV4_USE_64_BIT_VALUE_ENCODING
if (!isNumber())
return UINT_MAX;
if (isInteger())
@@ -461,7 +469,7 @@ struct Q_QML_PRIVATE_EXPORT Primitive : public Value
inline Primitive Primitive::undefinedValue()
{
Primitive v;
-#if QT_POINTER_SIZE == 8
+#ifdef QV4_USE_64_BIT_VALUE_ENCODING
v.setRawValue(quint64(Undefined_Type) << Tag_Shift);
#else
v.setRawValue(0);
@@ -481,7 +489,7 @@ inline Primitive Primitive::emptyValue()
inline Primitive Primitive::nullValue()
{
Primitive v;
-#if QT_POINTER_SIZE == 8
+#ifndef QV4_USE_64_BIT_VALUE_ENCODING
v.setRawValue(quint64(_Null_Type) << Tag_Shift);
#else
v.setTagValue(_Null_Type, 0);
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index d0ae44ccea..0edd7378a7 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -636,7 +636,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
MOTH_END_INSTR(CallGlobalLookup)
MOTH_BEGIN_INSTR(SetExceptionHandler)
- exceptionHandler = instr.offset ? ((uchar *)&instr.offset) + instr.offset : 0;
+ exceptionHandler = instr.offset ? ((const uchar *)&instr.offset) + instr.offset : 0;
MOTH_END_INSTR(SetExceptionHandler)
MOTH_BEGIN_INSTR(CallBuiltinThrow)
@@ -770,21 +770,21 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
MOTH_END_INSTR(ConstructGlobalLookup)
MOTH_BEGIN_INSTR(Jump)
- code = ((uchar *)&instr.offset) + instr.offset;
+ code = ((const uchar *)&instr.offset) + instr.offset;
MOTH_END_INSTR(Jump)
MOTH_BEGIN_INSTR(JumpEq)
bool cond = VALUEPTR(instr.condition)->toBoolean();
TRACE(condition, "%s", cond ? "TRUE" : "FALSE");
if (cond)
- code = ((uchar *)&instr.offset) + instr.offset;
+ code = ((const uchar *)&instr.offset) + instr.offset;
MOTH_END_INSTR(JumpEq)
MOTH_BEGIN_INSTR(JumpNe)
bool cond = VALUEPTR(instr.condition)->toBoolean();
TRACE(condition, "%s", cond ? "TRUE" : "FALSE");
if (!cond)
- code = ((uchar *)&instr.offset) + instr.offset;
+ code = ((const uchar *)&instr.offset) + instr.offset;
MOTH_END_INSTR(JumpNe)
MOTH_BEGIN_INSTR(UNot)
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp
index 03e78df91a..b880c9c8d5 100644
--- a/src/qml/memory/qv4mm.cpp
+++ b/src/qml/memory/qv4mm.cpp
@@ -95,6 +95,8 @@ struct MemoryManager::Data
uint maxShift;
std::size_t maxChunkSize;
QVector<PageAllocation> heapChunks;
+ std::size_t unmanagedHeapSize; // the amount of bytes of heap that is not managed by the memory manager, but which is held onto by managed items.
+ std::size_t unmanagedHeapSizeGCLimit;
struct LargeItem {
LargeItem *next;
@@ -121,6 +123,8 @@ struct MemoryManager::Data
, totalAlloc(0)
, maxShift(6)
, maxChunkSize(32*1024)
+ , unmanagedHeapSize(0)
+ , unmanagedHeapSizeGCLimit(64 * 1024)
, largeItems(0)
, totalLargeItemsAllocated(0)
{
@@ -154,8 +158,10 @@ struct MemoryManager::Data
namespace {
-bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, ExecutionEngine *engine)
+bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, ExecutionEngine *engine, std::size_t *unmanagedHeapSize)
{
+ Q_ASSERT(unmanagedHeapSize);
+
bool isEmpty = true;
Heap::Base *tail = &header->freeItems;
// qDebug("chunkStart @ %p, size=%x, pos=%x", header->itemStart, header->itemSize, header->itemSize>>4);
@@ -164,8 +170,8 @@ bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, Exec
#endif
for (char *item = header->itemStart; item <= header->itemEnd; item += header->itemSize) {
Heap::Base *m = reinterpret_cast<Heap::Base *>(item);
-// qDebug("chunk @ %p, size = %lu, in use: %s, mark bit: %s",
-// item, m->size, (m->inUse ? "yes" : "no"), (m->markBit ? "true" : "false"));
+// qDebug("chunk @ %p, in use: %s, mark bit: %s",
+// item, (m->inUse() ? "yes" : "no"), (m->isMarked() ? "true" : "false"));
Q_ASSERT((qintptr) item % 16 == 0);
@@ -180,6 +186,13 @@ bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, Exec
#ifdef V4_USE_VALGRIND
VALGRIND_ENABLE_ERROR_REPORTING;
#endif
+ if (std::size_t(header->itemSize) == MemoryManager::align(sizeof(Heap::String)) && m->vtable()->isString) {
+ std::size_t heapBytes = static_cast<Heap::String *>(m)->retainedTextSize();
+ Q_ASSERT(*unmanagedHeapSize >= heapBytes);
+// qDebug() << "-- it's a string holding on to" << heapBytes << "bytes";
+ *unmanagedHeapSize -= heapBytes;
+ }
+
if (m->vtable()->destroy)
m->vtable()->destroy(m);
@@ -216,7 +229,7 @@ MemoryManager::MemoryManager(ExecutionEngine *engine)
m_d->engine = engine;
}
-Heap::Base *MemoryManager::allocData(std::size_t size)
+Heap::Base *MemoryManager::allocData(std::size_t size, std::size_t unmanagedSize)
{
if (m_d->aggressiveGC)
runGC();
@@ -227,11 +240,27 @@ Heap::Base *MemoryManager::allocData(std::size_t size)
Q_ASSERT(size >= 16);
Q_ASSERT(size % 16 == 0);
+// qDebug() << "unmanagedHeapSize:" << m_d->unmanagedHeapSize << "limit:" << m_d->unmanagedHeapSizeGCLimit << "unmanagedSize:" << unmanagedSize;
+ m_d->unmanagedHeapSize += unmanagedSize;
+ bool didGCRun = false;
+ if (m_d->unmanagedHeapSize > m_d->unmanagedHeapSizeGCLimit) {
+ runGC();
+
+ if (m_d->unmanagedHeapSizeGCLimit <= m_d->unmanagedHeapSize)
+ m_d->unmanagedHeapSizeGCLimit = std::max(m_d->unmanagedHeapSizeGCLimit, m_d->unmanagedHeapSize) * 2;
+ else if (m_d->unmanagedHeapSize * 4 <= m_d->unmanagedHeapSizeGCLimit)
+ m_d->unmanagedHeapSizeGCLimit /= 2;
+ else if (m_d->unmanagedHeapSizeGCLimit - m_d->unmanagedHeapSize < 5 * unmanagedSize)
+ // try preventing running the GC all the time when we're just below the threshold limit and manage to collect just enough to do this one allocation
+ m_d->unmanagedHeapSizeGCLimit += std::max(std::size_t(8 * 1024), 5 * unmanagedSize);
+ didGCRun = true;
+ }
+
size_t pos = size >> 4;
// doesn't fit into a small bucket
if (size >= MemoryManager::Data::MaxItemSize) {
- if (m_d->totalLargeItemsAllocated > 8 * 1024 * 1024)
+ if (!didGCRun && m_d->totalLargeItemsAllocated > 8 * 1024 * 1024)
runGC();
// we use malloc for this
@@ -254,7 +283,7 @@ Heap::Base *MemoryManager::allocData(std::size_t size)
}
// try to free up space, otherwise allocate
- if (m_d->allocCount[pos] > (m_d->availableItems[pos] >> 1) && m_d->totalAlloc > (m_d->totalItems >> 1) && !m_d->aggressiveGC) {
+ if (!didGCRun && m_d->allocCount[pos] > (m_d->availableItems[pos] >> 1) && m_d->totalAlloc > (m_d->totalItems >> 1) && !m_d->aggressiveGC) {
runGC();
header = m_d->nonFullChunks[pos];
if (header) {
@@ -344,7 +373,7 @@ void MemoryManager::mark()
for (PersistentValueStorage::Iterator it = m_weakValues->begin(); it != m_weakValues->end(); ++it) {
if (!(*it).isManaged())
continue;
- if ((*it).managed()->d()->vtable() != QObjectWrapper::staticVTable())
+ if (!(*it).as<QObjectWrapper>())
continue;
QObjectWrapper *qobjectWrapper = static_cast<QObjectWrapper*>((*it).managed());
QObject *qobject = qobjectWrapper->object();
@@ -381,10 +410,8 @@ void MemoryManager::sweep(bool lastSweep)
continue;
// we need to call detroyObject on qobjectwrappers now, so that they can emit the destroyed
// signal before we start sweeping the heap
- if ((*it).managed()->d()->vtable() == QObjectWrapper::staticVTable()) {
- QObjectWrapper *qobjectWrapper = static_cast<QObjectWrapper*>((*it).managed());
+ if (QObjectWrapper *qobjectWrapper = (*it).as<QObjectWrapper>())
qobjectWrapper->destroyObject(lastSweep);
- }
(*it) = Primitive::undefinedValue();
}
@@ -405,7 +432,7 @@ void MemoryManager::sweep(bool lastSweep)
for (int i = 0; i < m_d->heapChunks.size(); ++i) {
Data::ChunkHeader *header = reinterpret_cast<Data::ChunkHeader *>(m_d->heapChunks[i].base());
- chunkIsEmpty[i] = sweepChunk(header, &itemsInUse[header->itemSize >> 4], m_d->engine);
+ chunkIsEmpty[i] = sweepChunk(header, &itemsInUse[header->itemSize >> 4], m_d->engine, &m_d->unmanagedHeapSize);
}
QVector<PageAllocation>::iterator chunkIter = m_d->heapChunks.begin();
@@ -545,6 +572,11 @@ size_t MemoryManager::getLargeItemsMem() const
return total;
}
+void MemoryManager::growUnmanagedHeapSizeUsage(size_t delta)
+{
+ m_d->unmanagedHeapSize += delta;
+}
+
MemoryManager::~MemoryManager()
{
delete m_persistentValues;
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h
index 6d6ce1bad7..c01866ff11 100644
--- a/src/qml/memory/qv4mm_p.h
+++ b/src/qml/memory/qv4mm_p.h
@@ -83,10 +83,10 @@ public:
{ return (size + 15) & ~0xf; }
template<typename ManagedType>
- inline typename ManagedType::Data *allocManaged(std::size_t size)
+ inline typename ManagedType::Data *allocManaged(std::size_t size, std::size_t unmanagedSize = 0)
{
size = align(size);
- Heap::Base *o = allocData(size);
+ Heap::Base *o = allocData(size, unmanagedSize);
o->setVtable(ManagedType::staticVTable());
return static_cast<typename ManagedType::Data *>(o);
}
@@ -109,6 +109,15 @@ public:
return t->d();
}
+ template <typename ManagedType, typename Arg1>
+ typename ManagedType::Data *allocWithStringData(std::size_t unmanagedSize, Arg1 arg1)
+ {
+ Scope scope(engine());
+ Scoped<ManagedType> t(scope, allocManaged<ManagedType>(sizeof(typename ManagedType::Data), unmanagedSize));
+ (void)new (t->d()) typename ManagedType::Data(this, arg1);
+ return t->d();
+ }
+
template <typename ManagedType, typename Arg1, typename Arg2>
typename ManagedType::Data *alloc(Arg1 arg1, Arg2 arg2)
{
@@ -157,10 +166,12 @@ public:
size_t getAllocatedMem() const;
size_t getLargeItemsMem() const;
+ void growUnmanagedHeapSizeUsage(size_t delta); // called when a JS object grows itself. Specifically: Heap::String::append
+
protected:
/// expects size to be aligned
// TODO: try to inline
- Heap::Base *allocData(std::size_t size);
+ Heap::Base *allocData(std::size_t size, std::size_t unmanagedSize);
#ifdef DETAILED_MM_STATS
void willAllocate(std::size_t size);
diff --git a/src/qml/qml/ftw/qbitfield_p.h b/src/qml/qml/ftw/qbitfield_p.h
index 0b7d507b11..e3b6b0e498 100644
--- a/src/qml/qml/ftw/qbitfield_p.h
+++ b/src/qml/qml/ftw/qbitfield_p.h
@@ -129,15 +129,16 @@ QBitField QBitField::united(const QBitField &o)
rv.bits = max;
rv.ownData = new quint32[length + 1];
*(rv.ownData) = 1;
- rv.data = rv.ownData + 1;
+ quint32 *rvdata;
+ rv.data = rvdata = rv.ownData + 1;
if (bits > o.bits) {
- ::memcpy((quint32 *)rv.data, data, length * sizeof(quint32));
+ ::memcpy(rvdata, data, length * sizeof(quint32));
for (quint32 ii = 0; ii < (o.bits + quint32(31)) / 32; ++ii)
- ((quint32 *)rv.data)[ii] |= o.data[ii];
+ (rvdata)[ii] |= o.data[ii];
} else {
- ::memcpy((quint32 *)rv.data, o.data, length * sizeof(quint32));
+ ::memcpy(rvdata, o.data, length * sizeof(quint32));
for (quint32 ii = 0; ii < (bits + quint32(31)) / 32; ++ii)
- ((quint32 *)rv.data)[ii] |= data[ii];
+ (rvdata)[ii] |= data[ii];
}
return rv;
}
diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h
index 6ae2e17267..d38fd668f3 100644
--- a/src/qml/qml/ftw/qhashedstring_p.h
+++ b/src/qml/qml/ftw/qhashedstring_p.h
@@ -252,14 +252,14 @@ public:
inline bool equals(const QHashedStringRef &string) const {
return length == string.length() &&
hash == string.hash() &&
- (isQString()?QHashedString::compare(string.constData(), (QChar *)utf16Data(), length):
+ (isQString()?QHashedString::compare(string.constData(), (const QChar *)utf16Data(), length):
QHashedString::compare(string.constData(), cStrData(), length));
}
inline bool equals(const QHashedCStringRef &string) const {
return length == string.length() &&
hash == string.hash() &&
- (isQString()?QHashedString::compare((QChar *)utf16Data(), string.constData(), length):
+ (isQString()?QHashedString::compare((const QChar *)utf16Data(), string.constData(), length):
QHashedString::compare(string.constData(), cStrData(), length));
}
};
diff --git a/src/qml/qml/qqml.h b/src/qml/qml/qqml.h
index d6fd7b96f6..23cb69e2f1 100644
--- a/src/qml/qml/qqml.h
+++ b/src/qml/qml/qqml.h
@@ -502,17 +502,13 @@ namespace QtQml {
}
#endif
-#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wheader-hygiene"
-#endif
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_CLANG("-Wheader-hygiene")
// This is necessary to allow for QtQuick1 and QtQuick2 scenes in a single application.
using namespace QtQml;
-#if defined(Q_CC_CLANG) && !defined(Q_CC_INTEL)
-#pragma clang diagnostic pop
-#endif
+QT_WARNING_POP
//The C++ version of protected namespaces in qmldir
Q_QML_EXPORT bool qmlProtectModule(const char* uri, int majVersion);
diff --git a/src/qml/qml/qqmlabstracturlinterceptor.cpp b/src/qml/qml/qqmlabstracturlinterceptor.cpp
index e64b33b181..cb57bc2146 100644
--- a/src/qml/qml/qqmlabstracturlinterceptor.cpp
+++ b/src/qml/qml/qqmlabstracturlinterceptor.cpp
@@ -58,7 +58,7 @@
To implement support for a custom networked scheme, see setNetworkAccessManagerFactory.
*/
-/*
+/*!
\enum QQmlAbstractUrlInterceptor::DataType
Specifies where URL interception is taking place.
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index f17009569f..3613c17242 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -44,6 +44,7 @@
#include <private/qqmlcontextwrapper_p.h>
#include <private/qqmlbuiltinfunctions_p.h>
#include <private/qqmlvmemetaobject_p.h>
+#include <private/qqmlvaluetypewrapper_p.h>
#include <QVariant>
#include <QtCore/qdebug.h>
@@ -253,6 +254,11 @@ bool QQmlBinding::write(const QQmlPropertyData &core,
QUICK_STORE(QString, result.toQStringNoThrow())
break;
default:
+ if (const QV4::QQmlValueTypeWrapper *vtw = result.as<const QV4::QQmlValueTypeWrapper>()) {
+ if (vtw->d()->valueType->typeId == core.propType) {
+ return vtw->write(m_target.data(), core.coreIndex);
+ }
+ }
break;
}
}
@@ -327,7 +333,7 @@ bool QQmlBinding::write(const QQmlPropertyData &core,
const char *propertyType = 0;
if (value.userType() == QMetaType::QObjectStar) {
- if (QObject *o = *(QObject **)value.constData()) {
+ if (QObject *o = *(QObject *const *)value.constData()) {
valueType = o->metaObject()->className();
QQmlMetaObject propertyMetaObject = QQmlPropertyPrivate::rawMetaObjectForType(QQmlEnginePrivate::get(engine), type);
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp
index 56326df979..b056731e96 100644
--- a/src/qml/qml/qqmlcontext.cpp
+++ b/src/qml/qml/qqmlcontext.cpp
@@ -782,7 +782,7 @@ QString QQmlContextData::findObjectId(const QObject *obj) const
if (publicContext) {
QQmlContextPrivate *p = QQmlContextPrivate::get(publicContext);
for (int ii = 0; ii < p->propertyValues.count(); ++ii)
- if (p->propertyValues.at(ii) == QVariant::fromValue((QObject *)obj))
+ if (p->propertyValues.at(ii) == QVariant::fromValue(const_cast<QObject *>(obj)))
return properties.findId(ii);
}
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index 23084fb202..1007029416 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -93,19 +93,6 @@ ReturnedValue QmlContextWrapper::urlScope(ExecutionEngine *v4, const QUrl &url)
return w.asReturnedValue();
}
-QQmlContextData *QmlContextWrapper::getContext(const Value &value)
-{
- if (!value.isObject())
- return 0;
-
- QV4::ExecutionEngine *v4 = value.as<Object>()->engine();
- Scope scope(v4);
- QV4::Scoped<QmlContextWrapper> c(scope, value);
-
- return c ? c->getContext() : 0;
-}
-
-
ReturnedValue QmlContextWrapper::get(const Managed *m, String *name, bool *hasProperty)
{
Q_ASSERT(m->as<QmlContextWrapper>());
@@ -323,68 +310,4 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
Object::put(m, name, value);
}
-void QmlContextWrapper::registerQmlDependencies(ExecutionEngine *engine, const CompiledData::Function *compiledFunction)
-{
- // Let the caller check and avoid the function call :)
- Q_ASSERT(compiledFunction->hasQmlDependencies());
-
- QQmlEnginePrivate *ep = engine->qmlEngine() ? QQmlEnginePrivate::get(engine->qmlEngine()) : 0;
- if (!ep)
- return;
- QQmlPropertyCapture *capture = ep->propertyCapture;
- if (!capture)
- return;
-
- QV4::Scope scope(engine);
- QV4::Scoped<QmlContext> context(scope, engine->qmlContext());
- QQmlContextData *qmlContext = context->qmlContext();
-
- const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable();
- const int idObjectDependencyCount = compiledFunction->nDependingIdObjects;
- for (int i = 0; i < idObjectDependencyCount; ++i, ++idObjectDependency) {
- Q_ASSERT(int(*idObjectDependency) < qmlContext->idValueCount);
- capture->captureProperty(&qmlContext->idValues[*idObjectDependency].bindings);
- }
-
- Q_ASSERT(qmlContext->contextObject);
- const quint32 *contextPropertyDependency = compiledFunction->qmlContextPropertiesDependencyTable();
- const int contextPropertyDependencyCount = compiledFunction->nDependingContextProperties;
- for (int i = 0; i < contextPropertyDependencyCount; ++i) {
- const int propertyIndex = *contextPropertyDependency++;
- const int notifyIndex = *contextPropertyDependency++;
- capture->captureProperty(qmlContext->contextObject, propertyIndex, notifyIndex);
- }
-
- QObject *scopeObject = context->qmlScope();
- const quint32 *scopePropertyDependency = compiledFunction->qmlScopePropertiesDependencyTable();
- const int scopePropertyDependencyCount = compiledFunction->nDependingScopeProperties;
- for (int i = 0; i < scopePropertyDependencyCount; ++i) {
- const int propertyIndex = *scopePropertyDependency++;
- const int notifyIndex = *scopePropertyDependency++;
- capture->captureProperty(scopeObject, propertyIndex, notifyIndex);
- }
-
-}
-
-ReturnedValue QmlContextWrapper::qmlSingletonWrapper(ExecutionEngine *v4, String *name)
-{
- if (!d()->context->imports)
- return Encode::undefined();
- // Search for attached properties, enums and imported scripts
- QQmlTypeNameCache::Result r = d()->context->imports->query(name);
-
- Q_ASSERT(r.isValid());
- Q_ASSERT(r.type);
- Q_ASSERT(r.type->isSingleton());
- Q_ASSERT(v4);
-
- QQmlEngine *e = v4->qmlEngine();
- QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo();
- siinfo->init(e);
-
- if (QObject *qobjectSingleton = siinfo->qobjectApi(e))
- return QV4::QObjectWrapper::wrap(engine(), qobjectSingleton);
- return QJSValuePrivate::convertedToValue(engine(), siinfo->scriptApi(e));
-}
-
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h
index 7b5d3216df..192df9aed6 100644
--- a/src/qml/qml/qqmlcontextwrapper_p.h
+++ b/src/qml/qml/qqmlcontextwrapper_p.h
@@ -92,16 +92,11 @@ struct Q_QML_EXPORT QmlContextWrapper : Object
inline QObject *getScopeObject() const { return d()->scopeObject; }
inline QQmlContextData *getContext() const { return d()->context; }
- static QQmlContextData *getContext(const Value &value);
void setReadOnly(bool b) { d()->readOnly = b; }
static ReturnedValue get(const Managed *m, String *name, bool *hasProperty);
static void put(Managed *m, String *name, const Value &value);
-
- static void registerQmlDependencies(ExecutionEngine *context, const CompiledData::Function *compiledFunction);
-
- ReturnedValue qmlSingletonWrapper(ExecutionEngine *e, String *name);
};
}
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 70c682dedd..9c5e48ae32 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -258,6 +258,18 @@ void QQmlEnginePrivate::activateDesignerMode()
on producing the image without blocking the main thread.
*/
+/*!
+ \fn QQmlImageProviderBase::imageType() const
+
+ Implement this method to return the image type supported by this image provider.
+*/
+
+/*!
+ \fn QQmlImageProviderBase::flags() const
+
+ Implement this to return the properties of this image provider.
+*/
+
/*! \internal */
QQmlImageProviderBase::QQmlImageProviderBase()
{
@@ -1355,6 +1367,9 @@ QQmlEngine::ObjectOwnership QQmlEngine::objectOwnership(QObject *object)
return ddata->indestructible?CppOwnership:JavaScriptOwnership;
}
+/*!
+ \reimp
+*/
bool QQmlEngine::event(QEvent *e)
{
Q_D(QQmlEngine);
@@ -1496,16 +1511,28 @@ QQmlDataExtended::~QQmlDataExtended()
void QQmlData::NotifyList::layout(QQmlNotifierEndpoint *endpoint)
{
- if (endpoint->next)
- layout(endpoint->next);
+ // Add a temporary sentinel at beginning of list. This will be overwritten
+ // when the end point is inserted into the notifies further down.
+ endpoint->prev = 0;
- int index = endpoint->sourceSignal;
- index = qMin(index, 0xFFFF - 1);
+ while (endpoint->next) {
+ Q_ASSERT(reinterpret_cast<QQmlNotifierEndpoint *>(endpoint->next->prev) == endpoint);
+ endpoint = endpoint->next;
+ }
+
+ while (endpoint) {
+ QQmlNotifierEndpoint *ep = (QQmlNotifierEndpoint *) endpoint->prev;
- endpoint->next = notifies[index];
- if (endpoint->next) endpoint->next->prev = &endpoint->next;
- endpoint->prev = &notifies[index];
- notifies[index] = endpoint;
+ int index = endpoint->sourceSignal;
+ index = qMin(index, 0xFFFF - 1);
+
+ endpoint->next = notifies[index];
+ if (endpoint->next) endpoint->next->prev = &endpoint->next;
+ endpoint->prev = &notifies[index];
+ notifies[index] = endpoint;
+
+ endpoint = ep;
+ }
}
void QQmlData::NotifyList::layout()
@@ -2182,7 +2209,7 @@ QObject *QQmlEnginePrivate::toQObject(const QVariant &v, bool *ok) const
int t = v.userType();
if (t == QMetaType::QObjectStar || m_compositeTypes.contains(t)) {
if (ok) *ok = true;
- return *(QObject **)(v.constData());
+ return *(QObject *const *)(v.constData());
} else {
return QQmlMetaType::toQObject(v, ok);
}
diff --git a/src/qml/qml/qqmlextensionplugin.cpp b/src/qml/qml/qqmlextensionplugin.cpp
index 7b560268ba..d86fbc5999 100644
--- a/src/qml/qml/qqmlextensionplugin.cpp
+++ b/src/qml/qml/qqmlextensionplugin.cpp
@@ -44,71 +44,7 @@ QT_BEGIN_NAMESPACE
\ingroup plugins
- QQmlExtensionPlugin is a plugin interface that makes it possible to
- create QML extensions that can be loaded dynamically into QML applications.
- These extensions allow custom QML types to be made available to the QML engine.
-
- To write a QML extension plugin:
-
- \list
- \li Subclass QQmlExtensionPlugin, implement registerTypes() method to register types
- using qmlRegisterType(), and export the class using the Q_PLUGIN_METADATA() macro
- \li Write an appropriate project file for the plugin
- \li Create a \l{Module Definition qmldir Files}{qmldir file} to describe the plugin
- \endlist
-
- QML extension plugins can be used to provide either application-specific or
- library-like plugins. Library plugins should limit themselves to registering types,
- as any manipulation of the engine's root context may cause conflicts
- or other issues in the library user's code.
-
-
- \section1 An Example
-
- Suppose there is a new \c TimeModel C++ class that should be made available
- as a new QML element. It provides the current time through \c hour and \c minute
- properties, like this:
-
- \snippet qmlextensionplugins/plugin.cpp 0
- \dots
-
- To make this class available as a QML type, create a plugin that registers
- this type with a specific \l {QML Modules}{module} using qmlRegisterType(). For this example the plugin
- module will be named \c TimeExample (as defined in the project
- file further below).
-
- \snippet qmlextensionplugins/plugin.cpp plugin
-
- This registers the \c TimeModel class with the 1.0 version of this
- plugin library, as a QML type called \c Time. The Q_ASSERT statement
- ensures the module is imported correctly by any QML components that use this plugin.
-
- The project file defines the project as a plugin library and specifies
- it should be built into the \c imports/TimeExample directory:
-
- \code
- TEMPLATE = lib
- CONFIG += qt plugin
- QT += qml
-
- DESTDIR = imports/TimeExample
- TARGET = qmlqtimeexampleplugin
- ...
- \endcode
-
- Finally, a \l{Module Definition qmldir Files}{qmldir file} is required in the \c imports/TimeExample directory
- that describes the plugin. This directory includes a \c Clock.qml file that
- should be bundled with the plugin, so it needs to be specified in the \c qmldir
- file:
-
- \quotefile qmlextensionplugins/imports/TimeExample/qmldir
-
- Once the project is built and installed, the new \c Time element can be
- used by any QML component that imports the \c TimeExample module:
-
- \snippet qmlextensionplugins/plugins.qml 0
-
- The full source code is available in the \l {qmlextensionplugins}{plugins example}.
+ \include qqmlextensionplugin.qdocinc
The \l {Writing QML Extensions with C++} tutorial also contains a chapter
on creating QML plugins.
diff --git a/src/qml/qml/qqmlfileselector.cpp b/src/qml/qml/qqmlfileselector.cpp
index 3ee7bb3040..8597e8a5c7 100644
--- a/src/qml/qml/qqmlfileselector.cpp
+++ b/src/qml/qml/qqmlfileselector.cpp
@@ -102,6 +102,9 @@ QQmlFileSelector::QQmlFileSelector(QQmlEngine* engine, QObject* parent)
d->engine->setUrlInterceptor(d->myInstance.data());
}
+/*!
+ Destroys the QQmlFileSelector object.
+*/
QQmlFileSelector::~QQmlFileSelector()
{
Q_D(QQmlFileSelector);
diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp
index 0a2f4079c2..aa2b4b6aee 100644
--- a/src/qml/qml/qqmlglobal.cpp
+++ b/src/qml/qml/qqmlglobal.cpp
@@ -62,40 +62,11 @@ const QMetaObject *QQmlValueTypeProvider::metaObjectForMetaType(int type)
return 0;
}
-bool QQmlValueTypeProvider::initValueType(int type, void *data, size_t n)
+bool QQmlValueTypeProvider::initValueType(int type, QVariant& dst)
{
- Q_ASSERT(data);
-
- QQmlValueTypeProvider *p = this;
- do {
- if (p->init(type, data, n))
- return true;
- } while ((p = p->next));
-
- return false;
-}
-
-bool QQmlValueTypeProvider::destroyValueType(int type, void *data, size_t n)
-{
- Q_ASSERT(data);
-
QQmlValueTypeProvider *p = this;
do {
- if (p->destroy(type, data, n))
- return true;
- } while ((p = p->next));
-
- return false;
-}
-
-bool QQmlValueTypeProvider::copyValueType(int type, const void *src, void *dst, size_t n)
-{
- Q_ASSERT(src);
- Q_ASSERT(dst);
-
- QQmlValueTypeProvider *p = this;
- do {
- if (p->copy(type, src, dst, n))
+ if (p->init(type, dst))
return true;
} while ((p = p->next));
@@ -188,14 +159,13 @@ QVariant QQmlValueTypeProvider::createVariantFromJsObject(int type, QQmlV4Handle
return QVariant();
}
-bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const void *rhs, size_t rhsSize)
+bool QQmlValueTypeProvider::equalValueType(int type, const void *lhs, const QVariant& rhs)
{
Q_ASSERT(lhs);
- Q_ASSERT(rhs);
QQmlValueTypeProvider *p = this;
do {
- if (p->equal(type, lhs, rhs, rhsSize))
+ if (p->equal(type, lhs, rhs))
return true;
} while ((p = p->next));
@@ -216,28 +186,26 @@ bool QQmlValueTypeProvider::storeValueType(int type, const void *src, void *dst,
return false;
}
-bool QQmlValueTypeProvider::readValueType(int srcType, const void *src, size_t srcSize, int dstType, void *dst)
+bool QQmlValueTypeProvider::readValueType(const QVariant& src, void *dst, int dstType)
{
- Q_ASSERT(src);
Q_ASSERT(dst);
QQmlValueTypeProvider *p = this;
do {
- if (p->read(srcType, src, srcSize, dstType, dst))
+ if (p->read(src, dst, dstType))
return true;
} while ((p = p->next));
return false;
}
-bool QQmlValueTypeProvider::writeValueType(int type, const void *src, void *dst, size_t n)
+bool QQmlValueTypeProvider::writeValueType(int type, const void *src, QVariant& dst)
{
Q_ASSERT(src);
- Q_ASSERT(dst);
QQmlValueTypeProvider *p = this;
do {
- if (p->write(type, src, dst, n))
+ if (p->write(type, src, dst))
return true;
} while ((p = p->next));
@@ -245,19 +213,17 @@ bool QQmlValueTypeProvider::writeValueType(int type, const void *src, void *dst,
}
const QMetaObject *QQmlValueTypeProvider::getMetaObjectForMetaType(int) { return 0; }
-bool QQmlValueTypeProvider::init(int, void *, size_t) { return false; }
-bool QQmlValueTypeProvider::destroy(int, void *, size_t) { return false; }
-bool QQmlValueTypeProvider::copy(int, const void *, void *, size_t) { return false; }
+bool QQmlValueTypeProvider::init(int, QVariant&) { return false; }
bool QQmlValueTypeProvider::create(int, int, const void *[], QVariant *) { return false; }
bool QQmlValueTypeProvider::createFromString(int, const QString &, void *, size_t) { return false; }
bool QQmlValueTypeProvider::createStringFrom(int, const void *, QString *) { return false; }
bool QQmlValueTypeProvider::variantFromString(const QString &, QVariant *) { return false; }
bool QQmlValueTypeProvider::variantFromString(int, const QString &, QVariant *) { return false; }
bool QQmlValueTypeProvider::variantFromJsObject(int, QQmlV4Handle, QV4::ExecutionEngine *, QVariant *) { return false; }
-bool QQmlValueTypeProvider::equal(int, const void *, const void *, size_t) { return false; }
+bool QQmlValueTypeProvider::equal(int, const void *, const QVariant&) { return false; }
bool QQmlValueTypeProvider::store(int, const void *, void *, size_t) { return false; }
-bool QQmlValueTypeProvider::read(int, const void *, size_t, int, void *) { return false; }
-bool QQmlValueTypeProvider::write(int, const void *, void *, size_t) { return false; }
+bool QQmlValueTypeProvider::read(const QVariant&, void *, int) { return false; }
+bool QQmlValueTypeProvider::write(int, const void *, QVariant&) { return false; }
Q_GLOBAL_STATIC(QQmlValueTypeProvider, nullValueTypeProvider)
static QQmlValueTypeProvider *valueTypeProvider = 0;
diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h
index 7856d85376..d09ae21f56 100644
--- a/src/qml/qml/qqmlglobal_p.h
+++ b/src/qml/qml/qqmlglobal_p.h
@@ -224,9 +224,7 @@ public:
const QMetaObject *metaObjectForMetaType(int);
- bool initValueType(int, void *, size_t);
- bool destroyValueType(int, void *, size_t);
- bool copyValueType(int, const void *, void *, size_t);
+ bool initValueType(int, QVariant&);
QVariant createValueType(int, int, const void *[]);
bool createValueFromString(int, const QString &, void *, size_t);
@@ -236,16 +234,14 @@ public:
QVariant createVariantFromString(int, const QString &, bool *);
QVariant createVariantFromJsObject(int, QQmlV4Handle, QV4::ExecutionEngine *, bool*);
- bool equalValueType(int, const void *, const void *, size_t);
+ bool equalValueType(int, const void *, const QVariant&);
bool storeValueType(int, const void *, void *, size_t);
- bool readValueType(int, const void *, size_t, int, void *);
- bool writeValueType(int, const void *, void *, size_t);
+ bool readValueType(const QVariant&, void *, int);
+ bool writeValueType(int, const void *, QVariant&);
private:
virtual const QMetaObject *getMetaObjectForMetaType(int);
- virtual bool init(int, void *, size_t);
- virtual bool destroy(int, void *, size_t);
- virtual bool copy(int, const void *, void *, size_t);
+ virtual bool init(int, QVariant&);
virtual bool create(int, int, const void *[], QVariant *);
virtual bool createFromString(int, const QString &, void *, size_t);
@@ -255,10 +251,10 @@ private:
virtual bool variantFromString(int, const QString &, QVariant *);
virtual bool variantFromJsObject(int, QQmlV4Handle, QV4::ExecutionEngine *, QVariant *);
- virtual bool equal(int, const void *, const void *, size_t);
+ virtual bool equal(int, const void *, const QVariant&);
virtual bool store(int, const void *, void *, size_t);
- virtual bool read(int, const void *, size_t, int, void *);
- virtual bool write(int, const void *, void *, size_t);
+ virtual bool read(const QVariant&, void *, int);
+ virtual bool write(int, const void *, QVariant&);
friend Q_QML_PRIVATE_EXPORT void QQml_addValueTypeProvider(QQmlValueTypeProvider *);
friend Q_QML_PRIVATE_EXPORT void QQml_removeValueTypeProvider(QQmlValueTypeProvider *);
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index cf509a96ec..b17bb0455d 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -1653,7 +1653,7 @@ QString QQmlImportDatabase::resolvePlugin(QQmlTypeLoader *typeLoader,
\row \li Unix/Linux \li \c .so
\row \li AIX \li \c .a
\row \li HP-UX \li \c .sl, \c .so (HP-UXi)
- \row \li Mac OS X \li \c .dylib, \c .bundle, \c .so
+ \row \li OS X \li \c .dylib, \c .bundle, \c .so
\endtable
Version number on unix are ignored.
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index 5f30eac066..967a7e75d7 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -287,6 +287,50 @@ void QQmlPropertyCapture::captureProperty(QObject *o, int c, int n)
}
}
+void QQmlPropertyCapture::registerQmlDependencies(QV4::ExecutionEngine *engine, const QV4::CompiledData::Function *compiledFunction)
+{
+ // Let the caller check and avoid the function call :)
+ Q_ASSERT(compiledFunction->hasQmlDependencies());
+
+ QQmlEnginePrivate *ep = engine->qmlEngine() ? QQmlEnginePrivate::get(engine->qmlEngine()) : 0;
+ if (!ep)
+ return;
+ QQmlPropertyCapture *capture = ep->propertyCapture;
+ if (!capture)
+ return;
+
+ QV4::Scope scope(engine);
+ QV4::Scoped<QV4::QmlContext> context(scope, engine->qmlContext());
+ QQmlContextData *qmlContext = context->qmlContext();
+
+ const quint32 *idObjectDependency = compiledFunction->qmlIdObjectDependencyTable();
+ const int idObjectDependencyCount = compiledFunction->nDependingIdObjects;
+ for (int i = 0; i < idObjectDependencyCount; ++i, ++idObjectDependency) {
+ Q_ASSERT(int(*idObjectDependency) < qmlContext->idValueCount);
+ capture->captureProperty(&qmlContext->idValues[*idObjectDependency].bindings);
+ }
+
+ Q_ASSERT(qmlContext->contextObject);
+ const quint32 *contextPropertyDependency = compiledFunction->qmlContextPropertiesDependencyTable();
+ const int contextPropertyDependencyCount = compiledFunction->nDependingContextProperties;
+ for (int i = 0; i < contextPropertyDependencyCount; ++i) {
+ const int propertyIndex = *contextPropertyDependency++;
+ const int notifyIndex = *contextPropertyDependency++;
+ capture->captureProperty(qmlContext->contextObject, propertyIndex, notifyIndex);
+ }
+
+ QObject *scopeObject = context->qmlScope();
+ const quint32 *scopePropertyDependency = compiledFunction->qmlScopePropertiesDependencyTable();
+ const int scopePropertyDependencyCount = compiledFunction->nDependingScopeProperties;
+ for (int i = 0; i < scopePropertyDependencyCount; ++i) {
+ const int propertyIndex = *scopePropertyDependency++;
+ const int notifyIndex = *scopePropertyDependency++;
+ capture->captureProperty(scopeObject, propertyIndex, notifyIndex);
+ }
+
+}
+
+
void QQmlJavaScriptExpression::clearError()
{
if (m_error)
diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h
index dfcf8b2d68..f0a3741588 100644
--- a/src/qml/qml/qqmljavascriptexpression_p.h
+++ b/src/qml/qml/qqmljavascriptexpression_p.h
@@ -176,6 +176,8 @@ public:
void captureProperty(QQmlNotifier *);
void captureProperty(QObject *, int, int);
+ static void registerQmlDependencies(QV4::ExecutionEngine *engine, const QV4::CompiledData::Function *compiledFunction);
+
QQmlEngine *engine;
QQmlJavaScriptExpression *expression;
QQmlJavaScriptExpression::DeleteWatcher *watcher;
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 41629801ea..fbb21f4562 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -225,6 +225,9 @@ void QQmlType::SingletonInstanceInfo::init(QQmlEngine *e)
v4->pushGlobalContext();
QObject *o = qobjectCallback(e, e);
setQObjectApi(e, o);
+ if (!o) {
+ qFatal("qmlRegisterSingletonType(): \"%s\" is not available because the callback function returns a null pointer.", qPrintable(typeName));
+ }
// if this object can use a property cache, create it now
QQmlData::ensurePropertyCache(e, o);
v4->popContext();
@@ -1510,7 +1513,7 @@ QObject *QQmlMetaType::toQObject(const QVariant &v, bool *ok)
if (ok) *ok = true;
- return *(QObject **)v.constData();
+ return *(QObject *const *)v.constData();
}
bool QQmlMetaType::isQObject(int userType)
diff --git a/src/qml/qml/qqmlnotifier.cpp b/src/qml/qml/qqmlnotifier.cpp
index 4ce5be4d1a..ea3f7a1530 100644
--- a/src/qml/qml/qqmlnotifier.cpp
+++ b/src/qml/qml/qqmlnotifier.cpp
@@ -51,30 +51,52 @@ static Callback QQmlNotifier_callbacks[] = {
QQmlVMEMetaObjectEndpoint_callback
};
+namespace {
+ struct NotifyListTraversalData {
+ NotifyListTraversalData(QQmlNotifierEndpoint *ep = 0)
+ : originalSenderPtr(0)
+ , disconnectWatch(0)
+ , endpoint(ep)
+ {}
+
+ qintptr originalSenderPtr;
+ qintptr *disconnectWatch;
+ QQmlNotifierEndpoint *endpoint;
+ };
+}
+
void QQmlNotifier::emitNotify(QQmlNotifierEndpoint *endpoint, void **a)
{
- qintptr originalSenderPtr;
- qintptr *disconnectWatch;
-
- if (!endpoint->isNotifying()) {
- originalSenderPtr = endpoint->senderPtr;
- disconnectWatch = &originalSenderPtr;
- endpoint->senderPtr = qintptr(disconnectWatch) | 0x1;
- } else {
- disconnectWatch = (qintptr *)(endpoint->senderPtr & ~0x1);
+ QVarLengthArray<NotifyListTraversalData> stack;
+ while (endpoint) {
+ stack.append(NotifyListTraversalData(endpoint));
+ endpoint = endpoint->next;
}
- if (endpoint->next)
- emitNotify(endpoint->next, a);
+ int i = 0;
+ for (; i < stack.size(); ++i) {
+ NotifyListTraversalData &data = stack[i];
+
+ if (!data.endpoint->isNotifying()) {
+ data.originalSenderPtr = data.endpoint->senderPtr;
+ data.disconnectWatch = &data.originalSenderPtr;
+ data.endpoint->senderPtr = qintptr(data.disconnectWatch) | 0x1;
+ } else {
+ data.disconnectWatch = (qintptr *)(data.endpoint->senderPtr & ~0x1);
+ }
+ }
- if (*disconnectWatch) {
+ while (--i >= 0) {
+ const NotifyListTraversalData &data = stack.at(i);
+ if (*data.disconnectWatch) {
- Q_ASSERT(QQmlNotifier_callbacks[endpoint->callback]);
- QQmlNotifier_callbacks[endpoint->callback](endpoint, a);
+ Q_ASSERT(QQmlNotifier_callbacks[data.endpoint->callback]);
+ QQmlNotifier_callbacks[data.endpoint->callback](data.endpoint, a);
- if (disconnectWatch == &originalSenderPtr && originalSenderPtr) {
- // End of notifying, restore values
- endpoint->senderPtr = originalSenderPtr;
+ if (data.disconnectWatch == &data.originalSenderPtr && data.originalSenderPtr) {
+ // End of notifying, restore values
+ data.endpoint->senderPtr = data.originalSenderPtr;
+ }
}
}
}
diff --git a/src/qml/qml/qqmlnotifier_p.h b/src/qml/qml/qqmlnotifier_p.h
index bd2c0e6506..90902c089d 100644
--- a/src/qml/qml/qqmlnotifier_p.h
+++ b/src/qml/qml/qqmlnotifier_p.h
@@ -60,6 +60,8 @@ private:
class QQmlEngine;
class QQmlNotifierEndpoint
{
+ QQmlNotifierEndpoint *next;
+ QQmlNotifierEndpoint **prev;
public:
// QQmlNotifierEndpoint can only invoke one of a set of pre-defined callbacks.
// To add another callback, extend this enum and add the callback to the top
@@ -103,9 +105,6 @@ private:
// The index is in the range returned by QObjectPrivate::signalIndex().
// This is different from QMetaMethod::methodIndex().
signed int sourceSignal:28;
-
- QQmlNotifierEndpoint *next;
- QQmlNotifierEndpoint **prev;
};
QQmlNotifier::QQmlNotifier()
@@ -137,7 +136,7 @@ void QQmlNotifier::notify()
}
QQmlNotifierEndpoint::QQmlNotifierEndpoint(Callback callback)
-: senderPtr(0), callback(callback), sourceSignal(-1), next(0), prev(0)
+: next(0), prev(0), senderPtr(0), callback(callback), sourceSignal(-1)
{
}
diff --git a/src/qml/qml/qqmlopenmetaobject.cpp b/src/qml/qml/qqmlopenmetaobject.cpp
index c6d2d44ee1..16138508dd 100644
--- a/src/qml/qml/qqmlopenmetaobject.cpp
+++ b/src/qml/qml/qqmlopenmetaobject.cpp
@@ -35,6 +35,7 @@
#include <private/qqmlpropertycache_p.h>
#include <private/qqmldata_p.h>
#include <private/qmetaobjectbuilder_p.h>
+#include <private/qv8engine_p.h>
#include <qqmlengine.h>
#include <qdebug.h>
@@ -106,6 +107,28 @@ QMetaObject *QQmlOpenMetaObjectType::metaObject() const
return d->mem;
}
+void QQmlOpenMetaObjectType::createProperties(const QVector<QByteArray> &names)
+{
+ for (int i = 0; i < names.count(); ++i) {
+ const QByteArray &name = names.at(i);
+ const int id = d->mob.propertyCount();
+ d->mob.addSignal("__" + QByteArray::number(id) + "()");
+ QMetaPropertyBuilder build = d->mob.addProperty(name, "QVariant", id);
+ propertyCreated(id, build);
+ d->names.insert(name, id);
+ }
+ free(d->mem);
+ d->mem = d->mob.toMetaObject();
+ QSet<QQmlOpenMetaObject*>::iterator it = d->referers.begin();
+ while (it != d->referers.end()) {
+ QQmlOpenMetaObject *omo = *it;
+ *static_cast<QMetaObject *>(omo) = *d->mem;
+ if (d->cache)
+ d->cache->update(omo);
+ ++it;
+ }
+}
+
int QQmlOpenMetaObjectType::createProperty(const QByteArray &name)
{
int id = d->mob.propertyCount();
@@ -230,6 +253,14 @@ QQmlOpenMetaObjectType *QQmlOpenMetaObject::type() const
return d->type;
}
+void QQmlOpenMetaObject::emitPropertyNotification(const QByteArray &propertyName)
+{
+ QHash<QByteArray, int>::ConstIterator iter = d->type->d->names.constFind(propertyName);
+ if (iter == d->type->d->names.constEnd())
+ return;
+ activate(d->object, *iter + d->type->d->signalOffset, 0);
+}
+
int QQmlOpenMetaObject::metaCall(QMetaObject::Call c, int id, void **a)
{
if (( c == QMetaObject::ReadProperty || c == QMetaObject::WriteProperty)
@@ -337,7 +368,7 @@ void QQmlOpenMetaObject::setCached(bool c)
QQmlData *qmldata = QQmlData::get(d->object, true);
if (d->cacheProperties) {
if (!d->type->d->cache)
- d->type->d->cache = new QQmlPropertyCache(d->type->d->engine, this);
+ d->type->d->cache = new QQmlPropertyCache(QV8Engine::getV4(d->type->d->engine), this);
qmldata->propertyCache = d->type->d->cache;
d->type->d->cache->addref();
} else {
diff --git a/src/qml/qml/qqmlopenmetaobject_p.h b/src/qml/qml/qqmlopenmetaobject_p.h
index 6a29d08d4e..75ce9addd6 100644
--- a/src/qml/qml/qqmlopenmetaobject_p.h
+++ b/src/qml/qml/qqmlopenmetaobject_p.h
@@ -54,6 +54,7 @@ public:
QQmlOpenMetaObjectType(const QMetaObject *base, QQmlEngine *engine);
~QQmlOpenMetaObjectType();
+ void createProperties(const QVector<QByteArray> &names);
int createProperty(const QByteArray &name);
int propertyOffset() const;
@@ -101,6 +102,8 @@ public:
QQmlOpenMetaObjectType *type() const;
+ void emitPropertyNotification(const QByteArray &propertyName);
+
protected:
virtual int metaCall(QMetaObject::Call _c, int _id, void **_a);
virtual int createProperty(const char *, const char *);
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 414bf8fe0f..c1120b4542 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1240,12 +1240,12 @@ bool QQmlPropertyPrivate::write(QObject *object,
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, argv);
} else if (variantType == propertyType) {
- void *a[] = { (void *)value.constData(), 0, &status, &flags };
+ void *a[] = { const_cast<void *>(value.constData()), 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);
} else if (qMetaTypeId<QVariant>() == propertyType) {
- void *a[] = { (void *)&value, 0, &status, &flags };
+ void *a[] = { const_cast<QVariant *>(&value), 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);
} else if (property.isQObject()) {
@@ -1255,7 +1255,7 @@ bool QQmlPropertyPrivate::write(QObject *object,
if (valMo.isNull())
return false;
- QObject *o = *(QObject **)value.constData();
+ QObject *o = *(QObject *const *)value.constData();
QQmlMetaObject propMo = rawMetaObjectForType(enginePriv, propertyType);
if (o) valMo = o;
@@ -1401,7 +1401,7 @@ bool QQmlPropertyPrivate::write(QObject *object,
}
if (ok) {
- void *a[] = { (void *)v.constData(), 0, &status, &flags};
+ void *a[] = { const_cast<void *>(v.constData()), 0, &status, &flags};
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a);
} else {
return false;
@@ -1411,7 +1411,6 @@ bool QQmlPropertyPrivate::write(QObject *object,
return true;
}
-
QQmlMetaObject QQmlPropertyPrivate::rawMetaObjectForType(QQmlEnginePrivate *engine, int userType)
{
QMetaType metaType(userType);
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index 294f3ccdf9..9a935ed55f 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -231,10 +231,10 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
/*!
Creates a new empty QQmlPropertyCache.
*/
-QQmlPropertyCache::QQmlPropertyCache(QJSEngine *e)
-: engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
- signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false),
- _metaObject(0), argumentsCache(0)
+QQmlPropertyCache::QQmlPropertyCache(QV4::ExecutionEngine *e)
+ : engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
+ signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false),
+ _metaObject(0), argumentsCache(0)
{
Q_ASSERT(engine);
}
@@ -242,10 +242,10 @@ QQmlPropertyCache::QQmlPropertyCache(QJSEngine *e)
/*!
Creates a new QQmlPropertyCache of \a metaObject.
*/
-QQmlPropertyCache::QQmlPropertyCache(QJSEngine *e, const QMetaObject *metaObject)
-: engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
- signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false),
- _metaObject(0), argumentsCache(0)
+QQmlPropertyCache::QQmlPropertyCache(QV4::ExecutionEngine *e, const QMetaObject *metaObject)
+ : engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0),
+ signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false),
+ _metaObject(0), argumentsCache(0)
{
Q_ASSERT(engine);
Q_ASSERT(metaObject);
@@ -271,7 +271,7 @@ QQmlPropertyCache::~QQmlPropertyCache()
stringCache.clear();
if (_parent) _parent->release();
- if (_ownMetaObject) free((void *)_metaObject);
+ if (_ownMetaObject) free(const_cast<QMetaObject *>(_metaObject));
_metaObject = 0;
_parent = 0;
engine = 0;
@@ -818,7 +818,7 @@ void QQmlPropertyCache::resolve(QQmlPropertyData *data) const
data->propType = registerResult == -1 ? QMetaType::UnknownType : registerResult;
}
}
- data->flags |= flagsForPropertyType(data->propType, qobject_cast<QQmlEngine*>(engine));
+ data->flags |= flagsForPropertyType(data->propType, engine->qmlEngine());
}
data->flags &= ~QQmlPropertyData::NotFullyResolved;
@@ -1134,7 +1134,7 @@ QString QQmlPropertyCache::signalParameterStringForJS(int index, QString *errorS
}
QString error;
- QString parameters = signalParameterStringForJS(QV8Engine::getV4(engine), parameterNameList, &error);
+ QString parameters = signalParameterStringForJS(engine, parameterNameList, &error);
A *arguments = static_cast<A *>(signalData->arguments);
arguments->signalParameterStringForJS = new QString(!error.isEmpty() ? error : parameters);
diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h
index 4d8c6dd9a5..2ee399c496 100644
--- a/src/qml/qml/qqmlpropertycache_p.h
+++ b/src/qml/qml/qqmlpropertycache_p.h
@@ -243,8 +243,8 @@ class QQmlPropertyCacheMethodArguments;
class Q_QML_PRIVATE_EXPORT QQmlPropertyCache : public QQmlRefCount, public QQmlCleanup
{
public:
- QQmlPropertyCache(QJSEngine *);
- QQmlPropertyCache(QJSEngine *, const QMetaObject *);
+ QQmlPropertyCache(QV4::ExecutionEngine *);
+ QQmlPropertyCache(QV4::ExecutionEngine *, const QMetaObject *);
virtual ~QQmlPropertyCache();
void update(const QMetaObject *);
@@ -377,8 +377,10 @@ private:
_hasPropertyOverrides |= isOverride;
}
- QJSEngine *engine;
+public:
+ QV4::ExecutionEngine *engine;
+private:
QQmlPropertyCache *_parent;
int propertyIndexCacheStart;
int methodIndexCacheStart;
diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp
index 7ebfcd64b7..6a71a07e9b 100644
--- a/src/qml/qml/qqmlvaluetype.cpp
+++ b/src/qml/qml/qqmlvaluetype.cpp
@@ -202,7 +202,7 @@ QQmlValueType::~QQmlValueType()
QObjectPrivate *op = QObjectPrivate::get(this);
Q_ASSERT(op->metaObject == this);
op->metaObject = 0;
- ::free((void*)_metaObject);
+ ::free(const_cast<QMetaObject *>(_metaObject));
metaType.destroy(gadgetPtr);
}
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index 08b1e09d76..0ffeddbabc 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 BasysKom GmbH.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
@@ -51,8 +52,8 @@
QT_BEGIN_NAMESPACE
-QQmlVMEVariantQObjectPtr::QQmlVMEVariantQObjectPtr(bool isVar)
- : QQmlGuard<QObject>(0), m_target(0), m_isVar(isVar), m_index(-1)
+QQmlVMEVariantQObjectPtr::QQmlVMEVariantQObjectPtr()
+ : QQmlGuard<QObject>(0), m_target(0), m_index(-1)
{
}
@@ -63,14 +64,12 @@ QQmlVMEVariantQObjectPtr::~QQmlVMEVariantQObjectPtr()
void QQmlVMEVariantQObjectPtr::objectDestroyed(QObject *)
{
if (m_target && m_index >= 0) {
- if (m_isVar && m_target->varPropertiesInitialized && !m_target->varProperties.isUndefined()) {
- // Set the var property to NULL
- QV4::ExecutionEngine *v4 = m_target->varProperties.engine();
+ if (m_target->propertiesInitialized && !m_target->properties.isUndefined()) {
+ QV4::ExecutionEngine *v4 = m_target->cache->engine;
if (v4) {
QV4::Scope scope(v4);
- QV4::ScopedArrayObject a(scope, m_target->varProperties.value());
- if (a)
- a->putIndexed(m_index - m_target->firstVarPropertyIndex, QV4::ScopedValue(scope, QV4::Primitive::nullValue()));
+ QV4::Scoped<QV4::MemberData> sp(scope, m_target->properties.value());
+ *(sp->data() + m_index) = QV4::Primitive::nullValue();
}
}
@@ -86,505 +85,382 @@ void QQmlVMEVariantQObjectPtr::setGuardedValue(QObject *obj, QQmlVMEMetaObject *
setObject(obj);
}
-class QQmlVMEVariant
-{
-public:
- inline QQmlVMEVariant();
- inline ~QQmlVMEVariant();
-
- inline const void *dataPtr() const;
- inline void *dataPtr();
- inline int dataType() const;
- inline size_t dataSize() const;
-
- inline QObject *asQObject();
- inline const QVariant &asQVariant();
- inline int asInt();
- inline bool asBool();
- inline double asDouble();
- inline const QString &asQString();
- inline const QUrl &asQUrl();
- inline const QDate &asQDate();
- inline const QDateTime &asQDateTime();
- inline const QRectF &asQRectF();
- inline const QPointF &asQPointF();
- inline const QSizeF &asQSizeF();
-
- inline void setValue(QObject *v, QQmlVMEMetaObject *target, int index);
- inline void setValue(const QVariant &);
- inline void setValue(int);
- inline void setValue(bool);
- inline void setValue(double);
- inline void setValue(const QString &);
- inline void setValue(const QUrl &);
- inline void setValue(const QTime &);
- inline void setValue(const QDate &);
- inline void setValue(const QDateTime &);
- inline void setValue(const QRectF &);
- inline void setValue(const QPointF &);
- inline void setValue(const QSizeF &);
-
- inline void ensureValueType(int);
-
-private:
- int type;
- void *data[8]; // Large enough to hold all types
-
- inline void cleanup();
-};
-
class QQmlVMEMetaObjectEndpoint : public QQmlNotifierEndpoint
{
public:
QQmlVMEMetaObjectEndpoint();
- static void vmecallback(QQmlNotifierEndpoint *, void **);
void tryConnect();
QFlagPointer<QQmlVMEMetaObject> metaObject;
};
-
-QQmlVMEVariant::QQmlVMEVariant()
-: type(QVariant::Invalid)
+QQmlVMEMetaObjectEndpoint::QQmlVMEMetaObjectEndpoint()
+ : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlVMEMetaObjectEndpoint)
{
}
-QQmlVMEVariant::~QQmlVMEVariant()
+void QQmlVMEMetaObjectEndpoint_callback(QQmlNotifierEndpoint *e, void **)
{
- cleanup();
+ QQmlVMEMetaObjectEndpoint *vmee = static_cast<QQmlVMEMetaObjectEndpoint*>(e);
+ vmee->tryConnect();
}
-void QQmlVMEVariant::cleanup()
+void QQmlVMEMetaObjectEndpoint::tryConnect()
{
- if (type == QVariant::Invalid) {
- } else if (type == QMetaType::Int ||
- type == QMetaType::Bool ||
- type == QMetaType::Double) {
- type = QVariant::Invalid;
- } else if (type == QMetaType::QObjectStar) {
- ((QQmlVMEVariantQObjectPtr*)dataPtr())->~QQmlVMEVariantQObjectPtr();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QString) {
- ((QString *)dataPtr())->~QString();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QUrl) {
- ((QUrl *)dataPtr())->~QUrl();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QTime) {
- ((QTime *)dataPtr())->~QTime();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QDate) {
- ((QDate *)dataPtr())->~QDate();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QDateTime) {
- ((QDateTime *)dataPtr())->~QDateTime();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QRectF) {
- ((QRectF *)dataPtr())->~QRectF();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QPointF) {
- ((QPointF *)dataPtr())->~QPointF();
- type = QVariant::Invalid;
- } else if (type == QMetaType::QSizeF) {
- ((QSizeF *)dataPtr())->~QSizeF();
- type = QVariant::Invalid;
- } else if (type == qMetaTypeId<QVariant>()) {
- ((QVariant *)dataPtr())->~QVariant();
- type = QVariant::Invalid;
+ int aliasId = this - metaObject->aliasEndpoints;
+
+ if (metaObject.flag()) {
+ // This is actually notify
+ int sigIdx = metaObject->methodOffset() + aliasId + metaObject->metaData->propertyCount;
+ metaObject->activate(metaObject->object, sigIdx, 0);
} else {
- if (QQml_valueTypeProvider()->destroyValueType(type, dataPtr(), dataSize())) {
- type = QVariant::Invalid;
+ QQmlVMEMetaData::AliasData *d = metaObject->metaData->aliasData() + aliasId;
+ if (!d->isObjectAlias()) {
+ QQmlContextData *ctxt = metaObject->ctxt;
+ QObject *target = ctxt->idValues[d->contextIdx].data();
+ if (!target)
+ return;
+
+ if (d->notifySignal != -1)
+ connect(target, d->notifySignal, ctxt->engine);
}
+
+ metaObject.setFlag();
}
}
-int QQmlVMEVariant::dataType() const
+QAbstractDynamicMetaObject *QQmlVMEMetaObject::toDynamicMetaObject(QObject *o)
{
- return type;
-}
+ if (!hasAssignedMetaObjectData) {
+ *static_cast<QMetaObject *>(this) = *cache->createMetaObject();
-const void *QQmlVMEVariant::dataPtr() const
-{
- return &data;
-}
+ if (parent.isT1())
+ this->d.superdata = parent.asT1()->toDynamicMetaObject(o);
+ else
+ this->d.superdata = parent.asT2();
-void *QQmlVMEVariant::dataPtr()
-{
- return &data;
-}
+ hasAssignedMetaObjectData = true;
+ }
-size_t QQmlVMEVariant::dataSize() const
-{
- return sizeof(data);
+ return this;
}
-QObject *QQmlVMEVariant::asQObject()
+QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj,
+ QQmlPropertyCache *cache,
+ const QQmlVMEMetaData *meta, QV4::ExecutionContext *qmlBindingContext, QQmlCompiledData *compiledData)
+: object(obj),
+ ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta),
+ hasAssignedMetaObjectData(false), aliasEndpoints(0),
+ propertiesInitialized(false), interceptors(0), methods(0)
{
- if (type != QMetaType::QObjectStar)
- setValue((QObject *)0, 0, -1);
-
- return *(QQmlGuard<QObject> *)(dataPtr());
-}
+ QObjectPrivate *op = QObjectPrivate::get(obj);
-const QVariant &QQmlVMEVariant::asQVariant()
-{
- if (type != QMetaType::QVariant)
- setValue(QVariant());
+ if (op->metaObject) {
+ parent = op->metaObject;
+ // Use the extra flag in QBiPointer to know if we can safely cast parent.asT1() to QQmlVMEMetaObject*
+ parent.setFlagValue(QQmlData::get(obj)->hasVMEMetaObject);
+ } else
+ parent = obj->metaObject();
- return *(QVariant *)(dataPtr());
-}
+ op->metaObject = this;
+ QQmlData::get(obj)->hasVMEMetaObject = true;
-int QQmlVMEVariant::asInt()
-{
- if (type != QMetaType::Int)
- setValue(int(0));
+ aConnected.resize(metaData->aliasCount);
+ int list_type = qMetaTypeId<QQmlListProperty<QObject> >();
+ int qobject_type = qMetaTypeId<QObject*>();
+ int variant_type = qMetaTypeId<QVariant>();
+ // Need JS wrapper to ensure properties are marked.
+ // ### FIXME: I hope that this can be removed once we have the proper scope chain
+ // set up and the JS wrappers always exist.
+ bool needsJSWrapper = (metaData->propertyCount > 0);
- return *(int *)(dataPtr());
-}
+ // ### Optimize
+ for (int ii = 0; ii < metaData->propertyCount; ++ii) {
+ int t = (metaData->propertyData() + ii)->propertyType;
+ if (t == list_type) {
+ listProperties.append(List(methodOffset() + ii, this));
+ writeProperty(ii, listProperties.count() - 1);
+ } else if (!needsJSWrapper && (t == qobject_type || t == variant_type)) {
+ needsJSWrapper = true;
+ }
+ }
-bool QQmlVMEVariant::asBool()
-{
- if (type != QMetaType::Bool)
- setValue(bool(false));
+ if (needsJSWrapper)
+ ensureQObjectWrapper();
- return *(bool *)(dataPtr());
-}
+ if (qmlBindingContext && metaData->methodCount) {
+ methods = new QV4::PersistentValue[metaData->methodCount];
-double QQmlVMEVariant::asDouble()
-{
- if (type != QMetaType::Double)
- setValue(double(0));
+ QV4::CompiledData::CompilationUnit *compilationUnit = compiledData->compilationUnit;
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedObject o(scope);
+ for (int index = 0; index < metaData->methodCount; ++index) {
+ QQmlVMEMetaData::MethodData *data = metaData->methodData() + index;
- return *(double *)(dataPtr());
+ QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[data->runtimeFunctionIndex];
+ o = QV4::FunctionObject::createScriptFunction(qmlBindingContext, runtimeFunction);
+ methods[index].set(qmlBindingContext->engine(), o);
+ }
+ }
}
-const QString &QQmlVMEVariant::asQString()
+QQmlVMEMetaObject::~QQmlVMEMetaObject()
{
- if (type != QMetaType::QString)
- setValue(QString());
+ if (parent.isT1()) parent.asT1()->objectDestroyed(object);
+ delete [] aliasEndpoints;
+ delete [] methods;
- return *(QString *)(dataPtr());
+ qDeleteAll(varObjectGuards);
}
-const QUrl &QQmlVMEVariant::asQUrl()
+QV4::MemberData *QQmlVMEMetaObject::propertiesAsMemberData()
{
- if (type != QMetaType::QUrl)
- setValue(QUrl());
+ if (!ensurePropertiesAllocated())
+ return 0;
- return *(QUrl *)(dataPtr());
+ return static_cast<QV4::MemberData*>(properties.asManaged());
}
-const QDate &QQmlVMEVariant::asQDate()
+void QQmlVMEMetaObject::writeProperty(int id, int v)
{
- if (type != QMetaType::QDate)
- setValue(QDate());
-
- return *(QDate *)(dataPtr());
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = QV4::Primitive::fromInt32(v);
}
-const QDateTime &QQmlVMEVariant::asQDateTime()
+void QQmlVMEMetaObject::writeProperty(int id, bool v)
{
- if (type != QMetaType::QDateTime)
- setValue(QDateTime());
-
- return *(QDateTime *)(dataPtr());
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = QV4::Primitive::fromBoolean(v);
}
-const QRectF &QQmlVMEVariant::asQRectF()
+void QQmlVMEMetaObject::writeProperty(int id, double v)
{
- if (type != QMetaType::QRectF)
- setValue(QRectF());
-
- return *(QRectF *)(dataPtr());
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = QV4::Primitive::fromDouble(v);
}
-const QSizeF &QQmlVMEVariant::asQSizeF()
+void QQmlVMEMetaObject::writeProperty(int id, const QString& v)
{
- if (type != QMetaType::QSizeF)
- setValue(QSizeF());
-
- return *(QSizeF *)(dataPtr());
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = cache->engine->newString(v);
}
-const QPointF &QQmlVMEVariant::asQPointF()
+void QQmlVMEMetaObject::writeProperty(int id, const QUrl& v)
{
- if (type != QMetaType::QPointF)
- setValue(QPointF());
-
- return *(QPointF *)(dataPtr());
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v));
}
-void QQmlVMEVariant::setValue(QObject *v, QQmlVMEMetaObject *target, int index)
+void QQmlVMEMetaObject::writeProperty(int id, const QDate& v)
{
- if (type != QMetaType::QObjectStar) {
- cleanup();
- type = QMetaType::QObjectStar;
- new (dataPtr()) QQmlVMEVariantQObjectPtr(false);
- }
- reinterpret_cast<QQmlVMEVariantQObjectPtr*>(dataPtr())->setGuardedValue(v, target, index);
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v));
}
-void QQmlVMEVariant::setValue(const QVariant &v)
+void QQmlVMEMetaObject::writeProperty(int id, const QDateTime& v)
{
- if (type != qMetaTypeId<QVariant>()) {
- cleanup();
- type = qMetaTypeId<QVariant>();
- new (dataPtr()) QVariant(v);
- } else {
- *(QVariant *)(dataPtr()) = v;
- }
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v));
}
-void QQmlVMEVariant::setValue(int v)
+void QQmlVMEMetaObject::writeProperty(int id, const QPointF& v)
{
- if (type != QMetaType::Int) {
- cleanup();
- type = QMetaType::Int;
- }
- *(int *)(dataPtr()) = v;
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v));
}
-void QQmlVMEVariant::setValue(bool v)
+void QQmlVMEMetaObject::writeProperty(int id, const QSizeF& v)
{
- if (type != QMetaType::Bool) {
- cleanup();
- type = QMetaType::Bool;
- }
- *(bool *)(dataPtr()) = v;
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v));
}
-void QQmlVMEVariant::setValue(double v)
+void QQmlVMEMetaObject::writeProperty(int id, const QRectF& v)
{
- if (type != QMetaType::Double) {
- cleanup();
- type = QMetaType::Double;
- }
- *(double *)(dataPtr()) = v;
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = cache->engine->newVariantObject(QVariant::fromValue(v));
}
-void QQmlVMEVariant::setValue(const QString &v)
+void QQmlVMEMetaObject::writeProperty(int id, QObject* v)
{
- if (type != QMetaType::QString) {
- cleanup();
- type = QMetaType::QString;
- new (dataPtr()) QString(v);
- } else {
- *(QString *)(dataPtr()) = v;
- }
-}
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ *(md->data() + id) = QV4::QObjectWrapper::wrap(cache->engine, v);
-void QQmlVMEVariant::setValue(const QUrl &v)
-{
- if (type != QMetaType::QUrl) {
- cleanup();
- type = QMetaType::QUrl;
- new (dataPtr()) QUrl(v);
- } else {
- *(QUrl *)(dataPtr()) = v;
+ QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id);
+ if (v && !guard) {
+ guard = new QQmlVMEVariantQObjectPtr();
+ varObjectGuards.append(guard);
}
+ if (guard)
+ guard->setGuardedValue(v, this, id);
}
-void QQmlVMEVariant::setValue(const QTime &v)
+int QQmlVMEMetaObject::readPropertyAsInt(int id)
{
- if (type != QMetaType::QTime) {
- cleanup();
- type = QMetaType::QTime;
- new (dataPtr()) QTime(v);
- } else {
- *(QTime *)(dataPtr()) = v;
- }
-}
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return 0;
-void QQmlVMEVariant::setValue(const QDate &v)
-{
- if (type != QMetaType::QDate) {
- cleanup();
- type = QMetaType::QDate;
- new (dataPtr()) QDate(v);
- } else {
- *(QDate *)(dataPtr()) = v;
- }
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ if (!sv->isInt32())
+ return 0;
+ return sv->integerValue();
}
-void QQmlVMEVariant::setValue(const QDateTime &v)
+bool QQmlVMEMetaObject::readPropertyAsBool(int id)
{
- if (type != QMetaType::QDateTime) {
- cleanup();
- type = QMetaType::QDateTime;
- new (dataPtr()) QDateTime(v);
- } else {
- *(QDateTime *)(dataPtr()) = v;
- }
-}
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return false;
-void QQmlVMEVariant::setValue(const QRectF &v)
-{
- if (type != QMetaType::QRectF) {
- cleanup();
- type = QMetaType::QRectF;
- new (dataPtr()) QRectF(v);
- } else {
- *(QRectF *)(dataPtr()) = v;
- }
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ if (!sv->isBoolean())
+ return false;
+ return sv->booleanValue();
}
-void QQmlVMEVariant::setValue(const QPointF &v)
+double QQmlVMEMetaObject::readPropertyAsDouble(int id)
{
- if (type != QMetaType::QPointF) {
- cleanup();
- type = QMetaType::QPointF;
- new (dataPtr()) QPointF(v);
- } else {
- *(QPointF *)(dataPtr()) = v;
- }
-}
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return 0.0;
-void QQmlVMEVariant::setValue(const QSizeF &v)
-{
- if (type != QMetaType::QSizeF) {
- cleanup();
- type = QMetaType::QSizeF;
- new (dataPtr()) QSizeF(v);
- } else {
- *(QSizeF *)(dataPtr()) = v;
- }
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ if (!sv->isDouble())
+ return 0.0;
+ return sv->doubleValue();
}
-void QQmlVMEVariant::ensureValueType(int t)
+QString QQmlVMEMetaObject::readPropertyAsString(int id)
{
- if (type != t) {
- cleanup();
- type = t;
- QQml_valueTypeProvider()->initValueType(t, dataPtr(), dataSize());
- }
-}
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return QString();
-QQmlVMEMetaObjectEndpoint::QQmlVMEMetaObjectEndpoint()
- : QQmlNotifierEndpoint(QQmlNotifierEndpoint::QQmlVMEMetaObjectEndpoint)
-{
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ if (!sv->isString())
+ return QString();
+ return sv->stringValue()->toQString();
}
-void QQmlVMEMetaObjectEndpoint_callback(QQmlNotifierEndpoint *e, void **)
+QUrl QQmlVMEMetaObject::readPropertyAsUrl(int id)
{
- QQmlVMEMetaObjectEndpoint *vmee = static_cast<QQmlVMEMetaObjectEndpoint*>(e);
- vmee->tryConnect();
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return QUrl();
+
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::Url)
+ return QUrl();
+ return v->d()->data.value<QUrl>();
}
-void QQmlVMEMetaObjectEndpoint::tryConnect()
+QDate QQmlVMEMetaObject::readPropertyAsDate(int id)
{
- int aliasId = this - metaObject->aliasEndpoints;
-
- if (metaObject.flag()) {
- // This is actually notify
- int sigIdx = metaObject->methodOffset() + aliasId + metaObject->metaData->propertyCount;
- metaObject->activate(metaObject->object, sigIdx, 0);
- } else {
- QQmlVMEMetaData::AliasData *d = metaObject->metaData->aliasData() + aliasId;
- if (!d->isObjectAlias()) {
- QQmlContextData *ctxt = metaObject->ctxt;
- QObject *target = ctxt->idValues[d->contextIdx].data();
- if (!target)
- return;
-
- if (d->notifySignal != -1)
- connect(target, d->notifySignal, ctxt->engine);
- }
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return QDate();
- metaObject.setFlag();
- }
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::Date)
+ return QDate();
+ return v->d()->data.value<QDate>();
}
-QAbstractDynamicMetaObject *QQmlVMEMetaObject::toDynamicMetaObject(QObject *o)
+QDateTime QQmlVMEMetaObject::readPropertyAsDateTime(int id)
{
- if (!hasAssignedMetaObjectData) {
- *static_cast<QMetaObject *>(this) = *cache->createMetaObject();
-
- if (parent.isT1())
- this->d.superdata = parent.asT1()->toDynamicMetaObject(o);
- else
- this->d.superdata = parent.asT2();
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return QDateTime();
- hasAssignedMetaObjectData = true;
- }
-
- return this;
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::DateTime)
+ return QDateTime();
+ return v->d()->data.value<QDateTime>();
}
-QQmlVMEMetaObject::QQmlVMEMetaObject(QObject *obj,
- QQmlPropertyCache *cache,
- const QQmlVMEMetaData *meta, QV4::ExecutionContext *qmlBindingContext, QQmlCompiledData *compiledData)
-: object(obj),
- ctxt(QQmlData::get(obj, true)->outerContext), cache(cache), metaData(meta),
- hasAssignedMetaObjectData(false), data(0), aliasEndpoints(0), firstVarPropertyIndex(-1),
- varPropertiesInitialized(false), interceptors(0), v8methods(0)
+QSizeF QQmlVMEMetaObject::readPropertyAsSizeF(int id)
{
- QObjectPrivate *op = QObjectPrivate::get(obj);
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return QSizeF();
- if (op->metaObject) {
- parent = op->metaObject;
- // Use the extra flag in QBiPointer to know if we can safely cast parent.asT1() to QQmlVMEMetaObject*
- parent.setFlagValue(QQmlData::get(obj)->hasVMEMetaObject);
- } else
- parent = obj->metaObject();
-
- op->metaObject = this;
- QQmlData::get(obj)->hasVMEMetaObject = true;
-
- data = new QQmlVMEVariant[metaData->propertyCount - metaData->varPropertyCount];
-
- aConnected.resize(metaData->aliasCount);
- int list_type = qMetaTypeId<QQmlListProperty<QObject> >();
- int qobject_type = qMetaTypeId<QObject*>();
- int variant_type = qMetaTypeId<QVariant>();
- // Need JS wrapper to ensure variant and var properties are marked.
- // ### FIXME: I hope that this can be removed once we have the proper scope chain
- // set up and the JS wrappers always exist.
- bool needsJSWrapper = (metaData->varPropertyCount > 0);
-
- // ### Optimize
- for (int ii = 0; ii < metaData->propertyCount - metaData->varPropertyCount; ++ii) {
- int t = (metaData->propertyData() + ii)->propertyType;
- if (t == list_type) {
- listProperties.append(List(methodOffset() + ii, this));
- data[ii].setValue(listProperties.count() - 1);
- } else if (!needsJSWrapper && (t == qobject_type || t == variant_type)) {
- needsJSWrapper = true;
- }
- }
-
- firstVarPropertyIndex = metaData->propertyCount - metaData->varPropertyCount;
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::SizeF)
+ return QSizeF();
+ return v->d()->data.value<QSizeF>();
+}
- if (needsJSWrapper)
- ensureQObjectWrapper();
+QPointF QQmlVMEMetaObject::readPropertyAsPointF(int id)
+{
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return QPointF();
- if (qmlBindingContext && metaData->methodCount) {
- v8methods = new QV4::PersistentValue[metaData->methodCount];
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::PointF)
+ return QPointF();
+ return v->d()->data.value<QPointF>();
+}
- QV4::CompiledData::CompilationUnit *compilationUnit = compiledData->compilationUnit;
- QV4::Scope scope(QQmlEnginePrivate::get(ctxt->engine)->v4engine());
- QV4::ScopedObject o(scope);
- for (int index = 0; index < metaData->methodCount; ++index) {
- QQmlVMEMetaData::MethodData *data = metaData->methodData() + index;
+QObject* QQmlVMEMetaObject::readPropertyAsQObject(int id)
+{
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return 0;
- QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[data->runtimeFunctionIndex];
- o = QV4::FunctionObject::createScriptFunction(qmlBindingContext, runtimeFunction);
- v8methods[index].set(qmlBindingContext->engine(), o);
- }
- }
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ const QV4::QObjectWrapper *wrapper = sv->as<QV4::QObjectWrapper>();
+ if (!wrapper)
+ return 0;
+ return wrapper->object();
}
-QQmlVMEMetaObject::~QQmlVMEMetaObject()
+QRectF QQmlVMEMetaObject::readPropertyAsRectF(int id)
{
- if (parent.isT1()) parent.asT1()->objectDestroyed(object);
- delete [] data;
- delete [] aliasEndpoints;
- delete [] v8methods;
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
+ return QRectF();
- qDeleteAll(varObjectGuards);
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue sv(scope, *(md->data() + id));
+ const QV4::VariantObject *v = sv->as<QV4::VariantObject>();
+ if (!v || v->d()->data.type() != QVariant::RectF)
+ return QRectF();
+ return v->d()->data.value<QRectF>();
}
-int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
+int QQmlVMEMetaObject::metaCall(QObject *o, QMetaObject::Call c, int _id, void **a)
{
+ Q_ASSERT(o == object);
+ Q_UNUSED(o);
+
int id = _id;
if (c == QMetaObject::WriteProperty && interceptors &&
!(*reinterpret_cast<int*>(a[3]) & QQmlPropertyPrivate::BypassInterceptor)) {
@@ -668,8 +544,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
int t = (metaData->propertyData() + id)->propertyType;
bool needActivate = false;
- if (id >= firstVarPropertyIndex) {
- Q_ASSERT(t == QMetaType::QVariant);
+ if (t == QQmlVMEMetaData::VarPropertyType) {
// the context can be null if accessing var properties from cpp after re-parenting an item.
QQmlEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QQmlEnginePrivate::get(ctxt->engine);
QV8Engine *v8e = (ep == 0) ? 0 : ep->v8engine();
@@ -689,50 +564,57 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
if (c == QMetaObject::ReadProperty) {
switch(t) {
case QVariant::Int:
- *reinterpret_cast<int *>(a[0]) = data[id].asInt();
+ *reinterpret_cast<int *>(a[0]) = readPropertyAsInt(id);
break;
case QVariant::Bool:
- *reinterpret_cast<bool *>(a[0]) = data[id].asBool();
+ *reinterpret_cast<bool *>(a[0]) = readPropertyAsBool(id);
break;
case QVariant::Double:
- *reinterpret_cast<double *>(a[0]) = data[id].asDouble();
+ *reinterpret_cast<double *>(a[0]) = readPropertyAsDouble(id);
break;
case QVariant::String:
- *reinterpret_cast<QString *>(a[0]) = data[id].asQString();
+ *reinterpret_cast<QString *>(a[0]) = readPropertyAsString(id);
break;
case QVariant::Url:
- *reinterpret_cast<QUrl *>(a[0]) = data[id].asQUrl();
+ *reinterpret_cast<QUrl *>(a[0]) = readPropertyAsUrl(id);
break;
case QVariant::Date:
- *reinterpret_cast<QDate *>(a[0]) = data[id].asQDate();
+ *reinterpret_cast<QDate *>(a[0]) = readPropertyAsDate(id);
break;
case QVariant::DateTime:
- *reinterpret_cast<QDateTime *>(a[0]) = data[id].asQDateTime();
+ *reinterpret_cast<QDateTime *>(a[0]) = readPropertyAsDateTime(id);
break;
case QVariant::RectF:
- *reinterpret_cast<QRectF *>(a[0]) = data[id].asQRectF();
+ *reinterpret_cast<QRectF *>(a[0]) = readPropertyAsRectF(id);
break;
case QVariant::SizeF:
- *reinterpret_cast<QSizeF *>(a[0]) = data[id].asQSizeF();
+ *reinterpret_cast<QSizeF *>(a[0]) = readPropertyAsSizeF(id);
break;
case QVariant::PointF:
- *reinterpret_cast<QPointF *>(a[0]) = data[id].asQPointF();
+ *reinterpret_cast<QPointF *>(a[0]) = readPropertyAsPointF(id);
break;
case QMetaType::QObjectStar:
- *reinterpret_cast<QObject **>(a[0]) = data[id].asQObject();
+ *reinterpret_cast<QObject **>(a[0]) = readPropertyAsQObject(id);
break;
case QMetaType::QVariant:
*reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id);
break;
default:
- QQml_valueTypeProvider()->readValueType(data[id].dataType(), data[id].dataPtr(), data->dataSize(), t, a[0]);
+ {
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md) {
+ QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>();
+ if (v)
+ QQml_valueTypeProvider()->readValueType(v->d()->data, a[0], t);
+ }
break;
}
+ }
if (t == qMetaTypeId<QQmlListProperty<QObject> >()) {
- int listIndex = data[id].asInt();
+ const int listIndex = readPropertyAsInt(id);
const List *list = &listProperties.at(listIndex);
*reinterpret_cast<QQmlListProperty<QObject> *>(a[0]) =
- QQmlListProperty<QObject>(object, (void *)list,
+ QQmlListProperty<QObject>(object, const_cast<List *>(list),
list_append, list_count, list_at,
list_clear);
}
@@ -741,58 +623,67 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
switch(t) {
case QVariant::Int:
- needActivate = *reinterpret_cast<int *>(a[0]) != data[id].asInt();
- data[id].setValue(*reinterpret_cast<int *>(a[0]));
+ needActivate = *reinterpret_cast<int *>(a[0]) != readPropertyAsInt(id);
+ writeProperty(id, *reinterpret_cast<int *>(a[0]));
break;
case QVariant::Bool:
- needActivate = *reinterpret_cast<bool *>(a[0]) != data[id].asBool();
- data[id].setValue(*reinterpret_cast<bool *>(a[0]));
+ needActivate = *reinterpret_cast<bool *>(a[0]) != readPropertyAsBool(id);
+ writeProperty(id, *reinterpret_cast<bool *>(a[0]));
break;
case QVariant::Double:
- needActivate = *reinterpret_cast<double *>(a[0]) != data[id].asDouble();
- data[id].setValue(*reinterpret_cast<double *>(a[0]));
+ needActivate = *reinterpret_cast<double *>(a[0]) != readPropertyAsDouble(id);
+ writeProperty(id, *reinterpret_cast<double *>(a[0]));
break;
case QVariant::String:
- needActivate = *reinterpret_cast<QString *>(a[0]) != data[id].asQString();
- data[id].setValue(*reinterpret_cast<QString *>(a[0]));
+ needActivate = *reinterpret_cast<QString *>(a[0]) != readPropertyAsString(id);
+ writeProperty(id, *reinterpret_cast<QString *>(a[0]));
break;
case QVariant::Url:
- needActivate = *reinterpret_cast<QUrl *>(a[0]) != data[id].asQUrl();
- data[id].setValue(*reinterpret_cast<QUrl *>(a[0]));
+ needActivate = *reinterpret_cast<QUrl *>(a[0]) != readPropertyAsUrl(id);
+ writeProperty(id, *reinterpret_cast<QUrl *>(a[0]));
break;
case QVariant::Date:
- needActivate = *reinterpret_cast<QDate *>(a[0]) != data[id].asQDate();
- data[id].setValue(*reinterpret_cast<QDate *>(a[0]));
+ needActivate = *reinterpret_cast<QDate *>(a[0]) != readPropertyAsDate(id);
+ writeProperty(id, *reinterpret_cast<QDate *>(a[0]));
break;
case QVariant::DateTime:
- needActivate = *reinterpret_cast<QDateTime *>(a[0]) != data[id].asQDateTime();
- data[id].setValue(*reinterpret_cast<QDateTime *>(a[0]));
+ needActivate = *reinterpret_cast<QDateTime *>(a[0]) != readPropertyAsDateTime(id);
+ writeProperty(id, *reinterpret_cast<QDateTime *>(a[0]));
break;
case QVariant::RectF:
- needActivate = *reinterpret_cast<QRectF *>(a[0]) != data[id].asQRectF();
- data[id].setValue(*reinterpret_cast<QRectF *>(a[0]));
+ needActivate = *reinterpret_cast<QRectF *>(a[0]) != readPropertyAsRectF(id);
+ writeProperty(id, *reinterpret_cast<QRectF *>(a[0]));
break;
case QVariant::SizeF:
- needActivate = *reinterpret_cast<QSizeF *>(a[0]) != data[id].asQSizeF();
- data[id].setValue(*reinterpret_cast<QSizeF *>(a[0]));
+ needActivate = *reinterpret_cast<QSizeF *>(a[0]) != readPropertyAsSizeF(id);
+ writeProperty(id, *reinterpret_cast<QSizeF *>(a[0]));
break;
case QVariant::PointF:
- needActivate = *reinterpret_cast<QPointF *>(a[0]) != data[id].asQPointF();
- data[id].setValue(*reinterpret_cast<QPointF *>(a[0]));
+ needActivate = *reinterpret_cast<QPointF *>(a[0]) != readPropertyAsPointF(id);
+ writeProperty(id, *reinterpret_cast<QPointF *>(a[0]));
break;
case QMetaType::QObjectStar:
- needActivate = *reinterpret_cast<QObject **>(a[0]) != data[id].asQObject();
- data[id].setValue(*reinterpret_cast<QObject **>(a[0]), this, id);
+ needActivate = *reinterpret_cast<QObject **>(a[0]) != readPropertyAsQObject(id);
+ writeProperty(id, *reinterpret_cast<QObject **>(a[0]));
break;
case QMetaType::QVariant:
writeProperty(id, *reinterpret_cast<QVariant *>(a[0]));
break;
- default:
- data[id].ensureValueType(t);
- needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], data[id].dataPtr(), data[id].dataSize());
- QQml_valueTypeProvider()->writeValueType(t, a[0], data[id].dataPtr(), data[id].dataSize());
+ default: {
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md) {
+ QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>();
+ if (!v) {
+ *(md->data() + id) = cache->engine->newVariantObject(QVariant());
+ v = (md->data() + id)->as<QV4::VariantObject>();
+ }
+ QQml_valueTypeProvider()->initValueType(t, v->d()->data);
+ needActivate = !QQml_valueTypeProvider()->equalValueType(t, a[0], v->d()->data);
+ QQml_valueTypeProvider()->writeValueType(t, a[0], v->d()->data);
+ }
break;
}
+ }
}
}
@@ -936,126 +827,122 @@ QV4::ReturnedValue QQmlVMEMetaObject::method(int index)
return QV4::Primitive::undefinedValue().asReturnedValue();
}
- if (!v8methods)
- v8methods = new QV4::PersistentValue[metaData->methodCount];
+ if (!methods)
+ methods = new QV4::PersistentValue[metaData->methodCount];
- return v8methods[index].value();
+ return methods[index].value();
}
QV4::ReturnedValue QQmlVMEMetaObject::readVarProperty(int id)
{
- Q_ASSERT(id >= firstVarPropertyIndex);
+ Q_ASSERT((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType);
- if (ensureVarPropertiesAllocated()) {
- QV4::Scope scope(varProperties.engine());
- QV4::ScopedObject o(scope, varProperties.value());
- return o->getIndexed(id - firstVarPropertyIndex);
- }
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md)
+ return (md->data() + id)->asReturnedValue();
return QV4::Primitive::undefinedValue().asReturnedValue();
}
QVariant QQmlVMEMetaObject::readPropertyAsVariant(int id)
{
- if (id >= firstVarPropertyIndex) {
- if (ensureVarPropertiesAllocated()) {
- QV4::ExecutionEngine *v4 = varProperties.engine();
- QV4::Scope scope(v4);
- QV4::ScopedObject o(scope, varProperties.value());
- QV4::ScopedValue val(scope, o->getIndexed(id - firstVarPropertyIndex));
- return scope.engine->toVariant(val, -1);
- }
- return QVariant();
- } else {
- if (data[id].dataType() == QMetaType::QObjectStar) {
- return QVariant::fromValue(data[id].asQObject());
- } else {
- return data[id].asQVariant();
- }
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md) {
+ const QV4::QObjectWrapper *wrapper = (md->data() + id)->as<QV4::QObjectWrapper>();
+ if (wrapper)
+ return QVariant::fromValue(wrapper->object());
+ const QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>();
+ if (v)
+ return v->d()->data;
+ return cache->engine->toVariant(*(md->data() + id), -1);
}
+ return QVariant();
}
void QQmlVMEMetaObject::writeVarProperty(int id, const QV4::Value &value)
{
- Q_ASSERT(id >= firstVarPropertyIndex);
- if (!ensureVarPropertiesAllocated())
+ Q_ASSERT((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType);
+
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
return;
- QV4::Scope scope(varProperties.engine());
// Importantly, if the current value is a scarce resource, we need to ensure that it
// gets automatically released by the engine if no other references to it exist.
- QV4::ScopedObject vp(scope, varProperties.value());
- QV4::Scoped<QV4::VariantObject> oldv(scope, vp->getIndexed(id - firstVarPropertyIndex));
- if (!!oldv)
- oldv->removeVmePropertyReference();
+ QV4::VariantObject *oldVariant = (md->data() + id)->as<QV4::VariantObject>();
+ if (oldVariant)
+ oldVariant->removeVmePropertyReference();
QObject *valueObject = 0;
QQmlVMEVariantQObjectPtr *guard = getQObjectGuardForProperty(id);
- QV4::ScopedObject o(scope, value);
- if (o) {
- // And, if the new value is a scarce resource, we need to ensure that it does not get
- // automatically released by the engine until no other references to it exist.
- if (QV4::VariantObject *v = o->as<QV4::VariantObject>()) {
- v->addVmePropertyReference();
- } else if (QV4::QObjectWrapper *wrapper = o->as<QV4::QObjectWrapper>()) {
- // We need to track this QObject to signal its deletion
- valueObject = wrapper->object();
-
- // Do we already have a QObject guard for this property?
- if (valueObject && !guard) {
- guard = new QQmlVMEVariantQObjectPtr(true);
- varObjectGuards.append(guard);
- }
+ // And, if the new value is a scarce resource, we need to ensure that it does not get
+ // automatically released by the engine until no other references to it exist.
+ if (QV4::VariantObject *v = const_cast<QV4::VariantObject*>(value.as<QV4::VariantObject>())) {
+ v->addVmePropertyReference();
+ } else if (QV4::QObjectWrapper *wrapper = const_cast<QV4::QObjectWrapper*>(value.as<QV4::QObjectWrapper>())) {
+ // We need to track this QObject to signal its deletion
+ valueObject = wrapper->object();
+
+ // Do we already have a QObject guard for this property?
+ if (valueObject && !guard) {
+ guard = new QQmlVMEVariantQObjectPtr();
+ varObjectGuards.append(guard);
}
}
- if (guard) {
+ if (guard)
guard->setGuardedValue(valueObject, this, id);
- }
// Write the value and emit change signal as appropriate.
- vp->putIndexed(id - firstVarPropertyIndex, value);
+ *(md->data() + id) = value;
activate(object, methodOffset() + id, 0);
}
void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value)
{
- if (id >= firstVarPropertyIndex) {
- if (!ensureVarPropertiesAllocated())
+ if ((metaData->propertyData() + id)->propertyType == QQmlVMEMetaData::VarPropertyType) {
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (!md)
return;
- QV4::Scope scope(varProperties.engine());
-
// Importantly, if the current value is a scarce resource, we need to ensure that it
// gets automatically released by the engine if no other references to it exist.
- QV4::ScopedObject vp(scope, varProperties.value());
- QV4::Scoped<QV4::VariantObject> oldv(scope, vp->getIndexed(id - firstVarPropertyIndex));
- if (!!oldv)
+ QV4::VariantObject *oldv = (md->data() + id)->as<QV4::VariantObject>();
+ if (oldv)
oldv->removeVmePropertyReference();
// And, if the new value is a scarce resource, we need to ensure that it does not get
// automatically released by the engine until no other references to it exist.
- QV4::ScopedValue newv(scope, scope.engine->fromVariant(value));
+ QV4::Scope scope(cache->engine);
+ QV4::ScopedValue newv(scope, cache->engine->fromVariant(value));
QV4::Scoped<QV4::VariantObject> v(scope, newv);
if (!!v)
v->addVmePropertyReference();
// Write the value and emit change signal as appropriate.
QVariant currentValue = readPropertyAsVariant(id);
- vp->putIndexed(id - firstVarPropertyIndex, newv);
+ *(md->data() + id) = newv;
if ((currentValue.userType() != value.userType() || currentValue != value))
activate(object, methodOffset() + id, 0);
} else {
bool needActivate = false;
if (value.userType() == QMetaType::QObjectStar) {
- QObject *o = *(QObject **)value.data();
- needActivate = (data[id].dataType() != QMetaType::QObjectStar || data[id].asQObject() != o);
- data[id].setValue(o, this, id);
+ QObject *o = *(QObject *const *)value.data();
+ needActivate = readPropertyAsQObject(id) != o; // TODO: still correct?
+ writeProperty(id, o);
} else {
- needActivate = (data[id].dataType() != qMetaTypeId<QVariant>() ||
- data[id].asQVariant().userType() != value.userType() ||
- data[id].asQVariant() != value);
- data[id].setValue(value);
+ QV4::MemberData *md = propertiesAsMemberData();
+ if (md) {
+ QV4::VariantObject *v = (md->data() + id)->as<QV4::VariantObject>();
+ needActivate = (!v ||
+ v->d()->data.userType() != value.userType() ||
+ v->d()->data != value);
+ if (v)
+ v->removeVmePropertyReference();
+ *(md->data() + id) = cache->engine->newVariantObject(value);
+ v = static_cast<QV4::VariantObject *>(md->data() + id);
+ v->addVmePropertyReference();
+ }
}
if (needActivate)
@@ -1137,11 +1024,11 @@ void QQmlVMEMetaObject::setVmeMethod(int index, const QV4::Value &function)
int plainSignals = metaData->signalCount + metaData->propertyCount + metaData->aliasCount;
Q_ASSERT(index >= (methodOffset() + plainSignals) && index < (methodOffset() + plainSignals + metaData->methodCount));
- if (!v8methods)
- v8methods = new QV4::PersistentValue[metaData->methodCount];
+ if (!methods)
+ methods = new QV4::PersistentValue[metaData->methodCount];
int methodIndex = index - methodOffset() - plainSignals;
- v8methods[methodIndex].set(function.as<QV4::Object>()->engine(), function);
+ methods[methodIndex].set(function.as<QV4::Object>()->engine(), function);
}
QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index)
@@ -1163,58 +1050,47 @@ void QQmlVMEMetaObject::setVMEProperty(int index, const QV4::Value &v)
return writeVarProperty(index - propOffset(), v);
}
-bool QQmlVMEMetaObject::ensureVarPropertiesAllocated()
+bool QQmlVMEMetaObject::ensurePropertiesAllocated()
{
- if (!varPropertiesInitialized)
- allocateVarPropertiesArray();
+ if (!propertiesInitialized)
+ allocateProperties();
// in some situations, the QObject's v8object (and associated v8 data,
// such as the varProperties array) will have been cleaned up, but the
// QObject ptr will not yet have been deleted (eg, waiting on deleteLater).
// In this situation, the varProperties handle will be (and should remain)
// empty.
- return !varProperties.isUndefined();
+ return !properties.isUndefined();
}
void QQmlVMEMetaObject::ensureQObjectWrapper()
{
- Q_ASSERT(ctxt && ctxt->engine);
- QQmlEnginePrivate *ep = QQmlEnginePrivate::get(ctxt->engine);
- QV4::ExecutionEngine *v4 = ep->v4engine();
+ Q_ASSERT(cache && cache->engine);
+ QV4::ExecutionEngine *v4 = cache->engine;
QV4::QObjectWrapper::wrap(v4, object);
}
void QQmlVMEMetaObject::mark(QV4::ExecutionEngine *e)
{
- QQmlEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QQmlEnginePrivate::get(ctxt->engine);
- QV4::ExecutionEngine *v4 = (ep == 0) ? 0 : ep->v4engine();
+ QV4::ExecutionEngine *v4 = cache ? cache->engine : 0;
if (v4 != e)
return;
- varProperties.markOnce(e);
-
- // add references created by VMEVariant properties
- int maxDataIdx = metaData->propertyCount - metaData->varPropertyCount;
- for (int ii = 0; ii < maxDataIdx; ++ii) { // XXX TODO: optimize?
- if (data[ii].dataType() == QMetaType::QObjectStar) {
- // possible QObject reference.
- if (QObject *ref = data[ii].asQObject())
- QV4::QObjectWrapper::markWrapper(ref, e);
- }
- }
+ properties.markOnce(e);
if (QQmlVMEMetaObject *parent = parentVMEMetaObject())
parent->mark(e);
}
-void QQmlVMEMetaObject::allocateVarPropertiesArray()
+void QQmlVMEMetaObject::allocateProperties()
{
- QQmlEngine *qml = qmlEngine(object);
- Q_ASSERT(qml);
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(qml->handle());
- QV4::Scope scope(v4);
- varProperties.set(scope.engine, v4->newArrayObject(metaData->varPropertyCount));
- varPropertiesInitialized = true;
+ Q_ASSERT(cache && cache->engine);
+ QV4::ExecutionEngine *v4 = cache->engine;
+ QV4::Heap::MemberData *data = QV4::MemberData::reallocate(v4, 0, metaData->propertyCount);
+ properties.set(v4, data);
+ for (uint i = 0; i < data->size; ++i)
+ data->data[i] = QV4::Encode::undefined();
+ propertiesInitialized = true;
}
bool QQmlVMEMetaObject::aliasTarget(int index, QObject **target, int *coreIndex, int *valueTypeIndex) const
diff --git a/src/qml/qml/qqmlvmemetaobject_p.h b/src/qml/qml/qqmlvmemetaobject_p.h
index 44809a26f0..427e751f5d 100644
--- a/src/qml/qml/qqmlvmemetaobject_p.h
+++ b/src/qml/qml/qqmlvmemetaobject_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 BasysKom GmbH.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtQml module of the Qt Toolkit.
@@ -71,7 +72,6 @@ QT_BEGIN_NAMESPACE
struct QQmlVMEMetaData
{
- short varPropertyCount;
short propertyCount;
short aliasCount;
short signalCount;
@@ -108,6 +108,10 @@ struct QQmlVMEMetaData
}
};
+ enum {
+ VarPropertyType = -1
+ };
+
struct PropertyData {
int propertyType;
};
@@ -119,7 +123,7 @@ struct QQmlVMEMetaData
};
PropertyData *propertyData() const {
- return (PropertyData *)(((const char *)this) + sizeof(QQmlVMEMetaData));
+ return (PropertyData *)(((char *)const_cast<QQmlVMEMetaData *>(this)) + sizeof(QQmlVMEMetaData));
}
AliasData *aliasData() const {
@@ -135,15 +139,14 @@ class QQmlVMEMetaObject;
class QQmlVMEVariantQObjectPtr : public QQmlGuard<QObject>
{
public:
- inline QQmlVMEVariantQObjectPtr(bool isVar);
+ inline QQmlVMEVariantQObjectPtr();
inline ~QQmlVMEVariantQObjectPtr();
inline void objectDestroyed(QObject *);
inline void setGuardedValue(QObject *obj, QQmlVMEMetaObject *target, int index);
QQmlVMEMetaObject *m_target;
- unsigned m_isVar : 1;
- int m_index : 31;
+ int m_index;
};
class QQmlVMEVariant;
@@ -177,7 +180,7 @@ public:
static QQmlVMEMetaObject *getForSignal(QObject *o, int coreIndex);
protected:
- virtual int metaCall(QMetaObject::Call _c, int _id, void **_a);
+ virtual int metaCall(QObject *o, QMetaObject::Call _c, int _id, void **_a);
public:
friend class QQmlVMEMetaObjectEndpoint;
@@ -195,14 +198,37 @@ public:
inline int signalCount() const;
bool hasAssignedMetaObjectData;
- QQmlVMEVariant *data;
QQmlVMEMetaObjectEndpoint *aliasEndpoints;
- QV4::WeakValue varProperties;
- int firstVarPropertyIndex;
- bool varPropertiesInitialized;
- inline void allocateVarPropertiesArray();
- inline bool ensureVarPropertiesAllocated();
+ QV4::WeakValue properties;
+ bool propertiesInitialized;
+ inline void allocateProperties();
+ inline bool ensurePropertiesAllocated();
+ QV4::MemberData *propertiesAsMemberData();
+
+ int readPropertyAsInt(int id);
+ bool readPropertyAsBool(int id);
+ double readPropertyAsDouble(int id);
+ QString readPropertyAsString(int id);
+ QSizeF readPropertyAsSizeF(int id);
+ QPointF readPropertyAsPointF(int id);
+ QUrl readPropertyAsUrl(int id);
+ QDate readPropertyAsDate(int id);
+ QDateTime readPropertyAsDateTime(int id);
+ QRectF readPropertyAsRectF(int id);
+ QObject* readPropertyAsQObject(int id);
+
+ void writeProperty(int id, int v);
+ void writeProperty(int id, bool v);
+ void writeProperty(int id, double v);
+ void writeProperty(int id, const QString& v);
+ void writeProperty(int id, const QPointF& v);
+ void writeProperty(int id, const QSizeF& v);
+ void writeProperty(int id, const QUrl& v);
+ void writeProperty(int id, const QDate& v);
+ void writeProperty(int id, const QDateTime& v);
+ void writeProperty(int id, const QRectF& v);
+ void writeProperty(int id, QObject *v);
void ensureQObjectWrapper();
@@ -213,7 +239,7 @@ public:
QQmlPropertyValueInterceptor *interceptors;
- QV4::PersistentValue *v8methods;
+ QV4::PersistentValue *methods;
QV4::ReturnedValue method(int);
QV4::ReturnedValue readVarProperty(int);
diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp
index 0edb672517..0870e2b2c5 100644
--- a/src/qml/qml/qqmlxmlhttprequest.cpp
+++ b/src/qml/qml/qqmlxmlhttprequest.cpp
@@ -95,16 +95,6 @@ static inline QQmlXMLHttpRequestData *xhrdata(ExecutionEngine *v4)
return (QQmlXMLHttpRequestData *)v4->v8Engine->xmlHttpRequestData();
}
-static ReturnedValue constructMeObject(const Value &thisObj, ExecutionEngine *v4)
-{
- Scope scope(v4);
- ScopedObject meObj(scope, v4->newObject());
- meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ThisObject"))), thisObj);
- ScopedValue v(scope, QmlContextWrapper::qmlScope(v4, v4->callingQmlContext(), 0));
- meObj->put(ScopedString(scope, v4->newString(QStringLiteral("ActivationObject"))), v);
- return meObj.asReturnedValue();
-}
-
QQmlXMLHttpRequestData::QQmlXMLHttpRequestData()
{
}
@@ -1015,7 +1005,7 @@ public:
Opened = 1, HeadersReceived = 2,
Loading = 3, Done = 4 };
- QQmlXMLHttpRequest(ExecutionEngine *engine, QNetworkAccessManager *manager);
+ QQmlXMLHttpRequest(QNetworkAccessManager *manager);
virtual ~QQmlXMLHttpRequest();
bool sendFlag() const;
@@ -1024,9 +1014,9 @@ public:
int replyStatus() const;
QString replyStatusText() const;
- ReturnedValue open(const Value &me, const QString &, const QUrl &, LoadType);
- ReturnedValue send(const Value &me, const QByteArray &);
- ReturnedValue abort(const Value &me);
+ ReturnedValue open(Object *thisObject, QQmlContextData *context, const QString &, const QUrl &, LoadType);
+ ReturnedValue send(Object *thisObject, QQmlContextData *context, const QByteArray &);
+ ReturnedValue abort(Object *thisObject, QQmlContextData *context);
void addHeader(const QString &, const QString &);
QString header(const QString &name);
@@ -1049,7 +1039,6 @@ private slots:
private:
void requestFromUrl(const QUrl &url);
- ExecutionEngine *v4;
State m_state;
bool m_errorFlag;
bool m_sendFlag;
@@ -1073,12 +1062,11 @@ private:
#endif
void readEncoding();
- ReturnedValue getMe() const;
- void setMe(const Value &me);
- PersistentValue m_me;
+ PersistentValue m_thisObject;
+ QQmlGuardedContextData m_qmlContext;
- void dispatchCallbackImpl(const Value &me);
- void dispatchCallback(const Value &me);
+ static void dispatchCallback(Object *thisObj, QQmlContextData *context);
+ void dispatchCallback();
int m_status;
QString m_statusText;
@@ -1094,9 +1082,8 @@ private:
QV4::PersistentValue m_parsedDocument;
};
-QQmlXMLHttpRequest::QQmlXMLHttpRequest(ExecutionEngine *engine, QNetworkAccessManager *manager)
- : v4(engine)
- , m_state(Unsent), m_errorFlag(false), m_sendFlag(false)
+QQmlXMLHttpRequest::QQmlXMLHttpRequest(QNetworkAccessManager *manager)
+ : m_state(Unsent), m_errorFlag(false), m_sendFlag(false)
, m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager)
, m_responseType()
, m_parsedDocument()
@@ -1133,7 +1120,7 @@ QString QQmlXMLHttpRequest::replyStatusText() const
return m_statusText;
}
-ReturnedValue QQmlXMLHttpRequest::open(const Value &me, const QString &method, const QUrl &url, LoadType loadType)
+ReturnedValue QQmlXMLHttpRequest::open(Object *thisObject, QQmlContextData *context, const QString &method, const QUrl &url, LoadType loadType)
{
destroyNetwork();
m_sendFlag = false;
@@ -1144,7 +1131,7 @@ ReturnedValue QQmlXMLHttpRequest::open(const Value &me, const QString &method, c
m_request.setAttribute(QNetworkRequest::SynchronousRequestAttribute, loadType == SynchronousLoad);
m_state = Opened;
m_addedHeaders.clear();
- dispatchCallback(me);
+ dispatchCallback(thisObject, context);
return Encode::undefined();
}
@@ -1279,21 +1266,22 @@ void QQmlXMLHttpRequest::requestFromUrl(const QUrl &url)
}
}
-ReturnedValue QQmlXMLHttpRequest::send(const Value &me, const QByteArray &data)
+ReturnedValue QQmlXMLHttpRequest::send(Object *thisObject, QQmlContextData *context, const QByteArray &data)
{
m_errorFlag = false;
m_sendFlag = true;
m_redirectCount = 0;
m_data = data;
- setMe(me);
+ m_thisObject = thisObject;
+ m_qmlContext = context;
requestFromUrl(m_url);
return Encode::undefined();
}
-ReturnedValue QQmlXMLHttpRequest::abort(const Value &me)
+ReturnedValue QQmlXMLHttpRequest::abort(Object *thisObject, QQmlContextData *context)
{
destroyNetwork();
m_responseEntityBody = QByteArray();
@@ -1306,7 +1294,7 @@ ReturnedValue QQmlXMLHttpRequest::abort(const Value &me)
m_state = Done;
m_sendFlag = false;
- dispatchCallback(me);
+ dispatchCallback(thisObject, context);
}
m_state = Unsent;
@@ -1314,16 +1302,6 @@ ReturnedValue QQmlXMLHttpRequest::abort(const Value &me)
return Encode::undefined();
}
-ReturnedValue QQmlXMLHttpRequest::getMe() const
-{
- return m_me.value();
-}
-
-void QQmlXMLHttpRequest::setMe(const Value &me)
-{
- m_me.set(v4, me);
-}
-
void QQmlXMLHttpRequest::readyRead()
{
m_status =
@@ -1331,14 +1309,11 @@ void QQmlXMLHttpRequest::readyRead()
m_statusText =
QString::fromUtf8(m_network->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toByteArray());
- Scope scope(v4);
- ScopedValue me(scope, m_me.value());
-
// ### We assume if this is called the headers are now available
if (m_state < HeadersReceived) {
m_state = HeadersReceived;
fillHeadersList ();
- dispatchCallback(me);
+ dispatchCallback();
}
bool wasEmpty = m_responseEntityBody.isEmpty();
@@ -1346,7 +1321,7 @@ void QQmlXMLHttpRequest::readyRead()
if (wasEmpty && !m_responseEntityBody.isEmpty())
m_state = Loading;
- dispatchCallback(me);
+ dispatchCallback();
}
static const char *errorToString(QNetworkReply::NetworkError error)
@@ -1377,9 +1352,6 @@ void QQmlXMLHttpRequest::error(QNetworkReply::NetworkError error)
qWarning().nospace() << " " << error << ' ' << errorToString(error) << ' ' << m_statusText;
}
- Scope scope(v4);
- ScopedValue me(scope, m_me.value());
-
if (error == QNetworkReply::ContentAccessDenied ||
error == QNetworkReply::ContentOperationNotPermittedError ||
error == QNetworkReply::ContentNotFoundError ||
@@ -1388,15 +1360,14 @@ void QQmlXMLHttpRequest::error(QNetworkReply::NetworkError error)
error == QNetworkReply::UnknownContentError ||
error == QNetworkReply::ProtocolInvalidOperationError) {
m_state = Loading;
- dispatchCallback(me);
+ dispatchCallback();
} else {
m_errorFlag = true;
m_responseEntityBody = QByteArray();
}
m_state = Done;
-
- dispatchCallback(me);
+ dispatchCallback();
}
#define XMLHTTPREQUEST_MAXIMUM_REDIRECT_RECURSION 15
@@ -1428,7 +1399,7 @@ void QQmlXMLHttpRequest::finished()
if (m_state < HeadersReceived) {
m_state = HeadersReceived;
fillHeadersList ();
- dispatchCallback(*m_me.valueRef());
+ dispatchCallback();
}
m_responseEntityBody.append(m_network->readAll());
readEncoding();
@@ -1445,15 +1416,14 @@ void QQmlXMLHttpRequest::finished()
destroyNetwork();
if (m_state < Loading) {
m_state = Loading;
- dispatchCallback(*m_me.valueRef());
+ dispatchCallback();
}
m_state = Done;
- dispatchCallback(*m_me.valueRef());
+ dispatchCallback();
- Scope scope(v4);
- ScopedValue v(scope, Primitive::undefinedValue());
- setMe(v);
+ m_thisObject.clear();
+ m_qmlContext.setContextData(0);
}
@@ -1567,57 +1537,38 @@ const QByteArray &QQmlXMLHttpRequest::rawResponseBody() const
return m_responseEntityBody;
}
-void QQmlXMLHttpRequest::dispatchCallbackImpl(const Value &me)
+void QQmlXMLHttpRequest::dispatchCallback(Object *thisObj, QQmlContextData *context)
{
- QV4::Scope scope(v4);
- ScopedObject o(scope, me);
- if (!o) {
- v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
- return;
- }
+ Q_ASSERT(thisObj);
- ScopedString s(scope, v4->newString(QStringLiteral("ThisObject")));
- ScopedObject thisObj(scope, o->get(s));
- if (!thisObj) {
- v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
+ if (!context)
+ // if the calling context object is no longer valid, then it has been
+ // deleted explicitly (e.g., by a Loader deleting the itemContext when
+ // the source is changed). We do nothing in this case, as the evaluation
+ // cannot succeed.
return;
- }
- s = v4->newString(QStringLiteral("onreadystatechange"));
+ QV4::Scope scope(thisObj->engine());
+ ScopedString s(scope, scope.engine->newString(QStringLiteral("onreadystatechange")));
ScopedFunctionObject callback(scope, thisObj->get(s));
if (!callback) {
// not an error, but no onreadystatechange function to call.
return;
}
- s = v4->newString(QStringLiteral("ActivationObject"));
- ScopedObject activationObject(scope, o->get(s));
- if (!activationObject) {
- v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ActivationObject"));
- return;
- }
+ QV4::ScopedCallData callData(scope);
+ callData->thisObject = Encode::undefined();
+ callback->call(callData);
- QQmlContextData *callingContext = QmlContextWrapper::getContext(activationObject);
- if (callingContext) {
- QV4::ScopedCallData callData(scope);
- callData->thisObject = activationObject.asReturnedValue();
- callback->call(callData);
+ if (scope.engine->hasException) {
+ QQmlError error = scope.engine->catchExceptionAsQmlError();
+ QQmlEnginePrivate::warning(QQmlEnginePrivate::get(scope.engine->qmlEngine()), error);
}
-
- // if the callingContext object is no longer valid, then it has been
- // deleted explicitly (e.g., by a Loader deleting the itemContext when
- // the source is changed). We do nothing in this case, as the evaluation
- // cannot succeed.
-
}
-void QQmlXMLHttpRequest::dispatchCallback(const Value &me)
+void QQmlXMLHttpRequest::dispatchCallback()
{
- dispatchCallbackImpl(me);
- if (v4->hasException) {
- QQmlError error = v4->catchExceptionAsQmlError();
- QQmlEnginePrivate::warning(QQmlEnginePrivate::get(v4->qmlEngine()), error);
- }
+ dispatchCallback(m_thisObject.as<Object>(), m_qmlContext.contextData());
}
void QQmlXMLHttpRequest::destroyNetwork()
@@ -1676,7 +1627,7 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject
if (!ctor)
return scope.engine->throwTypeError();
- QQmlXMLHttpRequest *r = new QQmlXMLHttpRequest(scope.engine, scope.engine->v8Engine->networkAccessManager());
+ QQmlXMLHttpRequest *r = new QQmlXMLHttpRequest(scope.engine->v8Engine->networkAccessManager());
Scoped<QQmlXMLHttpRequestWrapper> w(scope, scope.engine->memoryManager->alloc<QQmlXMLHttpRequestWrapper>(scope.engine, r));
ScopedObject proto(scope, ctor->d()->proto);
w->setPrototype(proto);
@@ -1813,8 +1764,7 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_open(CallContext *ctx)
if (!username.isNull()) url.setUserName(username);
if (!password.isNull()) url.setPassword(password);
- ScopedValue meObject(scope, constructMeObject(ctx->thisObject(), scope.engine));
- return r->open(meObject, method, url, async ? QQmlXMLHttpRequest::AsynchronousLoad : QQmlXMLHttpRequest::SynchronousLoad);
+ return r->open(w, scope.engine->callingQmlContext(), method, url, async ? QQmlXMLHttpRequest::AsynchronousLoad : QQmlXMLHttpRequest::SynchronousLoad);
}
ReturnedValue QQmlXMLHttpRequestCtor::method_setRequestHeader(CallContext *ctx)
@@ -1880,8 +1830,7 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_send(CallContext *ctx)
if (ctx->argc() > 0)
data = ctx->args()[0].toQStringNoThrow().toUtf8();
- ScopedValue meObject(scope, constructMeObject(ctx->thisObject(), scope.engine));
- return r->send(meObject, data);
+ return r->send(w, scope.engine->callingQmlContext(), data);
}
ReturnedValue QQmlXMLHttpRequestCtor::method_abort(CallContext *ctx)
@@ -1892,8 +1841,7 @@ ReturnedValue QQmlXMLHttpRequestCtor::method_abort(CallContext *ctx)
V4THROW_REFERENCE("Not an XMLHttpRequest object");
QQmlXMLHttpRequest *r = w->d()->request;
- ScopedValue meObject(scope, constructMeObject(ctx->thisObject(), scope.engine));
- return r->abort(meObject);
+ return r->abort(w, scope.engine->callingQmlContext());
}
ReturnedValue QQmlXMLHttpRequestCtor::method_getResponseHeader(CallContext *ctx)
diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h
index 5d12244dcb..08bbbb8548 100644
--- a/src/qml/qml/v8/qv8engine_p.h
+++ b/src/qml/qml/v8/qv8engine_p.h
@@ -63,6 +63,7 @@
#include <private/qv4value_p.h>
#include <private/qv4object_p.h>
#include <private/qv4identifier_p.h>
+#include <private/qqmlcontextwrapper_p.h>
QT_BEGIN_NAMESPACE
@@ -119,8 +120,8 @@ class QQmlV4Function
public:
int length() const { return callData->argc; }
QV4::ReturnedValue operator[](int idx) { return (idx < callData->argc ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); }
- QQmlContextData *context() { return ctx; }
- QV4::ReturnedValue qmlGlobal() { return callData->thisObject.asReturnedValue(); }
+ QQmlContextData *context() { return e->qmlContextObject()->context.contextData(); }
+ QV4::ReturnedValue qmlGlobal() { return e->qmlContextObject()->asReturnedValue(); }
void setReturnValue(QV4::ReturnedValue rv) { *retVal = rv; }
QV4::ExecutionEngine *v4engine() const { return e; }
private:
@@ -129,16 +130,14 @@ private:
QQmlV4Function(const QQmlV4Function &);
QQmlV4Function &operator=(const QQmlV4Function &);
- QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal,
- const QV4::Value &global, QQmlContextData *c, QV4::ExecutionEngine *e)
- : callData(callData), retVal(retVal), ctx(c), e(e)
+ QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal, QV4::ExecutionEngine *e)
+ : callData(callData), retVal(retVal), e(e)
{
- callData->thisObject = QV4::Value::fromReturnedValue(global.asReturnedValue());
+ callData->thisObject = QV4::Encode::undefined();
}
QV4::CallData *callData;
QV4::Value *retVal;
- QQmlContextData *ctx;
QV4::ExecutionEngine *e;
};
diff --git a/src/qml/types/qqmlinstantiator.cpp b/src/qml/types/qqmlinstantiator.cpp
index 7626ba5a05..735463a058 100644
--- a/src/qml/types/qqmlinstantiator.cpp
+++ b/src/qml/types/qqmlinstantiator.cpp
@@ -321,7 +321,7 @@ int QQmlInstantiator::count() const
Note that an extra variable, index, will be available inside instances of the
delegate. This variable refers to the index of the instance inside the Instantiator,
- and can be used to obtain the object through the itemAt method of the Instantiator.
+ and can be used to obtain the object through the objectAt method of the Instantiator.
If this property is changed, all instances using the old delegate will be destroyed
and new instances will be created using the new delegate.
diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp
index de46020ad8..799f7a0b8a 100644
--- a/src/qml/types/qqmllistmodel.cpp
+++ b/src/qml/types/qqmllistmodel.cpp
@@ -242,11 +242,12 @@ const ListLayout::Role *ListLayout::getExistingRole(QV4::String *key)
return r;
}
-ModelObject *ListModel::getOrCreateModelObject(QQmlListModel *model, int elementIndex)
+QObject *ListModel::getOrCreateModelObject(QQmlListModel *model, int elementIndex)
{
ListElement *e = elements[elementIndex];
if (e->m_objectCache == 0) {
- e->m_objectCache = new ModelObject(model, elementIndex);
+ e->m_objectCache = new QObject;
+ (void)new ModelNodeMetaObject(e->m_objectCache, model, elementIndex);
}
return e->m_objectCache;
}
@@ -317,8 +318,8 @@ void ListModel::sync(ListModel *src, ListModel *target, QHash<int, ListModel *>
// Update values stored in target meta objects
for (int i=0 ; i < target->elements.count() ; ++i) {
ListElement *e = target->elements[i];
- if (e->m_objectCache)
- e->m_objectCache->updateValues();
+ if (ModelNodeMetaObject *mo = e->objectCache())
+ mo->updateValues();
}
}
@@ -384,9 +385,8 @@ void ListModel::updateCacheIndices()
{
for (int i=0 ; i < elements.count() ; ++i) {
ListElement *e = elements.at(i);
- if (e->m_objectCache) {
- e->m_objectCache->m_elementIndex = i;
- }
+ if (ModelNodeMetaObject *mo = e->objectCache())
+ mo->m_elementIndex = i;
}
}
@@ -470,9 +470,8 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector<int> *roles)
roles->append(roleIndex);
}
- if (e->m_objectCache) {
- e->m_objectCache->updateValues(*roles);
- }
+ if (ModelNodeMetaObject *mo = e->objectCache())
+ mo->updateValues(*roles);
}
void ListModel::set(int elementIndex, QV4::Object *object)
@@ -591,10 +590,12 @@ int ListModel::setOrCreateProperty(int elementIndex, const QString &key, const Q
if (r) {
roleIndex = e->setVariantProperty(*r, data);
- if (roleIndex != -1 && e->m_objectCache) {
+ ModelNodeMetaObject *cache = e->objectCache();
+
+ if (roleIndex != -1 && cache) {
QVector<int> roles;
roles << roleIndex;
- e->m_objectCache->updateValues(roles);
+ cache->updateValues(roles);
}
}
}
@@ -633,6 +634,13 @@ inline char *ListElement::getPropertyMemory(const ListLayout::Role &role)
return mem;
}
+ModelNodeMetaObject *ListElement::objectCache()
+{
+ if (!m_objectCache)
+ return 0;
+ return ModelNodeMetaObject::get(m_objectCache);
+}
+
QString *ListElement::getStringProperty(const ListLayout::Role &role)
{
char *mem = getPropertyMemory(role);
@@ -1209,15 +1217,48 @@ int ListElement::setJsProperty(const ListLayout::Role &role, const QV4::Value &d
return roleIndex;
}
-ModelObject::ModelObject(QQmlListModel *model, int elementIndex)
-: m_model(model), m_elementIndex(elementIndex), m_meta(new ModelNodeMetaObject(this))
+ModelNodeMetaObject::ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex)
+: QQmlOpenMetaObject(object), m_enabled(false), m_model(model), m_elementIndex(elementIndex), m_initialized(false)
+{}
+
+void ModelNodeMetaObject::initialize()
{
+ const int roleCount = m_model->m_listModel->roleCount();
+ QVector<QByteArray> properties;
+ properties.reserve(roleCount);
+ for (int i = 0 ; i < roleCount ; ++i) {
+ const ListLayout::Role &role = m_model->m_listModel->getExistingRole(i);
+ QByteArray name = role.name.toUtf8();
+ properties << name;
+ }
+ type()->createProperties(properties);
updateValues();
- setNodeUpdatesEnabled(true);
+ m_enabled = true;
+}
+
+ModelNodeMetaObject::~ModelNodeMetaObject()
+{
+}
+
+QAbstractDynamicMetaObject *ModelNodeMetaObject::toDynamicMetaObject(QObject *object)
+{
+ if (!m_initialized) {
+ m_initialized = true;
+ initialize();
+ }
+ return QQmlOpenMetaObject::toDynamicMetaObject(object);
+}
+
+ModelNodeMetaObject *ModelNodeMetaObject::get(QObject *obj)
+{
+ QObjectPrivate *op = QObjectPrivate::get(obj);
+ return static_cast<ModelNodeMetaObject*>(op->metaObject);
}
-void ModelObject::updateValues()
+void ModelNodeMetaObject::updateValues()
{
+ if (!m_initialized)
+ return;
int roleCount = m_model->m_listModel->roleCount();
for (int i=0 ; i < roleCount ; ++i) {
const ListLayout::Role &role = m_model->m_listModel->getExistingRole(i);
@@ -1227,8 +1268,10 @@ void ModelObject::updateValues()
}
}
-void ModelObject::updateValues(const QVector<int> &roles)
+void ModelNodeMetaObject::updateValues(const QVector<int> &roles)
{
+ if (!m_initialized)
+ return;
int roleCount = roles.count();
for (int i=0 ; i < roleCount ; ++i) {
int roleIndex = roles.at(i);
@@ -1239,15 +1282,6 @@ void ModelObject::updateValues(const QVector<int> &roles)
}
}
-ModelNodeMetaObject::ModelNodeMetaObject(ModelObject *object)
-: QQmlOpenMetaObject(object), m_enabled(false), m_obj(object)
-{
-}
-
-ModelNodeMetaObject::~ModelNodeMetaObject()
-{
-}
-
void ModelNodeMetaObject::propertyWritten(int index)
{
if (!m_enabled)
@@ -1256,17 +1290,75 @@ void ModelNodeMetaObject::propertyWritten(int index)
QString propName = QString::fromUtf8(name(index));
QVariant value = operator[](index);
- QV4::Scope scope(m_obj->m_model->engine());
+ QV4::Scope scope(m_model->engine());
QV4::ScopedValue v(scope, scope.engine->fromVariant(value));
- int roleIndex = m_obj->m_model->m_listModel->setExistingProperty(m_obj->m_elementIndex, propName, v, scope.engine);
+ int roleIndex = m_model->m_listModel->setExistingProperty(m_elementIndex, propName, v, scope.engine);
+ if (roleIndex != -1) {
+ QVector<int> roles;
+ roles << roleIndex;
+ m_model->emitItemsChanged(m_elementIndex, 1, roles);
+ }
+}
+
+namespace QV4 {
+
+void ModelObject::put(Managed *m, String *name, const Value &value)
+{
+ ModelObject *that = static_cast<ModelObject*>(m);
+
+ ExecutionEngine *eng = that->engine();
+ const int elementIndex = that->d()->m_elementIndex;
+ const QString propName = name->toQString();
+ int roleIndex = that->d()->m_model->m_listModel->setExistingProperty(elementIndex, propName, value, eng);
if (roleIndex != -1) {
QVector<int> roles;
roles << roleIndex;
- m_obj->m_model->emitItemsChanged(m_obj->m_elementIndex, 1, roles);
+ that->d()->m_model->emitItemsChanged(elementIndex, 1, roles);
+ }
+
+ ModelNodeMetaObject *mo = ModelNodeMetaObject::get(that->object());
+ if (mo->initialized())
+ mo->emitPropertyNotification(name->toQString().toUtf8());
+}
+
+ReturnedValue ModelObject::get(const Managed *m, String *name, bool *hasProperty)
+{
+ const ModelObject *that = static_cast<const ModelObject*>(m);
+ const ListLayout::Role *role = that->d()->m_model->m_listModel->getExistingRole(name);
+ if (!role)
+ return QObjectWrapper::get(m, name, hasProperty);
+ if (hasProperty)
+ *hasProperty = true;
+ const int elementIndex = that->d()->m_elementIndex;
+ QVariant value = that->d()->m_model->data(elementIndex, role->index);
+ return that->engine()->fromVariant(value);
+}
+
+void ModelObject::advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes)
+{
+ ModelObject *that = static_cast<ModelObject*>(m);
+ ExecutionEngine *v4 = that->engine();
+ name->setM(0);
+ *index = UINT_MAX;
+ if (it->arrayIndex < uint(that->d()->m_model->m_listModel->roleCount())) {
+ Scope scope(that->engine());
+ const ListLayout::Role &role = that->d()->m_model->m_listModel->getExistingRole(it->arrayIndex);
+ ++it->arrayIndex;
+ ScopedString roleName(scope, v4->newString(role.name));
+ name->setM(roleName->d());
+ *attributes = QV4::Attr_Data;
+ QVariant value = that->d()->m_model->data(that->d()->m_elementIndex, role.index);
+ p->value = v4->fromVariant(value);
+ return;
}
+ QV4::QObjectWrapper::advanceIterator(m, it, name, index, p, attributes);
}
+DEFINE_OBJECT_VTABLE(ModelObject);
+
+} // namespace QV4
+
DynamicRoleModelNode::DynamicRoleModelNode(QQmlListModel *owner, int uid) : m_owner(owner), m_uid(uid), m_meta(new DynamicRoleModelNodeMetaObject(this))
{
setNodeUpdatesEnabled(true);
@@ -2159,8 +2251,8 @@ QQmlV4Handle QQmlListModel::get(int index) const
DynamicRoleModelNode *object = m_modelObjects[index];
result = QV4::QObjectWrapper::wrap(scope.engine, object);
} else {
- ModelObject *object = m_listModel->getOrCreateModelObject(const_cast<QQmlListModel *>(this), index);
- result = QV4::QObjectWrapper::wrap(scope.engine, object);
+ QObject *object = m_listModel->getOrCreateModelObject(const_cast<QQmlListModel *>(this), index);
+ result = scope.engine->memoryManager->alloc<QV4::ModelObject>(scope.engine, object, const_cast<QQmlListModel *>(this), index);
}
}
diff --git a/src/qml/types/qqmllistmodel_p.h b/src/qml/types/qqmllistmodel_p.h
index 75373be47c..b5a5ef3265 100644
--- a/src/qml/types/qqmllistmodel_p.h
+++ b/src/qml/types/qqmllistmodel_p.h
@@ -54,6 +54,10 @@ class QQmlListModelWorkerAgent;
class ListModel;
class ListLayout;
+namespace QV4 {
+struct ModelObject;
+}
+
class Q_QML_PRIVATE_EXPORT QQmlListModel : public QAbstractListModel
{
Q_OBJECT
@@ -94,6 +98,7 @@ private:
friend class QQmlListModelParser;
friend class QQmlListModelWorkerAgent;
friend class ModelObject;
+ friend struct QV4::ModelObject;
friend class ModelNodeMetaObject;
friend class ListModel;
friend class ListElement;
diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h
index 4e3132b860..bd0f028e7a 100644
--- a/src/qml/types/qqmllistmodel_p_p.h
+++ b/src/qml/types/qqmllistmodel_p_p.h
@@ -111,56 +111,72 @@ private:
friend class DynamicRoleModelNodeMetaObject;
};
-class ModelObject;
-
class ModelNodeMetaObject : public QQmlOpenMetaObject
{
public:
- ModelNodeMetaObject(ModelObject *object);
+ ModelNodeMetaObject(QObject *object, QQmlListModel *model, int elementIndex);
~ModelNodeMetaObject();
+ virtual QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *object);
+
+ static ModelNodeMetaObject *get(QObject *obj);
+
bool m_enabled;
+ QQmlListModel *m_model;
+ int m_elementIndex;
+
+ void updateValues();
+ void updateValues(const QVector<int> &roles);
+
+ bool initialized() const { return m_initialized; }
protected:
void propertyWritten(int index);
private:
-
- ModelObject *m_obj;
-};
-
-class ModelObject : public QObject
-{
- Q_OBJECT
-public:
- ModelObject(QQmlListModel *model, int elementIndex);
-
+ using QQmlOpenMetaObject::setValue;
void setValue(const QByteArray &name, const QVariant &val, bool force)
{
if (force) {
- QVariant existingValue = m_meta->value(name);
+ QVariant existingValue = value(name);
if (existingValue.isValid()) {
- (*m_meta)[name] = QVariant();
+ (*this)[name] = QVariant();
}
}
- m_meta->setValue(name, val);
+ setValue(name, val);
}
- void setNodeUpdatesEnabled(bool enable)
- {
- m_meta->m_enabled = enable;
- }
+ void initialize();
+ bool m_initialized;
+};
- void updateValues();
- void updateValues(const QVector<int> &roles);
+namespace QV4 {
+
+namespace Heap {
+struct ModelObject : public QObjectWrapper {
+ ModelObject(QV4::ExecutionEngine *engine, QObject *object, QQmlListModel *model, int elementIndex)
+ : QObjectWrapper(engine, object)
+ , m_model(model)
+ , m_elementIndex(elementIndex)
+ {}
QQmlListModel *m_model;
int m_elementIndex;
+};
-private:
- ModelNodeMetaObject *m_meta;
+}
+
+struct ModelObject : public QObjectWrapper
+{
+ static void put(Managed *m, String *name, const Value& value);
+ static ReturnedValue get(const Managed *m, String *name, bool *hasProperty);
+ static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes);
+
+ V4_OBJECT2(ModelObject, QObjectWrapper)
};
+} // namespace QV4
+
class ListLayout
{
public:
@@ -236,7 +252,7 @@ public:
enum
{
- BLOCK_SIZE = 64 - sizeof(int) - sizeof(ListElement *) - sizeof(ModelObject *)
+ BLOCK_SIZE = 64 - sizeof(int) - sizeof(ListElement *) - sizeof(ModelNodeMetaObject *)
};
private:
@@ -278,11 +294,13 @@ private:
int getUid() const { return uid; }
+ ModelNodeMetaObject *objectCache();
+
char data[BLOCK_SIZE];
ListElement *next;
int uid;
- ModelObject *m_objectCache;
+ QObject *m_objectCache;
friend class ListModel;
};
@@ -315,6 +333,11 @@ public:
return m_layout->getExistingRole(index);
}
+ const ListLayout::Role *getExistingRole(QV4::String *key)
+ {
+ return m_layout->getExistingRole(key);
+ }
+
const ListLayout::Role &getOrCreateListRole(const QString &name)
{
return m_layout->getRoleOrCreate(name, ListLayout::Role::List);
@@ -343,7 +366,7 @@ public:
static void sync(ListModel *src, ListModel *target, QHash<int, ListModel *> *srcModelHash);
- ModelObject *getOrCreateModelObject(QQmlListModel *model, int elementIndex);
+ QObject *getOrCreateModelObject(QQmlListModel *model, int elementIndex);
private:
QPODVector<ListElement *, 4> elements;
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp
index 17f4ffd62b..f83798488c 100644
--- a/src/qml/util/qqmladaptormodel.cpp
+++ b/src/qml/util/qqmladaptormodel.cpp
@@ -547,7 +547,7 @@ public:
metaObject = builder.toMetaObject();
*static_cast<QMetaObject *>(this) = *metaObject;
- propertyCache = new QQmlPropertyCache(engine, metaObject);
+ propertyCache = new QQmlPropertyCache(QV8Engine::getV4(engine), metaObject);
}
};
diff --git a/src/qml/util/qqmllistaccessor.cpp b/src/qml/util/qqmllistaccessor.cpp
index 55b745ab6d..bebab80d28 100644
--- a/src/qml/util/qqmllistaccessor.cpp
+++ b/src/qml/util/qqmllistaccessor.cpp
@@ -96,7 +96,7 @@ int QQmlListAccessor::count() const
case VariantList:
return qvariant_cast<QVariantList>(d).count();
case ListProperty:
- return ((QQmlListReference *)d.constData())->count();
+ return ((const QQmlListReference *)d.constData())->count();
case Instance:
return 1;
case Integer:
@@ -116,7 +116,7 @@ QVariant QQmlListAccessor::at(int idx) const
case VariantList:
return qvariant_cast<QVariantList>(d).at(idx);
case ListProperty:
- return QVariant::fromValue(((QQmlListReference *)d.constData())->at(idx));
+ return QVariant::fromValue(((const QQmlListReference *)d.constData())->at(idx));
case Instance:
return d;
case Integer: