5#include <private/qv4mm_p.h>
11#include <private/qqmljsengine_p.h>
12#include <private/qqmljslexer_p.h>
13#include <private/qqmljsparser_p.h>
14#include <private/qqmljsast_p.h>
15#include <private/qqmlengine_p.h>
16#include <private/qqmlsourcecoordinate_p.h>
17#include <private/qv4profiling_p.h>
20#include <QtCore/QDebug>
21#include <QtCore/QString>
22#include <QScopedValueRollback>
29 , compilationUnit(compilationUnit), parseAsBinding(true)
57 static const int snippetLength = 70;
58 qWarning() <<
"Warning: Using function expressions as statements in scripts is not compliant with the ECMAScript specification:\n"
60 <<
"\nThis will throw a syntax error in Qt 5.12. If you want a function expression, surround it by parentheses.";
68 const bool parsed = parser.parseProgram();
70 const auto diagnosticMessages = parser.diagnosticMessages();
73 valueScope.engine->throwSyntaxError(
m.message,
sourceFile,
m.loc.startLine,
m.loc.startColumn);
77 <<
": warning: " <<
m.message;
83 Program *
program = AST::cast<Program *>(parser.rootNode());
120 QScopedValueRollback<Function*> savedGlobalCode(
engine->globalCode,
vmFunction);
126 return vmFunction->call(thisObject,
nullptr, 0, qml);
146 Lexer lexer(jsEngine);
150 parser.parseProgram();
153 if (!errors.isEmpty()) {
155 *reportedErrors << errors;
166 Codegen cg(unitGenerator,
false);
169 if (reportedErrors) {
170 const auto v4Error = cg.
error();
173 error.setLine(qmlConvertSourceCoordinate<quint32, int>(v4Error.loc.startLine));
174 error.setColumn(qmlConvertSourceCoordinate<quint32, int>(v4Error.loc.startColumn));
175 error.setDescription(v4Error.message);
176 reportedErrors->append(
error);
190 const ExecutionEngine::DiskCacheOptions options =
engine->diskCacheOptions();
200 QQmlRefPointer<QV4::ExecutableCompilationUnit> jsUnit
201 =
engine->insertCompilationUnit(
202 QQml::makeRefPointer<QV4::CompiledData::CompilationUnit>(
203 cachedUnit->qmlData, cachedUnit->aotCompiledFunctions));
211 *
error = originalUrl.toString() +
QString::fromUtf8(
" was compiled ahead of time with an incompatible version of Qt and the original source code cannot be found. Please recompile");
213 *
error =
QString::fromUtf8(
"Error opening source file %1: %2").arg(originalUrl.toString()).arg(
f.errorString());
QJSValue globalObject() const
Returns this engine's Global Object.
static QList< QQmlError > qmlErrorFromDiagnostics(const QString &fileName, const QList< QQmlJS::DiagnosticMessage > &diagnosticMessages)
The QQmlError class encapsulates a QML error.
void setCode(const QString &code, int lineno, bool qmlMode=true, CodeContinuation codeContinuation=CodeContinuation::Reset)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString left(qsizetype n) const &
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setUseFastLookups(bool b)
QQmlRefPointer< QV4::CompiledData::CompilationUnit > generateCompilationUnit(bool generateUnitData=true)
void generateFromProgram(const QString &fileName, const QString &finalUrl, const QString &sourceCode, QQmlJS::AST::Program *ast, Module *module, ContextType contextType=ContextType::Global)
QQmlJS::DiagnosticMessage error() const
ReturnedValue value() const
void set(ExecutionEngine *engine, const Value &value)
DBusConnection const char DBusError * error
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei GLsizei GLchar * source
GLenum GLenum GLsizei void GLsizei void * column
QQmlContext * qmlContext(const QObject *obj)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static constexpr ReturnedValue undefined()
QQmlRefPointer< ExecutableCompilationUnit > insertCompilationUnit(QQmlRefPointer< QV4::CompiledData::CompilationUnit > &&unit)
QV4::Debugging::Debugger * debugger() const
ReturnedValue throwError(const Value &value)
Heap::Object * newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column)
ExecutionEngine * engine() const
Script(ExecutionContext *scope, QV4::Compiler::ContextType mode, const QString &sourceCode, const QString &source=QString(), int line=1, int column=0)
ReturnedValue run(const QV4::Value *thisObject=nullptr)
QV4::Compiler::ContextType contextType
QV4::PersistentValue qmlContext
static Script * createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlContext, const QString &fileName, const QUrl &originalUrl, QString *error)
static QQmlRefPointer< QV4::CompiledData::CompilationUnit > precompile(QV4::Compiler::Module *module, QQmlJS::Engine *jsEngine, Compiler::JSUnitGenerator *unitGenerator, const QString &fileName, const QString &finalUrl, const QString &source, QList< QQmlError > *reportedErrors=nullptr, QV4::Compiler::ContextType contextType=QV4::Compiler::ContextType::Global)
ExecutionContext * context
QQmlRefPointer< ExecutableCompilationUnit > compilationUnit
QV4::WriteBarrier::Pointer< Function > vmFunction