aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-01-10 22:04:54 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2015-01-12 14:52:50 +0100
commit447844aa25754db7e868469de4537af4331709ac (patch)
tree80245a0d948e87c8cfd7a35eb5fdc93a65105ccd
parent56211be8a0429fb3e3fa268c7698e1df079aa04e (diff)
Get rid of Value::engine()
This method is not guaranteed to return an engine. We're safer checking for the value being an object first and then getting the engine from there. Change-Id: I5c95e675337e545f2421613bd31c42d1e58d6f9a Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/jsapi/qjsvalue.cpp4
-rw-r--r--src/qml/jsruntime/qv4include.cpp4
-rw-r--r--src/qml/jsruntime/qv4jsonobject.cpp6
-rw-r--r--src/qml/jsruntime/qv4objectiterator.cpp12
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp4
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp2
-rw-r--r--src/qml/jsruntime/qv4value_inl_p.h6
-rw-r--r--src/qml/jsruntime/qv4value_p.h2
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp8
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp8
10 files changed, 25 insertions, 31 deletions
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp
index 672cb23b20..d888ea3535 100644
--- a/src/qml/jsapi/qjsvalue.cpp
+++ b/src/qml/jsapi/qjsvalue.cpp
@@ -516,8 +516,8 @@ QVariant QJSValue::toVariant() const
if (d->value.isEmpty())
return d->unboundData;
- if (d->value.asObject())
- return d->value.engine()->toVariant(d->value, /*typeHint*/ -1, /*createJSValueForObjects*/ false);
+ if (Object *o = d->value.asObject())
+ return o->engine()->toVariant(d->value, /*typeHint*/ -1, /*createJSValueForObjects*/ false);
if (d->value.isString())
return QVariant(d->value.stringValue()->toQString());
diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp
index 03eb1505f4..2627e26d4b 100644
--- a/src/qml/jsruntime/qv4include.cpp
+++ b/src/qml/jsruntime/qv4include.cpp
@@ -92,9 +92,9 @@ QV4::ReturnedValue QV4Include::resultValue(QV4::ExecutionEngine *v4, Status stat
void QV4Include::callback(const QV4::ValueRef callback, const QV4::ValueRef status)
{
- QV4::ExecutionEngine *v4 = callback->engine();
- if (!v4)
+ if (!callback->isObject())
return;
+ QV4::ExecutionEngine *v4 = callback->asObject()->engine();
QV4::Scope scope(v4);
QV4::ScopedFunctionObject f(scope, callback);
if (!f)
diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp
index f320630181..0de2aa7e3b 100644
--- a/src/qml/jsruntime/qv4jsonobject.cpp
+++ b/src/qml/jsruntime/qv4jsonobject.cpp
@@ -984,9 +984,11 @@ QJsonValue JsonObject::toJsonValue(const ValueRef value,
return QJsonValue(QJsonValue::Null);
else if (value->isUndefined())
return QJsonValue(QJsonValue::Undefined);
+ else if (value->isString())
+ return QJsonValue(value->toQString());
- Q_ASSERT(value->engine());
- Scope scope(value->engine());
+ Q_ASSERT(value->isObject());
+ Scope scope(value->asObject()->engine());
ScopedArrayObject a(scope, value);
if (a)
return toJsonArray(a, visitedObjects);
diff --git a/src/qml/jsruntime/qv4objectiterator.cpp b/src/qml/jsruntime/qv4objectiterator.cpp
index f0970d160e..2ce5c98316 100644
--- a/src/qml/jsruntime/qv4objectiterator.cpp
+++ b/src/qml/jsruntime/qv4objectiterator.cpp
@@ -73,7 +73,7 @@ void ObjectIterator::init(Object *o)
#endif
if (object->as<ArgumentsObject>()) {
- Scope scope(object->engine());
+ Scope scope(engine);
Scoped<ArgumentsObject> (scope, object->asReturnedValue())->fullyCreate();
}
}
@@ -136,7 +136,7 @@ ReturnedValue ObjectIterator::nextPropertyName(ValueRef value)
PropertyAttributes attrs;
uint index;
- Scope scope(object->engine());
+ Scope scope(engine);
ScopedProperty p(scope);
ScopedString name(scope);
next(name.getRef(), &index, p, &attrs);
@@ -158,7 +158,7 @@ ReturnedValue ObjectIterator::nextPropertyNameAsString(ValueRef value)
PropertyAttributes attrs;
uint index;
- Scope scope(object->engine());
+ Scope scope(engine);
ScopedProperty p(scope);
ScopedString name(scope);
next(name.getRef(), &index, p, &attrs);
@@ -170,7 +170,7 @@ ReturnedValue ObjectIterator::nextPropertyNameAsString(ValueRef value)
if (!!name)
return name->asReturnedValue();
assert(index < UINT_MAX);
- return Encode(object->engine()->newString(QString::number(index)));
+ return Encode(engine->newString(QString::number(index)));
}
ReturnedValue ObjectIterator::nextPropertyNameAsString()
@@ -180,7 +180,7 @@ ReturnedValue ObjectIterator::nextPropertyNameAsString()
PropertyAttributes attrs;
uint index;
- Scope scope(object->engine());
+ Scope scope(engine);
ScopedProperty p(scope);
ScopedString name(scope);
next(name.getRef(), &index, p, &attrs);
@@ -190,7 +190,7 @@ ReturnedValue ObjectIterator::nextPropertyNameAsString()
if (!!name)
return name->asReturnedValue();
Q_ASSERT(index < UINT_MAX);
- return Encode(object->engine()->newString(QString::number(index)));
+ return Encode(engine->newString(QString::number(index)));
}
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 3f3e49918d..284d20d975 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -96,8 +96,8 @@ static QPair<QObject *, int> extractQtMethod(QV4::FunctionObject *function)
static QPair<QObject *, int> extractQtSignal(const ValueRef value)
{
- QV4::ExecutionEngine *v4 = value->engine();
- if (v4) {
+ if (value->isObject()) {
+ QV4::ExecutionEngine *v4 = value->asObject()->engine();
QV4::Scope scope(v4);
QV4::ScopedFunctionObject function(scope, value);
if (function)
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp
index a60a44642f..8c6d28305f 100644
--- a/src/qml/jsruntime/qv4sequenceobject.cpp
+++ b/src/qml/jsruntime/qv4sequenceobject.cpp
@@ -650,7 +650,7 @@ QVariant SequencePrototype::toVariant(const QV4::ValueRef array, int typeHint, b
*succeeded = false;
return QVariant();
}
- QV4::Scope scope(array->engine());
+ QV4::Scope scope(array->asObject()->engine());
QV4::ScopedArrayObject a(scope, array);
FOREACH_QML_SEQUENCE_TYPE(SEQUENCE_TO_VARIANT) { /* else */ *succeeded = false; return QVariant(); }
diff --git a/src/qml/jsruntime/qv4value_inl_p.h b/src/qml/jsruntime/qv4value_inl_p.h
index ea69c265fd..a551ac7e6b 100644
--- a/src/qml/jsruntime/qv4value_inl_p.h
+++ b/src/qml/jsruntime/qv4value_inl_p.h
@@ -70,12 +70,6 @@ inline String *Value::asString() const
return 0;
}
-inline ExecutionEngine *Value::engine() const
-{
- Managed *m = asManaged();
- return m ? m->engine() : 0;
-}
-
inline void Value::mark(ExecutionEngine *e) const
{
if (!val)
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h
index 526cb01ac4..8fff22ed86 100644
--- a/src/qml/jsruntime/qv4value_p.h
+++ b/src/qml/jsruntime/qv4value_p.h
@@ -379,8 +379,6 @@ struct Q_QML_PRIVATE_EXPORT Value
inline uint asArrayIndex() const;
inline uint asArrayLength(bool *ok) const;
- inline ExecutionEngine *engine() const;
-
ReturnedValue asReturnedValue() const { return val; }
static Value fromReturnedValue(ReturnedValue val) { Value v; v.val = val; return v; }
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index f3551d8488..78a77f79d4 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -102,10 +102,10 @@ QQmlContextData *QmlContextWrapper::callingContext(ExecutionEngine *v4)
QQmlContextData *QmlContextWrapper::getContext(const ValueRef value)
{
- QV4::ExecutionEngine *v4 = value->engine();
- if (!v4)
+ if (!value->isObject())
return 0;
+ QV4::ExecutionEngine *v4 = value->asObject()->engine();
Scope scope(v4);
QV4::Scoped<QmlContextWrapper> c(scope, value);
@@ -114,9 +114,9 @@ QQmlContextData *QmlContextWrapper::getContext(const ValueRef value)
void QmlContextWrapper::takeContextOwnership(const ValueRef qmlglobal)
{
- QV4::ExecutionEngine *v4 = qmlglobal->engine();
- Q_ASSERT(v4);
+ Q_ASSERT(qmlglobal->isObject());
+ QV4::ExecutionEngine *v4 = qmlglobal->asObject()->engine();
Scope scope(v4);
QV4::Scoped<QmlContextWrapper> c(scope, qmlglobal);
Q_ASSERT(c);
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 0f4d115f5e..88cb086d32 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -1630,10 +1630,10 @@ bool QQmlDelegateModelPrivate::insert(Compositor::insert_iterator &before, const
QQmlDelegateModelItem *cacheItem = m_adaptorModel.createItem(m_cacheMetaType, m_context->engine(), -1);
if (!cacheItem)
return false;
- QV4::ExecutionEngine *v4 = object->engine();
- if (!v4)
+ if (!object->isObject())
return false;
+ QV4::ExecutionEngine *v4 = object->asObject()->engine();
QV4::Scope scope(v4);
QV4::ScopedObject o(scope, object);
if (!o)
@@ -2502,10 +2502,10 @@ bool QQmlDelegateModelGroupPrivate::parseIndex(const QV4::ValueRef value, int *i
return true;
}
- QV4::ExecutionEngine *v4 = value->engine();
- if (!v4)
+ if (!value->isObject())
return false;
+ QV4::ExecutionEngine *v4 = value->asObject()->engine();
QV4::Scope scope(v4);
QV4::Scoped<QQmlDelegateModelItemObject> object(scope, value);