From 769d8ca7167cb108d82d3afbbd1cdfec23716375 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 8 Nov 2011 11:27:04 +0000 Subject: [PATCH] Don't crash on invalid expression Task-number: QTBUG-21310 Change-Id: I93de1c520b6f1c2aa3842e1091bcf2b34d9b0420 Reviewed-by: Kent Hansen --- src/declarative/qml/qdeclarativeexpression.cpp | 1 + .../qdeclarativeexpression/tst_qdeclarativeexpression.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index b178045..0895ffa 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -151,6 +151,7 @@ QDeclarativeExpressionPrivate::evalFunction(QDeclarativeContextData *ctxt, QObje v8::TryCatch tc; v8::Local scopeobject = ep->v8engine()->qmlScope(ctxt, scope); v8::Local script = ep->v8engine()->qmlModeCompile(code, filename, line); + if (tc.HasCaught()) return v8::Persistent(); v8::Local result = script->Run(scopeobject); if (tc.HasCaught()) return v8::Persistent(); if (qmlscope) *qmlscope = qPersistentNew(scopeobject); diff --git a/tests/auto/declarative/qdeclarativeexpression/tst_qdeclarativeexpression.cpp b/tests/auto/declarative/qdeclarativeexpression/tst_qdeclarativeexpression.cpp index a05c06f..a65045b 100644 --- a/tests/auto/declarative/qdeclarativeexpression/tst_qdeclarativeexpression.cpp +++ b/tests/auto/declarative/qdeclarativeexpression/tst_qdeclarativeexpression.cpp @@ -54,6 +54,7 @@ public: private slots: void scriptString(); + void syntaxError(); }; class TestObject : public QObject @@ -106,6 +107,15 @@ void tst_qdeclarativeexpression::scriptString() QCOMPARE(error.line(), 8); } +// QTBUG-21310 - crash test +void tst_qdeclarativeexpression::syntaxError() +{ + QDeclarativeEngine engine; + QDeclarativeExpression expression(engine.rootContext(), 0, "asd asd"); + QVariant v = expression.evaluate(); + QCOMPARE(v, QVariant()); +} + QTEST_MAIN(tst_qdeclarativeexpression) #include "tst_qdeclarativeexpression.moc" -- 2.7.4