diff options
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptengine_p.h | 22 | ||||
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 47 | ||||
-rw-r--r-- | src/script/api/qscriptvalue_p.h | 6 |
3 files changed, 47 insertions, 28 deletions
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index c9faa46..a16785c 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -489,6 +489,28 @@ inline QScriptValue QScriptValuePrivate::property(const QString &name, int resol return property(JSC::Identifier(exec, name), resolveMode); } +inline QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolveMode) const +{ + Q_ASSERT(isObject()); + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if ((resolveMode & QScriptValue::ResolvePrototype) && object->getPropertySlot(exec, id, slot)) + return engine->scriptValueFromJSCValue(slot.getValue(exec, id)); + return propertyHelper(id, resolveMode); +} + +inline QScriptValue QScriptValuePrivate::property(quint32 index, int resolveMode) const +{ + Q_ASSERT(isObject()); + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if ((resolveMode & QScriptValue::ResolvePrototype) && object->getPropertySlot(exec, index, slot)) + return engine->scriptValueFromJSCValue(slot.getValue(exec, index)); + return propertyHelper(index, resolveMode); +} + inline void* QScriptValuePrivate::operator new(size_t size, QScriptEnginePrivate *engine) { if (engine) diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 21673d1..76b2636 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -276,41 +276,36 @@ qsreal ToInteger(qsreal n) } // namespace QScript -QScriptValue QScriptValuePrivate::property(const JSC::Identifier &id, int resolveMode) const +QScriptValue QScriptValuePrivate::propertyHelper(const JSC::Identifier &id, int resolveMode) const { - Q_ASSERT(isObject()); - JSC::ExecState *exec = engine->currentFrame; - JSC::JSObject *object = JSC::asObject(jscValue); - JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); JSC::JSValue result; - if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) { - result = slot.getValue(exec, id); - } else { - if ((resolveMode & QScriptValue::ResolvePrototype) - && const_cast<JSC::JSObject*>(object)->getPropertySlot(exec, id, slot)) { + if (!(resolveMode & QScriptValue::ResolvePrototype)) { + // Look in the object's own properties + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if (object->getOwnPropertySlot(exec, id, slot)) result = slot.getValue(exec, id); - } else if (resolveMode & QScriptValue::ResolveScope) { - // ### check if it's a function object and look in the scope chain - QScriptValue scope = property(QString::fromLatin1("__qt_scope__"), QScriptValue::ResolveLocal); - if (scope.isObject()) - result = engine->scriptValueToJSCValue(QScriptValuePrivate::get(scope)->property(id, resolveMode)); - } + } + if (!result && (resolveMode & QScriptValue::ResolveScope)) { + // ### check if it's a function object and look in the scope chain + QScriptValue scope = property(QString::fromLatin1("__qt_scope__"), QScriptValue::ResolveLocal); + if (scope.isObject()) + result = engine->scriptValueToJSCValue(QScriptValuePrivate::get(scope)->property(id, resolveMode)); } return engine->scriptValueFromJSCValue(result); } -QScriptValue QScriptValuePrivate::property(quint32 index, int resolveMode) const +QScriptValue QScriptValuePrivate::propertyHelper(quint32 index, int resolveMode) const { - Q_ASSERT(isObject()); - JSC::ExecState *exec = engine->currentFrame; - JSC::JSObject *object = JSC::asObject(jscValue); - JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); JSC::JSValue result; - if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, index, slot)) { - result = slot.getValue(exec, index); - } else if ((resolveMode & QScriptValue::ResolvePrototype) - && const_cast<JSC::JSObject*>(object)->getPropertySlot(exec, index, slot)) { - result = slot.getValue(exec, index); + if (!(resolveMode & QScriptValue::ResolvePrototype)) { + // Look in the object's own properties + JSC::ExecState *exec = engine->currentFrame; + JSC::JSObject *object = JSC::asObject(jscValue); + JSC::PropertySlot slot(object); + if (object->getOwnPropertySlot(exec, index, slot)) + result = slot.getValue(exec, index); } return engine->scriptValueFromJSCValue(result); } diff --git a/src/script/api/qscriptvalue_p.h b/src/script/api/qscriptvalue_p.h index 9634515..b87b485 100644 --- a/src/script/api/qscriptvalue_p.h +++ b/src/script/api/qscriptvalue_p.h @@ -100,8 +100,10 @@ public: return QScriptValue(d); } - QScriptValue property(const JSC::Identifier &id, int resolveMode) const; - QScriptValue property(quint32 index, int resolveMode) const; + inline QScriptValue property(const JSC::Identifier &id, int resolveMode) const; + QScriptValue propertyHelper(const JSC::Identifier &id, int resolveMode) const; + inline QScriptValue property(quint32 index, int resolveMode) const; + QScriptValue propertyHelper(quint32, int resolveMode) const; inline QScriptValue property(const QString &, int resolveMode) const; void setProperty(const JSC::Identifier &id, const QScriptValue &value, const QScriptValue::PropertyFlags &flags); |