From e0284ab41f7a1889f28e719212df66e942959f4c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 21 Oct 2013 09:50:27 +0200 Subject: Properly propagate parse errors Replace all try/catch statements used when parsing with checks for engine->hasException. Change-Id: I4493cb600d5a3eb095c2003bb88bd031403e47c9 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4script.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/qml/jsruntime/qv4script.cpp') diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index daca700609..a2d89a3278 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -185,6 +185,7 @@ void Script::parse() foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) { if (m.isError()) { scope->throwSyntaxError(m.message, sourceFile, m.loc.startLine, m.loc.startColumn); + return; } else { qWarning() << sourceFile << ':' << m.loc.startLine << ':' << m.loc.startColumn << ": warning: " << m.message; @@ -208,6 +209,9 @@ void Script::parse() RuntimeCodegen cg(scope, strictMode); cg.generateFromProgram(sourceFile, sourceCode, program, &module, parseAsBinding ? QQmlJS::Codegen::QmlBinding : QQmlJS::Codegen::EvalCode, inheritedLocals); + if (v4->hasException) + return; + QV4::Compiler::JSUnitGenerator jsGenerator(&module); QScopedPointer isel(v4->iselFactory->create(v4->executableAllocator, &module, &jsGenerator)); if (inheritContext) @@ -378,11 +382,13 @@ QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &scr QV4::Script qmlScript(engine, scopeObject, script, QString()); QV4::ExecutionContext *ctx = engine->current; - try { - qmlScript.parse(); - return qmlScript.run(); - } catch (...) { + qmlScript.parse(); + QV4::ScopedValue result(scope); + if (!scope.engine->hasException) + result = qmlScript.run(); + if (scope.engine->hasException) { ctx->catchException(); + return Encode::undefined(); } - return Encode::undefined(); + return result.asReturnedValue(); } -- cgit v1.2.3