Reviewed by Darin.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Jun 2004 08:12:00 +0000 (08:12 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Jun 2004 08:12:00 +0000 (08:12 +0000)
<rdar://problem/3685309>: (properties not shared for JS wrappers of same DOM object, accessed from different frames)

        * khtml/ecma/kjs_binding.cpp:
        (ScriptInterpreter::domObjects):
        (ScriptInterpreter::domObjectsPerDocument):
        (ScriptInterpreter::ScriptInterpreter):
        (ScriptInterpreter::forgetDOMObject):
        (ScriptInterpreter::getDOMObjectForDocument):
        (ScriptInterpreter::putDOMObjectForDocument):
        (ScriptInterpreter::deleteDOMObjectsForDocument):
        (ScriptInterpreter::mark):
        (ScriptInterpreter::forgetDOMObjectsForDocument):
        (ScriptInterpreter::updateDOMObjectDocument):
        * khtml/ecma/kjs_binding.h:
        (KJS::ScriptInterpreter::getDOMObject):
        (KJS::ScriptInterpreter::putDOMObject):
        (KJS::ScriptInterpreter::deleteDOMObject):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@6851 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/ecma/kjs_binding.cpp
WebCore/khtml/ecma/kjs_binding.h

index cfdf378ad514bd1f4ec13a7a096efe918f0299bc..10230d3096c5729ba495309c74f4034a67104a59 100644 (file)
@@ -1,3 +1,25 @@
+2004-06-15  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Darin.
+
+       <rdar://problem/3685309>: (properties not shared for JS wrappers of same DOM object, accessed from different frames)
+
+        * khtml/ecma/kjs_binding.cpp:
+        (ScriptInterpreter::domObjects):
+        (ScriptInterpreter::domObjectsPerDocument):
+        (ScriptInterpreter::ScriptInterpreter):
+        (ScriptInterpreter::forgetDOMObject):
+        (ScriptInterpreter::getDOMObjectForDocument):
+        (ScriptInterpreter::putDOMObjectForDocument):
+        (ScriptInterpreter::deleteDOMObjectsForDocument):
+        (ScriptInterpreter::mark):
+        (ScriptInterpreter::forgetDOMObjectsForDocument):
+        (ScriptInterpreter::updateDOMObjectDocument):
+        * khtml/ecma/kjs_binding.h:
+        (KJS::ScriptInterpreter::getDOMObject):
+        (KJS::ScriptInterpreter::putDOMObject):
+        (KJS::ScriptInterpreter::deleteDOMObject):
+
 2004-06-15  Darin Adler  <darin@apple.com>
 
         - rolled out Ken's fix for <rdar://problem/3672377> assertion failure in AppendNodeCommandImpl::doApply due to non-0 exception code trying to insert a DIV markup string
index e9799ac7c602ec60aed5758fe45d42fca7608132..521968603cd5900fa17f9fd355f0ad6faf72ef9b 100644 (file)
@@ -140,14 +140,34 @@ Value DOMFunction::call(ExecState *exec, Object &thisObj, const List &args)
   return val;
 }
 
+static QPtrDict<DOMObject> * staticDomObjects = 0;
+QPtrDict< QPtrDict<DOMObject> > * staticDomObjectsPerDocument = 0;
+
+QPtrDict<DOMObject> & ScriptInterpreter::domObjects()
+{
+  if (!staticDomObjects) {
+    staticDomObjects = new QPtrDict<DOMObject>(1021);
+  }
+  return *staticDomObjects;
+}
+
+QPtrDict< QPtrDict<DOMObject> > & ScriptInterpreter::domObjectsPerDocument()
+{
+  if (!staticDomObjects) {
+    staticDomObjectsPerDocument = new QPtrDict<QPtrDict<DOMObject> >();
+    staticDomObjectsPerDocument->setAutoDelete(true);
+  }
+  return *staticDomObjectsPerDocument;
+}
+
+
 ScriptInterpreter::ScriptInterpreter( const Object &global, KHTMLPart* part )
-  : Interpreter( global ), m_part( part ), m_domObjects(1021),
+  : Interpreter( global ), m_part( part ),
     m_evt( 0L ), m_inlineCode(false), m_timerCallback(false)
 {
 #ifdef KJS_VERBOSE
   kdDebug(6070) << "ScriptInterpreter::ScriptInterpreter " << this << " for part=" << m_part << endl;
 #endif
-  m_domObjectsPerDocument.setAutoDelete(true);
 }
 
 ScriptInterpreter::~ScriptInterpreter()
@@ -159,20 +179,12 @@ ScriptInterpreter::~ScriptInterpreter()
 
 void ScriptInterpreter::forgetDOMObject( void* objectHandle )
 {
-  InterpreterImp *first = InterpreterImp::firstInterpreter();
-  if (first) {
-    InterpreterImp *scr = first;
-    do {
-      if ( scr->interpreter()->rtti() == 1 )
-        static_cast<ScriptInterpreter *>(scr->interpreter())->deleteDOMObject( objectHandle );
-      scr = scr->nextInterpreter();
-    } while (scr != first);
-  }
+  deleteDOMObject( objectHandle );
 }
 
