Bug 1538042 Part 1: Change nsIFind::Find to have access to text length. r=mccr8
authorBrad Werth <bwerth@mozilla.com>
Fri, 29 Mar 2019 15:55:57 +0000
changeset 466786 9414b7e93b3570b3e4209992a3adf3c94e388dc1
parent 466785 f7f9e20d71b78bdbd94d73d9ab3225b212a2be37
child 466787 1f79ed91a20bbe91ced53c1fe3c70fafd6272fd5
push id35780
push useropoprus@mozilla.com
push dateFri, 29 Mar 2019 21:53:01 +0000
treeherdermozilla-central@414f37afbe07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1538042
milestone68.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 1538042 Part 1: Change nsIFind::Find to have access to text length. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D25005
toolkit/components/find/nsFind.cpp
toolkit/components/find/nsIFind.idl
toolkit/components/find/nsWebBrowserFind.cpp
toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
toolkit/components/windowcreator/test/test_nsFind.html
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -443,17 +443,17 @@ char16_t nsFind::PeekNextChar(State& aSt
 #define OVERFLOW_PINDEX (mFindBackward ? pindex < 0 : pindex > patLen)
 #define DONE_WITH_PINDEX (mFindBackward ? pindex <= 0 : pindex >= patLen)
 #define ALMOST_DONE_WITH_PINDEX \
   (mFindBackward ? pindex <= 0 : pindex >= patLen - 1)
 
 // Take nodes out of the tree with NextNode, until null (NextNode will return 0
 // at the end of our range).
 NS_IMETHODIMP
-nsFind::Find(const char16_t* aPatText, nsRange* aSearchRange,
+nsFind::Find(const nsAString& aPatText, nsRange* aSearchRange,
              nsRange* aStartPoint, nsRange* aEndPoint, nsRange** aRangeRet) {
   DEBUG_FIND_PRINTF("============== nsFind::Find('%s'%s, %p, %p, %p)\n",
                     NS_LossyConvertUTF16toASCII(aPatText).get(),
                     mFindBackward ? " (backward)" : " (forward)",
                     (void*)aSearchRange, (void*)aStartPoint, (void*)aEndPoint);
 
   NS_ENSURE_ARG(aSearchRange);
   NS_ENSURE_ARG(aStartPoint);
@@ -464,20 +464,16 @@ nsFind::Find(const char16_t* aPatText, n
       aStartPoint->GetRoot() ? aStartPoint->GetRoot()->OwnerDoc() : nullptr;
   NS_ENSURE_ARG(document);
 
   Element* root = document->GetRootElement();
   NS_ENSURE_ARG(root);
 
   *aRangeRet = 0;
 
-  if (!aPatText) {
-    return NS_ERROR_NULL_POINTER;
-  }
-
   nsAutoString patAutoStr(aPatText);
   if (!mCaseSensitive) {
     ToLowerCase(patAutoStr);
   }
 
   // Ignore soft hyphens in the pattern
   static const char kShy[] = {char(CH_SHY), 0};
   patAutoStr.StripChars(kShy);
--- a/toolkit/components/find/nsIFind.idl
+++ b/toolkit/components/find/nsIFind.idl
@@ -1,13 +1,13 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- 
+
 #include "nsISupports.idl"
 
 interface nsIWordBreaker;
 
 webidl Range;
 
 [scriptable, uuid(40aba110-2a56-4678-be90-e2c17a9ae7d7)]
 interface nsIFind : nsISupports
@@ -25,11 +25,11 @@ interface nsIFind : nsISupports
    * @param aStartPoint  A Range specifying search start point.
    *                     If not collapsed, we'll start from
    *                     end (forward) or start (backward).
    * @param aEndPoint    A Range specifying search end point.
    *                     If not collapsed, we'll end at
    *                     end (forward) or start (backward).
    * @retval             A range spanning the match that was found (or null).
    */
-  Range Find(in wstring aPatText, in Range aSearchRange,
+  Range Find(in AString aPatText, in Range aSearchRange,
              in Range aStartPoint, in Range aEndPoint);
 };
--- a/toolkit/components/find/nsWebBrowserFind.cpp
+++ b/toolkit/components/find/nsWebBrowserFind.cpp
@@ -668,17 +668,17 @@ nsresult nsWebBrowserFind::SearchInFrame
   RefPtr<nsRange> endPt = new nsRange(theDoc);
   NS_ENSURE_ARG_POINTER(endPt);
 
   RefPtr<nsRange> foundRange;
 
   rv = GetSearchLimits(searchRange, startPt, endPt, theDoc, sel, aWrapping);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = find->Find(mSearchString.get(), searchRange, startPt, endPt,
+  rv = find->Find(mSearchString, searchRange, startPt, endPt,
                   getter_AddRefs(foundRange));
 
   if (NS_SUCCEEDED(rv) && foundRange) {
     *aDidFind = true;
     sel->RemoveAllRanges(IgnoreErrors());
     // Beware! This may flush notifications via synchronous
     // ScrollSelectionIntoView.
     SetSelectionAndScroll(aWindow, foundRange);
--- a/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
+++ b/toolkit/components/typeaheadfind/nsTypeAheadFind.cpp
@@ -429,17 +429,17 @@ nsresult nsTypeAheadFind::FindItNow(nsIP
   bool hasWrapped = (rangeCompareResult < 0);
 
   if (mTypeAheadBuffer.IsEmpty() || !EnsureFind()) return NS_ERROR_FAILURE;
 
   mFind->SetFindBackwards(aFindPrev);
 
   while (true) {    // ----- Outer while loop: go through all docs -----
     while (true) {  // === Inner while loop: go through a single doc ===
-      mFind->Find(mTypeAheadBuffer.get(), mSearchRange, mStartPointRange,
+      mFind->Find(mTypeAheadBuffer, mSearchRange, mStartPointRange,
                   mEndPointRange, getter_AddRefs(returnRange));
       if (!returnRange) {
         break;  // Nothing found in this doc, go to outer loop (try next doc)
       }
 
       // ------- Test resulting found range for success conditions ------
       bool isInsideLink = false, isStartingLink = false;
 
--- a/toolkit/components/windowcreator/test/test_nsFind.html
+++ b/toolkit/components/windowcreator/test/test_nsFind.html
@@ -28,30 +28,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 
   var display = window.document.getElementById("display");
   var searchRange = window.document.createRange();
   searchRange.setStart(display, 0);
   searchRange.setEnd(display, display.childNodes.length);
   var startPt = searchRange;
   var endPt = searchRange;
 
-  // Check |null| detection on |aPatText| parameter.
-  try {
-    rf.Find(null, searchRange, startPt, endPt);
-
-    ok(false, "Missing NS_ERROR_NULL_POINTER exception");
-  } catch (e) {
-    let wrappedError = SpecialPowers.wrap(e);
-    if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_NULL_POINTER) {
-      ok(true, null);
-    } else {
-      throw wrappedError;
-    }
-  }
-
   // Check |null| detection on |aSearchRange| parameter.
   try {
     rf.Find("", null, startPt, endPt);
 
     ok(false, "Missing NS_ERROR_ILLEGAL_VALUE exception");
   } catch (e) {
     let wrappedError = SpecialPowers.wrap(e);
     if (wrappedError.result == SpecialPowers.Cr.NS_ERROR_ILLEGAL_VALUE) {