diff options
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 8 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index d2569ae..9bf4ff2 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1964,10 +1964,14 @@ QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QScriptString &nam return 0; QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(d->engine); JSC::ExecState *exec = eng_p->currentFrame; + JSC::JSObject *object = JSC::asObject(d->jscValue); JSC::Identifier id = name.d_ptr->identifier; unsigned attribs = 0; - if (!JSC::asObject(d->jscValue)->getPropertyAttributes(exec, id, attribs)) + if (!object->getPropertyAttributes(exec, id, attribs)) { + if ((mode & QScriptValue::ResolvePrototype) && object->prototype()) + return eng_p->scriptValueFromJSCValue(object->prototype()).propertyFlags(name, mode); return 0; + } QScriptValue::PropertyFlags result = 0; if (attribs & JSC::ReadOnly) result |= QScriptValue::ReadOnly; @@ -1976,9 +1980,9 @@ QScriptValue::PropertyFlags QScriptValue::propertyFlags(const QScriptString &nam if (attribs & JSC::DontDelete) result |= QScriptValue::Undeletable; //We cannot rely on attribs JSC::Setter/Getter because they are not necesserly set by JSC (bug?) - if (attribs & JSC::Getter || !JSC::asObject(d->jscValue)->lookupGetter(exec, id).isUndefinedOrNull()) + if (attribs & JSC::Getter || !object->lookupGetter(exec, id).isUndefinedOrNull()) result |= QScriptValue::PropertyGetter; - if (attribs & JSC::Setter || !JSC::asObject(d->jscValue)->lookupSetter(exec, id).isUndefinedOrNull()) + if (attribs & JSC::Setter || !object->lookupSetter(exec, id).isUndefinedOrNull()) result |= QScriptValue::PropertySetter; if (attribs & QScript::QObjectMemberAttribute) result |= QScriptValue::QObjectMember; diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index 2b48c30..56a91be 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -2077,6 +2077,14 @@ void tst_QScriptValue::getSetProperty() object.setProperty("flagProperty", str, QScriptValue::UserRange); QCOMPARE(object.propertyFlags("flagProperty"), QScriptValue::UserRange); + // flags of property in the prototype + { + QScriptValue object2 = eng.newObject(); + object2.setPrototype(object); + QCOMPARE(object2.propertyFlags("flagProperty", QScriptValue::ResolveLocal), 0); + QCOMPARE(object2.propertyFlags("flagProperty"), QScriptValue::UserRange); + } + // using interned strings QScriptString foo = eng.toStringHandle("foo"); |