| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 2 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Lesser General Public | 5 * modify it under the terms of the GNU Lesser General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 void QtRuntimeObjectImp::removeFromCache() | 92 void QtRuntimeObjectImp::removeFromCache() |
| 93 { | 93 { |
| 94 JSLock lock(false); | 94 JSLock lock(false); |
| 95 QtInstance* key = cachedObjects.key(this); | 95 QtInstance* key = cachedObjects.key(this); |
| 96 if (key) | 96 if (key) |
| 97 cachedObjects.remove(key); | 97 cachedObjects.remove(key); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // QtInstance | 100 // QtInstance |
| 101 QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject) | 101 QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject, QScriptEng
ine::ValueOwnership ownership) |
| 102 : Instance(rootObject) | 102 : Instance(rootObject) |
| 103 , m_class(0) | 103 , m_class(0) |
| 104 , m_object(o) | 104 , m_object(o) |
| 105 , m_hashkey(o) | 105 , m_hashkey(o) |
| 106 , m_defaultMethod(0) | 106 , m_defaultMethod(0) |
| 107 , m_ownership(ownership) |
| 107 { | 108 { |
| 108 } | 109 } |
| 109 | 110 |
| 110 QtInstance::~QtInstance() | 111 QtInstance::~QtInstance() |
| 111 { | 112 { |
| 112 JSLock lock(false); | 113 JSLock lock(false); |
| 113 | 114 |
| 114 cachedObjects.remove(this); | 115 cachedObjects.remove(this); |
| 115 cachedInstances.remove(m_hashkey); | 116 cachedInstances.remove(m_hashkey); |
| 116 | 117 |
| 117 // clean up (unprotect from gc) the JSValues we've created | 118 // clean up (unprotect from gc) the JSValues we've created |
| 118 m_methods.clear(); | 119 m_methods.clear(); |
| 119 | 120 |
| 120 foreach(QtField* f, m_fields.values()) { | 121 foreach(QtField* f, m_fields.values()) { |
| 121 delete f; | 122 delete f; |
| 122 } | 123 } |
| 123 m_fields.clear(); | 124 m_fields.clear(); |
| 124 } | 125 |
| 125 | 126 if (m_object) { |
| 126 PassRefPtr<QtInstance> QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObje
ct> rootObject) | 127 switch (m_ownership) { |
| 128 case QScriptEngine::QtOwnership: |
| 129 break; |
| 130 case QScriptEngine::AutoOwnership: |
| 131 if (m_object->parent()) |
| 132 break; |
| 133 // fall through! |
| 134 case QScriptEngine::ScriptOwnership: |
| 135 delete m_object; |
| 136 break; |
| 137 } |
| 138 } |
| 139 } |
| 140 |
| 141 PassRefPtr<QtInstance> QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObje
ct> rootObject, QScriptEngine::ValueOwnership ownership) |
| 127 { | 142 { |
| 128 JSLock lock(false); | 143 JSLock lock(false); |
| 129 | 144 |
| 130 foreach(QtInstance* instance, cachedInstances.values(o)) { | 145 foreach(QtInstance* instance, cachedInstances.values(o)) { |
| 131 if (instance->rootObject() == rootObject) | 146 if (instance->rootObject() == rootObject) |
| 132 return instance; | 147 return instance; |
| 133 } | 148 } |
| 134 | 149 |
| 135 RefPtr<QtInstance> ret = QtInstance::create(o, rootObject); | 150 RefPtr<QtInstance> ret = QtInstance::create(o, rootObject, ownership); |
| 136 cachedInstances.insert(o, ret.get()); | 151 cachedInstances.insert(o, ret.get()); |
| 137 | 152 |
| 138 return ret.release(); | 153 return ret.release(); |
| 139 } | 154 } |
| 140 | 155 |
| 141 bool QtInstance::getOwnPropertySlot(JSObject* object, ExecState* exec, const Ide
ntifier& propertyName, PropertySlot& slot) | 156 bool QtInstance::getOwnPropertySlot(JSObject* object, ExecState* exec, const Ide
ntifier& propertyName, PropertySlot& slot) |
| 142 { | 157 { |
| 143 return object->JSObject::getOwnPropertySlot(exec, propertyName, slot); | 158 return object->JSObject::getOwnPropertySlot(exec, propertyName, slot); |
| 144 } | 159 } |
| 145 | 160 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 obj->setProperty(m_dynamicProperty.constData(), val); | 389 obj->setProperty(m_dynamicProperty.constData(), val); |
| 375 } else { | 390 } else { |
| 376 QString msg = QString(QLatin1String("cannot access member `%1' of delete
d QObject")).arg(QLatin1String(name())); | 391 QString msg = QString(QLatin1String("cannot access member `%1' of delete
d QObject")).arg(QLatin1String(name())); |
| 377 throwError(exec, GeneralError, msg.toLatin1().constData()); | 392 throwError(exec, GeneralError, msg.toLatin1().constData()); |
| 378 } | 393 } |
| 379 } | 394 } |
| 380 | 395 |
| 381 | 396 |
| 382 } | 397 } |
| 383 } | 398 } |
| OLD | NEW |