diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-15 08:40:24 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-15 08:40:24 (GMT) |
commit | 2fe8eb61d878c74674415ec32d1d0b420a7c656f (patch) | |
tree | 34cdbb0212cd7eb291cada8b9b91c9092a34f9a9 /src/script/api | |
parent | b0e9dc67c7bc2ef7292e7aac20fae846ea89cccf (diff) | |
download | Qt-2fe8eb61d878c74674415ec32d1d0b420a7c656f.zip Qt-2fe8eb61d878c74674415ec32d1d0b420a7c656f.tar.gz Qt-2fe8eb61d878c74674415ec32d1d0b420a7c656f.tar.bz2 |
implement QObject wrapper caching (PreferExistingWrapperObject)
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 5f63fde..562515d 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -999,9 +999,19 @@ JSC::JSValue QScriptEnginePrivate::newQObject( if (!object) return JSC::jsNull(); JSC::ExecState* exec = currentFrame; - QScriptObject *result = new (exec) QScriptObject(qobjectWrapperObjectStructure); + QScript::QObjectData *data = qobjectData(object); + bool preferExisting = (options & QScriptEngine::PreferExistingWrapperObject) != 0; + QScriptEngine::QObjectWrapOptions opt = options & ~QScriptEngine::PreferExistingWrapperObject; + QScriptObject *result = 0; + if (preferExisting) + result = data->findWrapper(ownership, opt); + if (!result) { + result = new (exec) QScriptObject(qobjectWrapperObjectStructure); + if (preferExisting) + data->registerWrapper(result, ownership, opt); + } + Q_ASSERT(result != 0); result->setDelegate(new QScript::QObjectDelegate(object, ownership, options)); - // ### TODO /*if (setDefaultPrototype)*/ { const QMetaObject *meta = object->metaObject(); while (meta) { |