TreeFrogFramework  1.18
tjsloader.h
Go to the documentation of this file.
1 #ifndef TJSLOADER_H
2 #define TJSLOADER_H
3 
4 #include <QJSValue>
5 #include <TGlobal>
6 #include <TJSModule>
7 #include <TJSInstance>
8 
9 
11 {
12 public:
13  enum AltJS {
14  Default = 0, // JavaScript (ES5)
15  Jsx,
16  };
17 
18  TJSLoader(const QString &moduleName, AltJS alt = Default);
19  TJSLoader(const QString &defaultMember, const QString &moduleName, AltJS alt = Default);
20 
21  TJSModule *load(bool reload = false);
22  void import(const QString &moduleName);
23  void import(const QString &defaultMember, const QString &moduleName);
24  TJSInstance loadAsConstructor(const QJSValue &arg) const;
25  TJSInstance loadAsConstructor(const QJSValueList &args = QJSValueList()) const;
26 
27  void setSearchPaths(const QStringList &paths);
28  static void setDefaultSearchPaths(const QStringList &paths);
29  static QStringList defaultSearchPaths();
30  static QString compileJsx(const QString &jsx);
31 
32 protected:
33  QJSValue importTo(TJSModule *context, bool isMain) const;
34  QString search(const QString &moduleName, AltJS alt) const;
35  QString absolutePath(const QString &moduleName, const QDir &dir, AltJS alt) const;
36  void replaceRequire(TJSModule *context, QString &content, const QDir &dir) const;
37 
38 private:
39  QString module;
40  AltJS altJs;
41  QString member;
42  QStringList searchPaths;
43  QList<QPair<QString, QString>> importFiles;
44 
45  friend class TJSModule;
46 };
47 
48 #endif // TJSLOADER_H
#define T_CORE_EXPORT
Definition: tglobal.h:81
Definition: tjsloader.h:15
The TJSModule class represents a module for evaluating JavaScript code.
Definition: tjsmodule.h:17
The TJSLoader class loads a JavaScript module at run-time.
Definition: tjsloader.h:10
AltJS
Definition: tjsloader.h:13
The TJSInstance class acts as a instance for JavaScript data types.
Definition: tjsinstance.h:9