Bug 1551684 part 2. Stop using [array] in nsIAccessiblePivot. r=surkov
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 15 May 2019 11:54:07 +0000
changeset 532757 6eba5e15b3bc7e5ffdc7289ecd564dfa72b38167
parent 532756 68e703f2f17b61b73652afed22ebff6afd43e503
child 532758 5a94b7075ddaa1a1958606ae59d3e683b659ee26
push id11272
push userapavel@mozilla.com
push dateThu, 16 May 2019 15:28:22 +0000
treeherdermozilla-beta@2265bfc5920d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs1551684
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 1551684 part 2. Stop using [array] in nsIAccessiblePivot. r=surkov Differential Revision: https://phabricator.services.mozilla.com/D31180
accessible/base/nsAccessiblePivot.cpp
accessible/interfaces/nsIAccessiblePivot.idl
accessible/jsat/Traversal.jsm
accessible/tests/mochitest/pivot.js
--- a/accessible/base/nsAccessiblePivot.cpp
+++ b/accessible/base/nsAccessiblePivot.cpp
@@ -5,39 +5,36 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsAccessiblePivot.h"
 
 #include "HyperTextAccessible.h"
 #include "nsAccUtils.h"
 #include "States.h"
 #include "xpcAccessibleDocument.h"
+#include "nsTArray.h"
+#include "mozilla/Maybe.h"
 
 using namespace mozilla::a11y;
