summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptstring.cpp
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-03 14:36:15 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-03 14:36:15 (GMT)
commitf0844f9da7a834c282f6f04b2676f28de444e9dc (patch)
tree8e121429e25959043cc04c4364adbe8239e44a67 /src/script/api/qscriptstring.cpp
parentfe763ef6cd255ccb54d0de1894c1a772f959585e (diff)
parentf360180890298618ef3284c08789c2a243e1ba9d (diff)
downloadQt-f0844f9da7a834c282f6f04b2676f28de444e9dc.zip
Qt-f0844f9da7a834c282f6f04b2676f28de444e9dc.tar.gz
Qt-f0844f9da7a834c282f6f04b2676f28de444e9dc.tar.bz2
Merge commit 'qt/4.6' into kinetic-declarativeui
Diffstat (limited to 'src/script/api/qscriptstring.cpp')
-rw-r--r--src/script/api/qscriptstring.cpp64
1 files changed, 35 insertions, 29 deletions
diff --git a/src/script/api/qscriptstring.cpp b/src/script/api/qscriptstring.cpp
index 58a7c2b..94b69b9 100644
--- a/src/script/api/qscriptstring.cpp
+++ b/src/script/api/qscriptstring.cpp
@@ -39,10 +39,11 @@
**
****************************************************************************/
-#include "config.h"
+#include "config.h" // compile on Windows
#include "qscriptstring.h"
-
#include "qscriptstring_p.h"
+#include "qscriptengine.h"
+#include "qscriptengine_p.h"
QT_BEGIN_NAMESPACE
@@ -70,32 +71,6 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \internal
-*/
-QScriptStringPrivate::QScriptStringPrivate(QScriptEngine *e, const JSC::Identifier &id)
- : engine(e), identifier(id)
-{
- ref = 0;
-}
-
-/*!
- \internal
-*/
-QScriptStringPrivate::~QScriptStringPrivate()
-{
-}
-
-/*!
- \internal
-*/
-void QScriptStringPrivate::init(QScriptString &q, QScriptEngine *engine,
- const JSC::Identifier &value)
-{
- Q_ASSERT(!q.isValid());
- q.d_ptr = new QScriptStringPrivate(engine, value);
-}
-
-/*!
Constructs an invalid QScriptString.
*/
QScriptString::QScriptString()
@@ -109,6 +84,13 @@ QScriptString::QScriptString()
QScriptString::QScriptString(const QScriptString &other)
: d_ptr(other.d_ptr)
{
+ if (d_func() && (d_func()->type == QScriptStringPrivate::StackAllocated)) {
+ Q_ASSERT(d_func()->ref != 1);
+ d_ptr.detach();
+ d_func()->ref = 1;
+ d_func()->type = QScriptStringPrivate::HeapAllocated;
+ d_func()->engine->registerScriptString(d_func());
+ }
}
/*!
@@ -116,6 +98,19 @@ QScriptString::QScriptString(const QScriptString &other)
*/
QScriptString::~QScriptString()
{
+ Q_D(QScriptString);
+ if (d) {
+ switch (d->type) {
+ case QScriptStringPrivate::StackAllocated:
+ Q_ASSERT(d->ref == 1);
+ d->ref.ref(); // avoid deletion
+ break;
+ case QScriptStringPrivate::HeapAllocated:
+ if (d->engine && (d->ref == 1))
+ d->engine->unregisterScriptString(d);
+ break;
+ }
+ }
}
/*!
@@ -123,7 +118,18 @@ QScriptString::~QScriptString()
*/
QScriptString &QScriptString::operator=(const QScriptString &other)
{
+ if (d_func() && d_func()->engine && (d_func()->ref == 1) && (d_func()->type == QScriptStringPrivate::HeapAllocated)) {
+ // current d_ptr will be deleted at the assignment below, so unregister it first
+ d_func()->engine->unregisterScriptString(d_func());
+ }
d_ptr = other.d_ptr;
+ if (d_func() && (d_func()->type == QScriptStringPrivate::StackAllocated)) {
+ Q_ASSERT(d_func()->ref != 1);
+ d_ptr.detach();
+ d_func()->ref = 1;
+ d_func()->type = QScriptStringPrivate::HeapAllocated;
+ d_func()->engine->registerScriptString(d_func());
+ }
return *this;
}
@@ -147,7 +153,7 @@ bool QScriptString::operator==(const QScriptString &other) const
if (d == other.d_func())
return true;
if (!d || !other.d_func())
- return false;
+ return d == other.d_func();
if (d->engine != other.d_func()->engine)
return false;
if (!d->engine)