Commit 1613ae76 authored by morrita@google.com's avatar morrita@google.com

ShadowRoot.getElementById() returns removed node.

https://bugs.webkit.org/show_bug.cgi?id=62184

Source/WebCore:

Deregitration of m_elementsById map is done at Element::removedFrom()
But the tree scope of the removed node is already reset from a shadow root
to a document.

This change lookup the old shadow root through its parent node and
deregitrater the node against it.

Reviewed by Dimitri Glazkov.

Test: fast/dom/shadow/get-element-by-id-in-shadow-mutation.html

* dom/Element.cpp:
(WebCore::treeScopeOfParent):
(WebCore):
(WebCore::Element::removedFrom):
* dom/Element.h:
(Element):
(WebCore::Element::updateId):
(WebCore):

LayoutTests:

Reviewed by Dimitri Glazkov.

* fast/dom/shadow/get-element-by-id-in-shadow-mutation-expected.txt: Added.
* fast/dom/shadow/get-element-by-id-in-shadow-mutation.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@118804 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9260d05d
2012-05-29 MORITA Hajime <morrita@google.com>
ShadowRoot.getElementById() returns removed node.
https://bugs.webkit.org/show_bug.cgi?id=62184
Reviewed by Dimitri Glazkov.
* fast/dom/shadow/get-element-by-id-in-shadow-mutation-expected.txt: Added.
* fast/dom/shadow/get-element-by-id-in-shadow-mutation.html: Added.
2012-05-29 Alexey Proskuryakov <ap@apple.com>
* platform/mac/Skipped: Skipping a heap profiler test (unsupported functionality).
......
Tests to ensure that ShadowRoot.getElementById works even after mutation
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS null is shadow.getElementById('foo')
PASS e0a is shadow.getElementById('foo')
PASS e0b is shadow.getElementById('foo')
PASS e0c is shadow.getElementById('foo')
PASS e0b is shadow.getElementById('foo')
PASS e0a is shadow.getElementById('foo')
PASS null is shadow.getElementById('foo')
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<div id="host"></div>
<script>
description("Tests to ensure that ShadowRoot.getElementById works even after mutation");
var host = document.getElementById("host");
var shadow = new WebKitShadowRoot(host);
shouldBe("null", "shadow.getElementById('foo')");
e0a = document.createElement("div");
e0a.id = "foo";
shadow.appendChild(e0a);
shouldBe("e0a", "shadow.getElementById('foo')");
e0b = document.createElement("span");
e0b.id = "foo";
shadow.insertBefore(e0b, e0a);
shouldBe("e0b", "shadow.getElementById('foo')");
e0c = document.createElement("p");
e0c.id = "foo";
e0cParent = document.createElement("div");
e0cParent.appendChild(e0c);
shadow.insertBefore(e0cParent, e0b);
shouldBe("e0c", "shadow.getElementById('foo')");
shadow.removeChild(e0cParent);
shouldBe("e0b", "shadow.getElementById('foo')");
shadow.removeChild(e0b);
shouldBe("e0a", "shadow.getElementById('foo')");
shadow.removeChild(e0a);
shouldBe("null", "shadow.getElementById('foo')");
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
2012-05-29 MORITA Hajime <morrita@google.com>
ShadowRoot.getElementById() returns removed node.
https://bugs.webkit.org/show_bug.cgi?id=62184
Deregitration of m_elementsById map is done at Element::removedFrom()
But the tree scope of the removed node is already reset from a shadow root
to a document.
This change lookup the old shadow root through its parent node and
deregitrater the node against it.
Reviewed by Dimitri Glazkov.
Test: fast/dom/shadow/get-element-by-id-in-shadow-mutation.html
* dom/Element.cpp:
(WebCore::treeScopeOfParent):
(WebCore):
(WebCore::Element::removedFrom):
* dom/Element.h:
(Element):
(WebCore::Element::updateId):
(WebCore):
2012-05-29 Dana Jansens <danakj@chromium.org>
[chromium] Unoccluded area in surfaces should always be clipped to the rootScissorRect
......
......@@ -914,6 +914,14 @@ Node::InsertionNotificationRequest Element::insertedInto(ContainerNode* insertio
return InsertionDone;
}
static inline TreeScope* treeScopeOfParent(Node* node, ContainerNode* insertionPoint)
{
if (Node* parent = node->parentNode())
parent->treeScope();
return insertionPoint->treeScope();
}
void Element::removedFrom(ContainerNode* insertionPoint)
{
#if ENABLE(FULLSCREEN_API)
......@@ -925,8 +933,8 @@ void Element::removedFrom(ContainerNode* insertionPoint)
if (insertionPoint->inDocument()) {
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull())
updateId(idValue, nullAtom);
if (!idValue.isNull() && inDocument())
updateId(treeScopeOfParent(this, insertionPoint), idValue, nullAtom);
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull())
......
......@@ -303,6 +303,7 @@ public:
virtual String title() const;
void updateId(const AtomicString& oldId, const AtomicString& newId);
void updateId(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
void updateName(const AtomicString& oldName, const AtomicString& newName);
void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
......@@ -587,7 +588,14 @@ inline void Element::updateId(const AtomicString& oldId, const AtomicString& new
if (oldId == newId)
return;
TreeScope* scope = treeScope();
updateId(treeScope(), oldId, newId);
}
inline void Element::updateId(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
{
ASSERT(inDocument());
ASSERT(oldId != newId);
if (!oldId.isEmpty())
scope->removeElementById(oldId, this);
if (!newId.isEmpty())
......
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