Clear stale RuntimeObjectImps.
Since other objects can have refs to the QtInstance,
we can't rely on the QtInstance being deleted when the
RuntimeObjectImp is invalidate or deleted. This
could result in a stale JSObject being returned for
a valid Instance.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29756
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2008-01-24 Michael Goddard <michael.goddard@trolltech.com>
+
+ Reviewed by Simon.
+
+ Clear stale RuntimeObjectImps.
+ Since other objects can have refs to the QtInstance,
+ we can't rely on the QtInstance being deleted when the
+ RuntimeObjectImp is invalidate or deleted. This
+ could result in a stale JSObject being returned for
+ a valid Instance.
+
+
+ * bindings/qt/qt_instance.cpp:
+ (KJS::Bindings::QtRuntimeObjectImp::QtRuntimeObjectImp):
+ (KJS::Bindings::QtRuntimeObjectImp::~QtRuntimeObjectImp):
+ (KJS::Bindings::QtRuntimeObjectImp::invalidate):
+ (KJS::Bindings::QtRuntimeObjectImp::removeFromCache):
+ (KJS::Bindings::QtInstance::getRuntimeObject):
+ * bindings/runtime.cpp:
+ (KJS::Bindings::Instance::createRuntimeObject):
+ * bindings/runtime.h:
+
2008-01-23 Alp Toker <alp@atoker.com>
Rubber-stamped by Mark Rowe.
typedef QHash<QtInstance*, JSObject*> InstanceJSObjectMap;
static InstanceJSObjectMap cachedObjects;
+// Derived RuntimeObject
+class QtRuntimeObjectImp : public RuntimeObjectImp {
+ public:
+ QtRuntimeObjectImp(Instance *instance);
+ ~QtRuntimeObjectImp();
+ virtual void invalidate();
+ protected:
+ void removeFromCache();
+};
+
+QtRuntimeObjectImp::QtRuntimeObjectImp(Instance *instance)
+ : RuntimeObjectImp(instance)
+{
+}
+
+QtRuntimeObjectImp::~QtRuntimeObjectImp()
+{
+ removeFromCache();
+}
+
+void QtRuntimeObjectImp::invalidate()
+{
+ removeFromCache();
+ RuntimeObjectImp::invalidate();
+}
+
+void QtRuntimeObjectImp::removeFromCache()
+{
+ JSLock lock;
+ QtInstance *key = cachedObjects.key(this);
+ if (key)
+ cachedObjects.remove(key);
+}
+
+// QtInstance
QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject)
: Instance(rootObject)
, m_class(0)
JSLock lock;
JSObject* ret = cachedObjects.value(instance);
if (!ret) {
- ret = Instance::reallyCreateRuntimeObject(instance);
+ ret = new QtRuntimeObjectImp(instance);
cachedObjects.insert(instance, ret);
}
return ret;
if (instance->getBindingLanguage() == QtLanguage)
return QtInstance::getRuntimeObject(static_cast<QtInstance*>(instance));
#endif
- return reallyCreateRuntimeObject(instance);
-}
-
-JSObject* Instance::reallyCreateRuntimeObject(Instance* instance)
-{
JSLock lock;
return new RuntimeObjectImp(instance);
virtual BindingLanguage getBindingLanguage() const = 0;
protected:
- static JSObject* reallyCreateRuntimeObject(Instance*);
-
RefPtr<RootObject> _rootObject;
unsigned _refCount;
};