Commit 54a5ebef authored by eae@chromium.org's avatar eae@chromium.org

2011-03-10 Emil A Eklund <eae@chromium.org>

        Reviewed by Darin Adler.

        Collection cache not reset when moving base node between documents
        https://bugs.webkit.org/show_bug.cgi?id=55446

        Add tests for accessing elements moved across documents using namedItem.

        * fast/dom/HTMLFormElement/invalid-form-field-expected.txt: Added.
        * fast/dom/HTMLFormElement/invalid-form-field.html: Added.
        * fast/dom/HTMLFormElement/move-option-between-documents-expected.txt: Added.
        * fast/dom/HTMLFormElement/move-option-between-documents.html: Added.
        * fast/dom/collection-nameditem-move-between-documents-expected.txt: Added.
        * fast/dom/collection-nameditem-move-between-documents.html: Added.
2011-03-10  Emil A Eklund  <eae@chromium.org>

        Reviewed by Darin Adler.

        Collection cache not reset when moving base node between documents
        https://bugs.webkit.org/show_bug.cgi?id=55446

        Fix bug where HTMLCollection::resetCollectionInfo does not reset the
        cache when the base node is moved to a different document by making sure
        that the DOMVersion is updated and that it's unique across documents.

        Tests: fast/dom/HTMLFormElement/invalid-form-field.html
               fast/dom/HTMLFormElement/move-option-between-documents.html
               fast/dom/collection-nameditem-move-between-documents.html

        * dom/Document.cpp:
        (WebCore::Document::Document):
        * dom/Document.h:
        (WebCore::Document::incDOMTreeVersion):
        (WebCore::Document::domTreeVersion):
        * dom/Node.cpp:
        (WebCore::Node::setDocumentRecursively):
        * html/FormAssociatedElement.cpp:
        (WebCore::FormAssociatedElement::resetFormOwner):
        * html/HTMLCollection.cpp:
        (WebCore::HTMLCollection::resetCollectionInfo):
        * xml/XPathResult.h:

