aboutsummaryrefslogtreecommitdiff
path: root/www/waterfox/files/patch-bug1402469
blob: 4dae69a93f04b0291da5ca5c5f8e39983c685115 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
commit 6b4f644b9a4e
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date:   Mon Sep 25 14:15:50 2017 +0900

    Bug 1402469 - Part 1. Return value of ConvertListType should use Element instead of nsresult. r=masayuki, a=sledru
    
    This is a typo bug of Bug 1053779 Part 2.  ConvertListType might return NS_OK
    even if ReplaceContainer doesn't return valid value.
    
    So, to clean up code, we should return Element instead of nsresult since out
    parameter of this function is Element only.
    
    MozReview-Commit-ID: 44UHETzcdGy
    
    --HG--
    extra : source : 5efdecc086858b4b4e5b0fcf9b7f27ef63d91738
---
 editor/libeditor/HTMLEditRules.cpp | 47 +++++++++++++++++---------------------
 editor/libeditor/HTMLEditRules.h   |  4 ++--
 2 files changed, 23 insertions(+), 28 deletions(-)

diff --git editor/libeditor/HTMLEditRules.cpp editor/libeditor/HTMLEditRules.cpp
index ad613517269d..fdb15fec7b2f 100644
--- editor/libeditor/HTMLEditRules.cpp
+++ editor/libeditor/HTMLEditRules.cpp
@@ -2960,9 +2960,8 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
     // Nodes are same type.  merge them.
     EditorDOMPoint pt = JoinNodesSmart(*leftBlock, *rightBlock);
     if (pt.node && mergeLists) {
-      nsCOMPtr<Element> newBlock;
-      ConvertListType(rightBlock, getter_AddRefs(newBlock),
-                      existingList, nsGkAtoms::li);
+      RefPtr<Element> newBlock =
+        ConvertListType(rightBlock, existingList, nsGkAtoms::li);
     }
     ret.MarkAsHandled();
   } else {
@@ -3320,18 +3319,19 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
         NS_ENSURE_STATE(mHTMLEditor);
         rv = mHTMLEditor->MoveNode(curNode, curList, -1);
         NS_ENSURE_SUCCESS(rv, rv);
-        rv = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
-                             listType, itemType);
-        NS_ENSURE_SUCCESS(rv, rv);
+        newBlock = ConvertListType(curNode->AsElement(), listType, itemType);
+        if (NS_WARN_IF(!newBlock)) {
+          return NS_ERROR_FAILURE;
+        }
         NS_ENSURE_STATE(mHTMLEditor);
         rv = mHTMLEditor->RemoveBlockContainer(*newBlock);
         NS_ENSURE_SUCCESS(rv, rv);
       } else {
         // replace list with new list type
-        rv = ConvertListType(curNode->AsElement(), getter_AddRefs(newBlock),
-                             listType, itemType);
-        NS_ENSURE_SUCCESS(rv, rv);
-        curList = newBlock;
+        curList = ConvertListType(curNode->AsElement(), listType, itemType);
+        if (NS_WARN_IF(!curList)) {
+          return NS_ERROR_FAILURE;
+        }
       }
       prevListItem = nullptr;
       continue;
