Title: [151627] trunk
Revision
151627
Author
[email protected]
Date
2013-06-16 19:25:37 -0700 (Sun, 16 Jun 2013)

Log Message

Fix two assertion failures in Range::insertNode
https://bugs.webkit.org/show_bug.cgi?id=116511

Reviewed by Ryosuke Niwa.

Source/WebCore:

> ASSERTION FAILED: childBefore == (offset ? container->childNode(offset - 1) : 0)
> third_party/WebKit/Source/WebCore/dom/RangeBoundaryPoint.h(115) : void WebCore::RangeBoundaryPoint::set(PassRefPtr<WebCore::Node>, int, WebCore::Node *)

> ASSERTION FAILED: child->parentNode()
> ../../third_party/WebKit/Source/core/dom/RangeBoundaryPoint.h(133) : void WebCore::RangeBoundaryPoint::setToBeforeChild(WebCore::Node *)
>  1   0x87594b2 WebCore::RangeBoundaryPoint::setToBeforeChild(WebCore::Node*)
>  2   0x87534a9 WebCore::Range::insertNode(WTF::PassRefPtr<WebCore::Node>, int&)

Range::insertNode calls Node::insertBefore, in which an event handler
can update the DOM structure so that RangeBoundaryPoint don't like. We
postpone event dispatching by EventQueueScope.

