TreeFrogFramework  1.18
tjsmodule.h
Go to the documentation of this file.
1 #ifndef TJSMODULE_H
2 #define TJSMODULE_H
3 
4 #include <QString>
5 #include <QObject>
6 #include <QStringList>
7 #include <QJSValue>
8 #include <QDir>
9 #include <QMap>
10 #include <QMutex>
11 #include <TGlobal>
12 
13 class QJSEngine;
14 class TJSInstance;
15 
16 
17 class T_CORE_EXPORT TJSModule : public QObject
18 {
19 public:
20  TJSModule(QObject *parent = nullptr);
21  virtual ~TJSModule();
22 
23  QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1);
24  QJSValue call(const QString &func, const QJSValue &arg);
25  QJSValue call(const QString &func, const QJSValueList &args = QJSValueList());
26  TJSInstance callAsConstructor(const QString &constructorName, const QJSValue &arg);
27  TJSInstance callAsConstructor(const QString &constructorName, const QJSValueList &args = QJSValueList());
28  QString modulePath() const { return moduleFilePath; }
29 
30  QJSValue import(const QString &moduleName);
31  QJSValue import(const QString &defaultMember, const QString &moduleName);
32 
33 private:
34  QJSEngine *jsEngine;
35  QMap<QString, QString> loadedFiles;
36  QJSValue *funcObj;
37  QString lastFunc;
38  QString moduleFilePath;
39  QMutex mutex;
40 
43 
44  friend class TJSLoader;
45  friend class TReactComponent;
46 };
47 
48 #endif // TJSMODULE_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
#define T_DISABLE_COPY(Class)
Definition: tglobal.h:137
The TJSModule class represents a module for evaluating JavaScript code.
Definition: tjsmodule.h:17
#define T_DISABLE_MOVE(Class)
Definition: tglobal.h:141
The TJSLoader class loads a JavaScript module at run-time.
Definition: tjsloader.h:10
The TJSInstance class acts as a instance for JavaScript data types.
Definition: tjsinstance.h:9
QString modulePath() const
Definition: tjsmodule.h:28