summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-06-30 14:51:38 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-06-30 14:51:38 (GMT)
commit80e3aadafffcfedf5e4646fd229abe9740a6b6fb (patch)
tree62f1ba452c76ea12ed7cbe587d40685c5d6749e7
parent7a04df50d6ea4c2d7ee1c8fdea7a7c259636db17 (diff)
downloadQt-80e3aadafffcfedf5e4646fd229abe9740a6b6fb.zip
Qt-80e3aadafffcfedf5e4646fd229abe9740a6b6fb.tar.gz
Qt-80e3aadafffcfedf5e4646fd229abe9740a6b6fb.tar.bz2
implement setting of default prototype in newQObject()
-rw-r--r--src/script/api/qscriptengine.cpp62
-rw-r--r--src/script/api/qscriptengine_p.h3
2 files changed, 51 insertions, 14 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index d644a73..f6f637d 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -276,7 +276,7 @@ public:
QByteArray signature;
QScriptEngine::MarshalFunction marshal;
QScriptEngine::DemarshalFunction demarshal;
- QScriptValue prototype;
+ JSC::JSValue prototype;
};
namespace QScript
@@ -488,6 +488,12 @@ void GlobalObject::mark()
}
}
#endif
+
+ {
+ QHash<int, QScriptTypeInfo*>::const_iterator it;
+ for (it = engine->m_typeInfos.constBegin(); it != engine->m_typeInfos.constEnd(); ++it)
+ (*it)->prototype.mark();
+ }
}
static JSC::JSValue JSC_HOST_CALL functionPrint(JSC::ExecState*, JSC::JSObject*, JSC::JSValue, const JSC::ArgList&);
@@ -837,6 +843,24 @@ QVariantMap QScriptEnginePrivate::variantMapFromObject(const QScriptValue &obj)
return vmap;
}
+JSC::JSValue QScriptEnginePrivate::defaultPrototype(int metaTypeId) const
+{
+ QScriptTypeInfo *info = m_typeInfos.value(metaTypeId);
+ if (!info)
+ return JSC::JSValue();
+ return info->prototype;
+}
+
+void QScriptEnginePrivate::setDefaultPrototype(int metaTypeId, JSC::JSValue prototype)
+{
+ QScriptTypeInfo *info = m_typeInfos.value(metaTypeId);
+ if (!info) {
+ info = new QScriptTypeInfo();
+ m_typeInfos.insert(metaTypeId, info);
+ }
+ info->prototype = prototype;
+}
+
#ifndef QT_NO_QOBJECT
JSC::JSValue QScriptEnginePrivate::newQObject(
@@ -847,6 +871,24 @@ JSC::JSValue QScriptEnginePrivate::newQObject(
return JSC::jsNull();
JSC::ExecState* exec = globalObject->globalExec();
QScript::QObjectWrapperObject *result = new (exec) QScript::QObjectWrapperObject(object, ownership, options, qobjectWrapperObjectStructure);
+
+ /*if (setDefaultPrototype)*/ {
+ const QMetaObject *meta = object->metaObject();
+ while (meta) {
+ QByteArray typeString = meta->className();
+ typeString.append('*');
+ int typeId = QMetaType::type(typeString);
+ if (typeId != 0) {
+ JSC::JSValue proto = defaultPrototype(typeId);
+ if (proto) {
+ result->setPrototype(proto);
+ break;
+ }
+ }
+ meta = meta->superClass();
+ }
+ }
+
return result;
}
@@ -1821,10 +1863,7 @@ void QScriptEngine::clearExceptions()
QScriptValue QScriptEngine::defaultPrototype(int metaTypeId) const
{
Q_D(const QScriptEngine);
- QScriptTypeInfo *info = d->m_typeInfos.value(metaTypeId);
- if (!info)
- return QScriptValue();
- return info->prototype;
+ return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(d->defaultPrototype(metaTypeId));
}
/*!
@@ -1850,12 +1889,7 @@ QScriptValue QScriptEngine::defaultPrototype(int metaTypeId) const
void QScriptEngine::setDefaultPrototype(int metaTypeId, const QScriptValue &prototype)
{
Q_D(QScriptEngine);
- QScriptTypeInfo *info = d->m_typeInfos.value(metaTypeId);
- if (!info) {
- info = new QScriptTypeInfo();
- d->m_typeInfos.insert(metaTypeId, info);
- }
- info->prototype = prototype;
+ d->setDefaultPrototype(metaTypeId, d->scriptValueToJSCValue(prototype));
}
/*!
@@ -2012,8 +2046,8 @@ QScriptValue QScriptEnginePrivate::create(int type, const void *ptr)
}
}
}
- if (result.isObject() && info && info->prototype.isValid())
- result.setPrototype(info->prototype);
+ if (result.isObject() && info && info->prototype)
+ result.setPrototype(scriptValueFromJSCValue(info->prototype));
return result;
}
@@ -2239,7 +2273,7 @@ void QScriptEngine::registerCustomType(int type, MarshalFunction mf,
}
info->marshal = mf;
info->demarshal = df;
- info->prototype = prototype;
+ info->prototype = d->scriptValueToJSCValue(prototype);
}
/*!
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h
index f6c12f1..ff4b2ce 100644
--- a/src/script/api/qscriptengine_p.h
+++ b/src/script/api/qscriptengine_p.h
@@ -98,6 +98,9 @@ public:
QScriptValue objectFromVariantMap(const QVariantMap &vmap);
static QVariantMap variantMapFromObject(const QScriptValue &obj);
+ JSC::JSValue defaultPrototype(int metaTypeId) const;
+ void setDefaultPrototype(int metaTypeId, JSC::JSValue prototype);
+
#ifndef QT_NO_QOBJECT
JSC::JSValue newQObject(QObject *object,
QScriptEngine::ValueOwnership ownership = QScriptEngine::QtOwnership,