aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsapi
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-01-14 12:50:34 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2015-01-21 18:22:47 +0100
commitd8131513b07d3f0a6d749c9961b294fc955fed6d (patch)
tree8d757fffe19623bd1ea78a40240dc41c25b81a8f /src/qml/jsapi
parent630f118f043edb88501e387d779c62c86b1030d4 (diff)
Add C++11 move operators, and a simpler internal constructor
Move semantics should optimize some copy operations on QJSValues, and the internal constructor will simplify refactoring the QJSValue class to get rid of the extra allocated private. Change-Id: I24863b30523af2432aa81ad6b87fda7fe35749c4 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r--src/qml/jsapi/qjsengine.cpp12
-rw-r--r--src/qml/jsapi/qjsvalue.cpp22
-rw-r--r--src/qml/jsapi/qjsvalue.h13
-rw-r--r--src/qml/jsapi/qjsvalueiterator.cpp2
4 files changed, 31 insertions, 18 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp
index d54af28f26..e82849746f 100644
--- a/src/qml/jsapi/qjsengine.cpp
+++ b/src/qml/jsapi/qjsengine.cpp
@@ -317,7 +317,7 @@ QJSValue QJSEngine::evaluate(const QString& program, const QString& fileName, in
result = v4->catchException();
if (ctx->d() != v4->rootContext())
v4->popContext();
- return new QJSValuePrivate(v4, result);
+ return QJSValue(v4, result.asReturnedValue());
}
/*!
@@ -332,7 +332,7 @@ QJSValue QJSEngine::newObject()
{
QV4::Scope scope(d->m_v4Engine);
QV4::ScopedValue v(scope, d->m_v4Engine->newObject());
- return new QJSValuePrivate(d->m_v4Engine, v);
+ return QJSValue(d->m_v4Engine, v.asReturnedValue());
}
/*!
@@ -347,7 +347,7 @@ QJSValue QJSEngine::newArray(uint length)
if (length < 0x1000)
array->arrayReserve(length);
array->setArrayLengthUnchecked(length);
- return new QJSValuePrivate(d->m_v4Engine, array);
+ return QJSValue(d->m_v4Engine, array.asReturnedValue());
}
/*!
@@ -381,7 +381,7 @@ QJSValue QJSEngine::newQObject(QObject *object)
QQmlEngine::setObjectOwnership(object, QQmlEngine::JavaScriptOwnership);
}
QV4::ScopedValue v(scope, QV4::QObjectWrapper::wrap(v4, object));
- return new QJSValuePrivate(v4, v);
+ return QJSValue(v4, v.asReturnedValue());
}
/*!
@@ -399,7 +399,7 @@ QJSValue QJSEngine::globalObject() const
Q_D(const QJSEngine);
QV4::Scope scope(d->m_v4Engine);
QV4::ScopedValue v(scope, d->m_v4Engine->globalObject());
- return new QJSValuePrivate(d->m_v4Engine, v);
+ return QJSValue(d->m_v4Engine, v.asReturnedValue());
}
/*!
@@ -411,7 +411,7 @@ QJSValue QJSEngine::create(int type, const void *ptr)
Q_D(QJSEngine);
QV4::Scope scope(d->m_v4Engine);
QV4::ScopedValue v(scope, scope.engine->metaTypeToJS(type, ptr));
- return new QJSValuePrivate(d->m_v4Engine, v);
+ return QJSValue(d->m_v4Engine, v.asReturnedValue());
}
/*!
diff --git a/src/qml/jsapi/qjsvalue.cpp b/src/qml/jsapi/qjsvalue.cpp
index 0a29e7802c..479a2d0901 100644
--- a/src/qml/jsapi/qjsvalue.cpp
+++ b/src/qml/jsapi/qjsvalue.cpp
@@ -172,8 +172,11 @@ QJSValue::QJSValue(bool value)
{
}
-QJSValue::QJSValue(QJSValuePrivate *dd)
- : d(dd)
+/*!
+ \internal
+*/
+QJSValue::QJSValue(ExecutionEngine *e, quint64 val)
+ : d(new QJSValuePrivate(e, val))
{
}
@@ -255,7 +258,8 @@ QJSValue::QJSValue(const QJSValue& other)
*/
QJSValue::~QJSValue()
{
- d->deref();
+ if (d)
+ d->deref();
}
/*!
@@ -642,7 +646,7 @@ QJSValue QJSValue::call(const QJSValueList &args)
if (engine->hasException)
result = engine->catchException();
- return new QJSValuePrivate(engine, result);
+ return QJSValue(engine, result.asReturnedValue());
}
/*!
@@ -697,7 +701,7 @@ QJSValue QJSValue::callWithInstance(const QJSValue &instance, const QJSValueList
if (engine->hasException)
result = engine->catchException();
- return new QJSValuePrivate(engine, result);
+ return QJSValue(engine, result.asReturnedValue());
}
/*!
@@ -744,7 +748,7 @@ QJSValue QJSValue::callAsConstructor(const QJSValueList &args)
if (engine->hasException)
result = engine->catchException();
- return new QJSValuePrivate(engine, result);
+ return QJSValue(engine, result.asReturnedValue());
}
#ifdef QT_DEPRECATED
@@ -785,7 +789,7 @@ QJSValue QJSValue::prototype() const
ScopedObject p(scope, o->prototype());
if (!p)
return QJSValue(NullValue);
- return new QJSValuePrivate(o->internalClass()->engine, p);
+ return QJSValue(o->internalClass()->engine, p.asReturnedValue());
}
/*!
@@ -979,7 +983,7 @@ QJSValue QJSValue::property(const QString& name) const
if (engine->hasException)
result = engine->catchException();
- return new QJSValuePrivate(engine, result);
+ return QJSValue(engine, result.asReturnedValue());
}
/*!
@@ -1008,7 +1012,7 @@ QJSValue QJSValue::property(quint32 arrayIndex) const
QV4::ScopedValue result(scope, arrayIndex == UINT_MAX ? o->get(engine->id_uintMax) : o->getIndexed(arrayIndex));
if (engine->hasException)
engine->catchException();
- return new QJSValuePrivate(engine, result);
+ return QJSValue(engine, result.asReturnedValue());
}
/*!
diff --git a/src/qml/jsapi/qjsvalue.h b/src/qml/jsapi/qjsvalue.h
index d184cf6537..4ff86b1edc 100644
--- a/src/qml/jsapi/qjsvalue.h
+++ b/src/qml/jsapi/qjsvalue.h
@@ -41,7 +41,6 @@
QT_BEGIN_NAMESPACE
-
class QJSValue;
class QJSEngine;
class QVariant;
@@ -51,6 +50,10 @@ class QDateTime;
typedef QList<QJSValue> QJSValueList;
class QJSValuePrivate;
+namespace QV4 {
+ struct ExecutionEngine;
+ struct Value;
+}
class Q_QML_EXPORT QJSValue
{
@@ -65,6 +68,12 @@ public:
~QJSValue();
QJSValue(const QJSValue &other);
+#ifdef Q_COMPILER_RVALUE_REFS
+ inline QJSValue(QJSValue && other) : d(other.d) { other.d = 0; }
+ inline QJSValue &operator=(QJSValue &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
+
QJSValue(bool value);
QJSValue(int value);
QJSValue(uint value);
@@ -125,7 +134,7 @@ public:
QT_DEPRECATED QJSEngine *engine() const;
#endif
- QJSValue(QJSValuePrivate *dd);
+ QJSValue(QV4::ExecutionEngine *e, quint64 val);
private:
friend class QJSValuePrivate;
// force compile error, prevent QJSValue(bool) to be called
diff --git a/src/qml/jsapi/qjsvalueiterator.cpp b/src/qml/jsapi/qjsvalueiterator.cpp
index e23bd5d763..2b27f655c8 100644
--- a/src/qml/jsapi/qjsvalueiterator.cpp
+++ b/src/qml/jsapi/qjsvalueiterator.cpp
@@ -201,7 +201,7 @@ QJSValue QJSValueIterator::value() const
engine->catchException();
return QJSValue();
}
- return new QJSValuePrivate(engine, v);
+ return QJSValue(engine, v.asReturnedValue());
}