+using mozilla::Maybe;
 
 /**
  * An object that stores a given traversal rule during the pivot movement.
  */
 class RuleCache {
  public:
   explicit RuleCache(nsIAccessibleTraversalRule* aRule)
-      : mRule(aRule),
-        mAcceptRoles(nullptr),
-        mAcceptRolesLength{0},
-        mPreFilter{0} {}
-  ~RuleCache() {
-    if (mAcceptRoles) free(mAcceptRoles);
-  }
+      : mRule(aRule), mPreFilter{0} {}
+  ~RuleCache() {}
 
   nsresult ApplyFilter(Accessible* aAccessible, uint16_t* aResult);
 
  private:
   nsCOMPtr<nsIAccessibleTraversalRule> mRule;
-  uint32_t* mAcceptRoles;
-  uint32_t mAcceptRolesLength;
+  Maybe<nsTArray<uint32_t>> mAcceptRoles;
   uint32_t mPreFilter;
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsAccessiblePivot
 
 nsAccessiblePivot::nsAccessiblePivot(Accessible* aRoot)
     : mRoot(aRoot),
@@ -817,33 +814,34 @@ bool nsAccessiblePivot::NotifyOfPivotCha
                                             int16_t aReason,
                                             int16_t aBoundaryType,
                                             bool aIsFromUserInput) {
   if (aOldPosition == mPosition && aOldStart == mStartOffset &&
       aOldEnd == mEndOffset)
     return false;
 
   nsCOMPtr<nsIAccessible> xpcOldPos = ToXPC(aOldPosition);  // death grip
-  nsTObserverArray<nsCOMPtr<nsIAccessiblePivotObserver> >::ForwardIterator iter(
+  nsTObserverArray<nsCOMPtr<nsIAccessiblePivotObserver>>::ForwardIterator iter(
       mObservers);
   while (iter.HasMore()) {
     nsIAccessiblePivotObserver* obs = iter.GetNext();
     obs->OnPivotChanged(this, xpcOldPos, aOldStart, aOldEnd, ToXPC(mPosition),
                         mStartOffset, mEndOffset, aReason, aBoundaryType,
                         aIsFromUserInput);
   }
 
   return true;
 }
 
 nsresult RuleCache::ApplyFilter(Accessible* aAccessible, uint16_t* aResult) {
   *aResult = nsIAccessibleTraversalRule::FILTER_IGNORE;
 
   if (!mAcceptRoles) {
-    nsresult rv = mRule->GetMatchRoles(&mAcceptRoles, &mAcceptRolesLength);
+    mAcceptRoles.emplace();
+    nsresult rv = mRule->GetMatchRoles(*mAcceptRoles);
     NS_ENSURE_SUCCESS(rv, rv);
     rv = mRule->GetPreFilter(&mPreFilter);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (mPreFilter) {
     uint64_t state = aAccessible->State();
 
@@ -869,21 +867,21 @@ nsresult RuleCache::ApplyFilter(Accessib
       nsIFrame* frame = aAccessible->GetFrame();
       if (frame->StyleEffects()->mOpacity == 0.0f) {
         *aResult |= nsIAccessibleTraversalRule::FILTER_IGNORE_SUBTREE;
         return NS_OK;
       }
     }
   }
 
-  if (mAcceptRolesLength > 0) {
+  if (mAcceptRoles->Length() > 0) {
     uint32_t accessibleRole = aAccessible->Role();
     bool matchesRole = false;
-    for (uint32_t idx = 0; idx < mAcceptRolesLength; idx++) {
-      matchesRole = mAcceptRoles[idx] == accessibleRole;
+    for (uint32_t idx = 0; idx < mAcceptRoles->Length(); idx++) {
+      matchesRole = mAcceptRoles->ElementAt(idx) == accessibleRole;
       if (matchesRole) break;
     }
     if (!matchesRole) return NS_OK;
   }
 
   uint16_t matchResult = nsIAccessibleTraversalRule::FILTER_IGNORE;
   nsresult rv = mRule->Match(ToXPC(aAccessible), &matchResult);
   if (NS_SUCCEEDED(rv)) {
--- a/accessible/interfaces/nsIAccessiblePivot.idl
+++ b/accessible/interfaces/nsIAccessiblePivot.idl
@@ -240,21 +240,19 @@ interface nsIAccessibleTraversalRule : n
 
   /**
    * Retrieve a list of roles that the traversal rule should test for. Any node
    * with a role not in this list will automatically be ignored. An empty list
    * will match all roles. It should be assumed that this method is called once
    * at the start of a traversal, so changing the method's return result after
    * that would have no affect.
    *
-   * @param aRoles [out] an array of the roles to match.
-   * @param aCount [out] the length of the array.
+   * @return an array of the roles to match.
    */
-  void getMatchRoles([array, size_is(aCount)]out unsigned long aRoles,
-                     [retval]out unsigned long aCount);
+  Array<unsigned long> getMatchRoles();
 
   /**
    * Determines if a given accessible is to be accepted in our traversal rule
    *
    * @param aAccessible [in] accessible to examine.
    * @return a bitfield of FILTER_MATCH and FILTER_IGNORE_SUBTREE.
    */
   unsigned short match(in nsIAccessible aAccessible);
--- a/accessible/jsat/Traversal.jsm
+++ b/accessible/jsat/Traversal.jsm
@@ -31,19 +31,18 @@ function BaseTraversalRule(aRoles, aMatc
     }
   }
   this._matchFunc = aMatchFunc || function() { return Filters.MATCH; };
   this.preFilter = aPreFilter || gSimplePreFilter;
   this.containerRule = aContainerRule;
 }
 
 BaseTraversalRule.prototype = {
-    getMatchRoles: function BaseTraversalRule_getmatchRoles(aRoles) {
-      aRoles.value = this._matchRoles;
-      return aRoles.value.length;
+    getMatchRoles: function BaseTraversalRule_getmatchRoles() {
+      return this._matchRoles;
     },
 
     match: function BaseTraversalRule_match(aAccessible) {
       let role = aAccessible.role;
       if (role == Roles.INTERNAL_FRAME) {
         return (Utils.getMessageManagerForFrame(aAccessible.DOMNode)) ?
           Filters.MATCH | Filters.IGNORE_SUBTREE : Filters.IGNORE;
       }
--- a/accessible/tests/mochitest/pivot.js
+++ b/accessible/tests/mochitest/pivot.js
@@ -18,38 +18,36 @@ const NS_ERROR_INVALID_ARG = 0x80070057;
 // //////////////////////////////////////////////////////////////////////////////
 // Traversal rules
 
 /**
  * Rule object to traverse all focusable nodes and text nodes.
  */
 var HeadersTraversalRule =
 {
-  getMatchRoles(aRules) {
-    aRules.value = [ROLE_HEADING];
-    return aRules.value.length;
+  getMatchRoles() {
+    return [ROLE_HEADING];
   },
 
   preFilter: PREFILTER_INVISIBLE,
 
   match(aAccessible) {
     return FILTER_MATCH;
   },
 
   QueryInterface: ChromeUtils.generateQI([nsIAccessibleTraversalRule]),
 };
 
 /**
  * Traversal rule for all focusable nodes or leafs.
  */
 var ObjectTraversalRule =
 {
-  getMatchRoles(aRules) {
-    aRules.value = [];
-    return 0;
+  getMatchRoles() {
+    return [];
   },
 
   preFilter: PREFILTER_INVISIBLE | PREFILTER_TRANSPARENT,
 
   match(aAccessible) {
     var rv = FILTER_IGNORE;
     var role = aAccessible.role;
     if (hasState(aAccessible, STATE_FOCUSABLE) &&