src/script/bridge/qscriptqobject.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/script/bridge/qscriptqobject.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/script/bridge/qscriptqobject.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -6,35 +6,17 @@
 **
 ** This file is part of the QtScript module of the Qt Toolkit.
 **
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
+** $QT_BEGIN_LICENSE:LGPL-ONLY$
 ** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
+** This file may be used under the terms of the GNU Lesser
 ** General Public License version 2.1 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.LGPL included in the
 ** packaging of this file.  Please review the following information to
 ** ensure the GNU Lesser General Public License version 2.1 requirements
 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
-** In addition, as a special exception, Nokia gives you certain additional
-** rights.  These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
 ** If you have questions regarding the use of this file, please contact
 ** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
 ** $QT_END_LICENSE$
 **
 ****************************************************************************/
@@ -101,22 +83,23 @@
 
     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)
@@ -1190,6 +1173,7 @@
                                          const JSC::Identifier &propertyName,
                                          JSC::PropertySlot &slot)
 {
+#ifndef QT_NO_PROPERTIES
     QByteArray name = QString(propertyName.ustring()).toLatin1();
     QObject *qobject = data->value;
     if (!qobject) {
@@ -1296,12 +1280,16 @@
     }
 
     return QScriptObjectDelegate::getOwnPropertySlot(object, exec, propertyName, slot);
+#else //QT_NO_PROPERTIES
+    return false;
+#endif //QT_NO_PROPERTIES
 }
 
 void QObjectDelegate::put(QScriptObject *object, JSC::ExecState* exec,
                           const JSC::Identifier& propertyName,
                           JSC::JSValue value, JSC::PutPropertySlot &slot)
 {
+#ifndef QT_NO_PROPERTIES
     QByteArray name = ((QString)propertyName.ustring()).toLatin1();
     QObject *qobject = data->value;
     if (!qobject) {
@@ -1392,12 +1380,14 @@
     }
 
     QScriptObjectDelegate::put(object, exec, propertyName, value, slot);
+#endif //QT_NO_PROPERTIES
 }
 
 bool QObjectDelegate::deleteProperty(QScriptObject *object, JSC::ExecState *exec,
                                      const JSC::Identifier& propertyName,
                                      bool checkDontDelete)
 {
+#ifndef QT_NO_PROPERTIES
     QByteArray name = ((QString)propertyName.ustring()).toLatin1();
     QObject *qobject = data->value;
     if (!qobject) {
@@ -1436,6 +1426,9 @@
     }
 
     return QScriptObjectDelegate::deleteProperty(object, exec, propertyName, checkDontDelete);
+#else //QT_NO_PROPERTIES
+    return false;
+#endif //QT_NO_PROPERTIES
 }
 
 bool QObjectDelegate::getPropertyAttributes(const QScriptObject *object,
@@ -1443,6 +1436,7 @@
                                             const JSC::Identifier &propertyName,
                                             unsigned &attributes) const
 {
+#ifndef QT_NO_PROPERTIES
     // ### try to avoid duplicating logic from getOwnPropertySlot()
     QByteArray name = ((QString)propertyName.ustring()).toLatin1();
     QObject *qobject = data->value;
@@ -1511,12 +1505,16 @@
     }
 
     return QScriptObjectDelegate::getPropertyAttributes(object, exec, propertyName, attributes);
+#else //QT_NO_PROPERTIES
+    return false;
+#endif //QT_NO_PROPERTIES
 }
 
 void QObjectDelegate::getOwnPropertyNames(QScriptObject *object, JSC::ExecState *exec,
                                           JSC::PropertyNameArray &propertyNames,
                                           bool includeNonEnumerable)
 {
+#ifndef QT_NO_PROPERTIES
     QObject *qobject = data->value;
     if (!qobject) {
         QString message = QString::fromLatin1("cannot get property names of deleted QObject");
@@ -1560,6 +1558,7 @@
     }
 
     QScriptObjectDelegate::getOwnPropertyNames(object, exec, propertyNames, includeNonEnumerable);
+#endif //QT_NO_PROPERTIES
 }
 
 void QObjectDelegate::markChildren(QScriptObject *object, JSC::MarkStack& markStack)