Commit 4d93d495 authored by mjs's avatar mjs
Browse files

Reviewed by Darin.

	- fixed 3128383 - DOM nodes should always use the same JS object

        * khtml/ecma/kjs_binding.h:
        * khtml/ecma/kjs_binding.cpp:
        (ScriptInterpreter::ScriptInterpreter): Set auto-delete to true on
	document dictionary.
        (ScriptInterpreter::getDOMObjectForDocument): New function - gets
	DOM object from per-document dictionary.
        (ScriptInterpreter::putDOMObjectForDocument): New function - put
	DOM object into per-document dictionary.
        (ScriptInterpreter::deleteDOMObjectsForDocument): Clear all
	objects from specific per-document dictionary.
        (ScriptInterpreter::mark): Mark per-document objects.
	(ScriptInterpreter::forgetDOMObjectsForDocument): Clear objects
	for this document from all interpreters.
        * khtml/ecma/kjs_dom.h:
        * khtml/ecma/kjs_dom.cpp:
        (KJS::getDOMNode): Use per-document rather than general DOM object
	dictionary.
        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::~DocumentImpl): Call forgetDOMObjectsForDocument.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3070 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1a418d9c
2002-12-15 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin.
- fixed 3128383 - DOM nodes should always use the same JS object
* khtml/ecma/kjs_binding.h:
* khtml/ecma/kjs_binding.cpp:
(ScriptInterpreter::ScriptInterpreter): Set auto-delete to true on
document dictionary.
(ScriptInterpreter::getDOMObjectForDocument): New function - gets
DOM object from per-document dictionary.
(ScriptInterpreter::putDOMObjectForDocument): New function - put
DOM object into per-document dictionary.
(ScriptInterpreter::deleteDOMObjectsForDocument): Clear all
objects from specific per-document dictionary.
(ScriptInterpreter::mark): Mark per-document objects.
(ScriptInterpreter::forgetDOMObjectsForDocument): Clear objects
for this document from all interpreters.
* khtml/ecma/kjs_dom.h:
* khtml/ecma/kjs_dom.cpp:
(KJS::getDOMNode): Use per-document rather than general DOM object
dictionary.
* khtml/xml/dom_docimpl.cpp:
(DocumentImpl::~DocumentImpl): Call forgetDOMObjectsForDocument.
2002-12-15 David Hyatt <hyatt@apple.com>
Fix for 3057974 and 3128713. I needed to make frames check to
......@@ -11,6 +37,7 @@
2002-12-15 David Hyatt <hyatt@apple.com>
>>>>>>> 1.1128
Fix for 3109226, epinions page is mostly blank. Add a hack
to disallow > but only inside attribute values for which there
is no corresponding attribute name.
......
2002-12-15 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin.
- fixed 3128383 - DOM nodes should always use the same JS object
* khtml/ecma/kjs_binding.h:
* khtml/ecma/kjs_binding.cpp:
(ScriptInterpreter::ScriptInterpreter): Set auto-delete to true on
document dictionary.
(ScriptInterpreter::getDOMObjectForDocument): New function - gets
DOM object from per-document dictionary.
(ScriptInterpreter::putDOMObjectForDocument): New function - put
DOM object into per-document dictionary.
(ScriptInterpreter::deleteDOMObjectsForDocument): Clear all
objects from specific per-document dictionary.
(ScriptInterpreter::mark): Mark per-document objects.
(ScriptInterpreter::forgetDOMObjectsForDocument): Clear objects
for this document from all interpreters.
* khtml/ecma/kjs_dom.h:
* khtml/ecma/kjs_dom.cpp:
(KJS::getDOMNode): Use per-document rather than general DOM object
dictionary.
* khtml/xml/dom_docimpl.cpp:
(DocumentImpl::~DocumentImpl): Call forgetDOMObjectsForDocument.
2002-12-15 David Hyatt <hyatt@apple.com>
Fix for 3057974 and 3128713. I needed to make frames check to
......@@ -11,6 +37,7 @@
2002-12-15 David Hyatt <hyatt@apple.com>
>>>>>>> 1.1128
Fix for 3109226, epinions page is mostly blank. Add a hack
to disallow > but only inside attribute values for which there
is no corresponding attribute name.
......
......@@ -141,6 +141,7 @@ ScriptInterpreter::ScriptInterpreter( const Object &global, KHTMLPart* part )
#ifdef KJS_VERBOSE
kdDebug(6070) << "ScriptInterpreter::ScriptInterpreter " << this << " for part=" << m_part << endl;
#endif
m_domObjectsPerDocument.setAutoDelete(true);
}
ScriptInterpreter::~ScriptInterpreter()
......@@ -163,6 +164,65 @@ void ScriptInterpreter::forgetDOMObject( void* objectHandle )
}
}
DOMObject* ScriptInterpreter::getDOMObjectForDocument( void* documentHandle, void *objectHandle ) const
{
QPtrDict<DOMObject> *documentDict = (QPtrDict<DOMObject> *)m_domObjectsPerDocument[documentHandle];
if (documentDict) {
return (*documentDict)[objectHandle];
}
return NULL;
}
void ScriptInterpreter::putDOMObjectForDocument( void* documentHandle, void *objectHandle, DOMObject *obj )
{
QPtrDict<DOMObject> *documentDict = (QPtrDict<DOMObject> *)m_domObjectsPerDocument[documentHandle];
if (!documentDict) {
documentDict = new QPtrDict<DOMObject>();
m_domObjectsPerDocument.insert(documentHandle, documentDict);
}
documentDict->insert( objectHandle, obj );
}
bool ScriptInterpreter::deleteDOMObjectsForDocument( void* documentHandle )
{
return m_domObjectsPerDocument.remove( documentHandle );
}
void ScriptInterpreter::mark()
{
QPtrDictIterator<QPtrDict<DOMObject> > dictIterator(m_domObjectsPerDocument);
QPtrDict<DOMObject> *objectDict;
while ((objectDict = dictIterator.current())) {
QPtrDictIterator<DOMObject> objectIterator(*objectDict);
DOMObject *obj;
while ((obj = objectIterator.current())) {
if (!obj->marked()) {
obj->mark();
}
++objectIterator;
}
++dictIterator;
}
}
void ScriptInterpreter::forgetDOMObjectsForDocument( void* 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);
}
}
bool ScriptInterpreter::isWindowOpenAllowed() const
{
if ( m_evt )
......
......@@ -96,10 +96,16 @@ namespace KJS {
bool deleteDOMObject( void* objectHandle ) {
return m_domObjects.remove( objectHandle );
}
DOMObject* getDOMObjectForDocument( void* documentHandle, void *objectHandle ) const;
void putDOMObjectForDocument( void* documentHandle, void *objectHandle, DOMObject *obj );
bool deleteDOMObjectsForDocument( void* documentHandle );
/**
* Static method. Makes all interpreters forget about the object
*/
static void forgetDOMObject( void* objectHandle );
static void forgetDOMObjectsForDocument( void* documentHandle );
KHTMLPart* part() const { return m_part; }
......@@ -116,9 +122,12 @@ namespace KJS {
*/
bool isWindowOpenAllowed() const;
virtual void mark();
private:
KHTMLPart* m_part;
QPtrDict<DOMObject> m_domObjects;
QPtrDict<QPtrDict<DOMObject> > m_domObjectsPerDocument;
DOM::Event *m_evt;
bool m_inlineCode;
bool m_timerCallback;
......
......@@ -76,11 +76,6 @@ DOMNode::DOMNode(const Object &proto, const DOM::Node &n)
{
}
DOMNode::~DOMNode()
{
ScriptInterpreter::forgetDOMObject(node.handle());
}
bool DOMNode::toBoolean(ExecState *) const
{
return !node.isNull();
......@@ -1255,7 +1250,9 @@ Value KJS::getDOMNode(ExecState *exec, const DOM::Node &n)
if (n.isNull())
return Null();
ScriptInterpreter* interp = static_cast<ScriptInterpreter *>(exec->interpreter());
if ((ret = interp->getDOMObject(n.handle())))
DOM::NodeImpl *doc = n.ownerDocument().handle();
if ((ret = interp->getDOMObjectForDocument(doc, n.handle())))
return Value(ret);
switch (n.nodeType()) {
......@@ -1289,6 +1286,7 @@ Value KJS::getDOMNode(ExecState *exec, const DOM::Node &n)
ret = new HTMLDocument(exec, static_cast<DOM::HTMLDocument>(n));
else
ret = new DOMDocument(exec, static_cast<DOM::Document>(n));
doc = n.handle();
break;
case DOM::Node::DOCUMENT_TYPE_NODE:
ret = new DOMDocumentType(exec, static_cast<DOM::DocumentType>(n));
......@@ -1302,7 +1300,8 @@ Value KJS::getDOMNode(ExecState *exec, const DOM::Node &n)
default:
ret = new DOMNode(exec, n);
}
interp->putDOMObject(n.handle(),ret);
interp->putDOMObjectForDocument(doc, n.handle(), ret);
return Value(ret);
}
......
......@@ -36,7 +36,6 @@ namespace KJS {
DOMNode(ExecState *exec, const DOM::Node &n);
// Constructor for inherited classes
DOMNode(const Object &proto, const DOM::Node &n);
~DOMNode();
virtual bool toBoolean(ExecState *) const;
virtual Value tryGet(ExecState *exec, const Identifier &propertyName) const;
Value getValueProperty(ExecState *exec, int token) const;
......
......@@ -35,6 +35,7 @@
#include "misc/htmlhashes.h"
#include "misc/helper.h"
#include "ecma/kjs_proxy.h"
#include "ecma/kjs_binding.h"
#include <qptrstack.h>
#include <qpaintdevicemetrics.h>
......@@ -294,6 +295,8 @@ DocumentImpl::DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
DocumentImpl::~DocumentImpl()
{
KJS::ScriptInterpreter::forgetDOMObjectsForDocument(this);
if (changedDocuments && m_docChanged)
changedDocuments->remove(this);
delete m_tokenizer;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment