diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-05-23 14:57:09 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-06-14 19:08:51 +0200 |
commit | d4d197d06279f9257647628f7e1ccc9ec763a6bb (patch) | |
tree | fb2a69b85cb1d7aee173267062421058d5e9d57c /src/qml/jsruntime/qv4script.cpp | |
parent | 67191c2b3213259c6eaf045154e9370faa085868 (diff) |
Simplify errors and diagnostics
We only need two classes to describe all possible diagnostics:
* A low-level private POD DiagnosticMessage. This is easily copied and
passed around internally. It doesn't need to adhere to a stable API
and it doesn't carry any extra baggage.
* The high-level public QQmlError with its stable interface. This can
internally also use a DiagnosticMessage as storage.
Change-Id: I52be88d9b5d9855a661b8032b01eedb43a0fb0b3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4script.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index ee7f4dff0b..4dc5030fb0 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -108,10 +108,10 @@ void Script::parse() const auto diagnosticMessages = parser.diagnosticMessages(); for (const DiagnosticMessage &m : diagnosticMessages) { if (m.isError()) { - valueScope.engine->throwSyntaxError(m.message, sourceFile, m.loc.startLine, m.loc.startColumn); + valueScope.engine->throwSyntaxError(m.message, sourceFile, m.line, m.column); return; } else { - qWarning() << sourceFile << ':' << m.loc.startLine << ':' << m.loc.startColumn + qWarning() << sourceFile << ':' << m.line << ':' << m.column << ": warning: " << m.message; } } @@ -203,10 +203,19 @@ QV4::CompiledData::CompilationUnit Script::precompile( Codegen cg(unitGenerator, /*strict mode*/false); cg.generateFromProgram(fileName, finalUrl, source, program, module, contextType); - errors = cg.qmlErrors(); - if (!errors.isEmpty()) { - if (reportedErrors) - *reportedErrors << errors; + const auto v4Errors = cg.errors(); + if (!v4Errors.isEmpty()) { + const QUrl url = cg.url(); + if (reportedErrors) { + for (const auto &v4Error : v4Errors) { + QQmlError error; + error.setUrl(url); + error.setLine(v4Error.line); + error.setColumn(v4Error.column); + error.setDescription(v4Error.message); + reportedErrors->append(error); + } + } return nullptr; } |