summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-07-27 08:31:21 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-07-27 10:30:23 (GMT)
commitab7c405ac2e528eb23b2c56ef02bd33c42bc3256 (patch)
treef6e90a9ede2252deb4a948c1a8dba52ebc6966e1 /tests/auto
parent39097c5d652efd3eb0946e5a215d82573a46dbf9 (diff)
downloadQt-ab7c405ac2e528eb23b2c56ef02bd33c42bc3256.zip
Qt-ab7c405ac2e528eb23b2c56ef02bd33c42bc3256.tar.gz
Qt-ab7c405ac2e528eb23b2c56ef02bd33c42bc3256.tar.bz2
QScriptEngineAgent: recompile all the function when installing a debugger.
Recompile all the function is necessary to ger the debug opcode that notifies us when the position changes. The change in CollectorHeapIterator.h is nessesary to get it work as Debugger::recompileAllJSFunctions uses LiveObjectIterator, LiveObjectIterator initialied m_cell to -1 and to ++(*this) in its constructor. But as m_cell is of type size_t (unsigned) then the < comparison will always fail as it is an unsigned comparison. This was already fixed upstream in r54672 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
index ed00b96..c30a636 100644
--- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
+++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
@@ -97,6 +97,7 @@ private slots:
void functionEntryAndExit_objectCall();
void positionChange_1();
void positionChange_2();
+ void positionChange_3();
void exceptionThrowAndCatch();
void eventOrder_assigment();
void eventOrder_functionDefinition();
@@ -1625,6 +1626,56 @@ void tst_QScriptEngineAgent::positionChange_2()
delete spy;
}
+void tst_QScriptEngineAgent::positionChange_3()
+{
+ QScriptEngine eng;
+ eng.evaluate("function some_function1(a) {\n a++; \n return a + 12; } \n some_function1(42);", "function1.qs", 12);
+ QScriptValue some_function2 = eng.evaluate("(function (b) {\n b--; \n return b + 11; })", "function2.qs", 21);
+ some_function2.call(QScriptValue(), QScriptValueList() << 2 );
+
+ // Test that the agent work, even if installed after the function has been evaluated.
+ ScriptEngineSpy *spy = new ScriptEngineSpy(&eng, ~(ScriptEngineSpy::IgnorePositionChange));
+ {
+ spy->clear();
+ QScriptValue v = eng.evaluate("some_function1(15)");
+ QCOMPARE(v.toInt32(), (15+1+12));
+ QCOMPARE(spy->count(), 3);
+
+ // some_function1()
+ QCOMPARE(spy->at(0).type, ScriptEngineEvent::PositionChange);
+ QVERIFY(spy->at(0).scriptId != -1);
+ QCOMPARE(spy->at(0).lineNumber, 1);
+
+ // a++
+ QCOMPARE(spy->at(1).type, ScriptEngineEvent::PositionChange);
+ QVERIFY(spy->at(1).scriptId != spy->at(0).scriptId);
+ QCOMPARE(spy->at(1).lineNumber, 13);
+ // return a + 12
+ QCOMPARE(spy->at(2).type, ScriptEngineEvent::PositionChange);
+ QVERIFY(spy->at(2).scriptId == spy->at(1).scriptId);
+ QCOMPARE(spy->at(2).lineNumber, 14);
+ }
+
+ {
+ spy->clear();
+ QScriptValue v = some_function2.call(QScriptValue(), QScriptValueList() << 89 );
+ QCOMPARE(v.toInt32(), (89-1+11));
+ QCOMPARE(spy->count(), 2);
+
+ // b--
+ QCOMPARE(spy->at(0).type, ScriptEngineEvent::PositionChange);
+ QVERIFY(spy->at(0).scriptId != -1);
+ QCOMPARE(spy->at(0).lineNumber, 22);
+ // return b + 11
+ QCOMPARE(spy->at(1).type, ScriptEngineEvent::PositionChange);
+ QVERIFY(spy->at(1).scriptId == spy->at(0).scriptId);
+ QCOMPARE(spy->at(1).lineNumber, 23);
+ }
+
+ QVERIFY(!eng.hasUncaughtException());
+}
+
+
void tst_QScriptEngineAgent::exceptionThrowAndCatch()
{
QScriptEngine eng;