mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 16:42:08 +02:00
Listing objects and their properties on API debugger now works
This commit is contained in:
parent
37cc62d082
commit
f65e72c8f2
7 changed files with 118 additions and 8 deletions
|
@ -25,8 +25,12 @@
|
|||
class PlatformInfoScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
static PlatformInfoScriptingInterface* getInstance();
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
|
||||
PlatformInfoScriptingInterface();
|
||||
virtual ~PlatformInfoScriptingInterface();
|
||||
|
||||
|
@ -55,11 +59,10 @@ public:
|
|||
Q_ENUM(PlatformTier);
|
||||
|
||||
public slots:
|
||||
/*@jsdoc
|
||||
/*
|
||||
* @function PlatformInfo.getInstance
|
||||
* @deprecated This function is deprecated and will be removed.
|
||||
*/
|
||||
static PlatformInfoScriptingInterface* getInstance();
|
||||
|
||||
/*@jsdoc
|
||||
* Gets the operating system type.
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QColor>
|
||||
#include <QtGui/QVector2D>
|
||||
#include <QtGui/QVector3D>
|
||||
#include <QtCore/QRect>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QUuid>
|
||||
|
@ -52,6 +54,9 @@ bool isListOfStrings(const ScriptValue& arg) {
|
|||
}
|
||||
|
||||
void registerMetaTypes(ScriptEngine* engine) {
|
||||
scriptRegisterMetaType<QVector2D, qVector2DToScriptValue, qVector2DFromScriptValue>(engine);
|
||||
scriptRegisterMetaType<QVector3D, qVector3DToScriptValue, qVector3DFromScriptValue>(engine);
|
||||
|
||||
scriptRegisterMetaType<glm::vec2, vec2ToScriptValue, vec2FromScriptValue>(engine);
|
||||
scriptRegisterMetaType<glm::vec3, vec3ToScriptValue, vec3FromScriptValue>(engine);
|
||||
scriptRegisterMetaType<glm::u8vec3, u8vec3ToScriptValue, u8vec3FromScriptValue>(engine);
|
||||
|
@ -93,6 +98,39 @@ void registerMetaTypes(ScriptEngine* engine) {
|
|||
scriptRegisterSequenceMetaType<QVector<QString>>(engine);
|
||||
}
|
||||
|
||||
ScriptValue qVector2DToScriptValue(ScriptEngine* engine, const QVector2D& qVector2D) {
|
||||
glm::vec2 vec2(qVector2D.x(), qVector2D.y());
|
||||
return vec2ToScriptValue(engine, vec2);
|
||||
}
|
||||
|
||||
bool qVector2DFromScriptValue(const ScriptValue& object, QVector2D& qVector2D) {
|
||||
glm::vec2 vec2;
|
||||
if (vec2FromScriptValue(object, vec2)) {
|
||||
qVector2D.setX(vec2.x);
|
||||
qVector2D.setY(vec2.y);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ScriptValue qVector3DToScriptValue(ScriptEngine* engine, const QVector3D& qVector3D) {
|
||||
glm::vec3 vec3(qVector3D.x(), qVector3D.y(), qVector3D.z());
|
||||
return vec3ToScriptValue(engine, vec3);
|
||||
}
|
||||
|
||||
bool qVector3DFromScriptValue(const ScriptValue& object, QVector3D& qVector3D) {
|
||||
glm::vec3 vec3;
|
||||
if (vec3FromScriptValue(object, vec3)) {
|
||||
qVector3D.setX(vec3.x);
|
||||
qVector3D.setY(vec3.y);
|
||||
qVector3D.setZ(vec3.z);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ScriptValue vec2ToScriptValue(ScriptEngine* engine, const glm::vec2& vec2) {
|
||||
auto prototype = engine->globalObject().property("__hifi_vec2__");
|
||||
if (!prototype.property("defined").toBool()) {
|
||||
|
|
|
@ -161,6 +161,14 @@ bool quatFromScriptValue(const ScriptValue& object, glm::quat& quat);
|
|||
* @property {number} width - Width of the rectangle.
|
||||
* @property {number} height - Height of the rectangle.
|
||||
*/
|
||||
class QVector2D;
|
||||
ScriptValue qVector2DToScriptValue(ScriptEngine* engine, const QVector2D& qVector2D);
|
||||
bool qVector2DFromScriptValue(const ScriptValue& object, QVector2D& qVector2D);
|
||||
|
||||
class QVector3D;
|
||||
ScriptValue qVector3DToScriptValue(ScriptEngine* engine, const QVector3D& qVector3D);
|
||||
bool qVector3DFromScriptValue(const ScriptValue& object, QVector3D& qVector3D);
|
||||
|
||||
class QRect;
|
||||
ScriptValue qRectToScriptValue(ScriptEngine* engine, const QRect& rect);
|
||||
bool qRectFromScriptValue(const ScriptValue& object, QRect& rect);
|
||||
|
|
|
@ -769,7 +769,9 @@ V8ScriptValue ScriptEngineV8::castVariantToValue(const QVariant& val) {
|
|||
}
|
||||
// just do a generic variant
|
||||
//V8TODO
|
||||
Q_ASSERT(false);
|
||||
qDebug() << "ScriptEngineV8::castVariantToValue failed for " << QMetaType::typeName(valTypeId);
|
||||
logBacktrace("ScriptEngineV8::castVariantToValue failed");
|
||||
//Q_ASSERT(false);
|
||||
return V8ScriptValue(this, v8::Undefined(_v8Isolate));
|
||||
//return QScriptEngine::newVariant(val);
|
||||
}
|
||||
|
|
|
@ -225,14 +225,11 @@ void ScriptObjectV8Proxy::investigate() {
|
|||
//auto objectTemplate = _v8ObjectTemplate.Get(_engine->getIsolate());
|
||||
auto objectTemplate = v8::ObjectTemplate::New(_engine->getIsolate());
|
||||
objectTemplate->SetInternalFieldCount(3);
|
||||
objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set));
|
||||
objectTemplate->SetHandler(v8::NamedPropertyHandlerConfiguration(v8Get, v8Set, nullptr, nullptr, v8GetPropertyNames));
|
||||
|
||||
const QMetaObject* metaObject = qobject->metaObject();
|
||||
|
||||
//qDebug(scriptengine) << "Investigate: " << metaObject->className();
|
||||
if (QString("Vec3") == metaObject->className()) {
|
||||
printf("Vec3");
|
||||
}
|
||||
if (QString("ConsoleScriptingInterface") == metaObject->className()) {
|
||||
printf("ConsoleScriptingInterface");
|
||||
}
|
||||
|
@ -494,6 +491,60 @@ void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> v
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptObjectV8Proxy::v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info) {
|
||||
qDebug(scriptengine) << "ScriptObjectV8Proxy::v8GetPropertyNames called";
|
||||
v8::HandleScope handleScope(info.GetIsolate());
|
||||
auto context = info.GetIsolate()->GetCurrentContext();
|
||||
v8::Context::Scope contextScope(context);
|
||||
v8::Local<v8::Value> objectV8 = info.This();
|
||||
ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(info.GetIsolate(), objectV8);
|
||||
if (!proxy) {
|
||||
qDebug(scriptengine) << "ScriptObjectV8Proxy::v8GetPropertyNames: Proxy object not found when listing";
|
||||
return;
|
||||
}
|
||||
V8ScriptValue object(proxy->_engine, objectV8);
|
||||
uint id;
|
||||
v8::Local<v8::Array> properties = proxy->getPropertyNames();
|
||||
v8::Local<v8::Array> objectProperties;
|
||||
uint32_t propertiesLength = properties->Length();
|
||||
if (info.This()->GetInternalField(2).As<v8::Object>()->GetPropertyNames(context).ToLocal(&objectProperties)) {
|
||||
for (int n = 0; n < objectProperties->Length(); n++) {
|
||||
if(!properties->Set(context, propertiesLength+n, objectProperties->Get(context, n).ToLocalChecked()).FromMaybe(false)) {
|
||||
qDebug(scriptengine) << "ScriptObjectV8Proxy::v8GetPropertyNames: Cannot add member name";
|
||||
}
|
||||
}
|
||||
}
|
||||
info.GetReturnValue().Set(properties);
|
||||
}
|
||||
|
||||
v8::Local<v8::Array> ScriptObjectV8Proxy::getPropertyNames() {
|
||||
auto isolate = _engine->getIsolate();
|
||||
v8::Locker locker(isolate);
|
||||
v8::Isolate::Scope isolateScope(isolate);
|
||||
v8::EscapableHandleScope handleScope(_engine->getIsolate());
|
||||
auto context = _engine->getContext();
|
||||
v8::Context::Scope contextScope(_engine->getContext());
|
||||
|
||||
v8::Local<v8::Array> properties = v8::Array::New(isolate, _props.size() + _methods.size() + _signals.size());
|
||||
uint32_t position = 0;
|
||||
for (PropertyDefMap::const_iterator i = _props.begin(); i != _props.end(); i++){
|
||||
if(!properties->Set(context, position++, i.value().name.constGet()).FromMaybe(false)) {
|
||||
qDebug(scriptengine) << "ScriptObjectV8Proxy::getPropertyNames: Cannot add property member name";
|
||||
}
|
||||
}
|
||||
for (MethodDefMap::const_iterator i = _methods.begin(); i != _methods.end(); i++){
|
||||
if(!properties->Set(context, position++, i.value().name.constGet()).FromMaybe(false)) {
|
||||
qDebug(scriptengine) << "ScriptObjectV8Proxy::getPropertyNames: Cannot add property member name";
|
||||
}
|
||||
}
|
||||
for (SignalDefMap::const_iterator i = _signals.begin(); i != _signals.end(); i++){
|
||||
if(!properties->Set(context, position++, i.value().name.constGet()).FromMaybe(false)) {
|
||||
qDebug(scriptengine) << "ScriptObjectV8Proxy::getPropertyNames: Cannot add property member name";
|
||||
}
|
||||
}
|
||||
return handleScope.Escape(properties);
|
||||
}
|
||||
|
||||
|
||||
V8ScriptValue ScriptObjectV8Proxy::property(const V8ScriptValue& object, const V8ScriptString& name, uint id) {
|
||||
auto isolate = _engine->getIsolate();
|
||||
|
@ -840,7 +891,12 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume
|
|||
|
||||
// The Qt MOC engine will automatically call qRegisterMetaType on invokable parameters and properties, but there's
|
||||
// nothing in there for return values so these need to be explicitly runtime-registered!
|
||||
Q_ASSERT(returnTypeId != QMetaType::UnknownType);
|
||||
if (returnTypeId == QMetaType::UnknownType) {
|
||||
QString methodName = fullName();
|
||||
qDebug(scriptengine) << "returnTypeId == QMetaType::UnknownType for method " << methodName;
|
||||
_engine->logBacktrace("");
|
||||
//Q_ASSERT(false);
|
||||
}
|
||||
if (returnTypeId == QMetaType::UnknownType) {
|
||||
isolate->ThrowError(v8::String::NewFromUtf8(isolate, QString("Cannot call native function %1, its return value has not been registered with Qt").arg(fullName()).toStdString().c_str()).ToLocalChecked());
|
||||
return;
|
||||
|
|
|
@ -97,8 +97,10 @@ public:
|
|||
//V8TODO
|
||||
virtual QueryFlags queryProperty(const V8ScriptValue& object, const V8ScriptString& name, QueryFlags flags, uint* id);
|
||||
virtual void setProperty(V8ScriptValue& object, const V8ScriptString& name, uint id, const V8ScriptValue& value);
|
||||
v8::Local<v8::Array> getPropertyNames();
|
||||
static void v8Get(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
static void v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> value_obj, const v8::PropertyCallbackInfo<v8::Value>& info);
|
||||
static void v8GetPropertyNames(const v8::PropertyCallbackInfo<v8::Array>& info);
|
||||
|
||||
private: // implementation
|
||||
void investigate();
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
|
||||
var keys = Object.keys(object);
|
||||
for (var i = 0; i < keys.length; ++i) {
|
||||
print("key: " + keys[i]);
|
||||
if (string === "") {
|
||||
listKeys(keys[i], object[keys[i]]);
|
||||
} else if (keys[i] !== "parent") {
|
||||
|
|
Loading…
Reference in a new issue