Bug 1596680: remove superfluous `IsValidOffset` function. r=smaug
authorMirko Brodesser <mbrodesser@mozilla.com>
Fri, 15 Nov 2019 15:22:49 +0000
changeset 502185 5d471a86dc2963fadc67d4d37e03e8674289dbec
parent 502184 f5b772f54a1874b92274e8eab74f929db6346747
child 502186 5e324cc146e3171fd88d4ed2a3727cc1498e8d6a
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1596680
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1596680: remove superfluous `IsValidOffset` function. r=smaug `RangeBoundaryBase` accepts a `uint32_t` offset, hence not needed anymore. Differential Revision: https://phabricator.services.mozilla.com/D53162
dom/base/RangeUtils.cpp
dom/base/RangeUtils.h
dom/base/nsRange.cpp
--- a/dom/base/RangeUtils.cpp
+++ b/dom/base/RangeUtils.cpp
@@ -62,20 +62,18 @@ nsINode* RangeUtils::ComputeRootNode(nsI
 }
 
 // static
 template <typename SPT, typename SRT, typename EPT, typename ERT>
 bool RangeUtils::IsValidPoints(
     const RangeBoundaryBase<SPT, SRT>& aStartBoundary,
     const RangeBoundaryBase<EPT, ERT>& aEndBoundary) {
   // Use NS_WARN_IF() only for the cases where the arguments are unexpected.
-  if (NS_WARN_IF(!aStartBoundary.IsSet()) ||
-      NS_WARN_IF(!aEndBoundary.IsSet()) ||
-      NS_WARN_IF(!IsValidOffset(aStartBoundary)) ||
-      NS_WARN_IF(!IsValidOffset(aEndBoundary))) {
+  if (NS_WARN_IF(!aStartBoundary.IsSetAndValid()) ||
+      NS_WARN_IF(!aEndBoundary.IsSetAndValid())) {
     return false;
   }
 
   // Otherwise, don't use NS_WARN_IF() for preventing to make console messy.
   // Instead, check one by one since it is easier to catch the error reason
   // with debugger.
 
   if (ComputeRootNode(aStartBoundary.Container()) !=
--- a/dom/base/RangeUtils.h
+++ b/dom/base/RangeUtils.h
@@ -78,24 +78,16 @@ class RangeUtils final {
 
   /**
    * XXX nsRange should accept 0 - UINT32_MAX as offset.  However, users of
    *     nsRange treat offset as int32_t.  Additionally, some other internal
    *     APIs like nsINode::ComputeIndexOf() use int32_t.  Therefore,
    *     nsRange should accept only 0 - INT32_MAX as valid offset for now.
    */
   static bool IsValidOffset(uint32_t aOffset) { return aOffset <= INT32_MAX; }
-  static bool IsValidOffset(nsINode* aNode, uint32_t aOffset) {
-    return aNode && IsValidOffset(aOffset) &&
-           static_cast<size_t>(aOffset) <= aNode->Length();
-  }
-  template <typename PT, typename RT>
-  static bool IsValidOffset(const RangeBoundaryBase<PT, RT>& aBoundary) {
-    return IsValidOffset(aBoundary.Container(), aBoundary.Offset());
-  }
 
   /**
    * Return true if aStartContainer/aStartOffset and aEndContainer/aEndOffset
    * are valid start and end points for a range.  Otherwise, return false.
    */
   static bool IsValidPoints(nsINode* aStartContainer, uint32_t aStartOffset,
                             nsINode* aEndContainer, uint32_t aEndOffset) {
     return IsValidPoints(RawRangeBoundary(aStartContainer, aStartOffset),
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -1268,26 +1268,25 @@ void nsRange::SelectNode(nsINode& aNode,
     return;
   }
 
   int32_t index = container->ComputeIndexOf(&aNode);
   // MOZ_ASSERT(index != -1);
   // We need to compute the index here unfortunately, because, while we have
   // support for XBL, |container| may be the node's binding parent without
   // actually containing it.
-  if (NS_WARN_IF(index < 0) ||
-      !RangeUtils::IsValidOffset(static_cast<uint32_t>(index)) ||
-      !RangeUtils::IsValidOffset(static_cast<uint32_t>(index) + 1)) {
+  if (NS_WARN_IF(index < 0)) {
     aRv.Throw(NS_ERROR_DOM_INVALID_NODE_TYPE_ERR);
     return;
   }
 
   AutoInvalidateSelection atEndOfBlock(this);
-  DoSetRange(RawRangeBoundary(container, index),
-             RawRangeBoundary(container, index + 1), newRoot);
+  DoSetRange(RawRangeBoundary{container, static_cast<uint32_t>(index)},
+             RawRangeBoundary{container, static_cast<uint32_t>(index + 1)},
+             newRoot);
 }
 
 void nsRange::SelectNodeContentsJS(nsINode& aNode, ErrorResult& aErr) {
   AutoCalledByJSRestore calledByJSRestorer(*this);
   mCalledByJS = true;
   SelectNodeContents(aNode, aErr);
 }