Bug 1458016: Fix bad cast to Text. r?bz
I think it's harmless security-wise, since Text and char data are both
nsIContent, so the vtable offset should be the same.
I could also just do AsContent(), which may be cleaner but involve a virtual
call, or add AsCharacterData(), just let me know.
MozReview-Commit-ID: 79I9CuCmioF
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -3210,19 +3210,19 @@ Selection::ContainsNode(nsINode& aNode,
{
nsresult rv;
if (mRanges.Length() == 0) {
return false;
}
// XXXbz this duplicates the GetNodeLength code in nsRange.cpp
uint32_t nodeLength;
- bool isData = aNode.IsCharacterData();
- if (isData) {
- nodeLength = aNode.AsText()->TextLength();
+ auto* nodeAsCharData = CharacterData::FromNode(aNode);
+ if (nodeAsCharData) {
+ nodeLength = nodeAsCharData->TextLength();
} else {
nodeLength = aNode.GetChildCount();
}
nsTArray<nsRange*> overlappingRanges;
rv = GetRangesForIntervalArray(&aNode, 0, &aNode, nodeLength,
false, &overlappingRanges);
if (NS_FAILED(rv)) {
@@ -3233,17 +3233,17 @@ Selection::ContainsNode(nsINode& aNode,
return false; // no ranges overlap
// if the caller said partial intersections are OK, we're done
if (aAllowPartial) {
return true;
}
// text nodes always count as inside
- if (isData) {
+ if (nodeAsCharData) {
return true;
}
// The caller wants to know if the node is entirely within the given range,
// so we have to check all intersecting ranges.
for (uint32_t i = 0; i < overlappingRanges.Length(); i++) {
bool nodeStartsBeforeRange, nodeEndsAfterRange;
if (NS_SUCCEEDED(nsRange::CompareNodeToRange(&aNode, overlappingRanges[i],