diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-23 14:21:30 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-23 14:21:30 (GMT) |
commit | 2ce65133026e1f291f7b6b312d832acb0a4045ae (patch) | |
tree | 39cc0fce5f89ac03daf7f10659cf2748d0c4dedc /src/script/api/qscriptstring.cpp | |
parent | 268dfef13889b9a74e8bad3288791b62d20d0ff7 (diff) | |
download | Qt-2ce65133026e1f291f7b6b312d832acb0a4045ae.zip Qt-2ce65133026e1f291f7b6b312d832acb0a4045ae.tar.gz Qt-2ce65133026e1f291f7b6b312d832acb0a4045ae.tar.bz2 |
Implement QScriptString as a wraper around the JSC::Identifier
Diffstat (limited to 'src/script/api/qscriptstring.cpp')
-rw-r--r-- | src/script/api/qscriptstring.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/script/api/qscriptstring.cpp b/src/script/api/qscriptstring.cpp index ce38d81..e8a5d7e 100644 --- a/src/script/api/qscriptstring.cpp +++ b/src/script/api/qscriptstring.cpp @@ -17,6 +17,11 @@ QT_BEGIN_NAMESPACE +namespace QScript +{ + QString qtStringFromJSCUString(const JSC::UString &str); +} + /*! \since 4.4 \class QScriptString @@ -58,11 +63,12 @@ QScriptStringPrivate::~QScriptStringPrivate() /*! \internal */ -void QScriptStringPrivate::init(QScriptString &q, const QString &value) +void QScriptStringPrivate::init(QScriptString &q, QScriptEngine *engine, const JSC::Identifier &value) { Q_ASSERT(!q.isValid()); q.d_ptr = new QScriptStringPrivate(); - q.d_ptr->value = value; + q.d_ptr->identifier = value; + q.d_ptr->engine = engine; q.d_ptr->ref.ref(); } @@ -90,15 +96,6 @@ QScriptString::QScriptString(const QScriptString &other) QScriptString::~QScriptString() { if (d_ptr && !d_ptr->ref.deref()) { -// Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); -#if 0 - if (isValid()) { - d_ptr->engine->uninternString(d_ptr); - } else { - // the engine has already been deleted - delete d_ptr; - } -#endif delete d_ptr; d_ptr = 0; } @@ -112,7 +109,6 @@ QScriptString &QScriptString::operator=(const QScriptString &other) if (d_ptr == other.d_ptr) return *this; if (d_ptr && !d_ptr->ref.deref()) { -// Q_ASSERT_X(false, Q_FUNC_INFO, "not implemented"); delete d_ptr; } d_ptr = other.d_ptr; @@ -128,7 +124,7 @@ QScriptString &QScriptString::operator=(const QScriptString &other) bool QScriptString::isValid() const { Q_D(const QScriptString); - return (d != 0); + return (d && d->engine); } /*! @@ -138,9 +134,15 @@ bool QScriptString::isValid() const bool QScriptString::operator==(const QScriptString &other) const { Q_D(const QScriptString); - // ### change back once proper string handles are implemented - return toString() == other.toString(); -// return (d == other.d_func()); + if (d == other.d_func()) + return true; + if (!d || !other.d_func()) + return false; + if (d->engine != other.d_func()->engine) + return false; + if (!d->engine) + return true; + return d->identifier == other.d_func()->identifier; } /*! @@ -149,10 +151,7 @@ bool QScriptString::operator==(const QScriptString &other) const */ bool QScriptString::operator!=(const QScriptString &other) const { - Q_D(const QScriptString); - // ### change back once proper string handles are implemented - return toString() != other.toString(); -// return (d != other.d_func()); + return !operator==(other); } /*! @@ -164,9 +163,9 @@ bool QScriptString::operator!=(const QScriptString &other) const QString QScriptString::toString() const { Q_D(const QScriptString); - if (!d) + if (!d || !d->engine) return QString(); - return d->value; + return QScript::qtStringFromJSCUString(d->identifier.ustring()); } /*! |