complete invoke method on v8
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "JSValueHelper.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
std::string JS2String(v8::Local<v8::Value> object) {
|
||||
v8::Isolate *isolate = v8::Isolate::GetCurrent();
|
||||
v8::HandleScope handleScope(isolate);
|
||||
@@ -55,3 +58,27 @@ v8::Local<v8::Value> String2JS(std::string string) {
|
||||
|
||||
return handleScope.Escape(ret);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Variant2JS(QVariant variant) {
|
||||
v8::Isolate *isolate = v8::Isolate::GetCurrent();
|
||||
v8::EscapableHandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Value> jsValue;
|
||||
if (variant.type() == QVariant::String) {
|
||||
jsValue = NewV8String(variant.toString().toUtf8().constData());
|
||||
} else if (variant.type() == QVariant::Map) {
|
||||
QMap<QString, QVariant> map = variant.toMap();
|
||||
|
||||
QJsonObject jsonObject;
|
||||
foreach (QString key, map.keys()) {
|
||||
QVariant value = map.value(key);
|
||||
jsonObject.insert(key, QJsonValue::fromVariant(value));
|
||||
}
|
||||
QJsonDocument doc(jsonObject);
|
||||
QString strJson(doc.toJson(QJsonDocument::Compact));
|
||||
jsValue = String2JS(strJson.toUtf8().constData());
|
||||
} else if (variant.type() == QVariant::StringList) {
|
||||
qDebug() << "";
|
||||
}
|
||||
return handle_scope.Escape(jsValue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user