aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-16 13:06:22 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-17 11:06:18 +0000
commit4b2b1fc12137450d34e8324c0dbe2af1e90b9e6a (patch)
tree9e397602b5f584032cdc29354c0fcf485766cce2 /src/qml/jsruntime
parent29e4b97bad6511ebd6aa009a47594395957c0e8e (diff)
Add support for compiling ES modules ahead of time
This is also pretty straight-forward by adding .mjs as supported extension in the qmake and cmake support. This also tweaks qv4engine.cpp to share the same module compilation function across all code paths. Change-Id: Ia0e23c78a794f2330ecf8f991ee6ea948f4ac89d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/jsruntime.pri2
-rw-r--r--src/qml/jsruntime/qv4engine.cpp53
-rw-r--r--src/qml/jsruntime/qv4engine_p.h4
3 files changed, 32 insertions, 27 deletions
diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri
index c42c2d48c8..97819438cb 100644
--- a/src/qml/jsruntime/jsruntime.pri
+++ b/src/qml/jsruntime/jsruntime.pri
@@ -3,7 +3,6 @@ INCLUDEPATH += $$OUT_PWD
!qmldevtools_build {
SOURCES += \
- $$PWD/qv4engine.cpp \
$$PWD/qv4context.cpp \
$$PWD/qv4persistent.cpp \
$$PWD/qv4lookup.cpp \
@@ -147,6 +146,7 @@ HEADERS += \
$$PWD/qv4value_p.h
SOURCES += \
+ $$PWD/qv4engine.cpp \
$$PWD/qv4runtime.cpp \
$$PWD/qv4string.cpp \
$$PWD/qv4value.cpp \
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index c5eec33d18..ea17f3423c 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -37,6 +37,22 @@
**
****************************************************************************/
#include <qv4engine_p.h>
+
+#include <private/qqmljslexer_p.h>
+#include <private/qqmljsparser_p.h>
+#include <private/qqmljsast_p.h>
+#include <private/qv4compileddata_p.h>
+#include <private/qv4compiler_p.h>
+#include <private/qv4compilercontext_p.h>
+#include <private/qv4codegen_p.h>
+
+#include <QtCore/QTextStream>
+#include <QDateTime>
+#include <QDir>
+#include <QFileInfo>
+
+#ifndef V4_BOOTSTRAP
+
#include <qv4qmlcontext_p.h>
#include <qv4value_p.h>
#include <qv4object_p.h>
@@ -75,10 +91,6 @@
#include "qv4reflect_p.h"
#include "qv4proxy_p.h"
#include "qv4stackframe_p.h"
-#include <private/qqmljsengine_p.h>
-#include <private/qqmljslexer_p.h>
-#include <private/qqmljsparser_p.h>
-#include <private/qqmljsast_p.h>
#if QT_CONFIG(qml_sequence_object)
#include "qv4sequenceobject_p.h"
@@ -102,11 +114,6 @@
#endif
#include <qqmlfile.h>
-#include <QtCore/QTextStream>
-#include <QDateTime>
-#include <QDir>
-#include <QFileInfo>
-
#if USE(PTHREADS)
# include <pthread.h>
#if !defined(Q_OS_INTEGRITY)
@@ -121,10 +128,14 @@
#include <valgrind/memcheck.h>
#endif
+#endif // #ifndef V4_BOOTSTRAP
+
QT_BEGIN_NAMESPACE
using namespace QV4;
+#ifndef V4_BOOTSTRAP
+
static QBasicAtomicInt engineSerial = Q_BASIC_ATOMIC_INITIALIZER(1);
ReturnedValue throwTypeError(const FunctionObject *b, const QV4::Value *, const QV4::Value *, int)
@@ -132,19 +143,6 @@ ReturnedValue throwTypeError(const FunctionObject *b, const QV4::Value *, const
return b->engine()->throwTypeError();
}
-
-#ifdef V4_BOOTSTRAP
-QJSEngine *ExecutionEngine::jsEngine() const
-{
- return publicEngine;
-}
-
-QQmlEngine *ExecutionEngine::qmlEngine() const
-{
- return v8Engine->engine();
-}
-#endif // V4_BOOTSTRAP
-
qint32 ExecutionEngine::maxCallDepth = -1;
ExecutionEngine::ExecutionEngine(QJSEngine *jsEngine)
@@ -1645,7 +1643,7 @@ QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(con
QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp)
{
QList<QQmlJS::DiagnosticMessage> diagnostics;
- auto unit = compileModule(/*debugMode*/debugger() != nullptr, url, sourceCode, sourceTimeStamp, &diagnostics);
+ auto unit = compileModule(/*debugMode*/debugger() != nullptr, url.toString(), sourceCode, sourceTimeStamp, &diagnostics);
for (const QQmlJS::DiagnosticMessage &m : diagnostics) {
if (m.isError()) {
throwSyntaxError(m.message, url.toString(), m.loc.startLine, m.loc.startColumn);
@@ -1658,7 +1656,9 @@ QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(con
return unit;
}
-QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(bool debugMode, const QUrl &url, const QString &sourceCode,
+#endif // ifndef V4_BOOTSTRAP
+
+QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(bool debugMode, const QString &url, const QString &sourceCode,
const QDateTime &sourceTimeStamp, QList<QQmlJS::DiagnosticMessage> *diagnostics)
{
QQmlJS::Engine ee;
@@ -1689,7 +1689,7 @@ QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(boo
compilerModule.sourceTimeStamp = sourceTimeStamp;
JSUnitGenerator jsGenerator(&compilerModule);
Codegen cg(&jsGenerator, /*strictMode*/true);
- cg.generateFromModule(url.toString(), url.toString(), sourceCode, moduleNode, &compilerModule);
+ cg.generateFromModule(url, url, sourceCode, moduleNode, &compilerModule);
auto errors = cg.errors();
if (diagnostics)
*diagnostics << errors;
@@ -1700,6 +1700,8 @@ QQmlRefPointer<CompiledData::CompilationUnit> ExecutionEngine::compileModule(boo
return cg.generateCompilationUnit();
}
+#ifndef V4_BOOTSTRAP
+
void ExecutionEngine::injectModule(const QQmlRefPointer<CompiledData::CompilationUnit> &moduleUnit)
{
// Injection can happen from the QML type loader thread for example, but instantiation and
@@ -1982,5 +1984,6 @@ static QObject *qtObjectFromJS(QV4::ExecutionEngine *engine, const QV4::Value &v
return wrapper->object();
}
+#endif // ifndef V4_BOOTSTRAP
QT_END_NAMESPACE
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index c8f8efaebf..7608c04800 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -55,6 +55,8 @@
#include "qv4context_p.h"
#include <private/qintrusivelist_p.h>
#include "qv4enginebase_p.h"
+#include <private/qqmlrefcount_p.h>
+#include <private/qqmljsengine_p.h>
#ifndef V4_BOOTSTRAP
# include "qv4function_p.h"
@@ -575,10 +577,10 @@ public:
double localTZA = 0.0; // local timezone, initialized at startup
+ static QQmlRefPointer<CompiledData::CompilationUnit> compileModule(bool debugMode, const QString &url, const QString &sourceCode, const QDateTime &sourceTimeStamp, QList<QQmlJS::DiagnosticMessage> *diagnostics);
#ifndef V4_BOOTSTRAP
QQmlRefPointer<CompiledData::CompilationUnit> compileModule(const QUrl &url);
QQmlRefPointer<CompiledData::CompilationUnit> compileModule(const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp);
- static QQmlRefPointer<CompiledData::CompilationUnit> compileModule(bool debugMode, const QUrl &url, const QString &sourceCode, const QDateTime &sourceTimeStamp, QList<QQmlJS::DiagnosticMessage> *diagnostics);
mutable QMutex moduleMutex;
QHash<QUrl, QQmlRefPointer<CompiledData::CompilationUnit>> modules;