Also, remove old comments about Acid3. The behavior is standardized.
(Step 9 of http://dom.spec.whatwg.org/#dom-range-insertnode)

This patch imports http://src.chromium.org/viewvc/blink?view=revision&revision=150470 .

Test: fast/dom/Range/range-insertNode-assertion.html

* dom/Range.cpp:
(WebCore::Range::insertNode):
 - Add EventQueueScope
 - Remove obsolete comments

LayoutTests:

We need to update fast/dom/insertBefore-refChild-crash.html because the
test caused recursive calls to the event handler. container.innerHTML=''
did nothing before this CL. Now container has the newChild because
DOMNodeRemoved event dispatching is delayed until Range::insertNode
completion.

We need to update fast/text/split-text-crash.xhtml so that it doesn't
stop when the event handler is called twice. I'm not sure why the test
worked before this CL.

* fast/dom/Range/range-insertNode-assertion-expected.txt: Added.
* fast/dom/Range/range-insertNode-assertion.html: Added.
* fast/dom/insertBefore-refChild-crash.html:
* fast/text/split-text-crash.xhtml:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (151626 => 151627)


--- trunk/LayoutTests/ChangeLog	2013-06-17 01:58:38 UTC (rev 151626)
+++ trunk/LayoutTests/ChangeLog	2013-06-17 02:25:37 UTC (rev 151627)
@@ -1,3 +1,25 @@
+2013-06-16  Kent Tamura  <[email protected]>
+
+        Fix two assertion failures in Range::insertNode
+        https://bugs.webkit.org/show_bug.cgi?id=116511
+
+        Reviewed by Ryosuke Niwa.
+
+        We need to update fast/dom/insertBefore-refChild-crash.html because the
+        test caused recursive calls to the event handler. container.innerHTML=''
+        did nothing before this CL. Now container has the newChild because
+        DOMNodeRemoved event dispatching is delayed until Range::insertNode
+        completion.
+
+        We need to update fast/text/split-text-crash.xhtml so that it doesn't
+        stop when the event handler is called twice. I'm not sure why the test
+        worked before this CL.
+
+        * fast/dom/Range/range-insertNode-assertion-expected.txt: Added.
+        * fast/dom/Range/range-insertNode-assertion.html: Added.
+        * fast/dom/insertBefore-refChild-crash.html:
+        * fast/text/split-text-crash.xhtml:
+
 2013-06-16  Gyuyoung Kim  <[email protected]>
 
         Unreviewed. Added new baselines for some of editing/style tests, which works on EFL port.

Added: trunk/LayoutTests/fast/dom/Range/range-insertNode-assertion-expected.txt (0 => 151627)


--- trunk/LayoutTests/fast/dom/Range/range-insertNode-assertion-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Range/range-insertNode-assertion-expected.txt	2013-06-17 02:25:37 UTC (rev 151627)
@@ -0,0 +1,10 @@
+No assertion failures even if a DOM mutation event handler updates nodes in a Range during Range::insertNode.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS if this did not crash.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Range/range-insertNode-assertion.html (0 => 151627)


--- trunk/LayoutTests/fast/dom/Range/range-insertNode-assertion.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Range/range-insertNode-assertion.html	2013-06-17 02:25:37 UTC (rev 151627)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<body>
+<script src=""
+<div id="parent1">text</div>
+<div id="parent2">text</div>
+<script>
+function handleInsertion() {
+    document.removeEventListener('DOMNodeInserted', handleInsertion);
+    parent.innerHTML = '';
+}
+document.addEventListener('DOMNodeInserted', handleInsertion);
+var parent = document.getElementById('parent1');
+var range = document.createRange();
+range.setStart(parent, 0);
+range.setEnd(parent, 0);
+range.insertNode(document.createElement('span'));
+parent.remove();
+
+function handleInsertion2() {
+    if (parent.childNodes.length != 3)
+        return;
+    var textNodeCreatedBySplitText = parent.lastChild;
+    parent.removeChild(textNodeCreatedBySplitText);
+    document.removeEventListener('DOMNodeInserted', handleInsertion2);
+}
+document.addEventListener('DOMNodeInserted', handleInsertion2);
+parent = document.getElementById('parent2');
+range.setStart(parent2.firstChild, 2);
+range.setEnd(parent2.firstChild, 2);
+range.insertNode(document.createElement('span'));
+
+description('No assertion failures even if a DOM mutation event handler updates nodes in a Range during Range::insertNode.');
+testPassed('if this did not crash.');
+parent.remove();
+</script>
+<script src=""
+</body>

Modified: trunk/LayoutTests/fast/dom/insertBefore-refChild-crash.html (151626 => 151627)


--- trunk/LayoutTests/fast/dom/insertBefore-refChild-crash.html	2013-06-17 01:58:38 UTC (rev 151626)
+++ trunk/LayoutTests/fast/dom/insertBefore-refChild-crash.html	2013-06-17 02:25:37 UTC (rev 151627)
@@ -8,10 +8,12 @@
 
 var container = document.getElementById('container');
 var newChild = document.getElementById('newChild');
-newChild.addEventListener('DOMNodeRemoved', function() {
+function handleNodeRemoved() {
+    newChild.removeEventListener('DOMNodeRemoved', handleNodeRemoved);
     container.innerHTML = '';
     gc();
-}, false);
+}
+newChild.addEventListener('DOMNodeRemoved', handleNodeRemoved, false);
 var range = document.createRange();
 range.selectNodeContents(container);
 range.insertNode(newChild);

Modified: trunk/LayoutTests/fast/text/split-text-crash.xhtml (151626 => 151627)


--- trunk/LayoutTests/fast/text/split-text-crash.xhtml	2013-06-17 01:58:38 UTC (rev 151626)
+++ trunk/LayoutTests/fast/text/split-text-crash.xhtml	2013-06-17 02:25:37 UTC (rev 151627)
@@ -12,7 +12,8 @@
     var range = document.createRange();
     range.setStart(textNode, 0);
     document.addEventListener("DOMNodeInserted", function () {
-        document.body.removeChild(textNode);
+        if (textNode)
+            document.body.removeChild(textNode);
         textNode = null;
 
         if (window.testRunner) {

Modified: trunk/Source/WebCore/ChangeLog (151626 => 151627)


--- trunk/Source/WebCore/ChangeLog	2013-06-17 01:58:38 UTC (rev 151626)
+++ trunk/Source/WebCore/ChangeLog	2013-06-17 02:25:37 UTC (rev 151627)
@@ -1,3 +1,34 @@
+2013-06-16  Kent Tamura  <[email protected]>
+
+        Fix two assertion failures in Range::insertNode
+        https://bugs.webkit.org/show_bug.cgi?id=116511
+
+        Reviewed by Ryosuke Niwa.
+
+        > ASSERTION FAILED: childBefore == (offset ? container->childNode(offset - 1) : 0)
+        > third_party/WebKit/Source/WebCore/dom/RangeBoundaryPoint.h(115) : void WebCore::RangeBoundaryPoint::set(PassRefPtr<WebCore::Node>, int, WebCore::Node *)
+
+        > ASSERTION FAILED: child->parentNode()
+        > ../../third_party/WebKit/Source/core/dom/RangeBoundaryPoint.h(133) : void WebCore::RangeBoundaryPoint::setToBeforeChild(WebCore::Node *)
+        >  1   0x87594b2 WebCore::RangeBoundaryPoint::setToBeforeChild(WebCore::Node*)
+        >  2   0x87534a9 WebCore::Range::insertNode(WTF::PassRefPtr<WebCore::Node>, int&)
+
+        Range::insertNode calls Node::insertBefore, in which an event handler
+        can update the DOM structure so that RangeBoundaryPoint don't like. We
+        postpone event dispatching by EventQueueScope.
+
+        Also, remove old comments about Acid3. The behavior is standardized.
+        (Step 9 of http://dom.spec.whatwg.org/#dom-range-insertnode)
+
+        This patch imports http://src.chromium.org/viewvc/blink?view=revision&revision=150470 .
+
+        Test: fast/dom/Range/range-insertNode-assertion.html
+
+        * dom/Range.cpp:
+        (WebCore::Range::insertNode):
+         - Add EventQueueScope
+         - Remove obsolete comments
+
 2013-06-16  Simon Fraser  <[email protected]>
 
         Fixed backgrounds in composited layers not repainted on scrolling

Modified: trunk/Source/WebCore/dom/Range.cpp (151626 => 151627)


--- trunk/Source/WebCore/dom/Range.cpp	2013-06-17 01:58:38 UTC (rev 151626)
+++ trunk/Source/WebCore/dom/Range.cpp	2013-06-17 02:25:37 UTC (rev 151627)
@@ -42,6 +42,7 @@
 #include "RangeException.h"
 #include "RenderBoxModelObject.h"
 #include "RenderText.h"
+#include "ScopedEventQueue.h"
 #include "Text.h"
 #include "TextIterator.h"
 #include "VisiblePosition.h"
@@ -1021,6 +1022,7 @@
         break;
     }
 
+    EventQueueScope scope;
     bool collapsed = m_start == m_end;
     RefPtr<Node> container;
     if (startIsText) {
@@ -1034,8 +1036,6 @@
         if (ec)
             return;
 
-        // This special case doesn't seem to match the DOM specification, but it's currently required
-        // to pass Acid3. We might later decide to remove this.
         if (collapsed)
             m_end.setToBeforeChild(newText.get());
     } else {
@@ -1049,8 +1049,6 @@
         if (ec)
             return;
 
-        // This special case doesn't seem to match the DOM specification, but it's currently required
-        // to pass Acid3. We might later decide to remove this.
         if (collapsed && numNewChildren)
             m_end.set(m_start.container(), startOffset + numNewChildren, lastChild.get());
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to