Don't crash on invalid expression
authorAaron Kennedy <aaron.kennedy@nokia.com>
Tue, 8 Nov 2011 11:27:04 +0000 (11:27 +0000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 8 Nov 2011 12:49:28 +0000 (13:49 +0100)
Task-number: QTBUG-21310
Change-Id: I93de1c520b6f1c2aa3842e1091bcf2b34d9b0420
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>

src/declarative/qml/qdeclarativeexpression.cpp
tests/auto/declarative/qdeclarativeexpression/tst_qdeclarativeexpression.cpp

index b178045..0895ffa 100644 (file)
@@ -151,6 +151,7 @@ QDeclarativeExpressionPrivate::evalFunction(QDeclarativeContextData *ctxt, QObje
     v8::TryCatch tc;
     v8::Local<v8::Object> scopeobject = ep->v8engine()->qmlScope(ctxt, scope);
     v8::Local<v8::Script> script = ep->v8engine()->qmlModeCompile(code, filename, line);
+    if (tc.HasCaught()) return v8::Persistent<v8::Function>();
     v8::Local<v8::Value> result = script->Run(scopeobject);
     if (tc.HasCaught()) return v8::Persistent<v8::Function>();
     if (qmlscope) *qmlscope = qPersistentNew<v8::Object>(scopeobject);
index a05c06f..a65045b 100644 (file)
@@ -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"