aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2011-11-21 13:35:40 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-23 10:11:19 +0100
commit699b74dc1d288af3d1aaeb02335c10c21f37f56a (patch)
treea1d6ca0c1939d16e0f4876ac98e057801c6a741a /src
parent384fd7cdf1cb3061126c74c4f591cd2c0acdfedc (diff)
Don't crash when importing script with syntax error
Task-number: QTBUG-22843 Change-Id: I2b1ed6cbbc7a566f54b441359941ea121a9033ba Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index 19df52798e..313d7f1dc4 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -1239,8 +1239,11 @@ void QDeclarativeScriptData::initialize(QDeclarativeEngine *engine)
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
QV8Engine *v8engine = ep->v8engine();
- // XXX Handle errors during the script compile!
+ // If compilation throws an error, a surrounding v8::TryCatch will record it.
v8::Local<v8::Script> program = v8engine->qmlModeCompile(m_programSource, url.toString(), 1);
+ if (program.IsEmpty())
+ return;
+
m_program = qPersistentNew<v8::Script>(program);
addToEngine(engine);
@@ -1301,13 +1304,18 @@ v8::Persistent<v8::Object> QDeclarativeVME::run(QDeclarativeContextData *parentC
v8::HandleScope handle_scope;
v8::Context::Scope scope(v8engine->context());
- if (!script->isInitialized())
+ v8::TryCatch try_catch;
+ if (!script->isInitialized())
script->initialize(parentCtxt->engine);
v8::Local<v8::Object> qmlglobal = v8engine->qmlScope(ctxt, 0);
- v8::TryCatch try_catch;
- script->m_program->Run(qmlglobal);
+ if (!script->m_program.IsEmpty()) {
+ script->m_program->Run(qmlglobal);
+ } else {
+ // Compilation failed.
+ Q_ASSERT(try_catch.HasCaught());
+ }
v8::Persistent<v8::Object> rv;