summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-02 09:17:04 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-07-02 09:17:04 (GMT)
commit4518d4d0d8b5842bdc6a7c554b566e0e23e0bf82 (patch)
treece263441b36155f5b154a895593952b713117c1e /src/script
parentce9e05d57a22860b8b29a79d113702102f34659f (diff)
downloadQt-4518d4d0d8b5842bdc6a7c554b566e0e23e0bf82.zip
Qt-4518d4d0d8b5842bdc6a7c554b566e0e23e0bf82.tar.gz
Qt-4518d4d0d8b5842bdc6a7c554b566e0e23e0bf82.tar.bz2
implement QObject property flags
Diffstat (limited to 'src/script')
-rw-r--r--src/script/bridge/qscriptqobject.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index edfedbb..0162b63 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -142,6 +142,12 @@ static inline QByteArray methodName(const QMetaMethod &method)
return signature.left(signature.indexOf('('));
}
+static unsigned flagsForMetaProperty(const QMetaProperty &prop)
+{
+ return (JSC::DontDelete
+ | (!prop.isWritable() ? unsigned(JSC::ReadOnly) : unsigned(0)));
+}
+
static int indexOfMetaEnum(const QMetaObject *meta, const QByteArray &str)
{
QByteArray scope;
@@ -1116,6 +1122,74 @@ bool QObjectWrapperObject::getPropertyAttributes(JSC::ExecState *exec,
const JSC::Identifier &propertyName,
unsigned &attributes) const
{
+ // ### try to avoid duplicating logic from getOwnPropertySlot()
+ QByteArray name = qtStringFromJSCUString(propertyName.ustring()).toLatin1();
+ QObject *qobject = data->value;
+ if (!qobject)
+ return false;
+
+ const QScriptEngine::QObjectWrapOptions &opt = data->options;
+ const QMetaObject *meta = qobject->metaObject();
+ QScriptEnginePrivate *eng = static_cast<QScript::GlobalObject*>(exec->dynamicGlobalObject())->engine;
+ int index = -1;
+ if (name.contains('(')) {
+ QByteArray normalized = QMetaObject::normalizedSignature(name);
+ if (-1 != (index = meta->indexOfMethod(normalized))) {
+ QMetaMethod method = meta->method(index);
+ if (hasMethodAccess(method, index, opt)) {
+ if (!(opt & QScriptEngine::ExcludeSuperClassMethods)
+ || (index >= meta->methodOffset())) {
+ attributes = 0;
+ if (opt & QScriptEngine::SkipMethodsInEnumeration)
+ attributes |= JSC::DontEnum;
+ return true;
+ }
+ }
+ }
+ }
+
+ index = meta->indexOfProperty(name);
+ if (index != -1) {
+ QMetaProperty prop = meta->property(index);
+ if (prop.isScriptable()) {
+ if (!(opt & QScriptEngine::ExcludeSuperClassProperties)
+ || (index >= meta->propertyOffset())) {
+ attributes = flagsForMetaProperty(prop);
+ return true;
+ }
+ }
+ }
+
+ index = qobject->dynamicPropertyNames().indexOf(name);
+ if (index != -1) {
+ attributes = 0;
+ return true;
+ }
+
+ const int offset = (opt & QScriptEngine::ExcludeSuperClassMethods)
+ ? meta->methodOffset() : 0;
+ for (index = meta->methodCount() - 1; index >= offset; --index) {
+ QMetaMethod method = meta->method(index);
+ if (hasMethodAccess(method, index, opt)
+ && (methodName(method) == name)) {
+ attributes = 0;
+ if (opt & QScriptEngine::SkipMethodsInEnumeration)
+ attributes |= JSC::DontEnum;
+ return true;
+ }
+ }
+
+ if (!(opt & QScriptEngine::ExcludeChildObjects)) {
+ QList<QObject*> children = qobject->children();
+ for (index = 0; index < children.count(); ++index) {
+ QObject *child = children.at(index);
+ if (child->objectName() == qtStringFromJSCUString(propertyName.ustring())) {
+ attributes = JSC::ReadOnly | JSC::DontDelete | JSC::DontEnum;
+ return true;
+ }
+ }
+ }
+
return JSC::JSObject::getPropertyAttributes(exec, propertyName, attributes);
}