[v8] when a named item on document goes out of scope, actually remove it
authorjochen@chromium.org <jochen@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 13:41:02 +0000 (13:41 +0000)
committerjochen@chromium.org <jochen@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Feb 2012 13:41:02 +0000 (13:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79409

Reviewed by Adam Barth.

Source/WebCore:

The original change already included the code, but it led to some
problems, so it was reverted in http://trac.webkit.org/changeset/63845.
However, not removing the items leaks a considerable amount of memory,
so I'm adding the code back. The bug that led to the revert was that
the accessor was removed unconditionally. I'm now only removing it,
when the last item with that name is removed.

Test: fast/dom/HTMLDocument/named-item.html

* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::namedItemRemoved):

LayoutTests:

* fast/dom/HTMLDocument/named-item-expected.txt: Added.
* fast/dom/HTMLDocument/named-item.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLDocument/named-item-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLDocument/named-item.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/V8DOMWindowShell.cpp

index 159342c..3f17201 100644 (file)
@@ -1,3 +1,13 @@
+2012-02-24  Jochen Eisinger  <jochen@chromium.org>
+
+        [v8] when a named item on document goes out of scope, actually remove it
+        https://bugs.webkit.org/show_bug.cgi?id=79409
+
+        Reviewed by Adam Barth.
+
+        * fast/dom/HTMLDocument/named-item-expected.txt: Added.
+        * fast/dom/HTMLDocument/named-item.html: Added.
+
 2012-02-24  Flex Mobile  <rhauck@adobe.com>
 
         Convert some fast/regions pixel tests to reftests
diff --git a/LayoutTests/fast/dom/HTMLDocument/named-item-expected.txt b/LayoutTests/fast/dom/HTMLDocument/named-item-expected.txt
new file mode 100644 (file)
index 0000000..9eb935d
--- /dev/null
@@ -0,0 +1,3 @@
+Tests that the named item created for an image with an ID is correctly removed. The test passes, if you see a "PASS" message in the div below.
+
+PASS
diff --git a/LayoutTests/fast/dom/HTMLDocument/named-item.html b/LayoutTests/fast/dom/HTMLDocument/named-item.html
new file mode 100644 (file)
index 0000000..25818f5
--- /dev/null
@@ -0,0 +1,28 @@
+<html>
+<head>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+function test() {
+    var div = document.getElementById("testdiv");
+    var img = document.createElement("img");
+    img.id = "testimg";
+    div.appendChild(img);
+    div.innerHTML = "";
+    if ("testimg" in document)
+        div.innerText = "FAIL: named item was not removed";
+    else
+        div.innerText = "PASS";
+}
+</script>
+</head>
+<body onload="test()">
+<p>
+Tests that the named item created for an image with an ID is correctly removed.
+The test passes, if you see a "PASS" message in the div below.
+</p>
+<div id="testdiv"></div>
+</body>
+</html>
+
index fa50305..56710c5 100644 (file)
@@ -1,3 +1,22 @@
+2012-02-24  Jochen Eisinger  <jochen@chromium.org>
+
+        [v8] when a named item on document goes out of scope, actually remove it
+        https://bugs.webkit.org/show_bug.cgi?id=79409
+
+        Reviewed by Adam Barth.
+
+        The original change already included the code, but it led to some
+        problems, so it was reverted in http://trac.webkit.org/changeset/63845.
+        However, not removing the items leaks a considerable amount of memory,
+        so I'm adding the code back. The bug that led to the revert was that
+        the accessor was removed unconditionally. I'm now only removing it,
+        when the last item with that name is removed.
+
+        Test: fast/dom/HTMLDocument/named-item.html
+
+        * bindings/v8/V8DOMWindowShell.cpp:
+        (WebCore::V8DOMWindowShell::namedItemRemoved):
+
 2012-02-24  Kentaro Hara  <haraken@chromium.org>
 
         Move Worker-related APIs from DOMWindow.idl to DOMWindowWorker.idl
index a2fceb0..8d16a10 100644 (file)
@@ -577,6 +577,18 @@ void V8DOMWindowShell::namedItemAdded(HTMLDocument* doc, const AtomicString& nam
 
 void V8DOMWindowShell::namedItemRemoved(HTMLDocument* doc, const AtomicString& name)
 {
+    if (doc->hasNamedItem(name.impl()) || doc->hasExtraNamedItem(name.impl()))
+        return;
+
+    if (!initContextIfNeeded())
+        return;
+
+    v8::HandleScope handleScope;
+    v8::Context::Scope contextScope(m_context);
+
+    ASSERT(!m_document.IsEmpty());
+    checkDocumentWrapper(m_document, doc);
+    m_document->Delete(v8String(name));
 }
 
 void V8DOMWindowShell::updateSecurityOrigin()