diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-11-29 11:05:04 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-11-29 11:38:51 +0000 |
commit | 2fa1c92cb7e60f89e200eff48cf7e76d8d2febe6 (patch) | |
tree | 4b3218530ade7938bc25adcc4c43a6126866b29c /src/qml/jsruntime | |
parent | 597ce09c7a1d8b89e9473faae900321ef2d4181d (diff) |
Fix parsing of js files via Qt.include()
Make sure to parse them as JavaScript, not as QML, so that certain
keywords such as char or double map to identifiers as expected.
Also removed an unused function.
Fixes: QTBUG-71524
Change-Id: Ie8a8dabe717ee12def6af512943e6d01efcf9876
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4include.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 18 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script_p.h | 6 |
3 files changed, 4 insertions, 22 deletions
diff --git a/src/qml/jsruntime/qv4include.cpp b/src/qml/jsruntime/qv4include.cpp index e456879d9c..36569b0a60 100644 --- a/src/qml/jsruntime/qv4include.cpp +++ b/src/qml/jsruntime/qv4include.cpp @@ -166,7 +166,7 @@ void QV4Include::finished() QmlIR::Document::removeScriptPragmas(code); QV4::Scoped<QV4::QmlContext> qml(scope, m_qmlContext.value()); - QV4::Script script(v4, qml, code, m_url.toString()); + QV4::Script script(v4, qml, /*parse as QML binding*/false, code, m_url.toString()); script.parse(); if (!scope.engine->hasException) diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 951675b468..f80db86be5 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -240,23 +240,7 @@ Script *Script::createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlCo QString sourceCode = QString::fromUtf8(data); QmlIR::Document::removeScriptPragmas(sourceCode); - auto result = new QV4::Script(engine, qmlContext, sourceCode, originalUrl.toString()); + auto result = new QV4::Script(engine, qmlContext, /*parseAsBinding*/false, sourceCode, originalUrl.toString()); result->parse(); return result; } - -QV4::ReturnedValue Script::evaluate(ExecutionEngine *engine, const QString &script, QmlContext *qmlContext) -{ - QV4::Scope scope(engine); - QV4::Script qmlScript(engine, qmlContext, script, QString()); - - qmlScript.parse(); - QV4::ScopedValue result(scope); - if (!scope.engine->hasException) - result = qmlScript.run(); - if (scope.engine->hasException) { - scope.engine->catchException(); - return Encode::undefined(); - } - return result->asReturnedValue(); -} diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index c138e4a538..a1e9b83a8b 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -73,10 +73,10 @@ struct Q_QML_EXPORT Script { : sourceFile(source), line(line), column(column), sourceCode(sourceCode) , context(scope), strictMode(false), inheritContext(false), parsed(false), contextType(mode) , vmFunction(nullptr), parseAsBinding(false) {} - Script(ExecutionEngine *engine, QmlContext *qml, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0) + Script(ExecutionEngine *engine, QmlContext *qml, bool parseAsBinding, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0) : sourceFile(source), line(line), column(column), sourceCode(sourceCode) , context(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false) - , vmFunction(nullptr), parseAsBinding(true) { + , vmFunction(nullptr), parseAsBinding(parseAsBinding) { if (qml) qmlContext.set(engine, *qml); } @@ -106,8 +106,6 @@ struct Q_QML_EXPORT Script { QList<QQmlError> *reportedErrors = nullptr, QV4::Compiler::ContextType contextType = QV4::Compiler::ContextType::Global); static Script *createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlContext, const QString &fileName, const QUrl &originalUrl, QString *error); - - static ReturnedValue evaluate(ExecutionEngine *engine, const QString &script, QmlContext *qmlContext); }; } |