-DOMObject* ScriptInterpreter::getDOMObjectForDocument( DOM::DocumentImpl* documentHandle, void *objectHandle ) const
+DOMObject* ScriptInterpreter::getDOMObjectForDocument( DOM::DocumentImpl* documentHandle, void *objectHandle )
 {
-  QPtrDict<DOMObject> *documentDict = (QPtrDict<DOMObject> *)m_domObjectsPerDocument[documentHandle];
+  QPtrDict<DOMObject> *documentDict = (QPtrDict<DOMObject> *)domObjectsPerDocument()[documentHandle];
   if (documentDict) {
     return (*documentDict)[objectHandle];
   }
@@ -182,10 +194,10 @@ DOMObject* ScriptInterpreter::getDOMObjectForDocument( DOM::DocumentImpl* docume
 
 void ScriptInterpreter::putDOMObjectForDocument( DOM::DocumentImpl* documentHandle, void *objectHandle, DOMObject *obj )
 {
-  QPtrDict<DOMObject> *documentDict = (QPtrDict<DOMObject> *)m_domObjectsPerDocument[documentHandle];
+  QPtrDict<DOMObject> *documentDict = (QPtrDict<DOMObject> *)domObjectsPerDocument()[documentHandle];
   if (!documentDict) {
     documentDict = new QPtrDict<DOMObject>();
-    m_domObjectsPerDocument.insert(documentHandle, documentDict);
+    domObjectsPerDocument().insert(documentHandle, documentDict);
   }
 
   documentDict->insert( objectHandle, obj );
@@ -193,12 +205,12 @@ void ScriptInterpreter::putDOMObjectForDocument( DOM::DocumentImpl* documentHand
 
 bool ScriptInterpreter::deleteDOMObjectsForDocument( DOM::DocumentImpl* documentHandle )
 {
-  return m_domObjectsPerDocument.remove( documentHandle );
+  return domObjectsPerDocument().remove( documentHandle );
 }
 
 void ScriptInterpreter::mark()
 {
-  QPtrDictIterator<QPtrDict<DOMObject> > dictIterator(m_domObjectsPerDocument);
+  QPtrDictIterator<QPtrDict<DOMObject> > dictIterator(domObjectsPerDocument());
 
   QPtrDict<DOMObject> *objectDict;
   while ((objectDict = dictIterator.current())) {
@@ -217,34 +229,14 @@ void ScriptInterpreter::mark()
 
 void ScriptInterpreter::forgetDOMObjectsForDocument( DOM::DocumentImpl* documentHandle )
 {
-  InterpreterImp *first = InterpreterImp::firstInterpreter();
-  if (first) {
-    InterpreterImp *scr = first;
-    do {
-      if ( scr->interpreter()->rtti() == 1 )
-        static_cast<ScriptInterpreter *>(scr->interpreter())->deleteDOMObjectsForDocument( documentHandle );
-      scr = scr->nextInterpreter();
-    } while (scr != first);
-  }
+  deleteDOMObjectsForDocument( documentHandle );
 }
 
 void ScriptInterpreter::updateDOMObjectDocument(void *objectHandle, DOM::DocumentImpl *oldDoc, DOM::DocumentImpl *newDoc)
 {
-  InterpreterImp *first = InterpreterImp::firstInterpreter();
-  if (first) {
-    InterpreterImp *scr = first;
-    do {
-      if ( scr->interpreter()->rtti() == 1 ) {
-       ScriptInterpreter *interp = static_cast<ScriptInterpreter *>(scr->interpreter());
-       
-       DOMObject* cachedObject = interp->getDOMObjectForDocument(oldDoc, objectHandle);
-       if (cachedObject) {
-         interp->putDOMObjectForDocument(newDoc, objectHandle, cachedObject);
-       }
-      }
-       
-      scr = scr->nextInterpreter();
-    } while (scr != first);
+  DOMObject* cachedObject = getDOMObjectForDocument(oldDoc, objectHandle);
+  if (cachedObject) {
+    putDOMObjectForDocument(newDoc, objectHandle, cachedObject);
   }
 }
 
index 304e5b64676c883e0bae653991453def2316828d..29785c87502c17470fc72fe6550b98bd3493fda4 100644 (file)
@@ -90,19 +90,19 @@ namespace KJS {
     ScriptInterpreter( const Object &global, KHTMLPart* part );
     virtual ~ScriptInterpreter();
 
-    DOMObject* getDOMObject( void* objectHandle ) const {
-      return m_domObjects[objectHandle];
+    static DOMObject* getDOMObject( void* objectHandle ) {
+      return domObjects()[objectHandle];
     }
-    void putDOMObject( void* objectHandle, DOMObject* obj ) {
-      m_domObjects.insert( objectHandle, obj );
+    static void putDOMObject( void* objectHandle, DOMObject* obj ) {
+      domObjects().insert( objectHandle, obj );
     }
-    bool deleteDOMObject( void* objectHandle ) {
-      return m_domObjects.remove( objectHandle );
+    static bool deleteDOMObject( void* objectHandle ) {
+      return domObjects().remove( objectHandle );
     }
 
-    DOMObject* getDOMObjectForDocument( DOM::DocumentImpl* documentHandle, void *objectHandle ) const;
-    void putDOMObjectForDocument( DOM::DocumentImpl* documentHandle, void *objectHandle, DOMObject *obj );
-    bool deleteDOMObjectsForDocument( DOM::DocumentImpl* documentHandle );
+    static DOMObject* getDOMObjectForDocument( DOM::DocumentImpl* documentHandle, void *objectHandle );
+    static void putDOMObjectForDocument( DOM::DocumentImpl* documentHandle, void *objectHandle, DOMObject *obj );
+    static bool deleteDOMObjectsForDocument( DOM::DocumentImpl* documentHandle );
 
     /**
      * Static method. Makes all interpreters forget about the object
@@ -134,8 +134,9 @@ namespace KJS {
     
   private:
     KHTMLPart* m_part;
-    QPtrDict<DOMObject> m_domObjects;
-    QPtrDict<QPtrDict<DOMObject> > m_domObjectsPerDocument;
+
+    static QPtrDict<DOMObject> &domObjects();
+    static QPtrDict<QPtrDict<DOMObject> > &domObjectsPerDocument();
 
     DOM::Event *m_evt;
     bool m_inlineCode;