1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QV4SCRIPT_H
4#define QV4SCRIPT_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include "qv4global_p.h"
18#include "qv4engine_p.h"
19#include "qv4functionobject_p.h"
20#include "qv4qmlcontext_p.h"
21#include "private/qv4compilercontext_p.h"
22
23#include <QQmlError>
24
25QT_BEGIN_NAMESPACE
26
27class QQmlContextData;
28
29namespace QQmlJS {
30class Engine;
31}
32
33namespace QV4 {
34
35struct Q_QML_EXPORT Script {
36 Script(ExecutionContext *scope, QV4::Compiler::ContextType mode, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0)
37 : sourceFile(source), line(line), column(column), sourceCode(sourceCode)
38 , context(scope), strictMode(false), inheritContext(false), parsed(false), contextType(mode)
39 , vmFunction(nullptr), parseAsBinding(false) {}
40 Script(ExecutionEngine *engine, QmlContext *qml, bool parseAsBinding, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0)
41 : sourceFile(source), line(line), column(column), sourceCode(sourceCode)
42 , context(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false)
43 , vmFunction(nullptr), parseAsBinding(parseAsBinding) {
44 if (qml)
45 qmlContext.set(engine, value: *qml);
46 }
47 Script(ExecutionEngine *engine, QmlContext *qml, const QQmlRefPointer<ExecutableCompilationUnit> &compilationUnit);
48 ~Script();
49 QString sourceFile;
50 int line;
51 int column;
52 QString sourceCode;
53 ExecutionContext *context;
54 bool strictMode;
55 bool inheritContext;
56 bool parsed;
57 QV4::Compiler::ContextType contextType = QV4::Compiler::ContextType::Eval;
58 QV4::PersistentValue qmlContext;
59 QQmlRefPointer<ExecutableCompilationUnit> compilationUnit;
60 Function *vmFunction;
61 bool parseAsBinding;
62
63 void parse();
64 ReturnedValue run(const QV4::Value *thisObject = nullptr);
65
66 Function *function();
67
68 static QV4::CompiledData::CompilationUnit precompile(
69 QV4::Compiler::Module *module, QQmlJS::Engine *jsEngine,
70 Compiler::JSUnitGenerator *unitGenerator, const QString &fileName,
71 const QString &finalUrl, const QString &source,
72 QList<QQmlError> *reportedErrors = nullptr,
73 QV4::Compiler::ContextType contextType = QV4::Compiler::ContextType::Global);
74 static Script *createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlContext, const QString &fileName, const QUrl &originalUrl, QString *error);
75};
76
77}
78
79QT_END_NAMESPACE
80
81#endif
82

source code of qtdeclarative/src/qml/jsruntime/qv4script_p.h