2021-03-31 10:36:45 +08:00
|
|
|
#ifndef V8EXECUTOR_H
|
|
|
|
#define V8EXECUTOR_H
|
|
|
|
|
|
|
|
#include "libplatform/libplatform.h"
|
2021-04-07 09:43:35 +08:00
|
|
|
#include "v8.h"
|
2021-03-31 10:36:45 +08:00
|
|
|
|
2021-04-02 15:16:18 +08:00
|
|
|
#include <QMap>
|
2021-03-31 10:36:45 +08:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
2021-04-02 15:16:18 +08:00
|
|
|
static QMap<QString, QPair<QObject *, QString>> *map =
|
|
|
|
new QMap<QString, QPair<QObject *, QString>>();
|
|
|
|
|
2021-03-31 10:36:45 +08:00
|
|
|
class V8Executor {
|
|
|
|
|
|
|
|
private:
|
2021-03-31 16:25:11 +08:00
|
|
|
std::unique_ptr<v8::Platform> platform;
|
2021-03-31 10:36:45 +08:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
v8::Isolate *m_isolate;
|
|
|
|
v8::Isolate::Scope *m_isolate_scope;
|
|
|
|
v8::Global<v8::Context> *m_global_context;
|
|
|
|
|
2021-03-31 17:56:47 +08:00
|
|
|
void injectObject(const char *string, v8::Local<v8::Value> local);
|
|
|
|
|
2021-03-31 10:36:45 +08:00
|
|
|
v8::Local<v8::Value> innerExec(const char *script, const char *source,
|
|
|
|
std::string *exception_str);
|
|
|
|
|
2021-04-02 15:16:18 +08:00
|
|
|
void injectFunctions(const char *objectName, const char *functionName,
|
|
|
|
bool hashKey);
|
|
|
|
|
2021-04-02 17:23:36 +08:00
|
|
|
v8::Local<v8::Value> invokeMethod(const char *objectName,
|
|
|
|
const char *functionName, int argc,
|
|
|
|
v8::Local<v8::Value> argv[],
|
|
|
|
std::string *exception_str);
|
|
|
|
|
2021-03-31 10:36:45 +08:00
|
|
|
public:
|
|
|
|
V8Executor();
|
|
|
|
|
|
|
|
~V8Executor();
|
|
|
|
|
|
|
|
QString loadJS(QString script, QString source);
|
|
|
|
|
2021-04-02 15:16:18 +08:00
|
|
|
void injectGlobalJSObject(QString name, std::string target);
|
|
|
|
|
|
|
|
void injectGlobalJSFunction(QString name, QObject *function,
|
|
|
|
QString property);
|
2021-04-02 17:23:36 +08:00
|
|
|
|
|
|
|
void invokeObject(QString objectName, QString functionName,
|
|
|
|
QVariantList arguments);
|
2021-03-31 10:36:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // V8EXECUTOR_H
|