@@ -4495,14 +4495,12 @@ HTMLEditRules::OutdentPartOfBlock(Element& aBlock,
 /**
  * ConvertListType() converts list type and list item type.
  */
-nsresult
+already_AddRefed<Element>
 HTMLEditRules::ConvertListType(Element* aList,
-                               Element** aOutList,
                                nsIAtom* aListType,
                                nsIAtom* aItemType)
 {
   MOZ_ASSERT(aList);
-  MOZ_ASSERT(aOutList);
   MOZ_ASSERT(aListType);
   MOZ_ASSERT(aItemType);
 
@@ -4513,29 +4511,26 @@ HTMLEditRules::ConvertListType(Element* aList,
       if (HTMLEditUtils::IsListItem(element) &&
           !element->IsHTMLElement(aItemType)) {
         child = mHTMLEditor->ReplaceContainer(element, aItemType);
-        NS_ENSURE_STATE(child);
+        if (NS_WARN_IF(!child)) {
+          return nullptr;
+        }
       } else if (HTMLEditUtils::IsList(element) &&
                  !element->IsHTMLElement(aListType)) {
-        nsCOMPtr<dom::Element> temp;
-        nsresult rv = ConvertListType(child->AsElement(), getter_AddRefs(temp),
-                                      aListType, aItemType);
-        NS_ENSURE_SUCCESS(rv, rv);
-        child = temp.forget();
+        child = ConvertListType(child->AsElement(), aListType, aItemType);
+        if (NS_WARN_IF(!child)) {
+          return nullptr;
+        }
       }
     }
     child = child->GetNextSibling();
   }
 
   if (aList->IsHTMLElement(aListType)) {
-    nsCOMPtr<dom::Element> list = aList->AsElement();
-    list.forget(aOutList);
-    return NS_OK;
+    RefPtr<dom::Element> list = aList->AsElement();
+    return list.forget();
   }
 
-  *aOutList = mHTMLEditor->ReplaceContainer(aList, aListType).take();
-  NS_ENSURE_STATE(aOutList);
-
-  return NS_OK;
+  return mHTMLEditor->ReplaceContainer(aList, aListType);
 }
 
 
diff --git editor/libeditor/HTMLEditRules.h editor/libeditor/HTMLEditRules.h
index d1bb1fa7e3b2..0dde7f01e408 100644
--- editor/libeditor/HTMLEditRules.h
+++ editor/libeditor/HTMLEditRules.h
@@ -316,8 +316,8 @@ protected:
                               nsIContent** aOutLeftNode,
                               nsIContent** aOutRightNode);
 
-  nsresult ConvertListType(Element* aList, Element** aOutList,
-                           nsIAtom* aListType, nsIAtom* aItemType);
+  already_AddRefed<Element> ConvertListType(Element* aList, nsIAtom* aListType,
+                                            nsIAtom* aItemType);
 
   nsresult CreateStyleForInsertText(Selection& aSelection, nsIDocument& aDoc);
   enum class MozBRCounts { yes, no };

commit 5e5f298b8e42
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date:   Mon Sep 25 14:11:29 2017 +0900

    Bug 1402469 - Part 2. Add crash test. r=masayuki, a=sledru
    
    MozReview-Commit-ID: HogVH2OTyd6
    
    --HG--
    extra : source : 5e311cd7074e6b649187f5a79371f0681c2d7504
---
 editor/libeditor/crashtests/1402469.html    | 16 ++++++++++++++++
 editor/libeditor/crashtests/crashtests.list |  1 +
 2 files changed, 17 insertions(+)

diff --git editor/libeditor/crashtests/1402469.html editor/libeditor/crashtests/1402469.html
new file mode 100644
index 000000000000..04b1adc96f25
--- /dev/null
+++ editor/libeditor/crashtests/1402469.html
@@ -0,0 +1,16 @@
+<html>
+<head>
+<script type="application/javascript">
+function do_test() {
+  document.execCommand("insertUnorderedList", false);
+}
+</script>
+</head>
+<body onload="do_test()">
+<table>
+  <th contenteditable="true">
+    <ol contenteditable="false">
+  </th>
+</table>
+</body>
+</html>
diff --git editor/libeditor/crashtests/crashtests.list editor/libeditor/crashtests/crashtests.list
index 11672c41d102..840e26f2fe62 100644
--- editor/libeditor/crashtests/crashtests.list
+++ editor/libeditor/crashtests/crashtests.list
@@ -80,3 +80,4 @@ load 1366176.html
 load 1375131.html
 load 1381541.html
 load 1383755.html
+load 1402469.html