summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorRobert Griebl <rgriebl@trolltech.com>2009-06-10 11:46:23 (GMT)
committerRobert Griebl <rgriebl@trolltech.com>2009-06-10 11:46:23 (GMT)
commit7604f8087f88171ef933d8ae08f501467e647338 (patch)
tree51d071f462ed48d0b25884d9f62b8ba11c5dff13 /src/script
parent8c265860b41214daade7c8a28237c1e07ea71a3c (diff)
downloadQt-7604f8087f88171ef933d8ae08f501467e647338.zip
Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.gz
Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.bz2
Make Qt exception safer.
Squashed commit of the branch haralds-haralds-qt-s60-topics/topic/exceptions, which also contains the full history. Rev-By: Harald Fernengel Rev-By: Ralf Engels
Diffstat (limited to 'src/script')
-rw-r--r--src/script/qscriptable.cpp2
-rw-r--r--src/script/qscriptable.h4
-rw-r--r--src/script/qscriptclass.cpp2
-rw-r--r--src/script/qscriptclass.h3
-rw-r--r--src/script/qscriptclasspropertyiterator.cpp2
-rw-r--r--src/script/qscriptclasspropertyiterator.h3
-rw-r--r--src/script/qscriptcontext.cpp2
-rw-r--r--src/script/qscriptcontext.h3
-rw-r--r--src/script/qscriptcontextinfo.cpp23
-rw-r--r--src/script/qscriptcontextinfo.h3
-rw-r--r--src/script/qscriptengine.cpp20
-rw-r--r--src/script/qscriptengine.h5
-rw-r--r--src/script/qscriptengineagent.cpp2
-rw-r--r--src/script/qscriptengineagent.h3
-rw-r--r--src/script/qscriptstring.cpp48
-rw-r--r--src/script/qscriptstring.h5
-rw-r--r--src/script/qscriptvalue.cpp76
-rw-r--r--src/script/qscriptvalue.h8
-rw-r--r--src/script/qscriptvalue_p.h2
-rw-r--r--src/script/qscriptvalueiterator.cpp18
-rw-r--r--src/script/qscriptvalueiterator.h4
21 files changed, 106 insertions, 132 deletions
diff --git a/src/script/qscriptable.cpp b/src/script/qscriptable.cpp
index a6401d6..56291d8 100644
--- a/src/script/qscriptable.cpp
+++ b/src/script/qscriptable.cpp
@@ -118,8 +118,6 @@ QScriptable::QScriptable()
*/
QScriptable::~QScriptable()
{
- delete d_ptr;
- d_ptr = 0;
}
/*!
diff --git a/src/script/qscriptable.h b/src/script/qscriptable.h
index f990db2..d09b945 100644
--- a/src/script/qscriptable.h
+++ b/src/script/qscriptable.h
@@ -46,6 +46,8 @@
#ifndef QT_NO_SCRIPT
+#include <QtCore/qscopedpointer.h>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -73,7 +75,7 @@ public:
QScriptValue argument(int index) const;
private:
- QScriptablePrivate *d_ptr;
+ QScopedPointer<QScriptablePrivate> d_ptr;
Q_DISABLE_COPY(QScriptable)
Q_DECLARE_PRIVATE(QScriptable)
diff --git a/src/script/qscriptclass.cpp b/src/script/qscriptclass.cpp
index 14b8add..535a530 100644
--- a/src/script/qscriptclass.cpp
+++ b/src/script/qscriptclass.cpp
@@ -457,8 +457,6 @@ QScriptClass::QScriptClass(QScriptEngine *engine, QScriptClassPrivate &dd)
*/
QScriptClass::~QScriptClass()
{
- delete d_ptr;
- d_ptr = 0;
}
/*!
diff --git a/src/script/qscriptclass.h b/src/script/qscriptclass.h
index 9c06ea2..77e9b08 100644
--- a/src/script/qscriptclass.h
+++ b/src/script/qscriptclass.h
@@ -47,6 +47,7 @@
#ifndef QT_NO_SCRIPT
#include <QtCore/qvariant.h>
+#include <QtCore/qscopedpointer.h>
#include <QtScript/qscriptvalue.h>
QT_BEGIN_HEADER
@@ -103,7 +104,7 @@ public:
protected:
QScriptClass(QScriptEngine *engine, QScriptClassPrivate &dd);
- QScriptClassPrivate *d_ptr;
+ QScopedPointer<QScriptClassPrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QScriptClass)
diff --git a/src/script/qscriptclasspropertyiterator.cpp b/src/script/qscriptclasspropertyiterator.cpp
index 96f34d5..f328e14 100644
--- a/src/script/qscriptclasspropertyiterator.cpp
+++ b/src/script/qscriptclasspropertyiterator.cpp
@@ -111,8 +111,6 @@ QScriptClassPropertyIterator::QScriptClassPropertyIterator(const QScriptValue &o
*/
QScriptClassPropertyIterator::~QScriptClassPropertyIterator()
{
- delete d_ptr;
- d_ptr = 0;
}
/*!
diff --git a/src/script/qscriptclasspropertyiterator.h b/src/script/qscriptclasspropertyiterator.h
index 2041a65..05d49d8 100644
--- a/src/script/qscriptclasspropertyiterator.h
+++ b/src/script/qscriptclasspropertyiterator.h
@@ -46,6 +46,7 @@
#ifndef QT_NO_SCRIPT
+#include <QtCore/qscopedpointer.h>
#include <QtScript/qscriptvalue.h>
QT_BEGIN_HEADER
@@ -80,7 +81,7 @@ public:
protected:
QScriptClassPropertyIterator(const QScriptValue &object, QScriptClassPropertyIteratorPrivate &dd);
- QScriptClassPropertyIteratorPrivate *d_ptr;
+ QScopedPointer<QScriptClassPropertyIteratorPrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QScriptClassPropertyIterator)
diff --git a/src/script/qscriptcontext.cpp b/src/script/qscriptcontext.cpp
index 020601b..0b72342 100644
--- a/src/script/qscriptcontext.cpp
+++ b/src/script/qscriptcontext.cpp
@@ -219,8 +219,6 @@ QScriptContext::QScriptContext():
*/
QScriptContext::~QScriptContext()
{
- delete d_ptr;
- d_ptr = 0;
}
/*!
diff --git a/src/script/qscriptcontext.h b/src/script/qscriptcontext.h
index 1e1f987..25a2198 100644
--- a/src/script/qscriptcontext.h
+++ b/src/script/qscriptcontext.h
@@ -46,6 +46,7 @@
#ifndef QT_NO_SCRIPT
+#include <QtCore/qscopedpointer.h>
#include <QtScript/qscriptvalue.h>
QT_BEGIN_HEADER
@@ -111,7 +112,7 @@ public:
private:
QScriptContext();
- QScriptContextPrivate *d_ptr;
+ QScopedPointer<QScriptContextPrivate> d_ptr;
Q_DECLARE_PRIVATE(QScriptContext)
Q_DISABLE_COPY(QScriptContext)
diff --git a/src/script/qscriptcontextinfo.cpp b/src/script/qscriptcontextinfo.cpp
index 260d19f..0fa5c62 100644
--- a/src/script/qscriptcontextinfo.cpp
+++ b/src/script/qscriptcontextinfo.cpp
@@ -204,13 +204,12 @@ QScriptContextInfoPrivate::~QScriptContextInfoPrivate()
previously created QScriptContextInfo.
*/
QScriptContextInfo::QScriptContextInfo(const QScriptContext *context)
+ : d_ptr(0)
{
if (context) {
- d_ptr = new QScriptContextInfoPrivate(context);
+ d_ptr.data_ptr() = new QScriptContextInfoPrivate(context);
d_ptr->q_ptr = this;
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
@@ -218,7 +217,7 @@ QScriptContextInfo::QScriptContextInfo(const QScriptContext *context)
Constructs a new QScriptContextInfo from the \a other info.
*/
QScriptContextInfo::QScriptContextInfo(const QScriptContextInfo &other)
- : d_ptr(other.d_ptr)
+ : d_ptr(other.d_ptr.data())
{
if (d_ptr)
d_ptr->ref.ref();
@@ -239,10 +238,6 @@ QScriptContextInfo::QScriptContextInfo()
*/
QScriptContextInfo::~QScriptContextInfo()
{
- if (d_ptr && !d_ptr->ref.deref()) {
- delete d_ptr;
- d_ptr = 0;
- }
}
/*!
@@ -251,15 +246,7 @@ QScriptContextInfo::~QScriptContextInfo()
*/
QScriptContextInfo &QScriptContextInfo::operator=(const QScriptContextInfo &other)
{
- if (d_ptr == other.d_ptr)
- return *this;
- if (d_ptr && !d_ptr->ref.deref()) {
- delete d_ptr;
- d_ptr = 0;
- }
- d_ptr = other.d_ptr;
- if (d_ptr)
- d_ptr->ref.ref();
+ d_ptr.assign(other.d_ptr.data());
return *this;
}
@@ -510,7 +497,7 @@ QDataStream &operator<<(QDataStream &out, const QScriptContextInfo &info)
Q_SCRIPT_EXPORT QDataStream &operator>>(QDataStream &in, QScriptContextInfo &info)
{
if (!info.d_ptr) {
- info.d_ptr = new QScriptContextInfoPrivate();
+ info.d_ptr.data_ptr() = new QScriptContextInfoPrivate();
info.d_ptr->ref.ref();
}
diff --git a/src/script/qscriptcontextinfo.h b/src/script/qscriptcontextinfo.h
index a683733..20b6607 100644
--- a/src/script/qscriptcontextinfo.h
+++ b/src/script/qscriptcontextinfo.h
@@ -48,6 +48,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qstringlist.h>
+#include <QtCore/qscopedpointer.h>
QT_BEGIN_HEADER
@@ -104,7 +105,7 @@ public:
bool operator!=(const QScriptContextInfo &other) const;
private:
- QScriptContextInfoPrivate *d_ptr;
+ QScopedSharedPointer<QScriptContextInfoPrivate> d_ptr;
Q_DECLARE_PRIVATE(QScriptContextInfo)
};
diff --git a/src/script/qscriptengine.cpp b/src/script/qscriptengine.cpp
index d8908ed..2a36104 100644
--- a/src/script/qscriptengine.cpp
+++ b/src/script/qscriptengine.cpp
@@ -330,10 +330,6 @@ QScriptEngine::~QScriptEngine()
Q_D(QScriptEngine);
d->m_frameRepository.release(currentContext());
d->objectAllocator.destruct();
-#ifdef QT_NO_QOBJECT
- delete d_ptr;
- d_ptr = 0;
-#endif
}
/*!
@@ -1777,7 +1773,7 @@ QScriptValue QScriptEngine::objectById(qint64 id) const
Constructs a new QScriptSyntaxCheckResult from the \a other result.
*/
QScriptSyntaxCheckResult::QScriptSyntaxCheckResult(const QScriptSyntaxCheckResult &other)
- : d_ptr(other.d_ptr)
+ : d_ptr(other.d_ptr.data())
{
if (d_ptr)
d_ptr->ref.ref();
@@ -1806,10 +1802,6 @@ QScriptSyntaxCheckResult::QScriptSyntaxCheckResult()
*/
QScriptSyntaxCheckResult::~QScriptSyntaxCheckResult()
{
- if (d_ptr && !d_ptr->ref.deref()) {
- delete d_ptr;
- d_ptr = 0;
- }
}
/*!
@@ -1863,15 +1855,7 @@ QString QScriptSyntaxCheckResult::errorMessage() const
*/
QScriptSyntaxCheckResult &QScriptSyntaxCheckResult::operator=(const QScriptSyntaxCheckResult &other)
{
- if (d_ptr == other.d_ptr)
- return *this;
- if (d_ptr && !d_ptr->ref.deref()) {
- delete d_ptr;
- d_ptr = 0;
- }
- d_ptr = other.d_ptr;
- if (d_ptr)
- d_ptr->ref.ref();
+ d_ptr.assign(other.d_ptr.data());
return *this;
}
diff --git a/src/script/qscriptengine.h b/src/script/qscriptengine.h
index afd551b..c55caac 100644
--- a/src/script/qscriptengine.h
+++ b/src/script/qscriptengine.h
@@ -47,6 +47,7 @@
#ifndef QT_NO_SCRIPT
#include <QtCore/qvariant.h>
+#include <QtCore/qscopedpointer.h>
#ifndef QT_NO_QOBJECT
#include <QtCore/qobject.h>
@@ -114,7 +115,7 @@ public:
private:
QScriptSyntaxCheckResult();
QScriptSyntaxCheckResult(QScriptSyntaxCheckResultPrivate *d);
- QScriptSyntaxCheckResultPrivate *d_ptr;
+ QScopedSharedPointer<QScriptSyntaxCheckResultPrivate> d_ptr;
Q_DECLARE_PRIVATE(QScriptSyntaxCheckResult)
friend class QScriptEnginePrivate;
@@ -282,7 +283,7 @@ private:
protected:
#ifdef QT_NO_QOBJECT
- QScriptEnginePrivate *d_ptr;
+ QScopedPointer<QScriptEnginePrivate> d_ptr;
QScriptEngine(QScriptEnginePrivate &dd);
#else
diff --git a/src/script/qscriptengineagent.cpp b/src/script/qscriptengineagent.cpp
index bda94ae..c3eaf96 100644
--- a/src/script/qscriptengineagent.cpp
+++ b/src/script/qscriptengineagent.cpp
@@ -173,8 +173,6 @@ QScriptEngineAgent::QScriptEngineAgent(QScriptEngineAgentPrivate &dd, QScriptEng
*/
QScriptEngineAgent::~QScriptEngineAgent()
{
- delete d_ptr;
- d_ptr = 0;
}
/*!
diff --git a/src/script/qscriptengineagent.h b/src/script/qscriptengineagent.h
index 3334bc0..461d756 100644
--- a/src/script/qscriptengineagent.h
+++ b/src/script/qscriptengineagent.h
@@ -47,6 +47,7 @@
#ifndef QT_NO_SCRIPT
#include <QtCore/qvariant.h>
+#include <QtCore/qscopedpointer.h>
QT_BEGIN_HEADER
@@ -96,7 +97,7 @@ public:
protected:
QScriptEngineAgent(QScriptEngineAgentPrivate &dd, QScriptEngine *engine);
- QScriptEngineAgentPrivate *d_ptr;
+ QScopedPointer<QScriptEngineAgentPrivate> d_ptr;
private:
Q_DECLARE_PRIVATE(QScriptEngineAgent)
diff --git a/src/script/qscriptstring.cpp b/src/script/qscriptstring.cpp
index 69b0796..e7591e1 100644
--- a/src/script/qscriptstring.cpp
+++ b/src/script/qscriptstring.cpp
@@ -54,6 +54,29 @@
QT_BEGIN_NAMESPACE
+/*! \internal */
+struct QScriptStringPrivatePointerHandler
+{
+ static inline void cleanup(QScriptStringPrivate *d)
+ {
+ if (!d || d->ref.deref())
+ return;
+
+ if (d->nameId) {
+ d->engine->uninternString(d);
+ } else {
+ // the engine has already been deleted
+ delete d;
+ }
+ }
+
+ static inline void reset(QScriptStringPrivate *&d, QScriptStringPrivate *other)
+ {
+ cleanup(d);
+ d = other;
+ }
+};
+
/*!
\since 4.4
\class QScriptString
@@ -108,8 +131,8 @@ QScriptStringPrivate *QScriptStringPrivate::get(const QScriptString &q)
void QScriptStringPrivate::init(QScriptString &q, QScriptStringPrivate *d)
{
Q_ASSERT(q.d_ptr == 0);
- q.d_ptr = d;
- q.d_ptr->ref.ref();
+ q.d_ptr.data_ptr() = d;
+ d->ref.ref();
}
/*!
@@ -124,7 +147,7 @@ QScriptString::QScriptString()
Constructs a new QScriptString that is a copy of \a other.
*/
QScriptString::QScriptString(const QScriptString &other)
- : d_ptr(other.d_ptr)
+ : d_ptr(other.d_ptr.data())
{
if (d_ptr)
d_ptr->ref.ref();
@@ -135,15 +158,6 @@ QScriptString::QScriptString(const QScriptString &other)
*/
QScriptString::~QScriptString()
{
- if (d_ptr && !d_ptr->ref.deref()) {
- if (isValid()) {
- d_ptr->engine->uninternString(d_ptr);
- } else {
- // the engine has already been deleted
- delete d_ptr;
- }
- d_ptr = 0;
- }
}
/*!
@@ -153,15 +167,7 @@ QScriptString &QScriptString::operator=(const QScriptString &other)
{
if (d_ptr == other.d_ptr)
return *this;
- if (d_ptr && !d_ptr->ref.deref()) {
- if (isValid()) {
- d_ptr->engine->uninternString(d_ptr);
- } else {
- // the engine has already been deleted
- delete d_ptr;
- }
- }
- d_ptr = other.d_ptr;
+ d_ptr.reset(other.d_ptr.data());
if (d_ptr)
d_ptr->ref.ref();
return *this;
diff --git a/src/script/qscriptstring.h b/src/script/qscriptstring.h
index d2fecd8..f68be0c 100644
--- a/src/script/qscriptstring.h
+++ b/src/script/qscriptstring.h
@@ -46,6 +46,8 @@
#ifndef QT_NO_SCRIPT
+#include <QtCore/qscopedpointer.h>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -54,6 +56,7 @@ QT_MODULE(Script)
class QScriptEngine;
class QScriptStringPrivate;
+struct QScriptStringPrivatePointerHandler;
class Q_SCRIPT_EXPORT QScriptString
{
@@ -73,7 +76,7 @@ public:
operator QString() const;
private:
- QScriptStringPrivate *d_ptr;
+ QScopedCustomPointer<QScriptStringPrivate, QScriptStringPrivatePointerHandler> d_ptr;
Q_DECLARE_PRIVATE(QScriptString)
};
diff --git a/src/script/qscriptvalue.cpp b/src/script/qscriptvalue.cpp
index a253985..4282248 100644
--- a/src/script/qscriptvalue.cpp
+++ b/src/script/qscriptvalue.cpp
@@ -57,6 +57,28 @@
QT_BEGIN_NAMESPACE
+/*! \internal
+ */
+struct QScriptValuePrivatePointerHandler
+{
+ static inline void cleanup(QScriptValuePrivate *d)
+ {
+ if (!d || d->ref.deref())
+ return;
+ if (d->engine) {
+ QScriptEnginePrivate::get(d->engine)->unregisterValue(d);
+ } else {
+ delete d;
+ }
+ }
+
+ static inline void reset(QScriptValuePrivate *&d, QScriptValuePrivate *other)
+ {
+ cleanup(d);
+ d = other;
+ }
+};
+
/*!
\since 4.3
\class QScriptValue
@@ -194,14 +216,6 @@ QScriptValue::QScriptValue()
*/
QScriptValue::~QScriptValue()
{
- if (d_ptr && !d_ptr->ref.deref()) {
- if (engine()) {
- QScriptEnginePrivate::get(engine())->unregisterValue(d_ptr);
- } else {
- delete d_ptr;
- }
- d_ptr = 0;
- }
}
/*!
@@ -212,7 +226,7 @@ QScriptValue::~QScriptValue()
the new script value (i.e., the object itself is not copied).
*/
QScriptValue::QScriptValue(const QScriptValue &other)
- : d_ptr(other.d_ptr)
+ : d_ptr(other.d_ptr.data())
{
if (d_ptr)
d_ptr->ref.ref();
@@ -225,13 +239,12 @@ QScriptValue::QScriptValue(const QScriptValue &other)
registers it with the script \a engine.
*/
QScriptValue::QScriptValue(QScriptEngine *engine, QScriptValue::SpecialValue value)
+ : d_ptr(0)
{
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
- d_ptr = eng_p->registerValue(QScriptValueImpl(value));
+ d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(value));
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
@@ -244,13 +257,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, QScriptValue::SpecialValue val
registers it with the script \a engine.
*/
QScriptValue::QScriptValue(QScriptEngine *engine, bool val)
+ : d_ptr(0)
{
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
- d_ptr = eng_p->registerValue(QScriptValueImpl(val));
+ d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val));
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
@@ -262,13 +274,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, bool val)
registers it with the script \a engine.
*/
QScriptValue::QScriptValue(QScriptEngine *engine, int val)
+ : d_ptr(0)
{
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
- d_ptr = eng_p->registerValue(QScriptValueImpl(val));
+ d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val));
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
@@ -280,13 +291,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, int val)
registers it with the script \a engine.
*/
QScriptValue::QScriptValue(QScriptEngine *engine, uint val)
+ : d_ptr(0)
{
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
- d_ptr = eng_p->registerValue(QScriptValueImpl(val));
+ d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val));
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
@@ -298,13 +308,12 @@ QScriptValue::QScriptValue(QScriptEngine *engine, uint val)
registers it with the script \a engine.
*/
QScriptValue::QScriptValue(QScriptEngine *engine, qsreal val)
+ : d_ptr(0)
{
if (engine) {
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
- d_ptr = eng_p->registerValue(QScriptValueImpl(val));
+ d_ptr.data_ptr() = eng_p->registerValue(QScriptValueImpl(val));
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
@@ -316,15 +325,14 @@ QScriptValue::QScriptValue(QScriptEngine *engine, qsreal val)
registers it with the script \a engine.
*/
QScriptValue::QScriptValue(QScriptEngine *engine, const QString &val)
+ : d_ptr(0)
{
if (engine) {
QScriptValueImpl v;
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
eng_p->newString(&v, val);
- d_ptr = eng_p->registerValue(v);
+ d_ptr.data_ptr() = eng_p->registerValue(v);
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
@@ -338,15 +346,14 @@ QScriptValue::QScriptValue(QScriptEngine *engine, const QString &val)
#ifndef QT_NO_CAST_FROM_ASCII
QScriptValue::QScriptValue(QScriptEngine *engine, const char *val)
+ : d_ptr(0)
{
if (engine) {
QScriptValueImpl v;
QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);
eng_p->newString(&v, QString::fromAscii(val));
- d_ptr = eng_p->registerValue(v);
+ d_ptr.data_ptr() = eng_p->registerValue(v);
d_ptr->ref.ref();
- } else {
- d_ptr = 0;
}
}
#endif
@@ -464,14 +471,7 @@ QScriptValue &QScriptValue::operator=(const QScriptValue &other)
{
if (d_ptr == other.d_ptr)
return *this;
- if (d_ptr && !d_ptr->ref.deref()) {
- if (engine()) {
- QScriptEnginePrivate::get(engine())->unregisterValue(d_ptr);
- } else {
- delete d_ptr;
- }
- }
- d_ptr = other.d_ptr;
+ d_ptr.reset(other.d_ptr.data());
if (d_ptr)
d_ptr->ref.ref();
return *this;
diff --git a/src/script/qscriptvalue.h b/src/script/qscriptvalue.h
index 306da53..76b1186 100644
--- a/src/script/qscriptvalue.h
+++ b/src/script/qscriptvalue.h
@@ -47,6 +47,7 @@
#ifndef QT_NO_SCRIPT
#include <QtCore/qlist.h>
+#include <QtCore/qscopedpointer.h>
QT_BEGIN_HEADER
@@ -71,6 +72,7 @@ typedef QList<QScriptValue> QScriptValueList;
typedef double qsreal;
class QScriptValuePrivate;
+struct QScriptValuePrivatePointerHandler;
class Q_SCRIPT_EXPORT QScriptValue
{
public:
@@ -216,12 +218,12 @@ public:
private:
// force compile error, prevent QScriptValue(bool) to be called
- inline QScriptValue(void *) { Q_ASSERT(false); }
+ inline QScriptValue(void *);
// force compile error, prevent QScriptValue(QScriptEngine*, bool) to be called
- inline QScriptValue(QScriptEngine *, void *) { Q_ASSERT(false); }
+ inline QScriptValue(QScriptEngine *, void *);
private:
- QScriptValuePrivate *d_ptr;
+ QScopedCustomPointer<QScriptValuePrivate, QScriptValuePrivatePointerHandler> d_ptr;
Q_DECLARE_PRIVATE(QScriptValue)
};
diff --git a/src/script/qscriptvalue_p.h b/src/script/qscriptvalue_p.h
index 8463ed2..6528464 100644
--- a/src/script/qscriptvalue_p.h
+++ b/src/script/qscriptvalue_p.h
@@ -91,7 +91,7 @@ inline QScriptValueImpl QScriptValuePrivate::valueOf(const QScriptValue &value)
inline void QScriptValuePrivate::init(QScriptValue &value, QScriptValuePrivate *p)
{
- value.d_ptr = p;
+ value.d_ptr.data_ptr() = p;
value.d_ptr->ref.ref();
}
diff --git a/src/script/qscriptvalueiterator.cpp b/src/script/qscriptvalueiterator.cpp
index 1a60632..2cf5575 100644
--- a/src/script/qscriptvalueiterator.cpp
+++ b/src/script/qscriptvalueiterator.cpp
@@ -115,12 +115,11 @@ QScriptValueIteratorPrivate::~QScriptValueIteratorPrivate()
first property).
*/
QScriptValueIterator::QScriptValueIterator(const QScriptValue &object)
+ : d_ptr(0)
{
QScriptValueImpl val = QScriptValuePrivate::valueOf(object);
- if (!val.isObject()) {
- d_ptr = 0;
- } else {
- d_ptr = new QScriptValueIteratorPrivate();
+ if (val.isObject()) {
+ d_ptr.reset(new QScriptValueIteratorPrivate());
d_ptr->it = new QScriptValueIteratorImpl(val);
}
}
@@ -130,10 +129,6 @@ QScriptValueIterator::QScriptValueIterator(const QScriptValue &object)
*/
QScriptValueIterator::~QScriptValueIterator()
{
- if (d_ptr) {
- delete d_ptr;
- d_ptr = 0;
- }
}
/*!
@@ -311,13 +306,10 @@ void QScriptValueIterator::remove()
*/
QScriptValueIterator& QScriptValueIterator::operator=(QScriptValue &object)
{
- if (d_ptr) {
- delete d_ptr;
- d_ptr = 0;
- }
+ d_ptr.reset();
QScriptValueImpl val = QScriptValuePrivate::valueOf(object);
if (val.isObject()) {
- d_ptr = new QScriptValueIteratorPrivate();
+ d_ptr.reset(new QScriptValueIteratorPrivate());
d_ptr->it = new QScriptValueIteratorImpl(val);
}
return *this;
diff --git a/src/script/qscriptvalueiterator.h b/src/script/qscriptvalueiterator.h
index 91561e8..082158d 100644
--- a/src/script/qscriptvalueiterator.h
+++ b/src/script/qscriptvalueiterator.h
@@ -46,6 +46,8 @@
#ifndef QT_NO_SCRIPT
+#include <QtCore/qscopedpointer.h>
+
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@@ -84,7 +86,7 @@ public:
QScriptValueIterator& operator=(QScriptValue &value);
private:
- QScriptValueIteratorPrivate *d_ptr;
+ QScopedPointer<QScriptValueIteratorPrivate> d_ptr;
Q_DECLARE_PRIVATE(QScriptValueIterator)
Q_DISABLE_COPY(QScriptValueIterator)