From 7ae701ff4759bdfd12953c6f4d785c2d9241690f Mon Sep 17 00:00:00 2001 From: Jedrzej Nowacki Date: Wed, 19 Aug 2009 16:26:58 +0200 Subject: Fix QScriptValue::objectId(). QScriptValue id were made persistent. It depands on JSC:JSValue JSCell pointer not on QScriptValuePrivate attr. Reviewed-by: Kent Hansen --- src/script/api/qscriptengine.cpp | 5 ++--- src/script/api/qscriptengine_p.h | 2 -- src/script/api/qscriptvalue.cpp | 4 ++-- src/script/api/qscriptvalue_p.h | 9 ++++++++- tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 1 - 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 5ef07b9..3556c05 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -807,7 +807,7 @@ private: } // namespace QScript QScriptEnginePrivate::QScriptEnginePrivate() - : inEval(false), idGenerator(1) + : inEval(false) { qMetaTypeId(); @@ -1392,7 +1392,6 @@ bool QScriptEnginePrivate::scriptDisconnect(JSC::JSValue signal, JSC::JSValue re #endif void QScriptEnginePrivate::registerScriptValue(QScriptValuePrivate *value) { - value->id=idGenerator.fetchAndAddRelaxed(1); attachedScriptValues.insert(value); } @@ -3725,7 +3724,7 @@ QScriptValue QScriptEngine::objectById(qint64 id) const Q_D(const QScriptEngine); QSet::const_iterator i = d->attachedScriptValues.constBegin(); while(i != d->attachedScriptValues.constEnd()) { - if ( (*i)->id == id ) + if ( (*i)->objectId() == id ) return QScriptValuePrivate::get(*i); i++; } diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index bc1dc92..64af653 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -250,8 +250,6 @@ public: QSet attachedScriptValues; //keep trace to all QScriptValue evalueted - QAtomicInt idGenerator; //generate id for QScriptValue - #ifndef QT_NO_QOBJECT QHash m_qobjectData; #endif diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 7021cbc..edcb6ac 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -275,7 +275,7 @@ qsreal ToInteger(qsreal n) } // namespace QScript -QScriptValuePrivate::QScriptValuePrivate() : engine(this), valid(true), id(-1) +QScriptValuePrivate::QScriptValuePrivate() : engine(this), valid(true) { ref = 0; } @@ -2547,6 +2547,6 @@ void QScriptValue::setScriptClass(QScriptClass *scriptClass) */ qint64 QScriptValue::objectId() const { - return d_ptr?d_ptr->id:-1; + return d_ptr?d_ptr->objectId():-1; } QT_END_NAMESPACE diff --git a/src/script/api/qscriptvalue_p.h b/src/script/api/qscriptvalue_p.h index 43d48f3..7c1d538 100644 --- a/src/script/api/qscriptvalue_p.h +++ b/src/script/api/qscriptvalue_p.h @@ -148,6 +148,14 @@ public: engine=0; } + qint64 objectId() + { + if ( (type == JSC) && (valid) && (engine) ) + return (qint64)jscValue.asCell(); + else + return -1; + } + static void saveException(JSC::ExecState*, JSC::JSValue*); static void restoreException(JSC::ExecState*, JSC::JSValue); @@ -160,7 +168,6 @@ public: QBasicAtomicInt ref; bool valid; //object is valid ? - qint64 id; //object unique id number }; diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index 4b8dadd..3fafce9 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -3312,7 +3312,6 @@ void tst_QScriptValue::objectId() QVERIFY(globalObjectId != -1); QVERIFY(eng.objectById(globalObjectId).strictlyEquals(global)); } - QEXPECT_FAIL("", "In JSC back-end, the Global Object's ID does not persist", Continue); QVERIFY(eng.objectById(globalObjectId).strictlyEquals(eng.globalObject())); } -- cgit v0.12