TreeFrogFramework  2.8
tjsmodule.h
Go to the documentation of this file.
1 #pragma once
2 #include <QDir>
3 #include <QJSValue>
4 #include <QMap>
5 #include <QMutex>
6 #include <QObject>
7 #include <QString>
8 #include <QStringList>
9 #include <TGlobal>
10 
11 class QJSEngine;
12 class TJSInstance;
13 
14 
15 class T_CORE_EXPORT TJSModule : public QObject {
16 public:
17  TJSModule(QObject *parent = nullptr);
18  virtual ~TJSModule();
19 
20  QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1);
21  QJSValue call(const QString &func, const QJSValue &arg);
22  QJSValue call(const QString &func, const QJSValueList &args = QJSValueList());
23  TJSInstance callAsConstructor(const QString &constructorName, const QJSValue &arg);
24  TJSInstance callAsConstructor(const QString &constructorName, const QJSValueList &args = QJSValueList());
25  QString modulePath() const { return _modulePath; }
26 
27  QJSValue import(const QString &moduleName);
28  QJSValue import(const QString &defaultMember, const QString &moduleName);
29 
30 private:
31  QJSEngine *_jsEngine;
32  QMap<QString, QString> _loadedFiles;
33  QJSValue *_funcObj;
34  QString _lastFunc;
35  QString _modulePath;
36 #if QT_VERSION < 0x060000
37  QMutex _mutex {QMutex::Recursive};
38 #else
39  QRecursiveMutex _mutex;
40 #endif
41 
44 
45  friend class TJSLoader;
46  friend class TReactComponent;
47 };
The TJSInstance class acts as a instance for JavaScript data types.
Definition: tjsinstance.h:7
The TJSLoader class loads a JavaScript module in server side.
Definition: tjsloader.h:8
The TJSModule class represents a module for evaluating JavaScript code.
Definition: tjsmodule.h:15
QString modulePath() const
Definition: tjsmodule.h:25
#define T_CORE_EXPORT
Definition: tdeclexport.h:28
#define T_DISABLE_COPY(Class)
Definition: tdeclexport.h:37
#define T_DISABLE_MOVE(Class)
Definition: tdeclexport.h:41