git-svn-id: svn://svn.chromium.org/blink/trunk@80797 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 23fbdfd4
2011-03-10 Emil A Eklund <eae@chromium.org>
Reviewed by Darin Adler.
Collection cache not reset when moving base node between documents
https://bugs.webkit.org/show_bug.cgi?id=55446
Add tests for accessing elements moved across documents using namedItem.
* fast/dom/HTMLFormElement/invalid-form-field-expected.txt: Added.
* fast/dom/HTMLFormElement/invalid-form-field.html: Added.
* fast/dom/HTMLFormElement/move-option-between-documents-expected.txt: Added.
* fast/dom/HTMLFormElement/move-option-between-documents.html: Added.
* fast/dom/collection-nameditem-move-between-documents-expected.txt: Added.
* fast/dom/collection-nameditem-move-between-documents.html: Added.
2011-03-10 Alexey Proskuryakov <ap@apple.com> 2011-03-10 Alexey Proskuryakov <ap@apple.com>
Reviewed by Dan Bernstein. Reviewed by Dan Bernstein.
PASS str is 'threw exception'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<div id="test">
<div id="console"></div>
</body>
<script>
window.jsTestIsAsync = true;
var form, input, str;
window.onload = function()
{
form = document.body.appendChild(document.createElement("form"));
form.id = "form";
input = document.createElement("input");
input.id = "input";
input.setAttribute("form", "form");
form.elements.namedItem("input");
input = null;
gc();
setTimeout(step2, 100);
}
function step2()
{
try {
str = typeof form['input'].form;
} catch(e) {
str = 'threw exception';
}
shouldBe("str", "'threw exception'");
finishJSTest();
}
window.successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</html>
PASS typeof select.options.namedItem('option') is 'undefined'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<div id="test">
<div id="console"></div>
</body>
<script>
window.jsTestIsAsync = true;
var select, doc1, doc2, str;
window.onload = function()
{
select = document.createElement("select");
var option = select.appendChild(document.createElement("option"));
option.id = "option";
doc1 = document.implementation.createHTMLDocument();
doc2 = document.implementation.createHTMLDocument();
doc1.body.appendChild(select);
select.options.namedItem("option");
select.removeChild(option);
option = null;
gc();
setTimeout(step2, 100);
}
function step2()
{
doc1.body.removeChild(select);
doc2.body.appendChild(select);
shouldBe("typeof select.options.namedItem('option')", "'undefined'");
finishJSTest();
}
window.successfullyParsed = true;
</script>
<script src="../../js/resources/js-test-post.js"></script>
</html>
PASS typeof children.namedItem('child') is 'undefined'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<div id="test">
<div id="console"></div>
</body>
<script>
window.jsTestIsAsync = true;
var element, children;
window.onload = function()
{
element = document.createElement("div");
var child = element.appendChild(document.createElement("div"));
child.id = "child";
children = element.children;
children.namedItem("child");
var doc = document.implementation.createHTMLDocument();
doc.adoptNode(element);
element.removeChild(child);
child = null;
gc();
setTimeout(step2, 100);
}
function step2()
{
document.adoptNode(element);
shouldBe("typeof children.namedItem('child')", "'undefined'");
finishJSTest();
}
window.successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</html>
2011-03-10 Emil A Eklund <eae@chromium.org>
Reviewed by Darin Adler.
Collection cache not reset when moving base node between documents
https://bugs.webkit.org/show_bug.cgi?id=55446
Fix bug where HTMLCollection::resetCollectionInfo does not reset the
cache when the base node is moved to a different document by making sure
that the DOMVersion is updated and that it's unique across documents.
Tests: fast/dom/HTMLFormElement/invalid-form-field.html
fast/dom/HTMLFormElement/move-option-between-documents.html
fast/dom/collection-nameditem-move-between-documents.html
* dom/Document.cpp:
(WebCore::Document::Document):
* dom/Document.h:
(WebCore::Document::incDOMTreeVersion):
(WebCore::Document::domTreeVersion):
* dom/Node.cpp:
(WebCore::Node::setDocumentRecursively):
* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::resetFormOwner):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::resetCollectionInfo):
* xml/XPathResult.h:
2011-03-10 Gyuyoung Kim <gyuyoung.kim@samsung.com> 2011-03-10 Gyuyoung Kim <gyuyoung.kim@samsung.com>
Unreviewed build fix. Unreviewed build fix.
......
...@@ -372,11 +372,13 @@ private: ...@@ -372,11 +372,13 @@ private:
Document* m_document; Document* m_document;
}; };
uint64_t Document::s_globalTreeVersion = 0;
Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML) Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
: ContainerNode(0) : ContainerNode(0)
, m_compatibilityMode(NoQuirksMode) , m_compatibilityMode(NoQuirksMode)
, m_compatibilityModeLocked(false) , m_compatibilityModeLocked(false)
, m_domTreeVersion(0) , m_domTreeVersion(++s_globalTreeVersion)
, m_styleSheets(StyleSheetList::create(this)) , m_styleSheets(StyleSheetList::create(this))
, m_readyState(Complete) , m_readyState(Complete)
, m_styleRecalcTimer(this, &Document::styleRecalcTimerFired) , m_styleRecalcTimer(this, &Document::styleRecalcTimerFired)
......
...@@ -911,8 +911,8 @@ public: ...@@ -911,8 +911,8 @@ public:
TransformSource* transformSource() const { return m_transformSource.get(); } TransformSource* transformSource() const { return m_transformSource.get(); }
#endif #endif
void incDOMTreeVersion() { ++m_domTreeVersion; } void incDOMTreeVersion() { m_domTreeVersion = ++s_globalTreeVersion; }
unsigned domTreeVersion() const { return m_domTreeVersion; } uint64_t domTreeVersion() const { return m_domTreeVersion; }
void setDocType(PassRefPtr<DocumentType>); void setDocType(PassRefPtr<DocumentType>);
...@@ -1237,7 +1237,8 @@ private: ...@@ -1237,7 +1237,8 @@ private:
RefPtr<Node> m_activeNode; RefPtr<Node> m_activeNode;
mutable RefPtr<Element> m_documentElement; mutable RefPtr<Element> m_documentElement;
unsigned m_domTreeVersion; uint64_t m_domTreeVersion;
static uint64_t s_globalTreeVersion;
HashSet<NodeIterator*> m_nodeIterators; HashSet<NodeIterator*> m_nodeIterators;
HashSet<Range*> m_ranges; HashSet<Range*> m_ranges;
......
...@@ -762,6 +762,13 @@ void Node::setDocumentRecursively(Document* document) ...@@ -762,6 +762,13 @@ void Node::setDocumentRecursively(Document* document)
if (this->document() == document) if (this->document() == document)
return; return;
// If an element is moved from a document and then eventually back again the collection cache for
// that element may contain stale data as changes made to it will have updated the DOMTreeVersion
// of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
// we ensure that the collection cache will be invalidated as needed when the element is moved back.
if (this->document())
this->document()->incDOMTreeVersion();
for (Node* node = this; node; node = node->traverseNextNode(this)) { for (Node* node = this; node; node = node->traverseNextNode(this)) {
node->setDocument(document); node->setDocument(document);
if (!node->isElementNode()) if (!node->isElementNode())
......
...@@ -132,7 +132,7 @@ void FormAssociatedElement::resetFormOwner(HTMLFormElement* form) ...@@ -132,7 +132,7 @@ void FormAssociatedElement::resetFormOwner(HTMLFormElement* form)
m_form->removeFormElement(this); m_form->removeFormElement(this);
} }
m_form = 0; m_form = 0;
if (!formId.isNull()) { if (!formId.isNull() && element->inDocument()) {
// The HTML5 spec says that the element should be associated with // The HTML5 spec says that the element should be associated with
// the first element in the document to have an ID that equal to // the first element in the document to have an ID that equal to
// the value of form attribute, so we put the result of // the value of form attribute, so we put the result of
......
...@@ -67,7 +67,7 @@ HTMLCollection::~HTMLCollection() ...@@ -67,7 +67,7 @@ HTMLCollection::~HTMLCollection()
void HTMLCollection::resetCollectionInfo() const void HTMLCollection::resetCollectionInfo() const
{ {
unsigned docversion = static_cast<HTMLDocument*>(m_base->document())->domTreeVersion(); uint64_t docversion = static_cast<HTMLDocument*>(m_base->document())->domTreeVersion();
if (!m_info) { if (!m_info) {
m_info = new CollectionCache; m_info = new CollectionCache;
......
...@@ -80,7 +80,7 @@ namespace WebCore { ...@@ -80,7 +80,7 @@ namespace WebCore {
XPath::NodeSet m_nodeSet; // FIXME: why duplicate the node set stored in m_value? XPath::NodeSet m_nodeSet; // FIXME: why duplicate the node set stored in m_value?
unsigned short m_resultType; unsigned short m_resultType;
RefPtr<Document> m_document; RefPtr<Document> m_document;
unsigned m_domTreeVersion; uint64_t m_domTreeVersion;
}; };
} // namespace WebCore } // namespace WebCore
......
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