aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4qobjectwrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime/qv4qobjectwrapper.cpp')
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp85
1 files changed, 41 insertions, 44 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index e40875dff3..7f4ac22377 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -241,7 +241,7 @@ QObjectWrapper::QObjectWrapper(ExecutionEngine *engine, QObject *object)
: Object(engine)
, m_object(object)
{
- setVTable(&static_vtbl);
+ setVTable(staticVTable());
Scope scope(engine);
ScopedObject protectThis(scope, this);
@@ -695,42 +695,39 @@ PropertyAttributes QObjectWrapper::query(const Managed *m, StringRef name)
QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(engine);
QQmlPropertyData local;
if (that->findProperty(engine, qmlContext, name, IgnoreRevision, &local)
- || name->equals(const_cast<SafeString &>(that->m_destroy)) || name->equals(engine->id_toString))
+ || name->equals(const_cast<StringValue &>(that->m_destroy)) || name->equals(engine->id_toString))
return QV4::Attr_Data;
else
return QV4::Object::query(m, name);
}
-Property *QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, StringRef name, uint *index, PropertyAttributes *attributes)
+void QObjectWrapper::advanceIterator(Managed *m, ObjectIterator *it, StringRef name, uint *index, Property *p, PropertyAttributes *attributes)
{
name = (String *)0;
*index = UINT_MAX;
QObjectWrapper *that = static_cast<QObjectWrapper*>(m);
- if (!that->m_object)
- return QV4::Object::advanceIterator(m, it, name, index, attributes);
-
- const QMetaObject *mo = that->m_object->metaObject();
- const int propertyCount = mo->propertyCount();
- if (it->arrayIndex < static_cast<uint>(propertyCount)) {
- name = that->engine()->newString(QString::fromUtf8(mo->property(it->arrayIndex).name()));
- ++it->arrayIndex;
- if (attributes)
+ if (that->m_object) {
+ const QMetaObject *mo = that->m_object->metaObject();
+ const int propertyCount = mo->propertyCount();
+ if (it->arrayIndex < static_cast<uint>(propertyCount)) {
+ name = that->engine()->newString(QString::fromUtf8(mo->property(it->arrayIndex).name()));
+ ++it->arrayIndex;
*attributes = QV4::Attr_Data;
- it->tmpDynamicProperty.value = that->get(name);
- return &it->tmpDynamicProperty;
- }
- const int methodCount = mo->methodCount();
- if (it->arrayIndex < static_cast<uint>(propertyCount + methodCount)) {
- name = that->engine()->newString(QString::fromUtf8(mo->method(it->arrayIndex - propertyCount).name()));
- ++it->arrayIndex;
- if (attributes)
+ p->value = that->get(name);
+ return;
+ }
+ const int methodCount = mo->methodCount();
+ if (it->arrayIndex < static_cast<uint>(propertyCount + methodCount)) {
+ name = that->engine()->newString(QString::fromUtf8(mo->method(it->arrayIndex - propertyCount).name()));
+ ++it->arrayIndex;
*attributes = QV4::Attr_Data;
- it->tmpDynamicProperty.value = that->get(name);
- return &it->tmpDynamicProperty;
+ p->value = that->get(name);
+ return;
+ }
}
- return QV4::Object::advanceIterator(m, it, name, index, attributes);
+ QV4::Object::advanceIterator(m, it, name, index, p, attributes);
}
namespace QV4 {
@@ -1120,7 +1117,7 @@ static QV4::ReturnedValue CallMethod(QObject *object, int index, int returnType,
return args[0].toValue(engine);
} else if (returnType != QMetaType::Void) {
-
+
CallArgument arg;
arg.initAsType(returnType);
@@ -1140,7 +1137,7 @@ static QV4::ReturnedValue CallMethod(QObject *object, int index, int returnType,
}
/*!
- Returns the match score for converting \a actual to be of type \a conversionType. A
+ Returns the match score for converting \a actual to be of type \a conversionType. A
zero score means "perfect match" whereas a higher score is worse.
The conversion table is copied out of the \l QScript::callQtMethod() function.
@@ -1314,7 +1311,7 @@ static const QQmlPropertyData * RelatedMethod(QObject *object,
QMetaMethod method = mo->method(current->overrideIndex);
dummy.load(method);
-
+
// Look for overloaded methods
QByteArray methodName = method.name();
for (int ii = current->overrideIndex - 1; ii >= methodOffset; --ii) {
@@ -1348,7 +1345,7 @@ static QV4::ReturnedValue CallPrecise(QObject *object, const QQmlPropertyData &d
int *args = 0;
QVarLengthArray<int, 9> dummy;
- args = QQmlPropertyCache::methodParameterTypes(object, data.coreIndex, dummy,
+ args = QQmlPropertyCache::methodParameterTypes(object, data.coreIndex, dummy,
&unknownTypeError);
if (!args) {
@@ -1374,13 +1371,13 @@ static QV4::ReturnedValue CallPrecise(QObject *object, const QQmlPropertyData &d
/*!
Resolve the overloaded method to call. The algorithm works conceptually like this:
1. Resolve the set of overloads it is *possible* to call.
- Impossible overloads include those that have too many parameters or have parameters
- of unknown type.
- 2. Filter the set of overloads to only contain those with the closest number of
+ Impossible overloads include those that have too many parameters or have parameters
+ of unknown type.
+ 2. Filter the set of overloads to only contain those with the closest number of
parameters.
For example, if we are called with 3 parameters and there are 2 overloads that
take 2 parameters and one that takes 3, eliminate the 2 parameter overloads.
- 3. Find the best remaining overload based on its match score.
+ 3. Find the best remaining overload based on its match score.
If two or more overloads have the same match score, call the last one. The match
score is constructed by adding the matchScore() result for each of the parameters.
*/
@@ -1431,7 +1428,7 @@ static QV4::ReturnedValue CallOverloaded(QObject *object, const QQmlPropertyData
continue; // We already have a better option
int methodMatchScore = 0;
- for (int ii = 0; ii < methodArgumentCount; ++ii)
+ for (int ii = 0; ii < methodArgumentCount; ++ii)
methodMatchScore += MatchScore((v = callArgs->args[ii]), methodArgTypes[ii]);
if (bestParameterScore > methodParameterScore || bestMatchScore > methodMatchScore) {
@@ -1453,7 +1450,7 @@ static QV4::ReturnedValue CallOverloaded(QObject *object, const QQmlPropertyData
QString error = QLatin1String("Unable to determine callable overload. Candidates are:");
const QQmlPropertyData *candidate = &data;
while (candidate) {
- error += QLatin1String("\n ") +
+ error += QLatin1String("\n ") +
QString::fromUtf8(object->metaObject()->method(candidate->coreIndex).methodSignature().constData());
candidate = RelatedMethod(object, candidate, dummy);
}
@@ -1488,7 +1485,7 @@ void CallArgument::cleanup()
jsonObjectPtr->~QJsonObject();
} else if (type == QMetaType::QJsonValue) {
jsonValuePtr->~QJsonValue();
- }
+ }
}
void *CallArgument::dataPtr()
@@ -1595,7 +1592,7 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::ValueRe
if (array) {
Scoped<QV4::QObjectWrapper> qobjectWrapper(scope);
- uint32_t length = array->arrayLength();
+ uint32_t length = array->getLength();
for (uint32_t ii = 0; ii < length; ++ii) {
QObject *o = 0;
qobjectWrapper = array->getIndexed(ii);
@@ -1692,10 +1689,9 @@ QV4::ReturnedValue CallArgument::toValue(QV8Engine *engine)
QList<QObject *> &list = *qlistPtr;
QV4::Scoped<ArrayObject> array(scope, v4->newArrayObject());
array->arrayReserve(list.count());
- for (int ii = 0; ii < list.count(); ++ii) {
- array->arrayData[ii].value = QV4::QObjectWrapper::wrap(v4, list.at(ii));
- array->arrayDataLen = ii + 1;
- }
+ QV4::ScopedValue v(scope);
+ for (int ii = 0; ii < list.count(); ++ii)
+ array->arrayPut(ii, (v = QV4::QObjectWrapper::wrap(v4, list.at(ii))));
array->setArrayLengthUnchecked(list.count());
return array.asReturnedValue();
} else if (type == qMetaTypeId<QQmlV4Handle>()) {
@@ -1709,7 +1705,8 @@ QV4::ReturnedValue CallArgument::toValue(QV8Engine *engine)
} else if (type == -1 || type == qMetaTypeId<QVariant>()) {
QVariant value = *qvariantPtr;
QV4::ScopedValue rv(scope, engine->fromVariant(value));
- if (QV4::Referenced<QObjectWrapper> qobjectWrapper = rv->asRef<QV4::QObjectWrapper>()) {
+ QV4::QObjectWrapperRef qobjectWrapper = rv;
+ if (!!qobjectWrapper) {
if (QObject *object = qobjectWrapper->object())
QQmlData::get(object, true)->setImplicitDestructible();
}
@@ -1729,7 +1726,7 @@ QObjectMethod::QObjectMethod(ExecutionContext *scope, QObject *object, int index
, m_object(object)
, m_index(index)
{
- setVTable(&static_vtbl);
+ setVTable(staticVTable());
subtype = WrappedQtMethod;
m_qmlGlobal = qmlGlobal;
}
@@ -1843,17 +1840,17 @@ ReturnedValue QObjectMethod::callInternal(CallData *callData)
}
}
-DEFINE_MANAGED_VTABLE(QObjectMethod);
+DEFINE_OBJECT_VTABLE(QObjectMethod);
QmlSignalHandler::QmlSignalHandler(ExecutionEngine *engine, QObject *object, int signalIndex)
: Object(engine)
, m_object(object)
, m_signalIndex(signalIndex)
{
- setVTable(&static_vtbl);
+ setVTable(staticVTable());
}
-DEFINE_MANAGED_VTABLE(QmlSignalHandler);
+DEFINE_OBJECT_VTABLE(QmlSignalHandler);
void MultiplyWrappedQObjectMap::insert(QObject *key, Object *value)
{