mirror of
https://github.com/overte-org/overte.git
synced 2025-04-09 13:02:24 +02:00
Added ScriptValue::getPropertyNames
This commit is contained in:
parent
e114d86871
commit
ec3e87da5c
4 changed files with 40 additions and 0 deletions
|
@ -55,6 +55,7 @@ public:
|
|||
const ScriptValue::PropertyFlags& flags = ScriptValue::KeepExistingFlags) override;
|
||||
virtual void setPrototype(const ScriptValue& prototype) override;
|
||||
virtual bool strictlyEquals(const ScriptValue& other) const override;
|
||||
virtual inline QList<QString> getPropertyNames() const;
|
||||
|
||||
virtual bool toBool() const override;
|
||||
virtual qint32 toInt32() const override;
|
||||
|
@ -209,6 +210,10 @@ bool ScriptValueProxyNull::strictlyEquals(const ScriptValue& other) const {
|
|||
return !other.isValid();
|
||||
}
|
||||
|
||||
QList<QString> ScriptValueProxyNull::getPropertyNames() const {
|
||||
return QList<QString>();
|
||||
}
|
||||
|
||||
bool ScriptValueProxyNull::toBool() const {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ public:
|
|||
const PropertyFlags& flags = KeepExistingFlags);
|
||||
inline void setPrototype(const ScriptValue& prototype);
|
||||
inline bool strictlyEquals(const ScriptValue& other) const;
|
||||
inline QList<QString> getPropertyNames() const;
|
||||
|
||||
inline bool toBool() const;
|
||||
inline qint32 toInt32() const;
|
||||
|
@ -165,6 +166,7 @@ public:
|
|||
const ScriptValue::PropertyFlags& flags = ScriptValue::KeepExistingFlags) = 0;
|
||||
virtual void setPrototype(const ScriptValue& prototype) = 0;
|
||||
virtual bool strictlyEquals(const ScriptValue& other) const = 0;
|
||||
virtual QList<QString> getPropertyNames() const = 0;
|
||||
|
||||
virtual bool toBool() const = 0;
|
||||
virtual qint32 toInt32() const = 0;
|
||||
|
@ -349,6 +351,11 @@ bool ScriptValue::strictlyEquals(const ScriptValue& other) const {
|
|||
return _proxy->strictlyEquals(other);
|
||||
}
|
||||
|
||||
inline QList<QString> ScriptValue::getPropertyNames() const {
|
||||
Q_ASSERT(_proxy != nullptr);
|
||||
return _proxy->getPropertyNames();
|
||||
};
|
||||
|
||||
bool ScriptValue::toBool() const {
|
||||
Q_ASSERT(_proxy != nullptr);
|
||||
return _proxy->toBool();
|
||||
|
|
|
@ -454,6 +454,33 @@ bool ScriptValueV8Wrapper::strictlyEquals(const ScriptValue& other) const {
|
|||
return unwrappedOther ? _value.constGet()->StrictEquals(unwrappedOther->toV8Value().constGet()) : false;
|
||||
}
|
||||
|
||||
inline QList<QString> ScriptValueV8Wrapper::getPropertyNames() const {
|
||||
auto isolate = _engine->getIsolate();
|
||||
v8::Locker locker(isolate);
|
||||
v8::Isolate::Scope isolateScope(isolate);
|
||||
v8::HandleScope handleScope(isolate);
|
||||
auto context = _engine->getContext();
|
||||
v8::Context::Scope contextScope(context);
|
||||
v8::Local<v8::Value> value = _value.constGet();
|
||||
if (value->IsNullOrUndefined()) {
|
||||
return QList<QString>();
|
||||
}
|
||||
if (!value->IsObject()) {
|
||||
return QList<QString>();
|
||||
}
|
||||
v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
|
||||
v8::Local<v8::Array> array;
|
||||
if (!object->GetPropertyNames(context).ToLocal(&array)) {
|
||||
return QList<QString>();
|
||||
}
|
||||
QList<QString> names;
|
||||
for (uint32_t n = 0; n < array->Length(); n++) {
|
||||
v8::Local<v8::String> name = array->Get(context, n).ToLocalChecked()->ToString(context).ToLocalChecked();
|
||||
names.append(*v8::String::Utf8Value(isolate, name));
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
bool ScriptValueV8Wrapper::toBool() const {
|
||||
auto isolate = _engine->getIsolate();
|
||||
v8::Locker locker(isolate);
|
||||
|
|
|
@ -67,6 +67,7 @@ public: // ScriptValue implementation
|
|||
const ScriptValue::PropertyFlags& flags = ScriptValue::KeepExistingFlags) override;
|
||||
virtual void setPrototype(const ScriptValue& prototype) override;
|
||||
virtual bool strictlyEquals(const ScriptValue& other) const override;
|
||||
virtual QList<QString> getPropertyNames() const;
|
||||
|
||||
virtual bool equals(const ScriptValue& other) const override;
|
||||
virtual bool isArray() const override;
|
||||
|
|
Loading…
Reference in a new issue