mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 23:55:24 +02:00
Fixed script array to QVariant conversion
This commit is contained in:
parent
cb4dc4c7e8
commit
66a87def43
4 changed files with 37 additions and 1 deletions
|
@ -175,6 +175,7 @@ public: // not for public use, but I don't like how Qt strings this along with p
|
|||
bool castValueToVariant(const V8ScriptValue& val, QVariant& dest, int destTypeId);
|
||||
|
||||
// Converts JS objects created in V8 to variants. Iterates over all properties and converts them to variants.
|
||||
bool convertJSArrayToVariant(v8::Local<v8::Array> array, QVariant &dest);
|
||||
bool convertJSObjectToVariant(v8::Local<v8::Object> object, QVariant &dest);
|
||||
V8ScriptValue castVariantToValue(const QVariant& val);
|
||||
QString valueType(const V8ScriptValue& val);
|
||||
|
|
|
@ -389,6 +389,11 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (val->IsArray()) {
|
||||
if (convertJSArrayToVariant(v8::Local<v8::Array>::Cast(val), dest)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// This is for generic JS objects
|
||||
if (val->IsObject()) {
|
||||
if (convertJSObjectToVariant(v8::Local<v8::Object>::Cast(val), dest)) {
|
||||
|
@ -499,6 +504,11 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if (val->IsArray()) {
|
||||
if (convertJSArrayToVariant(v8::Local<v8::Array>::Cast(val), dest)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (val->IsObject()) {
|
||||
if (convertJSObjectToVariant(v8::Local<v8::Object>::Cast(val), dest)) {
|
||||
return true;
|
||||
|
@ -550,6 +560,30 @@ bool ScriptEngineV8::castValueToVariant(const V8ScriptValue& v8Val, QVariant& de
|
|||
return destTypeId == QMetaType::UnknownType || dest.userType() == destTypeId || dest.convert(destTypeId);
|
||||
}
|
||||
|
||||
bool ScriptEngineV8::convertJSArrayToVariant(v8::Local<v8::Array> array, QVariant &dest) {
|
||||
v8::HandleScope handleScope(_v8Isolate);
|
||||
auto context = getContext();
|
||||
int length = array->Length();
|
||||
QList<QVariant> properties;
|
||||
for (int i = 0; i < length; i++) {
|
||||
v8::Local<v8::Value> v8Property;
|
||||
if (!array->Get(context, i).ToLocal(&v8Property)) {
|
||||
qDebug() << "ScriptEngineV8::convertJSArrayToVariant could not get property: " + QString(i);
|
||||
continue;
|
||||
}
|
||||
QVariant property;
|
||||
// Maybe QMetaType::QVariant?
|
||||
if (castValueToVariant(V8ScriptValue(_v8Isolate, v8Property), property, QMetaType::UnknownType)) {
|
||||
properties.append(property);
|
||||
} else {
|
||||
qDebug() << "ScriptEngineV8::convertJSArrayToVariant could cast property to variant: " + QString(i);
|
||||
;
|
||||
}
|
||||
}
|
||||
dest = QVariant(properties);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScriptEngineV8::convertJSObjectToVariant(v8::Local<v8::Object> object, QVariant &dest) {
|
||||
v8::HandleScope handleScope(_v8Isolate);
|
||||
auto context = getContext();
|
||||
|
|
|
@ -264,7 +264,6 @@
|
|||
}
|
||||
document.getElementById("listInfo").innerHTML = metaverseCounter + metaversePageInfo + " of " + metaverseList.length + ".";
|
||||
} else {
|
||||
console.log(JSON.stringify(placeList));
|
||||
var placeRecords = placeList.slice();
|
||||
|
||||
if (currentListFormat === "DOMAINS") {
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
var n = d.getTime();
|
||||
|
||||
var messageObj = JSON.parse(message);
|
||||
print(message);
|
||||
if (messageObj.channel === channel) {
|
||||
if (messageObj.action === "READY_FOR_CONTENT" && (n - timestamp) > INTERCALL_DELAY) {
|
||||
d = new Date();
|
||||
|
@ -210,6 +211,7 @@
|
|||
warning = "WARNING: " + percentProtocolRejected + "% of the places are not listed because they are running under a different protocol. Maybe consider to upgrade.";
|
||||
}
|
||||
|
||||
print(JSON.stringify(portalList));
|
||||
var message = {
|
||||
"channel": channel,
|
||||
"action": "PLACE_DATA",
|
||||
|
|
Loading…
Reference in a new issue