summaryrefslogtreecommitdiffstats
path: root/src/script/bridge
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2009-11-30 13:15:50 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2009-11-30 14:53:12 (GMT)
commit132eccca92a90e4d67ba8b5a4052384a2b2cfdf9 (patch)
treecff488b3d812dcb077771aafd51be979797c63fa /src/script/bridge
parent634a2c456732903b116a73e674f1391f77d530d8 (diff)
downloadQt-132eccca92a90e4d67ba8b5a4052384a2b2cfdf9.zip
Qt-132eccca92a90e4d67ba8b5a4052384a2b2cfdf9.tar.gz
Qt-132eccca92a90e4d67ba8b5a4052384a2b2cfdf9.tar.bz2
Fix garbage collection issue with script-owned objects with connections
This reinstates the pre-4.6 behavior: A script-owned C++ object that's not referenced anymore should be garbage collected, even if it has connections. In order to achieve this, the "weak" reference to the C++ object's wrapper must be invalidated. Task-number: QTBUG-6366 Reviewed-by: Simon Hausmann
Diffstat (limited to 'src/script/bridge')
-rw-r--r--src/script/bridge/qscriptqobject.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index 559fcd3..63ba9ec 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -83,22 +83,23 @@ struct QObjectConnection
void mark(JSC::MarkStack& markStack)
{
- // ### need to find out if senderWrapper is marked
if (senderWrapper) {
- // see if the sender should be marked or not
+ // see if the sender should be marked or not;
+ // if the C++ object is owned by script, we don't want
+ // it to stay alive due to a script connection.
Q_ASSERT(senderWrapper.inherits(&QScriptObject::info));
QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(senderWrapper));
- QScriptObjectDelegate *delegate = scriptObject->delegate();
- Q_ASSERT(delegate && (delegate->type() == QScriptObjectDelegate::QtObject));
- QObjectDelegate *inst = static_cast<QObjectDelegate*>(delegate);
- if ((inst->ownership() == QScriptEngine::ScriptOwnership)
- || ((inst->ownership() == QScriptEngine::AutoOwnership)
- && inst->value() && !inst->value()->parent())) {
- // #### don't mark if not marked otherwise
- //senderWrapper = JSC::JSValue();
- markStack.append(senderWrapper);
- } else {
- markStack.append(senderWrapper);
+ if (!JSC::Heap::isCellMarked(scriptObject)) {
+ QScriptObjectDelegate *delegate = scriptObject->delegate();
+ Q_ASSERT(delegate && (delegate->type() == QScriptObjectDelegate::QtObject));
+ QObjectDelegate *inst = static_cast<QObjectDelegate*>(delegate);
+ if ((inst->ownership() == QScriptEngine::ScriptOwnership)
+ || ((inst->ownership() == QScriptEngine::AutoOwnership)
+ && inst->value() && !inst->value()->parent())) {
+ senderWrapper = JSC::JSValue();
+ } else {
+ markStack.append(senderWrapper);
+ }
}
}
if (receiver)