Merge autoland to m-c, a=merge
authorPhil Ringnalda <philringnalda@gmail.com>
Tue, 25 Oct 2016 21:57:34 -0700
changeset 319326 9471b3c49b2ca02466a653de56ff3d4c32d79c38
parent 319269 b1b18f25c0ea69d9ee57c4198d577dfcd0129ce1 (current diff)
parent 319325 570182c077eef4cef71fc99f80caaf671f6fa492 (diff)
child 319425 f9f3cc95d7282f1fd83f66dd74acbcdbfe821915
push id30869
push userphilringnalda@gmail.com
push dateWed, 26 Oct 2016 04:57:48 +0000
treeherdermozilla-central@9471b3c49b2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone52.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
Merge autoland to m-c, a=merge MozReview-Commit-ID: IwOWQT0vnYa
gfx/gl/TextureImageCGL.h
gfx/gl/TextureImageCGL.mm
mobile/android/chrome/content/ZoomHelper.js
toolkit/components/places/tests/unifiedcomplete/test_autoFill_default_behavior.js
toolkit/components/places/tests/unifiedcomplete/test_queryurl.js
toolkit/components/places/tests/unifiedcomplete/test_remotetabmatches.js
toolkit/components/places/tests/unifiedcomplete/test_searchEngine_alias.js
toolkit/components/places/tests/unifiedcomplete/test_searchEngine_current.js
toolkit/components/places/tests/unifiedcomplete/test_searchEngine_host.js
toolkit/components/places/tests/unifiedcomplete/test_searchEngine_restyle.js
toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js
toolkit/components/places/tests/unifiedcomplete/test_tabmatches.js
toolkit/components/places/tests/unifiedcomplete/test_visiturl.js
--- a/accessible/windows/ia2/ia2Accessible.cpp
+++ b/accessible/windows/ia2/ia2Accessible.cpp
@@ -668,17 +668,17 @@ ia2Accessible::get_relationTargetsOfType
 }
 
 STDMETHODIMP
 ia2Accessible::get_selectionRanges(IA2Range** aRanges,
                                    long *aNRanges)
 {
   A11Y_TRYBLOCK_BEGIN
 
-  if (!aRanges || !aNRanges || aNRanges <= 0)
+  if (!aRanges || !aNRanges)
     return E_INVALIDARG;
 
   *aNRanges = 0;
 
   AccessibleWrap* acc = static_cast<AccessibleWrap*>(this);
   if (acc->IsDefunct())
     return CO_E_OBJNOTCONNECTED;
 
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -491,47 +491,66 @@ var LightWeightThemeWebInstaller = {
 
   _installRequest: function (dataString, baseURI) {
     let data = this._manager.parseTheme(dataString, baseURI);
 
     if (!data) {
       return;
     }
 
+    let uri = makeURI(baseURI);
+
+    // A notification bar with the option to undo is normally shown after a
+    // theme is installed.  But the discovery pane served from the url(s)
+    // below has its own toggle switch for quick undos, so don't show the
+    // notification in that case.
+    let notify = uri.prePath != "https://discovery.addons.mozilla.org";
+    if (notify) {
+      try {
+        if (Services.prefs.getBoolPref("extensions.webapi.testing")
+            && (uri.prePath == "https://discovery.addons.allizom.org"
+                || uri.prePath == "https://discovery.addons-dev.allizom.org")) {
+          notify = false;
+        }
+      } catch (e) {
+        // getBoolPref() throws if the testing pref isn't set.  ignore it.
+      }
+    }
+
     if (this._isAllowed(baseURI)) {
-      this._install(data);
+      this._install(data, notify);
       return;
     }
 
     let allowButtonText =
       gNavigatorBundle.getString("lwthemeInstallRequest.allowButton");
     let allowButtonAccesskey =
       gNavigatorBundle.getString("lwthemeInstallRequest.allowButton.accesskey");
     let message =
       gNavigatorBundle.getFormattedString("lwthemeInstallRequest.message",
-                                          [makeURI(baseURI).host]);
+                                          [uri.host]);
     let buttons = [{
       label: allowButtonText,
       accessKey: allowButtonAccesskey,
       callback: function () {
-        LightWeightThemeWebInstaller._install(data);
+        LightWeightThemeWebInstaller._install(data, notify);
       }
     }];
 
     this._removePreviousNotifications();
 
     let notificationBox = gBrowser.getNotificationBox();
     let notificationBar =
       notificationBox.appendNotification(message, "lwtheme-install-request", "",
                                          notificationBox.PRIORITY_INFO_MEDIUM,
                                          buttons);
     notificationBar.persistence = 1;
   },
 
-  _install: function (newLWTheme) {
+  _install: function (newLWTheme, notify) {
     let previousLWTheme = this._manager.currentTheme;
 
     let listener = {
       onEnabling: function(aAddon, aRequiresRestart) {
         if (!aRequiresRestart) {
           return;
         }
 
@@ -551,17 +570,19 @@ var LightWeightThemeWebInstaller = {
         };
 
         PopupNotifications.show(gBrowser.selectedBrowser, "addon-theme-change",
                                 messageString, "addons-notification-icon",
                                 action, null, options);
       },
 
       onEnabled: function(aAddon) {
-        LightWeightThemeWebInstaller._postInstallNotification(newLWTheme, previousLWTheme);
+        if (notify) {
+          LightWeightThemeWebInstaller._postInstallNotification(newLWTheme, previousLWTheme);
+        }
       }
     };
 
     AddonManager.addAddonListener(listener);
     this._manager.currentTheme = newLWTheme;
     AddonManager.removeAddonListener(listener);
   },
 
--- a/browser/base/content/browser.css
+++ b/browser/base/content/browser.css
@@ -515,16 +515,20 @@ toolbar:not(#TabsToolbar) > #personal-bo
 #PopupAutoCompleteRichResult > richlistbox {
   transition: height 100ms;
 }
 
 #PopupAutoCompleteRichResult.showSearchSuggestionsNotification > richlistbox {
   transition: none;
 }
 
+#DateTimePickerPanel {
+  -moz-binding: url("chrome://global/content/bindings/datetimepopup.xml#datetime-popup");
+}
+
 #urlbar[pageproxystate="invalid"] > #urlbar-icons > .urlbar-icon,
 #urlbar[pageproxystate="invalid"][focused="true"] > #urlbar-go-button ~ toolbarbutton,
 #urlbar[pageproxystate="valid"] > #urlbar-go-button,
 #urlbar:not([focused="true"]) > #urlbar-go-button {
   visibility: collapse;
 }
 
 #urlbar[pageproxystate="invalid"] > #identity-box > #identity-icon-labels {
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -136,34 +136,43 @@
     <menupopup id="backForwardMenu"
                onpopupshowing="return FillHistoryMenu(event.target);"
                oncommand="gotoHistoryIndex(event); event.stopPropagation();"
                onclick="checkForMiddleClick(this, event);"/>
     <tooltip id="aHTMLTooltip" page="true"/>
     <tooltip id="remoteBrowserTooltip"/>
 
     <!-- for search and content formfill/pw manager -->
-    <panel type="autocomplete-richlistbox" id="PopupAutoComplete" noautofocus="true" hidden="true"/>
+
+    <panel type="autocomplete-richlistbox"
+           id="PopupAutoComplete"
+           noautofocus="true"
+           hidden="true"
+           norolluponanchor="true" />
 
     <!-- for search with one-off buttons -->
     <panel type="autocomplete" id="PopupSearchAutoComplete" noautofocus="true" hidden="true"/>
 
     <!-- for url bar autocomplete -->
     <panel type="autocomplete-richlistbox"
            id="PopupAutoCompleteRichResult"
            noautofocus="true"
            hidden="true"
            flip="none"
            level="parent"/>
 
     <panel id="DateTimePickerPanel"
+           type="arrow"
            hidden="true"
+           orient="vertical"
            noautofocus="true"
            consumeoutsideclicks="false"
-           level="parent"/>
+           level="parent">
+      <iframe id="dateTimePopupFrame"/>
+    </panel>
 
     <!-- for select dropdowns. The menupopup is what shows the list of options,
          and the popuponly menulist makes things like the menuactive attributes
          work correctly on the menupopup. ContentSelectDropdown expects the
          popuponly menulist to be its immediate parent. -->
     <menulist popuponly="true" id="ContentSelectDropdown" hidden="true">
       <menupopup rolluponmousewheel="true"
                  activateontab="true" position="after_start"
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -1367,25 +1367,25 @@ file, You can obtain one at http://mozil
                 onget="return this._overrideValue;"
                 onset="this._overrideValue = val; return val;"/>
 
       <method name="enableOneOffSearches">
         <parameter name="enable"/>
         <body><![CDATA[
           this._oneOffSearchesEnabled = enable;
           if (enable) {
+            this.oneOffSearchButtons.telemetryOrigin = "urlbar";
             this.oneOffSearchButtons.style.display = "-moz-box";
             this.oneOffSearchButtons.popup = this;
             this.oneOffSearchButtons.textbox = this.input;
-            this.oneOffSearchButtons.telemetryOrigin = "urlbar";
           } else {
+            this.oneOffSearchButtons.telemetryOrigin = null;
             this.oneOffSearchButtons.style.display = "none";
             this.oneOffSearchButtons.popup = null;
             this.oneOffSearchButtons.textbox = null;
-            this.oneOffSearchButtons.telemetryOrigin = null;
           }
         ]]></body>
       </method>
 
       <method name="openSearchSuggestionsNotificationLearnMoreURL">
         <body><![CDATA[
         let url = Services.urlFormatter.formatURL(
           Services.prefs.getCharPref("app.support.baseURL") + "suggestions"
--- a/browser/components/nsBrowserContentHandler.js
+++ b/browser/components/nsBrowserContentHandler.js
@@ -1,12 +1,14 @@
 /* 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/. */
 
+/* eslint no-undef:2 */
+
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "LaterRun",
                                   "resource:///modules/LaterRun.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
                                   "resource://gre/modules/PrivateBrowsingUtils.jsm");
@@ -226,17 +228,17 @@ function openWindow(parent, url, target,
 function openPreferences() {
   var args = Components.classes["@mozilla.org/array;1"]
                      .createInstance(Components.interfaces.nsIMutableArray);
 
   var wuri = Components.classes["@mozilla.org/supports-string;1"]
                        .createInstance(Components.interfaces.nsISupportsString);
   wuri.data = "about:preferences";
 
-  sa.appendElement(wuri, /*weak =*/ false);
+  args.appendElement(wuri, /*weak =*/ false);
 
   Services.ww.openWindow(null, gBrowserContentHandler.chromeURL,
                          "_blank",
                          "chrome,dialog=no,all",
                          args);
 }
 
 function logSystemBasedSearch(engine) {
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -971,20 +971,22 @@
                                ]) * -1;
           // Ensure the panel is wide enough to fit at least 3 engines.
           let minWidth = Math.max(
             parseInt(this.width) + magnifierWidth,
             this.oneOffButtons.buttonWidth * 3
           );
           this.style.minWidth = minWidth + "px";
 
+          // Set the origin before assigning the popup, as the assignment does
+          // a rebuild and would miss the origin.
+          this.oneOffButtons.telemetryOrigin = "searchbar";
           // Set popup after setting the minWidth since it builds the buttons.
           this.oneOffButtons.popup = this;
           this.oneOffButtons.textbox = this.input;
-          this.oneOffButtons.telemetryOrigin = "searchbar";
         }
 
         // First handle deciding if we are showing the reduced version of the
         // popup containing only the preferences button. We do this if the
         // glass icon has been clicked if the text field is empty.
         let searchbar = document.getElementById("searchbar");
         let tree = document.getAnonymousElementByAttribute(this, "anonid",
                                                            "tree")
@@ -2021,27 +2023,29 @@
           // Select the context-clicked button so that consumers can easily
           // tell which button was acted on.
           this.selectedButton = this._buttonForEngine(this._contextEngine);
           this.handleSearchCommand(event, this._contextEngine, true);
         }
         if (anonid == "search-one-offs-context-set-default") {
           let currentEngine = Services.search.currentEngine;
 
-          // Make the target button of the context menu reflect the current
-          // search engine first. Doing this as opposed to rebuilding all the
-          // one-off buttons avoids flicker.
-          let button = this._buttonForEngine(this._contextEngine);
-          button.id = this._buttonIDForEngine(currentEngine);
-          let uri = "chrome://browser/skin/search-engine-placeholder.png";
-          if (currentEngine.iconURI)
-            uri = currentEngine.iconURI.spec;
-          button.setAttribute("image", uri);
-          button.setAttribute("tooltiptext", currentEngine.name);
-          button.engine = currentEngine;
+          if (!this.getAttribute("includecurrentengine")) {
+            // Make the target button of the context menu reflect the current
+            // search engine first. Doing this as opposed to rebuilding all the
+            // one-off buttons avoids flicker.
+            let button = this._buttonForEngine(this._contextEngine);
+            button.id = this._buttonIDForEngine(currentEngine);
+            let uri = "chrome://browser/skin/search-engine-placeholder.png";
+            if (currentEngine.iconURI)
+              uri = currentEngine.iconURI.spec;
+            button.setAttribute("image", uri);
+            button.setAttribute("tooltiptext", currentEngine.name);
+            button.engine = currentEngine;
+          }
 
           Services.search.currentEngine = this._contextEngine;
         }
       ]]></handler>
 
       <handler event="contextmenu"><![CDATA[
         let target = event.originalTarget;
         // Prevent the context menu from appearing except on the one off buttons.
--- a/browser/components/search/test/browser.ini
+++ b/browser/components/search/test/browser.ini
@@ -25,16 +25,17 @@ support-files =
 skip-if = os == "mac" # bug 967013
 [browser_google.js]
 [browser_google_codes.js]
 [browser_google_behavior.js]
 [browser_healthreport.js]
 [browser_hiddenOneOffs_cleanup.js]
 [browser_hiddenOneOffs_diacritics.js]
 [browser_oneOffContextMenu.js]
+[browser_oneOffContextMenu_setDefault.js]
 [browser_oneOffHeader.js]
 [browser_private_search_perwindowpb.js]
 [browser_yahoo.js]
 [browser_yahoo_behavior.js]
 [browser_abouthome_behavior.js]
 skip-if = true # Bug ??????, Bug 1100301 - leaks windows until shutdown when --run-by-dir
 [browser_aboutSearchReset.js]
 [browser_searchbar_openpopup.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/search/test/browser_oneOffContextMenu_setDefault.js
@@ -0,0 +1,189 @@
+"use strict";
+
+const TEST_ENGINE_NAME = "Foo";
+const TEST_ENGINE_BASENAME = "testEngine.xml";
+const SEARCHBAR_BASE_ID = "searchbar-engine-one-off-item-";
+const URLBAR_BASE_ID = "urlbar-engine-one-off-item-";
+
+const searchbar = document.getElementById("searchbar");
+const urlbar = document.getElementById("urlbar");
+const searchPopup = document.getElementById("PopupSearchAutoComplete");
+const urlbarPopup = document.getElementById("PopupAutoCompleteRichResult");
+const searchIcon = document.getAnonymousElementByAttribute(
+  searchbar, "anonid", "searchbar-search-button"
+);
+const searchOneOffBinding = document.getAnonymousElementByAttribute(
+  searchPopup, "anonid", "search-one-off-buttons"
+);
+const urlBarOneOffBinding = document.getAnonymousElementByAttribute(
+  urlbarPopup, "anonid", "one-off-search-buttons"
+);
+
+let originalEngine = Services.search.currentEngine;
+
+function resetEngine() {
+  Services.search.currentEngine = originalEngine;
+}
+
+registerCleanupFunction(resetEngine);
+
+add_task(function* init() {
+  yield promiseNewEngine(TEST_ENGINE_BASENAME, {
+    setAsCurrent: false,
+  });
+});
+
+add_task(function* test_searchBarChangeEngine() {
+  let oneOffButton = yield openPopupAndGetEngineButton(true, searchPopup,
+                                                       searchOneOffBinding,
+                                                       SEARCHBAR_BASE_ID);
+
+  const setDefaultEngineMenuItem = document.getAnonymousElementByAttribute(
+    searchOneOffBinding, "anonid", "search-one-offs-context-set-default"
+  );
+
+  // Click the set default engine menu item.
+  let promise = promiseCurrentEngineChanged();
+  EventUtils.synthesizeMouseAtCenter(setDefaultEngineMenuItem, {});
+
+  // This also checks the engine correctly changed.
+  yield promise;
+
+  Assert.equal(oneOffButton.id, SEARCHBAR_BASE_ID + originalEngine.name,
+               "Should now have the original engine's id for the button");
+  Assert.equal(oneOffButton.getAttribute("tooltiptext"), originalEngine.name,
+               "Should now have the original engine's name for the tooltip");
+  Assert.equal(oneOffButton.image, originalEngine.iconURI.spec,
+               "Should now have the original engine's uri for the image");
+
+  yield promiseClosePopup(searchPopup);
+});
+
+add_task(function* test_urlBarChangeEngine() {
+  // Ensure the engine is reset.
+  resetEngine();
+
+  let oneOffButton = yield openPopupAndGetEngineButton(false, urlbarPopup,
+                                                       urlBarOneOffBinding,
+                                                       URLBAR_BASE_ID);
+
+  const setDefaultEngineMenuItem = document.getAnonymousElementByAttribute(
+    urlBarOneOffBinding, "anonid", "search-one-offs-context-set-default"
+  );
+
+  // Click the set default engine menu item.
+  let promise = promiseCurrentEngineChanged();
+  EventUtils.synthesizeMouseAtCenter(setDefaultEngineMenuItem, {});
+
+  // This also checks the engine correctly changed.
+  yield promise;
+
+  let currentEngine = Services.search.currentEngine;
+
+  // For the urlbar, we should keep the new engine's icon.
+  Assert.equal(oneOffButton.id, URLBAR_BASE_ID + currentEngine.name,
+               "Should now have the original engine's id for the button");
+  Assert.equal(oneOffButton.getAttribute("tooltiptext"), currentEngine.name,
+               "Should now have the original engine's name for the tooltip");
+  Assert.equal(oneOffButton.image, currentEngine.iconURI.spec,
+               "Should now have the original engine's uri for the image");
+
+  yield promiseClosePopup(urlbarPopup);
+});
+
+/**
+ * Promises that an engine change has happened for the current engine, which
+ * has resulted in the test engine now being the current engine.
+ *
+ * @return {Promise} Resolved once the test engine is set as the current engine.
+ */
+function promiseCurrentEngineChanged() {
+  return new Promise(resolve => {
+    function observer(aSub, aTopic, aData) {
+      if (aData == "engine-current") {
+        Assert.ok(Services.search.currentEngine.name, TEST_ENGINE_NAME, "currentEngine set");
+        Services.obs.removeObserver(observer, "browser-search-engine-modified");
+        resolve();
+      }
+    }
+
+    Services.obs.addObserver(observer, "browser-search-engine-modified", false);
+  });
+}
+
+/**
+ * Opens the specified urlbar/search popup and gets the test engine from the
+ * one-off buttons.
+ *
+ * @param {Boolean} isSearch true if the search popup should be opened; false
+ *                           for the urlbar popup.
+ * @param {Object} popup The expected popup.
+ * @param {Object} oneOffBinding The expected one-off-binding for the popup.
+ * @param {String} baseId The expected string for the id of the current
+ *                        engine button, without the engine name.
+ * @return {Object} Returns an object that represents the one off button for the
+ *                          test engine.
+ */
+function* openPopupAndGetEngineButton(isSearch, popup, oneOffBinding, baseId) {
+  // Open the popup.
+  let promise = promiseEvent(popup, "popupshown");
+  info("Opening panel");
+
+  // We have to open the popups in differnt ways.
+  if (isSearch) {
+    // Use the search icon to avoid hitting the network.
+    EventUtils.synthesizeMouseAtCenter(searchIcon, {});
+  } else {
+    // There's no history at this stage, so we need to press a key.
+    urlbar.focus();
+    EventUtils.synthesizeKey("a", {});
+  }
+  yield promise;
+
+  const contextMenu = document.getAnonymousElementByAttribute(
+    oneOffBinding, "anonid", "search-one-offs-context-menu"
+  );
+  const oneOffButtons = document.getAnonymousElementByAttribute(
+    oneOffBinding, "anonid", "search-panel-one-offs"
+  );
+
+  // Get the one-off button for the test engine.
+  let oneOffButton;
+  for (let node of oneOffButtons.childNodes) {
+    if (node.engine && node.engine.name == TEST_ENGINE_NAME) {
+      oneOffButton = node;
+      break;
+    }
+  }
+  Assert.notEqual(oneOffButton, undefined,
+                  "One-off for test engine should exist");
+  Assert.equal(oneOffButton.getAttribute("tooltiptext"), TEST_ENGINE_NAME,
+               "One-off should have the tooltip set to the engine name");
+  Assert.equal(oneOffButton.id, baseId + TEST_ENGINE_NAME,
+               "Should have the correct id");
+
+  // Open the context menu on the one-off.
+  promise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+  EventUtils.synthesizeMouseAtCenter(oneOffButton, {
+    type: "contextmenu",
+    button: 2,
+  });
+  yield promise;
+
+  return oneOffButton;
+}
+
+/**
+ * Closes the popup and moves the mouse away from it.
+ *
+ * @param {Button} popup The popup to close.
+ */
+function* promiseClosePopup(popup) {
+  // close the panel using the escape key.
+  let promise = promiseEvent(popup, "popuphidden");
+  EventUtils.synthesizeKey("VK_ESCAPE", {});
+  yield promise;
+
+  // Move the cursor out of the panel area to avoid messing with other tests.
+  yield EventUtils.synthesizeNativeMouseMove(popup);
+}
new file mode 100644
--- /dev/null
+++ b/browser/experiments/.eslintrc.js
@@ -0,0 +1,11 @@
+"use strict";
+
+module.exports = {
+  "rules": {
+    "no-unused-vars": ["error", {
+      "vars": "all",
+      "varsIgnorePattern": "^(Cc|Ci|Cr|Cu|EXPORTED_SYMBOLS)$",
+      "args": "none"
+    }]
+  }
+};
--- a/browser/experiments/Experiments.jsm
+++ b/browser/experiments/Experiments.jsm
@@ -39,17 +39,16 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "nsICrashReporter");
 
 const FILE_CACHE                = "experiments.json";
 const EXPERIMENTS_CHANGED_TOPIC = "experiments-changed";
 const MANIFEST_VERSION          = 1;
 const CACHE_VERSION             = 1;
 
 const KEEP_HISTORY_N_DAYS       = 180;
-const MIN_EXPERIMENT_ACTIVE_SECONDS = 60;
 
 const PREF_BRANCH               = "experiments.";
 const PREF_ENABLED              = "enabled"; // experiments.enabled
 const PREF_ACTIVE_EXPERIMENT    = "activeExperiment"; // whether we have an active experiment
 const PREF_LOGGING              = "logging";
 const PREF_LOGGING_LEVEL        = PREF_LOGGING + ".level"; // experiments.logging.level
 const PREF_LOGGING_DUMP         = PREF_LOGGING + ".dump"; // experiments.logging.dump
 const PREF_MANIFEST_URI         = "manifest.uri"; // experiments.logging.manifest.uri
@@ -1212,17 +1211,16 @@ Experiments.Experiments.prototype = {
       this._log.warn("_evaluateExperiments() - unknown add-ons in AddonManager: " +
                      unknownAddons.map(a => a.id).join(", "));
 
       yield uninstallAddons(unknownAddons);
     }
 
     let activeExperiment = this._getActiveExperiment();
     let activeChanged = false;
-    let now = this._policy.now();
 
     if (!activeExperiment) {
       // Avoid this pref staying out of sync if there were e.g. crashes.
       gPrefs.set(PREF_ACTIVE_EXPERIMENT, false);
     }
 
     // Ensure the active experiment is in the proper state. This may install,
     // uninstall, upgrade, or enable the experiment add-on. What exactly is
@@ -1272,17 +1270,16 @@ Experiments.Experiments.prototype = {
         }
         catch (e) {
           applicable = false;
           reason = e;
         }
 
         if (!applicable && reason && reason[0] != "was-active") {
           // Report this from here to avoid over-reporting.
-          let desc = TELEMETRY_LOG.ACTIVATION;
           let data = [TELEMETRY_LOG.ACTIVATION.REJECTED, id];
           data = data.concat(reason);
           const key = TELEMETRY_LOG.ACTIVATION_KEY;
           TelemetryLog.log(key, data);
           this._log.trace("evaluateExperiments() - added " + key + " to TelemetryLog: " + JSON.stringify(data));
         }
 
         if (!applicable) {
@@ -1338,17 +1335,17 @@ Experiments.Experiments.prototype = {
 
     let time = null;
     let now = this._policy.now().getTime();
     if (this._dirty) {
       // If we failed to write the cache, we should try again periodically
       time = now + 1000 * CACHE_WRITE_RETRY_DELAY_SEC;
     }
 
-    for (let [id, experiment] of this._experiments) {
+    for (let [, experiment] of this._experiments) {
       let scheduleTime = experiment.getScheduleTime();
       if (scheduleTime > now) {
         if (time !== null) {
           time = Math.min(time, scheduleTime);
         } else {
           time = scheduleTime;
         }
       }
@@ -1639,17 +1636,16 @@ Experiments.ExperimentEntry.prototype = 
     let runtime = Cc["@mozilla.org/xre/app-info;1"]
                     .getService(Ci.nsIXULRuntime);
 
     let locale = this._policy.locale();
     let channel = this._policy.updatechannel();
     let data = this._manifestData;
 
     let now = this._policy.now() / 1000; // The manifest times are in seconds.
-    let minActive = MIN_EXPERIMENT_ACTIVE_SECONDS;
     let maxActive = data.maxActiveSeconds || 0;
     let startSec = (this.startDate || 0) / 1000;
 
     this._log.trace("isApplicable() - now=" + now
                     + ", randomValue=" + this._randomValue);
 
     // Not applicable if it already ran.
 
@@ -2064,20 +2060,16 @@ Experiments.ExperimentEntry.prototype = 
   /**
    * Determine whether an active experiment should be stopped.
    */
   shouldStop: function () {
     if (!this._enabled) {
       throw new Error("shouldStop must not be called on disabled experiments.");
     }
 
-    let data = this._manifestData;
-    let now = this._policy.now() / 1000; // The manifest times are in seconds.
-    let maxActiveSec = data.maxActiveSeconds || 0;
-
     let deferred = Promise.defer();
     this.isApplicable().then(
       () => deferred.resolve({shouldStop: false}),
       reason => deferred.resolve({shouldStop: true, reason: reason})
     );
 
     return deferred.promise;
   },
@@ -2092,17 +2084,16 @@ Experiments.ExperimentEntry.prototype = 
   },
 
   /*
    * Get next date (in epoch-ms) to schedule a re-evaluation for this.
    * Returns 0 if it doesn't need one.
    */
   getScheduleTime: function () {
     if (this._enabled) {
-      let now = this._policy.now();
       let startTime = this._startDate.getTime();
       let maxActiveTime = startTime + 1000 * this._manifestData.maxActiveSeconds;
       return Math.min(1000 * this._manifestData.endTime,  maxActiveTime);
     }
 
     if (this._endDate) {
       return this._endDate.getTime();
     }
@@ -2223,17 +2214,17 @@ this.Experiments.PreviousExperimentProvi
         let wrapper = new PreviousExperimentAddon(newMap.get(id));
         AddonManagerPrivate.callInstallListeners("onExternalInstall", null, wrapper, null, false);
         AddonManagerPrivate.callAddonListeners("onInstalling", wrapper, false);
       }
 
       for (let id of removed) {
         this._log.trace("updateExperimentList() - removing " + id);
         let wrapper = new PreviousExperimentAddon(oldMap.get(id));
-        AddonManagerPrivate.callAddonListeners("onUninstalling", plugin, false);
+        AddonManagerPrivate.callAddonListeners("onUninstalling", wrapper, false);
       }
 
       this._experimentList = list;
 
       for (let id of added) {
         let wrapper = new PreviousExperimentAddon(newMap.get(id));
         AddonManagerPrivate.callAddonListeners("onInstalled", wrapper);
       }
--- a/browser/experiments/test/addons/experiment-racybranch/bootstrap.js
+++ b/browser/experiments/test/addons/experiment-racybranch/bootstrap.js
@@ -1,8 +1,10 @@
+/* exported startup, shutdown, install, uninstall */
+
 var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource:///modules/experiments/Experiments.jsm");
 
 var gStarted = false;
 
 function startup(data, reasonCode) {
   if (gStarted) {
--- a/browser/experiments/test/xpcshell/.eslintrc.js
+++ b/browser/experiments/test/xpcshell/.eslintrc.js
@@ -1,7 +1,15 @@
 "use strict";
 
 module.exports = {
   "extends": [
     "../../../../testing/xpcshell/xpcshell.eslintrc.js"
-  ]
+  ],
+
+  "rules": {
+    "no-unused-vars": ["error", {
+      "vars": "all",
+      "varsIgnorePattern": "^(Cc|Ci|Cr|Cu|EXPORTED_SYMBOLS|run_test)$",
+      "args": "none"
+    }]
+  }
 };
--- a/browser/experiments/test/xpcshell/head.js
+++ b/browser/experiments/test/xpcshell/head.js
@@ -1,11 +1,20 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
+/* exported PREF_EXPERIMENTS_ENABLED, PREF_LOGGING_LEVEL, PREF_LOGGING_DUMP
+            PREF_MANIFEST_URI, PREF_FETCHINTERVAL, EXPERIMENT1_ID,
+            EXPERIMENT1_NAME, EXPERIMENT1_XPI_SHA1, EXPERIMENT1A_NAME,
+            EXPERIMENT1A_XPI_SHA1, EXPERIMENT2_ID, EXPERIMENT2_XPI_SHA1,
+            EXPERIMENT3_ID, EXPERIMENT4_ID, FAKE_EXPERIMENTS_1,
+            FAKE_EXPERIMENTS_2, gAppInfo, removeCacheFile, defineNow,
+            futureDate, dateToSeconds, loadAddonManager, promiseRestartManager,
+            startAddonManagerOnly, getExperimentAddons, replaceExperiments */
+
 var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource://testing-common/AddonManagerTesting.jsm");
--- a/browser/experiments/test/xpcshell/test_activate.js
+++ b/browser/experiments/test/xpcshell/test_activate.js
@@ -1,21 +1,19 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource:///modules/experiments/Experiments.jsm");
 
-const FILE_MANIFEST            = "experiments.manifest";
 const SEC_IN_ONE_DAY  = 24 * 60 * 60;
 const MS_IN_ONE_DAY   = SEC_IN_ONE_DAY * 1000;
 
-var gProfileDir = null;
 var gHttpServer = null;
 var gHttpRoot   = null;
 var gPolicy     = null;
 
 function ManifestEntry(data) {
   this.id        = data.id        || EXPERIMENT1_ID;
   this.xpiURL    = data.xpiURL    || gHttpRoot + EXPERIMENT1_XPI_NAME;
   this.xpiHash   = data.xpiHash   || EXPERIMENT1_XPI_SHA1;
@@ -27,35 +25,32 @@ function ManifestEntry(data) {
 }
 
 function run_test() {
   run_next_test();
 }
 
 add_task(function* test_setup() {
   loadAddonManager();
-  gProfileDir = do_get_profile();
   gPolicy = new Experiments.Policy();
 
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
   let port = gHttpServer.identity.primaryPort;
   gHttpRoot = "http://localhost:" + port + "/";
   gHttpServer.registerDirectory("/", do_get_cwd());
   do_register_cleanup(() => gHttpServer.stop(() => {}));
 
   patchPolicy(gPolicy, {
     updatechannel: () => "nightly",
   });
 
   Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true);
   Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0);
   Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true);
-
-  let experiments = new Experiments.Experiments();
 });
 
 function isApplicable(experiment) {
   let deferred = Promise.defer();
   experiment.isApplicable().then(
     result => deferred.resolve({ applicable: true,  reason: null }),
     reason => deferred.resolve({ applicable: false, reason: reason })
   );
--- a/browser/experiments/test/xpcshell/test_api.js
+++ b/browser/experiments/test/xpcshell/test_api.js
@@ -4,23 +4,21 @@
 "use strict";
 
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource://testing-common/AddonManagerTesting.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Experiments",
   "resource:///modules/experiments/Experiments.jsm");
 
-const FILE_MANIFEST            = "experiments.manifest";
 const MANIFEST_HANDLER         = "manifests/handler";
 
 const SEC_IN_ONE_DAY  = 24 * 60 * 60;
 const MS_IN_ONE_DAY   = SEC_IN_ONE_DAY * 1000;
 
-var gProfileDir          = null;
 var gHttpServer          = null;
 var gHttpRoot            = null;
 var gDataRoot            = null;
 var gPolicy              = null;
 var gManifestObject      = null;
 var gManifestHandlerURI  = null;
 var gTimerScheduleOffset = -1;
 
@@ -42,17 +40,16 @@ function testCleanup(experimentsInstance
 }
 
 function run_test() {
   run_next_test();
 }
 
 add_task(function* test_setup() {
   loadAddonManager();
-  gProfileDir = do_get_profile();
 
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
   let port = gHttpServer.identity.primaryPort;
   gHttpRoot = "http://localhost:" + port + "/";
   gDataRoot = gHttpRoot + "data/";
   gManifestHandlerURI = gHttpRoot + MANIFEST_HANDLER;
   gHttpServer.registerDirectory("/data/", do_get_cwd());
@@ -157,17 +154,17 @@ add_task(function* test_getExperiments()
                "getActiveExperimentID should return null");
 
   let list = yield experiments.getExperiments();
   Assert.equal(list.length, 0, "Experiment list should be empty.");
   let addons = yield getExperimentAddons();
   Assert.equal(addons.length, 0, "Precondition: No experiment add-ons are installed.");
 
   try {
-    let b = yield experiments.getExperimentBranch();
+    yield experiments.getExperimentBranch();
     Assert.ok(false, "getExperimentBranch should fail with no experiment");
   }
   catch (e) {
     Assert.ok(true, "getExperimentBranch correctly threw");
   }
 
   // Trigger update, clock set for experiment 1 to start.
 
--- a/browser/experiments/test/xpcshell/test_cache.js
+++ b/browser/experiments/test/xpcshell/test_cache.js
@@ -7,32 +7,29 @@ Cu.import("resource://testing-common/htt
 XPCOMUtils.defineLazyModuleGetter(this, "Experiments",
   "resource:///modules/experiments/Experiments.jsm");
 
 const MANIFEST_HANDLER         = "manifests/handler";
 
 const SEC_IN_ONE_DAY  = 24 * 60 * 60;
 const MS_IN_ONE_DAY   = SEC_IN_ONE_DAY * 1000;
 
-var gProfileDir          = null;
 var gHttpServer          = null;
 var gHttpRoot            = null;
 var gDataRoot            = null;
 var gPolicy              = null;
 var gManifestObject      = null;
 var gManifestHandlerURI  = null;
-var gTimerScheduleOffset = -1;
 
 function run_test() {
   run_next_test();
 }
 
 add_task(function* test_setup() {
   loadAddonManager();
-  gProfileDir = do_get_profile();
   yield removeCacheFile();
 
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
   let port = gHttpServer.identity.primaryPort;
   gHttpRoot = "http://localhost:" + port + "/";
   gDataRoot = gHttpRoot + "data/";
   gManifestHandlerURI = gHttpRoot + MANIFEST_HANDLER;
@@ -49,17 +46,17 @@ add_task(function* test_setup() {
   Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0);
   Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true);
   Services.prefs.setCharPref(PREF_MANIFEST_URI, gManifestHandlerURI);
   Services.prefs.setIntPref(PREF_FETCHINTERVAL, 0);
 
   gPolicy = new Experiments.Policy();
   patchPolicy(gPolicy, {
     updatechannel: () => "nightly",
-    oneshotTimer: (callback, timeout, thisObj, name) => gTimerScheduleOffset = timeout,
+    oneshotTimer: (callback, timeout, thisObj, name) => {},
   });
 });
 
 function checkExperimentListsEqual(list, list2) {
   Assert.equal(list.length, list2.length, "Lists should have the same length.")
 
   for (let i=0; i<list.length; ++i) {
     for (let k of Object.keys(list[i])) {
--- a/browser/experiments/test/xpcshell/test_cacherace.js
+++ b/browser/experiments/test/xpcshell/test_cacherace.js
@@ -6,31 +6,29 @@
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource://gre/modules/Timer.jsm");
 
 const MANIFEST_HANDLER         = "manifests/handler";
 
 const SEC_IN_ONE_DAY  = 24 * 60 * 60;
 const MS_IN_ONE_DAY   = SEC_IN_ONE_DAY * 1000;
 
-var gProfileDir          = null;
 var gHttpServer          = null;
 var gHttpRoot            = null;
 var gDataRoot            = null;
 var gPolicy              = null;
 var gManifestObject      = null;
 var gManifestHandlerURI  = null;
 
 function run_test() {
   run_next_test();
 }
 
 add_task(function* test_setup() {
   loadAddonManager();
-  gProfileDir = do_get_profile();
   yield removeCacheFile();
 
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
   let port = gHttpServer.identity.primaryPort;
   gHttpRoot = "http://localhost:" + port + "/";
   gDataRoot = gHttpRoot + "data/";
   gManifestHandlerURI = gHttpRoot + MANIFEST_HANDLER;
--- a/browser/experiments/test/xpcshell/test_conditions.js
+++ b/browser/experiments/test/xpcshell/test_conditions.js
@@ -2,26 +2,20 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 
 Cu.import("resource:///modules/experiments/Experiments.jsm");
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
 
-const FILE_MANIFEST            = "experiments.manifest";
 const SEC_IN_ONE_DAY = 24 * 60 * 60;
-const MS_IN_ONE_DAY  = SEC_IN_ONE_DAY * 1000;
 
-var gProfileDir = null;
-var gHttpServer = null;
-var gHttpRoot   = null;
 var gPolicy     = null;
 
-
 function ManifestEntry(data) {
   this.id = EXPERIMENT1_ID;
   this.xpiURL = "http://localhost:1/dummy.xpi";
   this.xpiHash = EXPERIMENT1_XPI_SHA1;
   this.startTime = new Date(2010, 0, 1, 12).getTime() / 1000;
   this.endTime = new Date(9001, 0, 1, 12).getTime() / 1000;
   this.maxActiveSeconds = SEC_IN_ONE_DAY;
   this.appName = ["XPCShell"];
@@ -45,17 +39,17 @@ function applicableFromManifestData(data
 }
 
 function run_test() {
   run_next_test();
 }
 
 add_task(function* test_setup() {
   createAppInfo();
-  gProfileDir = do_get_profile();
+  do_get_profile();
   startAddonManagerOnly();
   yield TelemetryController.testSetup();
   gPolicy = new Experiments.Policy();
 
   patchPolicy(gPolicy, {
     updatechannel: () => "nightly",
     locale: () => "en-US",
     random: () => 0.5,
--- a/browser/experiments/test/xpcshell/test_disableExperiments.js
+++ b/browser/experiments/test/xpcshell/test_disableExperiments.js
@@ -4,37 +4,34 @@
 "use strict";
 
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource://testing-common/AddonManagerTesting.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Experiments",
   "resource:///modules/experiments/Experiments.jsm");
 
-const FILE_MANIFEST            = "experiments.manifest";
 const MANIFEST_HANDLER         = "manifests/handler";
 
 const SEC_IN_ONE_DAY  = 24 * 60 * 60;
 const MS_IN_ONE_DAY   = SEC_IN_ONE_DAY * 1000;
 
-var gProfileDir          = null;
 var gHttpServer          = null;
 var gHttpRoot            = null;
 var gDataRoot            = null;
 var gPolicy              = null;
 var gManifestObject      = null;
 var gManifestHandlerURI  = null;
 
 function run_test() {
   run_next_test();
 }
 
 add_task(function* test_setup() {
   loadAddonManager();
-  gProfileDir = do_get_profile();
 
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
   let port = gHttpServer.identity.primaryPort;
   gHttpRoot = "http://localhost:" + port + "/";
   gDataRoot = gHttpRoot + "data/";
   gManifestHandlerURI = gHttpRoot + MANIFEST_HANDLER;
   gHttpServer.registerDirectory("/data/", do_get_cwd());
--- a/browser/experiments/test/xpcshell/test_fetch.js
+++ b/browser/experiments/test/xpcshell/test_fetch.js
@@ -3,24 +3,22 @@
 
 "use strict";
 
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 Cu.import("resource:///modules/experiments/Experiments.jsm");
 
-var gProfileDir = null;
 var gHttpServer = null;
 var gHttpRoot   = null;
 var gPolicy     = new Experiments.Policy();
 
 function run_test() {
   loadAddonManager();
-  gProfileDir = do_get_profile();
 
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
   let port = gHttpServer.identity.primaryPort;
   gHttpRoot = "http://localhost:" + port + "/";
   gHttpServer.registerDirectory("/", do_get_cwd());
   do_register_cleanup(() => gHttpServer.stop(() => {}));
 
@@ -63,9 +61,8 @@ add_task(function* test_fetchInvalid() {
   Assert.notEqual(ex._experiments.size, 0, "There should be experiments");
 
   Services.prefs.setCharPref(PREF_MANIFEST_URI, gHttpRoot + "invalid.manifest");
   yield ex.updateManifest()
   Assert.notEqual(ex._experiments.size, 0, "There should still be experiments: fetch failure shouldn't remove them.");
 
   yield promiseRestartManager();
 });
-
--- a/browser/experiments/test/xpcshell/test_telemetry.js
+++ b/browser/experiments/test/xpcshell/test_telemetry.js
@@ -3,24 +3,22 @@
 
 "use strict";
 
 Cu.import("resource://testing-common/httpd.js");
 Cu.import("resource://gre/modules/TelemetryLog.jsm");
 var bsp = Cu.import("resource:///modules/experiments/Experiments.jsm");
 
 
-const FILE_MANIFEST            = "experiments.manifest";
 const MANIFEST_HANDLER         = "manifests/handler";
 
 const SEC_IN_ONE_DAY  = 24 * 60 * 60;
 const MS_IN_ONE_DAY   = SEC_IN_ONE_DAY * 1000;
 
 
-var gProfileDir          = null;
 var gHttpServer          = null;
 var gHttpRoot            = null;
 var gDataRoot            = null;
 var gPolicy              = null;
 var gManifestObject      = null;
 var gManifestHandlerURI  = null;
 
 const TLOG = bsp.TELEMETRY_LOG;
@@ -43,17 +41,16 @@ function checkEvent(event, id, data)
 }
 
 function run_test() {
   run_next_test();
 }
 
 add_task(function* test_setup() {
   loadAddonManager();
-  gProfileDir = do_get_profile();
 
   gHttpServer = new HttpServer();
   gHttpServer.start(-1);
   let port = gHttpServer.identity.primaryPort;
   gHttpRoot = "http://localhost:" + port + "/";
   gDataRoot = gHttpRoot + "data/";
   gManifestHandlerURI = gHttpRoot + MANIFEST_HANDLER;
   gHttpServer.registerDirectory("/data/", do_get_cwd());
@@ -82,18 +79,16 @@ add_task(function* test_setup() {
 });
 
 // Test basic starting and stopping of experiments.
 
 add_task(function* test_telemetryBasics() {
   // Check TelemetryLog instead of TelemetrySession.getPayload().log because
   // TelemetrySession gets Experiments.instance() and side-effects log entries.
 
-  const OBSERVER_TOPIC = "experiments-changed";
-  let observerFireCount = 0;
   let expectedLogLength = 0;
 
   // Dates the following tests are based on.
 
   let baseDate   = new Date(2014, 5, 1, 12);
   let startDate1 = futureDate(baseDate,  50 * MS_IN_ONE_DAY);
   let endDate1   = futureDate(baseDate, 100 * MS_IN_ONE_DAY);
   let startDate2 = futureDate(baseDate, 150 * MS_IN_ONE_DAY);
@@ -122,31 +117,16 @@ add_task(function* test_telemetryBasics(
         endTime:          dateToSeconds(endDate2),
         maxActiveSeconds: 10 * SEC_IN_ONE_DAY,
         appName:          ["XPCShell"],
         channel:          ["nightly"],
       },
     ],
   };
 
-  // Data to compare the result of Experiments.getExperiments() against.
-
-  let experimentListData = [
-    {
-      id: EXPERIMENT2_ID,
-      name: "Test experiment 2",
-      description: "And yet another experiment that experiments experimentally.",
-    },
-    {
-      id: EXPERIMENT1_ID,
-      name: EXPERIMENT1_NAME,
-      description: "Yet another experiment that experiments experimentally.",
-    },
-  ];
-
   let experiments = new Experiments.Experiments(gPolicy);
 
   // Trigger update, clock set to before any activation.
   // Use updateManifest() to provide for coverage of that path.
 
   let now = baseDate;
   defineNow(gPolicy, now);
 
--- a/browser/experiments/test/xpcshell/test_upgrade.js
+++ b/browser/experiments/test/xpcshell/test_upgrade.js
@@ -1,17 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 Cu.import("resource:///modules/experiments/Experiments.jsm");
 
-const SEC_IN_ONE_DAY  = 24 * 60 * 60;
-const MS_IN_ONE_DAY   = SEC_IN_ONE_DAY * 1000;
-
 var cacheData = {
   _enabled: true,
   _manifestData: {
     id: "foobartestid",
     xpiURL: "http://example.com/foo.xpi",
     xpiHash: "sha256:abcde",
     startTime: 0,
     endTime: 2000000000,
--- a/browser/modules/ContentCrashHandlers.jsm
+++ b/browser/modules/ContentCrashHandlers.jsm
@@ -109,16 +109,26 @@ this.TabCrashHandler = {
           // this list from getting too large by putting a reasonable upper
           // limit on how many childIDs we track. It's unlikely that this
           // array would ever get so large as to be unwieldy (that'd be a lot
           // or crashes!), but a leak is a leak.
           if (this.unseenCrashedChildIDs.length > MAX_UNSEEN_CRASHED_CHILD_IDS) {
             this.unseenCrashedChildIDs.shift();
           }
         }
+
+        // check for environment affecting crash reporting
+        let env = Cc["@mozilla.org/process/environment;1"]
+                    .getService(Ci.nsIEnvironment);
+        let shutdown = env.exists("MOZ_CRASHREPORTER_SHUTDOWN");
+
+        if (shutdown) {
+          Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
+        }
+
         break;
       }
       case "oop-frameloader-crashed": {
         aSubject.QueryInterface(Ci.nsIFrameLoader);
 
         let browser = aSubject.ownerElement;
         if (!browser) {
           return;
--- a/browser/themes/linux/browser.css
+++ b/browser/themes/linux/browser.css
@@ -913,16 +913,20 @@ notification[value="translation"] button
 notification[value="translation"] menulist > .menulist-dropmarker {
   display: block;
 }
 
 /* AutoComplete */
 
 %include ../shared/autocomplete.inc.css
 
+#PopupAutoComplete > richlistbox > richlistitem[originaltype~="datalist-first"] {
+  border-top: 1px solid ThreeDShadow;
+}
+
 #treecolAutoCompleteImage {
   max-width : 36px;
 }
 
 .autocomplete-richlistbox {
   padding: 4px;
 }
 
--- a/browser/themes/osx/browser.css
+++ b/browser/themes/osx/browser.css
@@ -1747,16 +1747,20 @@ toolbar .toolbarbutton-1 > .toolbarbutto
 }
 
 %include ../shared/urlbarSearchSuggestionsNotification.inc.css
 
 /* ----- AUTOCOMPLETE ----- */
 
 %include ../shared/autocomplete.inc.css
 
+#PopupAutoComplete > richlistbox > richlistitem[originaltype~="datalist-first"] {
+  border-top: 1px solid #C7C7C7;
+}
+
 #treecolAutoCompleteImage {
   max-width: 36px;
 }
 
 .autocomplete-richlistbox {
   padding: 4px;
 }
 
--- a/browser/themes/shared/autocomplete.inc.css
+++ b/browser/themes/shared/autocomplete.inc.css
@@ -2,17 +2,19 @@
 /* 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/. */
 %endif
 
 #PopupAutoComplete > richlistbox > richlistitem {
   height: 20px;
   min-height: 20px;
+  border: 0;
   border-radius: 0;
+  padding: 0px 1px 0px 1px;
 }
 
 #PopupAutoComplete > richlistbox > richlistitem > .ac-title {
   font: icon;
   margin-inline-start: 6px;
 }
 
 #PopupAutoComplete > richlistbox {
--- a/browser/themes/windows/browser.css
+++ b/browser/themes/windows/browser.css
@@ -1529,16 +1529,20 @@ html|*.urlbar-input:-moz-lwtheme::placeh
 /* page proxy icon */
 
 %include ../shared/identity-block/identity-block.inc.css
 
 /* autocomplete */
 
 %include ../shared/autocomplete.inc.css
 
+#PopupAutoComplete > richlistbox > richlistitem[originaltype~="datalist-first"] {
+  border-top: 1px solid ThreeDShadow;
+}
+
 #treecolAutoCompleteImage {
   max-width: 36px;
 }
 
 .autocomplete-richlistbox {
   padding: 4px;
 }
 
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -154,25 +154,30 @@ set_config('MOZ_USING_COMPILER_WRAPPER',
 # Cross-compilation related things.
 # ==============================================================
 js_option('--with-toolchain-prefix', env='TOOLCHAIN_PREFIX', nargs=1,
           help='Prefix for the target toolchain')
 
 @depends('--with-toolchain-prefix', target, host, cross_compiling)
 def toolchain_prefix(value, target, host, cross_compiling):
     if value:
-        return value[0]
-    # Special case x86-64 <-> x86 cross compiling until we have the right tests
-    # in moz.configure land.
-    if cross_compiling and not all(i.cpu in ('x86_64', 'x86')
-                                   for i in (target, host)):
-        return '%s-' % target.toolchain
+        return tuple(value)
+    if cross_compiling:
+        return ('%s-' % target.toolchain, '%s-' % target.alias)
 
-set_config('TOOLCHAIN_PREFIX', toolchain_prefix)
-add_old_configure_assignment('TOOLCHAIN_PREFIX', toolchain_prefix)
+@depends(toolchain_prefix, target)
+def first_toolchain_prefix(toolchain_prefix, target):
+    # Pass TOOLCHAIN_PREFIX down to the build system if it was given from the
+    # command line/environment (in which case there's only one value in the tuple),
+    # or when cross-compiling for Android.
+    if toolchain_prefix and (target.os == 'Android' or len(toolchain_prefix) == 1):
+        return toolchain_prefix[0]
+
+set_config('TOOLCHAIN_PREFIX', first_toolchain_prefix)
+add_old_configure_assignment('TOOLCHAIN_PREFIX', first_toolchain_prefix)
 
 
 # Compilers
 # ==============================================================
 include('compilers-util.configure')
 
 def try_preprocess(compiler, language, source):
     return try_invoke_compiler(compiler, language, source, ['-E'])
@@ -458,25 +463,27 @@ def toolchain_search_path(vc_compiler_pa
 def default_c_compilers(host_or_target):
     '''Template defining the set of default C compilers for the host and
     target platforms.
     `host_or_target` is either `host` or `target` (the @depends functions
     from init.configure.
     '''
     assert host_or_target in (host, target)
 
-    @depends(host_or_target, host, toolchain_prefix)
-    def default_c_compilers(host_or_target, host, toolchain_prefix):
+    @depends(host_or_target, target, toolchain_prefix)
+    def default_c_compilers(host_or_target, target, toolchain_prefix):
+        gcc = ('gcc',)
+        if toolchain_prefix and host_or_target is target:
+            gcc = tuple('%sgcc' % p for p in toolchain_prefix) + gcc
+
         if host_or_target.kernel == 'WINNT':
-            return ('cl', 'clang-cl', 'gcc', 'clang')
+            return ('cl', 'clang-cl') + gcc + ('clang',)
         if host_or_target.kernel == 'Darwin':
             return ('clang',)
-        if host_or_target != host:  # cross compilation
-            return ('%sgcc' % toolchain_prefix, 'gcc', 'clang')
-        return ('gcc', 'clang')
+        return gcc + ('clang',)
 
     return default_c_compilers
 
 
 @template
 def default_cxx_compilers(c_compiler):
     '''Template defining the set of default C++ compilers for the host and
     target platforms.
--- a/devtools/client/responsive.html/test/browser/browser_exit_button.js
+++ b/devtools/client/responsive.html/test/browser/browser_exit_button.js
@@ -1,30 +1,70 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-// Test global exit button
-
 const TEST_URL = "data:text/html;charset=utf-8,";
 
-addRDMTask(TEST_URL, function* ({ ui, manager }) {
-  let { toolWindow } = ui;
+// Test global exit button
+addRDMTask(TEST_URL, function* (...args) {
+  yield testExitButton(...args);
+});
+
+// Test global exit button on detached tab.
+// See Bug 1262806
+add_task(function* () {
+  let tab = yield addTab(TEST_URL);
+  let { ui, manager } = yield openRDM(tab);
+
+  yield waitBootstrap(ui);
+
+  let waitTabIsDetached = Promise.all([
+    once(tab, "TabClose"),
+    once(tab.linkedBrowser, "SwapDocShells")
+  ]);
+
+  // Detach the tab with RDM open.
+  let newWindow = gBrowser.replaceTabWithWindow(tab);
+
+  // Waiting the tab is detached.
+  yield waitTabIsDetached;
+
+  // Get the new tab instance.
+  tab = newWindow.gBrowser.tabs[0];
+
+  // Detaching a tab closes RDM.
+  ok(!manager.isActiveForTab(tab),
+    "Responsive Design Mode is not active for the tab");
+
+  // Reopen the RDM and test the exit button again.
+  yield testExitButton(yield openRDM(tab));
+  yield BrowserTestUtils.closeWindow(newWindow);
+});
+
+function* waitBootstrap(ui) {
+  let { toolWindow, tab } = ui;
   let { store } = toolWindow;
+  let url = String(tab.linkedBrowser.currentURI.spec);
 
-  // Wait until the viewport has been added
+  // Wait until the viewport has been added.
   yield waitUntilState(store, state => state.viewports.length == 1);
 
-  let exitButton = toolWindow.document.getElementById("global-exit-button");
+  // Wait until the document has been loaded.
+  yield waitForFrameLoad(ui, url);
+}
 
-  yield waitForFrameLoad(ui, TEST_URL);
+function* testExitButton({ui, manager}) {
+  yield waitBootstrap(ui);
+
+  let exitButton = ui.toolWindow.document.getElementById("global-exit-button");
 
   ok(manager.isActiveForTab(ui.tab),
     "Responsive Design Mode active for the tab");
 
   exitButton.click();
 
   yield once(manager, "off");
 
   ok(!manager.isActiveForTab(ui.tab),
     "Responsive Design Mode is not active for the tab");
-});
+}
--- a/devtools/client/responsivedesign/responsivedesign-child.js
+++ b/devtools/client/responsivedesign/responsivedesign-child.js
@@ -36,17 +36,18 @@ var global = this;
    */
   function isActive() {
     sendAsyncMessage("ResponsiveMode:IsActive:Done", { active });
   }
 
   function startResponsiveMode({data:data}) {
     debug("START");
     if (active) {
-      debug("ALREADY STARTED, ABORT");
+      debug("ALREADY STARTED");
+      sendAsyncMessage("ResponsiveMode:Start:Done");
       return;
     }
     addMessageListener("ResponsiveMode:RequestScreenshot", screenshot);
     let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress);
     webProgress.addProgressListener(WebProgressListener, Ci.nsIWebProgress.NOTIFY_ALL);
     docShell.deviceSizeIsPageSize = true;
     gRequiresFloatingScrollbars = data.requiresFloatingScrollbars;
     if (data.notifyOnResize) {
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -286,17 +286,17 @@ KeyframeEffectReadOnly::UpdateProperties
     nsTArray<ComputedKeyframeValues> computedValues =
       KeyframeUtils::GetComputedKeyframeValues(keyframesCopy,
                                                mTarget->mElement,
                                                aStyleContext);
 
     if (mEffectOptions.mSpacingMode == SpacingMode::paced) {
       KeyframeUtils::ApplySpacing(keyframesCopy, SpacingMode::paced,
                                   mEffectOptions.mPacedProperty,
-                                  computedValues);
+                                  computedValues, aStyleContext);
     }
 
     properties =
       KeyframeUtils::GetAnimationPropertiesFromKeyframes(keyframesCopy,
                                                          computedValues,
                                                          aStyleContext);
 
 #ifdef DEBUG
--- a/dom/animation/KeyframeUtils.cpp
+++ b/dom/animation/KeyframeUtils.cpp
@@ -412,17 +412,18 @@ static void
 DistributeRange(const Range<Keyframe>& aSpacingRange);
 
 static void
 PaceRange(const Range<Keyframe>& aKeyframes,
           const Range<double>& aCumulativeDistances);
 
 static nsTArray<double>
 GetCumulativeDistances(const nsTArray<ComputedKeyframeValues>& aValues,
-                       nsCSSPropertyID aProperty);
+                       nsCSSPropertyID aProperty,
+                       nsStyleContext* aStyleContext);
 
 // ------------------------------------------------------------------
 //
 // Public API
 //
 // ------------------------------------------------------------------
 
 /* static */ nsTArray<Keyframe>
@@ -476,28 +477,30 @@ KeyframeUtils::GetKeyframesFromObject(JS
 
   return keyframes;
 }
 
 /* static */ void
 KeyframeUtils::ApplySpacing(nsTArray<Keyframe>& aKeyframes,
                             SpacingMode aSpacingMode,
                             nsCSSPropertyID aProperty,
-                            nsTArray<ComputedKeyframeValues>& aComputedValues)
+                            nsTArray<ComputedKeyframeValues>& aComputedValues,
+                            nsStyleContext* aStyleContext)
 {
   if (aKeyframes.IsEmpty()) {
     return;
   }
 
   nsTArray<double> cumulativeDistances;
   if (aSpacingMode == SpacingMode::paced) {
     MOZ_ASSERT(IsAnimatableProperty(aProperty),
                "Paced property should be animatable");
 
-    cumulativeDistances = GetCumulativeDistances(aComputedValues, aProperty);
+    cumulativeDistances = GetCumulativeDistances(aComputedValues, aProperty,
+                                                 aStyleContext);
     // Reset the computed offsets if using paced spacing.
     for (Keyframe& keyframe : aKeyframes) {
       keyframe.mComputedOffset = Keyframe::kComputedOffsetNotSet;
     }
   }
 
   // If the first keyframe has an unspecified offset, fill it in with 0%.
   // If there is only a single keyframe, then it gets 100%.
@@ -578,17 +581,17 @@ KeyframeUtils::ApplySpacing(nsTArray<Key
   }
 }
 
 /* static */ void
 KeyframeUtils::ApplyDistributeSpacing(nsTArray<Keyframe>& aKeyframes)
 {
   nsTArray<ComputedKeyframeValues> emptyArray;
   ApplySpacing(aKeyframes, SpacingMode::distribute, eCSSProperty_UNKNOWN,
-               emptyArray);
+               emptyArray, nullptr);
 }
 
 /* static */ nsTArray<ComputedKeyframeValues>
 KeyframeUtils::GetComputedKeyframeValues(const nsTArray<Keyframe>& aKeyframes,
                                          dom::Element* aElement,
                                          nsStyleContext* aStyleContext)
 {
   MOZ_ASSERT(aStyleContext);
@@ -1556,22 +1559,24 @@ PaceRange(const Range<Keyframe>& aKeyfra
   }
 }
 
 /**
  * Get cumulative distances for the paced property.
  *
  * @param aValues The computed values returned by GetComputedKeyframeValues.
  * @param aPacedProperty The paced property.
+ * @param aStyleContext The style context for computing distance on transform.
  * @return The cumulative distances for the paced property. The length will be
  *   the same as aValues.
  */
 static nsTArray<double>
 GetCumulativeDistances(const nsTArray<ComputedKeyframeValues>& aValues,
-                       nsCSSPropertyID aPacedProperty)
+                       nsCSSPropertyID aPacedProperty,
+                       nsStyleContext* aStyleContext)
 {
   // a) If aPacedProperty is a shorthand property, get its components.
   //    Otherwise, just add the longhand property into the set.
   size_t pacedPropertyCount = 0;
   nsCSSPropertyIDSet pacedPropertySet;
   bool isShorthand = nsCSSProps::IsShorthand(aPacedProperty);
   if (isShorthand) {
     CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPacedProperty,
@@ -1629,29 +1634,31 @@ GetCumulativeDistances(const nsTArray<Co
           MOZ_ASSERT(pacedValues[propIdx].mProperty == prop,
                      "Property mismatch");
 
           double componentDistance = 0.0;
           if (StyleAnimationValue::ComputeDistance(
                 prop,
                 prevPacedValues[propIdx].mValue,
                 pacedValues[propIdx].mValue,
+                aStyleContext,
                 componentDistance)) {
             dist += componentDistance * componentDistance;
           }
         }
         dist = sqrt(dist);
       } else {
         // If the property is longhand, we just use the 1st value.
         // If ComputeDistance() fails, |dist| will remain zero so there will be
         // no distance between the previous paced value and this value.
         Unused <<
           StyleAnimationValue::ComputeDistance(aPacedProperty,
                                                prevPacedValues[0].mValue,
                                                pacedValues[0].mValue,
+                                               aStyleContext,
                                                dist);
       }
       cumulativeDistances[i] = cumulativeDistances[preIdx] + dist;
     }
     prevPacedValues.SwapElements(pacedValues);
     preIdx = i;
   }
   return cumulativeDistances;
--- a/dom/animation/KeyframeUtils.h
+++ b/dom/animation/KeyframeUtils.h
@@ -93,21 +93,24 @@ public:
    * @param aSpacingMode The spacing mode to apply.
    * @param aProperty The paced property. Only used when |aSpacingMode| is
    *   SpacingMode::paced. In all other cases it is ignored and hence may be
    *   any value, e.g. eCSSProperty_UNKNOWN.
    * @param aComputedValues The set of computed keyframe values as returned by
    *   GetComputedKeyframeValues. Only used when |aSpacingMode| is
    *   SpacingMode::paced. In all other cases this parameter is unused and may
    *   be any value including an empty array.
+   * @param aStyleContext The style context used for calculating paced spacing
+   *                      on transform.
    */
   static void ApplySpacing(nsTArray<Keyframe>& aKeyframes,
                            SpacingMode aSpacingMode,
                            nsCSSPropertyID aProperty,
-                           nsTArray<ComputedKeyframeValues>& aComputedValues);
+                           nsTArray<ComputedKeyframeValues>& aComputedValues,
+                           nsStyleContext* aStyleContext);
 
   /**
    * Wrapper for ApplySpacing to simplify using distribute spacing.
    *
    * @param aKeyframes The set of keyframes to adjust.
    */
   static void ApplyDistributeSpacing(nsTArray<Keyframe>& aKeyframes);
 
--- a/dom/animation/test/mochitest.ini
+++ b/dom/animation/test/mochitest.ini
@@ -39,16 +39,17 @@ support-files =
   mozilla/file_cubic_bezier_limits.html
   mozilla/file_deferred_start.html
   mozilla/file_disabled_properties.html
   mozilla/file_disable_animations_api_core.html
   mozilla/file_document-timeline-origin-time-range.html
   mozilla/file_hide_and_show.html
   mozilla/file_partial_keyframes.html
   mozilla/file_spacing_property_order.html
+  mozilla/file_spacing_transform.html
   mozilla/file_transform_limits.html
   mozilla/file_underlying-discrete-value.html
   mozilla/file_set-easing.html
   style/file_animation-seeking-with-current-time.html
   style/file_animation-seeking-with-start-time.html
   style/file_animation-setting-effect.html
   style/file_animation-setting-spacing.html
   testcommon.js
@@ -95,14 +96,15 @@ skip-if = buildapp == 'mulet'
 skip-if = (toolkit == 'gonk' && debug)
 [mozilla/test_disable_animations_api_core.html]
 [mozilla/test_disabled_properties.html]
 [mozilla/test_document-timeline-origin-time-range.html]
 [mozilla/test_hide_and_show.html]
 [mozilla/test_partial_keyframes.html]
 [mozilla/test_set-easing.html]
 [mozilla/test_spacing_property_order.html]
+[mozilla/test_spacing_transform.html]
 [mozilla/test_transform_limits.html]
 [mozilla/test_underlying-discrete-value.html]
 [style/test_animation-seeking-with-current-time.html]
 [style/test_animation-seeking-with-start-time.html]
 [style/test_animation-setting-effect.html]
 [style/test_animation-setting-spacing.html]
new file mode 100644
--- /dev/null
+++ b/dom/animation/test/mozilla/file_spacing_transform.html
@@ -0,0 +1,240 @@
+<!doctype html>
+<meta charset=utf-8>
+<script src="../testcommon.js"></script>
+<body>
+<script>
+'use strict';
+
+const pi  = Math.PI;
+const cos = Math.cos;
+const sin = Math.sin;
+const tan = Math.tan;
+const sqrt = Math.sqrt;
+
+// Help function for testing the computed offsets by the distance array.
+function assert_animation_offsets(anim, dist) {
+  const epsilon = 0.00000001;
+  const frames = anim.effect.getKeyframes();
+  const cumDist = dist.reduce( (prev, curr) => {
+    prev.push(prev.length == 0 ? curr : curr + prev[prev.length - 1]);
+    return prev;
+  }, []);
+
+  const total = cumDist[cumDist.length - 1];
+  for (var i = 0; i < frames.length; ++i) {
+    assert_approx_equals(frames[i].computedOffset, cumDist[i] / total,
+                         epsilon, 'computedOffset of frame ' + i);
+  }
+}
+
+function getAngleDist(rotate1, rotate2) {
+  function quaternion(axis, angle) {
+    var x = axis[0] * sin(angle/2.0);
+    var y = axis[1] * sin(angle/2.0);
+    var z = axis[2] * sin(angle/2.0);
+    var w = cos(angle/2.0);
+    return { 'x': x, 'y': y, 'z': z, 'w': w };
+  }
+  var q1 = quaternion(rotate1.axis, rotate1.angle);
+  var q2 = quaternion(rotate2.axis, rotate2.angle);
+  var dotProduct = q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
+  return 2.0 * Math.acos(dotProduct);
+}
+
+function createMatrix(elements, Is3D) {
+  return (Is3D ? "matrix3d" : "matrix") + "(" + elements.join() + ")";
+}
+
+test(function(t) {
+  var anim = addDiv(t).animate([ { transform: "none" },
+                                 { transform: "translate(-20px)" },
+                                 { transform: "translate(100px)" },
+                                 { transform: "translate(50px)"} ],
+                               { spacing: "paced(transform)" });
+  assert_animation_offsets(anim, [ 0, 20, 120, 50 ]);
+}, 'Test spacing on translate' );
+
+test(function(t) {
+  var anim =
+    addDiv(t).animate([ { transform: "none" },
+                        { transform: "translate3d(-20px, 10px, 100px)" },
+                        { transform: "translate3d(100px, 200px, 50px)" },
+                        { transform: "translate(50px, -10px)"} ],
+                      { spacing: "paced(transform)" });
+  var dist = [ 0,
+               Math.sqrt(20 * 20 + 10 * 10 + 100 * 100),
+               Math.sqrt(120 * 120 + 190 * 190 + 50 * 50),
+               Math.sqrt(50 * 50 + 210 * 210 + 50 * 50) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on translate3d' );
+
+test(function(t) {
+  var anim = addDiv(t).animate([ { transform: "scale(0.5)" },
+                                 { transform: "scale(4.5)" },
+                                 { transform: "scale(2.5)" },
+                                 { transform: "none"} ],
+                               { spacing: "paced(transform)" });
+  assert_animation_offsets(anim, [ 0, 4.0, 2.0, 1.5 ]);
+}, 'Test spacing on scale' );
+
+test(function(t) {
+  var anim = addDiv(t).animate([ { transform: "scale(0.5, 0.5)" },
+                                 { transform: "scale3d(4.5, 5.0, 2.5)" },
+                                 { transform: "scale3d(2.5, 1.0, 2.0)" },
+                                 { transform: "scale3d(1, 0.5, 1.0)"} ],
+                               { spacing:"paced(transform)" });
+  var dist = [ 0,
+               Math.sqrt(4.0 * 4.0 + 4.5 * 4.5 + 1.5 * 1.5),
+               Math.sqrt(2.0 * 2.0 + 4.0 * 4.0 + 0.5 * 0.5),
+               Math.sqrt(1.5 * 1.5 + 0.5 * 0.5 + 1.0 * 1.0) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on scale3d' );
+
+test(function(t) {
+  var anim = addDiv(t).animate([ { transform: "rotate(60deg)" },
+                                 { transform: "none" },
+                                 { transform: "rotate(720deg)" },
+                                 { transform: "rotate(-360deg)"} ],
+                               { spacing: "paced(transform)" });
+  assert_animation_offsets(anim, [ 0, 60, 720, 1080 ]);
+}, 'Test spacing on rotate' );
+
+test(function(t) {
+  var anim = addDiv(t).animate([ { transform: "rotate3d(1,0,0,60deg)" },
+                                 { transform: "rotate3d(1,0,0,70deg)" },
+                                 { transform: "rotate3d(0,0,1,-110deg)" },
+                                 { transform: "rotate3d(1,0,0,219deg)"} ],
+                               { spacing: "paced(transform)" });
+  var dist = [ 0,
+               getAngleDist({ axis: [1,0,0], angle: 60 * pi / 180 },
+                            { axis: [1,0,0], angle: 70 * pi / 180 }),
+               getAngleDist({ axis: [0,1,0], angle: 70 * pi / 180 },
+                            { axis: [0,0,1], angle: -110 * pi / 180 }),
+               getAngleDist({ axis: [0,0,1], angle: -110 * pi / 180 },
+                            { axis: [1,0,0], angle: 219 * pi / 180 }) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on rotate3d' );
+
+test(function(t) {
+  var anim = addDiv(t).animate([ { transform: "skew(60deg)" },
+                                 { transform: "none" },
+                                 { transform: "skew(-90deg)" },
+                                 { transform: "skew(90deg)"} ],
+                               { spacing: "paced(transform)" });
+  assert_animation_offsets(anim, [ 0, 60, 90, 180 ]);
+}, 'Test spacing on skew' );
+
+test(function(t) {
+  var anim = addDiv(t).animate([ { transform: "skew(60deg, 30deg)" },
+                                 { transform: "none" },
+                                 { transform: "skew(-90deg, 60deg)" },
+                                 { transform: "skew(90deg, 60deg)"} ],
+                               { spacing: "paced(transform)" });
+  var dist = [ 0,
+               sqrt(60 * 60 + 30 * 30),
+               sqrt(90 * 90 + 60 * 60),
+               sqrt(180 * 180 + 0) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on skew along both X and Y' );
+
+test(function(t) {
+  // We calculate the distance of two perspective functions by converting them
+  // into two matrix3ds, and then do matrix decomposition to get two
+  // perspective vectors, so the equivalent perspective vectors are:
+  // perspective 1: (0, 0, -1/128, 1);
+  // perspective 2: (0, 0, -1/infinity = 0, 1);
+  // perspective 3: (0, 0, -1/1024, 1);
+  // perspective 4: (0, 0, -1/32, 1);
+  var anim = addDiv(t).animate([ { transform: "perspective(128px)" },
+                                 { transform: "none" },
+                                 { transform: "perspective(1024px)" },
+                                 { transform: "perspective(32px)"} ],
+                               { spacing: "paced(transform)" });
+  assert_animation_offsets(anim,
+                           [ 0, 1/128, 1/1024, 1/32 - 1/1024 ]);
+}, 'Test spacing on perspective' );
+
+test(function(t) {
+  var anim =
+    addDiv(t).animate([ { transform: "none" },
+                        { transform: "rotate(180deg) translate(0px)" },
+                        { transform: "rotate(180deg) translate(1000px)" },
+                        { transform: "rotate(360deg) translate(1000px)"} ],
+                      { spacing: "paced(transform)" });
+  var dist = [ 0,
+               sqrt(pi * pi + 0),
+               sqrt(1000 * 1000),
+               sqrt(pi * pi + 0) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on matched transform lists' );
+
+test(function(t) {
+  // matrix1 => translate(100px, 50px), skewX(60deg).
+  // matrix2 => translate(1000px), rotate(180deg).
+  // matrix3 => translate(1000px), scale(1.5, 0.7).
+  const matrix1 = createMatrix([ 1, 0, tan(pi/4.0), 1, 100, 50 ]);
+  const matrix2 = createMatrix([ cos(pi), sin(pi),
+                                -sin(pi), cos(pi),
+                                 1000, 0 ]);
+  const matrix3 = createMatrix([ 1.5, 0, 0, 0.7, 1000, 0 ]);
+  var anim = addDiv(t).animate([ { transform: "none" },
+                                 { transform: matrix1 },
+                                 { transform: matrix2 },
+                                 { transform: matrix3 } ],
+                               { spacing: "paced(transform)" });
+  var dist = [ 0,
+               sqrt(100 * 100 + 50 * 50 + pi/4 * pi/4),
+               sqrt(900 * 900 + 50 * 50 + pi * pi + pi/4 * pi/4),
+               sqrt(pi * pi + 0.5 * 0.5 + 0.3 * 0.3) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on matrix' );
+
+test(function(t) {
+  // matrix1 => translate3d(100px, 50px, -10px), skew(60deg).
+  // matrix2 => translate3d(1000px, 0, 0), rotate3d(1, 0, 0, 180deg).
+  // matrix3 => translate3d(1000px, 0, 0), scale3d(1.5, 0.7, 2.2).
+  const matrix1 = createMatrix([ 1, 0, 0, 0,
+                                 tan(pi/4.0), 1, 0, 0,
+                                 0, 0, 1, 0,
+                                 100, 50, -10, 1 ], true);
+  const matrix2 = createMatrix([ 1, 0, 0, 0,
+                                 0, cos(pi), sin(pi), 0,
+                                 0, -sin(pi), cos(pi), 0,
+                                 1000, 0, 0, 1 ], true);
+  const matrix3 = createMatrix([ 1.5, 0, 0, 0,
+                                 0, 0.7, 0, 0,
+                                 0, 0, 2.2, 0,
+                                 1000, 0, 0, 1 ], true);
+  var anim = addDiv(t).animate([ { transform: "none" },
+                                 { transform: matrix1 },
+                                 { transform: matrix2 },
+                                 { transform: matrix3 } ],
+                               { spacing: "paced(transform)" });
+  var dist = [ 0,
+               sqrt(100 * 100 + 50 * 50 + 10 * 10 + pi/4 * pi/4),
+               sqrt(900 * 900 + 50 * 50 + 10 * 10 + pi/4 * pi/4 + pi * pi),
+               sqrt(0.5 * 0.5 + 0.3 * 0.3 + 1.2 * 1.2 + pi * pi) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on matrix3d' );
+
+test(function(t) {
+  var anim =
+    addDiv(t).animate([ { transform: "none" },
+                        { transform: "translate(100px, 50px) skew(45deg)" },
+                        { transform: "translate(1000px) " +
+                                     "rotate3d(1, 0, 0, 180deg)" },
+                        { transform: "translate(1000px) " +
+                                     "scale3d(2.5, 0.5, 0.7)" } ],
+                      { spacing: "paced(transform)" });
+
+  var dist = [ 0,
+               sqrt(100 * 100 + 50 * 50 + pi/4 * pi/4),
+               sqrt(900 * 900 + 50 * 50 + pi/4 * pi/4 + pi * pi),
+               sqrt(1.5 * 1.5 + 0.5 * 0.5 + 0.3 * 0.3 + pi * pi) ];
+  assert_animation_offsets(anim, dist);
+}, 'Test spacing on mismatched transform list' );
+
+done();
+
+</script>
+</body>
new file mode 100644
--- /dev/null
+++ b/dom/animation/test/mozilla/test_spacing_transform.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<meta charset=utf-8>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+'use strict';
+setup({explicit_done: true});
+SpecialPowers.pushPrefEnv(
+  { "set": [["dom.animations-api.core.enabled", true]]},
+  function() {
+    window.open("file_spacing_transform.html");
+  });
+</script>
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -48,16 +48,17 @@
 #include "mozilla/dom/StorageManager.h"
 #include "mozilla/dom/TCPSocket.h"
 #include "mozilla/dom/Telephony.h"
 #include "mozilla/dom/VRDisplay.h"
 #include "mozilla/dom/workers/RuntimeService.h"
 #include "mozilla/Hal.h"
 #include "nsISiteSpecificUserAgent.h"
 #include "mozilla/ClearOnShutdown.h"
+#include "mozilla/SSE.h"
 #include "mozilla/StaticPtr.h"
 #include "Connection.h"
 #include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
 #include "nsGlobalWindow.h"
 #ifdef MOZ_B2G_RIL
 #include "mozilla/dom/MobileConnectionArray.h"
 #endif
 #include "nsIIdleObserver.h"
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -2698,23 +2698,29 @@ nsDOMWindowUtils::ComputeAnimationDistan
     property = eCSSProperty_UNKNOWN;
   }
 
   MOZ_ASSERT(property == eCSSProperty_UNKNOWN ||
              !nsCSSProps::IsShorthand(property),
              "should not have shorthand");
 
   StyleAnimationValue v1, v2;
+  Element* element = content->AsElement();
   if (property == eCSSProperty_UNKNOWN ||
-      !ComputeAnimationValue(property, content->AsElement(), aValue1, v1) ||
-      !ComputeAnimationValue(property, content->AsElement(), aValue2, v2)) {
+      !ComputeAnimationValue(property, element, aValue1, v1) ||
+      !ComputeAnimationValue(property, element, aValue2, v2)) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
 
-  if (!StyleAnimationValue::ComputeDistance(property, v1, v2, *aResult)) {
+  nsIPresShell* shell = element->GetUncomposedDoc()->GetShell();
+  RefPtr<nsStyleContext> styleContext = shell
+    ? nsComputedDOMStyle::GetStyleContextForElement(element, nullptr, shell)
+    : nullptr;
+  if (!StyleAnimationValue::ComputeDistance(property, v1, v2, styleContext,
+                                            *aResult)) {
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsDOMWindowUtils::RenderDocument(const nsRect& aRect,
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4391,19 +4391,16 @@ void HTMLMediaElement::DecodeError(const
   nsAutoString src;
   GetCurrentSrc(src);
   const char16_t* params[] = { src.get() };
   ReportLoadError("MediaLoadDecodeError", params, ArrayLength(params));
 
   if (mDecoder) {
     ShutdownDecoder();
   }
-  RemoveMediaElementFromURITable();
-  mLoadingSrc = nullptr;
-  mMediaSource = nullptr;
   AudioTracks()->EmptyTracks();
   VideoTracks()->EmptyTracks();
   if (mIsLoadingFromSourceChildren) {
     mError = nullptr;
     if (mSourceLoadCandidate) {
       DispatchAsyncSourceError(mSourceLoadCandidate);
       QueueLoadFromSourceTask();
     } else {
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -26,19 +26,22 @@
 namespace mozilla {
 
 namespace {
 
 LazyLogModule gCubebLog("cubeb");
 
 void CubebLogCallback(const char* aFmt, ...)
 {
+  char buffer[256];
+
   va_list arglist;
   va_start(arglist, aFmt);
-  MOZ_LOG(gCubebLog, LogLevel::Verbose, (aFmt, arglist));
+  VsprintfLiteral (buffer, aFmt, arglist);
+  MOZ_LOG(gCubebLog, LogLevel::Verbose, ("%s", buffer));
   va_end(arglist);
 }
 
 // This mutex protects the variables below.
 StaticMutex sMutex;
 enum class CubebState {
   Uninitialized = 0,
   Initialized,
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -992,34 +992,37 @@ MediaDecoder::FirstFrameLoaded(nsAutoPtr
 
   DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s mIsDormant=%d",
               aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
               aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr(), mIsDormant);
 
   mInfo = aInfo.forget();
 
   Invalidate();
-  if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
-    mOwner->FirstFrameLoaded();
-  }
 
   // This can run cache callbacks.
   mResource->EnsureCacheUpToDate();
 
   // The element can run javascript via events
   // before reaching here, so only change the
   // state if we're still set to the original
   // loading state.
   if (mPlayState == PLAY_STATE_LOADING && !mIsDormant) {
     ChangeState(mNextState);
   }
 
   // Run NotifySuspendedStatusChanged now to give us a chance to notice
   // that autoplay should run.
   NotifySuspendedStatusChanged();
+
+  // mOwner->FirstFrameLoaded() might call us back. Put it at the bottom of
+  // this function to avoid unexpected shutdown from reentrant calls.
+  if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) {
+    mOwner->FirstFrameLoaded();
+  }
 }
 
 void
 MediaDecoder::NetworkError()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!IsShutdown());
   mOwner->NetworkError();
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -224,50 +224,40 @@ public:
 protected:
   using Master = MediaDecoderStateMachine;
   explicit StateObject(Master* aPtr) : mMaster(aPtr) {}
   TaskQueue* OwnerThread() const { return mMaster->mTaskQueue; }
   MediaResource* Resource() const { return mMaster->mResource; }
   MediaDecoderReaderWrapper* Reader() const { return mMaster->mReader; }
   const MediaInfo& Info() const { return mMaster->Info(); }
 
-public:
-  // TODO: this function is public because VisibilityChanged() calls it.
-  // We should handle visibility changes in state objects so this function
-  // can be made protected again.
-  //
   // Note this function will delete the current state object.
   // Don't access members to avoid UAF after this call.
   template <class S, typename... Ts>
-  auto SetState(Ts&&... aArgs)
-    -> decltype(DeclVal<S>().Enter(Forward<Ts>(aArgs)...))
+  auto SetState(Ts... aArgs)
+    -> decltype(DeclVal<S>().Enter(Move(aArgs)...))
   {
     // keep mMaster in a local object because mMaster will become invalid after
     // the current state object is deleted.
     auto master = mMaster;
 
     auto s = new S(master);
 
     MOZ_ASSERT(master->mState != s->GetState() ||
                master->mState == DECODER_STATE_SEEKING);
 
     SLOG("change state to: %s", ToStateStr(s->GetState()));
 
     Exit();
 
-    // Note |aArgs| might reference data members of |this|. We need to keep
-    // |this| alive until |s->Enter()| returns.
-    UniquePtr<StateObject> deathGrip(master->mStateObj.release());
-
     master->mState = s->GetState();
     master->mStateObj.reset(s);
-    return s->Enter(Forward<Ts>(aArgs)...);
+    return s->Enter(Move(aArgs)...);
   }
 
-protected:
   // Take a raw pointer in order not to change the life cycle of MDSM.
   // It is guaranteed to be valid by MDSM.
   Master* mMaster;
 };
 
 /**
  * Purpose: decode metadata like duration and dimensions of the media resource.
  *
@@ -983,16 +973,19 @@ private:
 class MediaDecoderStateMachine::CompletedState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit CompletedState(Master* aPtr) : StateObject(aPtr) {}
 
   void Enter()
   {
+    // We've decoded all samples. We don't need decoders anymore.
+    Reader()->ReleaseResources();
+
     mMaster->ScheduleStateMachine();
   }
 
   void Exit() override
   {
     mSentPlaybackEndedEvent = false;
   }
 
@@ -1286,31 +1279,29 @@ WaitForCDMState::HandleDormant(bool aDor
 }
 
 bool
 MediaDecoderStateMachine::
 DormantState::HandleDormant(bool aDormant)
 {
   if (!aDormant) {
     MOZ_ASSERT(!Info().IsEncrypted() || mMaster->mCDMProxy);
-    SeekJob seekJob = Move(mPendingSeek);
-    SetState<DecodingFirstFrameState>(Move(seekJob));
+    SetState<DecodingFirstFrameState>(Move(mPendingSeek));
   }
   return true;
 }
 
 bool
 MediaDecoderStateMachine::
 WaitForCDMState::HandleCDMProxyReady()
 {
-  SeekJob seekJob = Move(mPendingSeek);
   if (mPendingDormant) {
-    SetState<DormantState>(Move(seekJob));
+    SetState<DormantState>(Move(mPendingSeek));
   } else {
-    SetState<DecodingFirstFrameState>(Move(seekJob));
+    SetState<DecodingFirstFrameState>(Move(mPendingSeek));
   }
   return true;
 }
 
 void
 MediaDecoderStateMachine::
 DecodingFirstFrameState::Enter(SeekJob aPendingSeek)
 {
@@ -1361,18 +1352,17 @@ DecodingFirstFrameState::HandleSeek(Seek
   return SetState<SeekingState>(Move(seekJob));
 }
 
 bool
 MediaDecoderStateMachine::
 DecodingFirstFrameState::HandleDormant(bool aDormant)
 {
   if (aDormant) {
-    SeekJob seekJob = Move(mPendingSeek);
-    SetState<DormantState>(Move(seekJob));
+    SetState<DormantState>(Move(mPendingSeek));
   }
   return true;
 }
 
 void
 MediaDecoderStateMachine::
 DecodingFirstFrameState::MaybeFinishDecodeFirstFrame()
 {
@@ -1381,18 +1371,17 @@ DecodingFirstFrameState::MaybeFinishDeco
   if ((mMaster->IsAudioDecoding() && mMaster->AudioQueue().GetSize() == 0) ||
       (mMaster->IsVideoDecoding() && mMaster->VideoQueue().GetSize() == 0)) {
     return;
   }
 
   mMaster->FinishDecodeFirstFrame();
 
   if (mPendingSeek.Exists()) {
-    SeekJob seekJob = Move(mPendingSeek);
-    SetState<SeekingState>(Move(seekJob));
+    SetState<SeekingState>(Move(mPendingSeek));
   } else {
     SetState<DecodingState>();
   }
 }
 
 void
 MediaDecoderStateMachine::
 DecodingState::Enter()
@@ -1492,18 +1481,17 @@ SeekingState::HandleDormant(bool aDorman
   // Because both audio and video decoders are going to be reset in this
   // method later, we treat a VideoOnly seek task as a normal Accurate
   // seek task so that while it is resumed, both audio and video playback
   // are handled.
   if (mSeekJob.mTarget.IsVideoOnly()) {
     mSeekJob.mTarget.SetType(SeekTarget::Accurate);
     mSeekJob.mTarget.SetVideoOnly(false);
   }
-  SeekJob seekJob = Move(mSeekJob);
-  SetState<DormantState>(Move(seekJob));
+  SetState<DormantState>(Move(mSeekJob));
   return true;
 }
 
 RefPtr<MediaDecoder::SeekPromise>
 MediaDecoderStateMachine::
 SeekingState::HandleSeek(SeekTarget aTarget)
 {
   SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
--- a/dom/media/webaudio/AudioEventTimeline.cpp
+++ b/dom/media/webaudio/AudioEventTimeline.cpp
@@ -15,30 +15,42 @@ static float LinearInterpolate(double t0
 
 static float ExponentialInterpolate(double t0, float v0, double t1, float v1, double t)
 {
   return v0 * powf(v1 / v0, (t - t0) / (t1 - t0));
 }
 
 static float ExponentialApproach(double t0, double v0, float v1, double timeConstant, double t)
 {
-  return v1 + (v0 - v1) * expf(-(t - t0) / timeConstant);
+  if (!mozilla::dom::WebAudioUtils::FuzzyEqual(timeConstant, 0.0)) {
+    return v1 + (v0 - v1) * expf(-(t - t0) / timeConstant);
+  } else {
+    return v1;
+  }
 }
 
 static float ExtractValueFromCurve(double startTime, float* aCurve, uint32_t aCurveLength, double duration, double t)
 {
   if (t >= startTime + duration) {
     // After the duration, return the last curve value
     return aCurve[aCurveLength - 1];
   }
   double ratio = std::max((t - startTime) / duration, 0.0);
   if (ratio >= 1.0) {
     return aCurve[aCurveLength - 1];
   }
-  return aCurve[uint32_t(aCurveLength * ratio)];
+  uint32_t current = uint32_t(aCurveLength * ratio);
+  uint32_t next = current + 1;
+  if (next < aCurveLength) {
+    double t0 = double(current) / double(aCurveLength) * duration ;
+    double t1 = double(next) / double(aCurveLength) * duration ;
+    return LinearInterpolate(t0, aCurve[current], t1, aCurve[next], t - startTime);
+  } else {
+    return aCurve[current];
+  }
 }
 
 namespace mozilla {
 namespace dom {
 
 template <class ErrorResult> bool
 AudioEventTimeline::ValidateEvent(AudioTimelineEvent& aEvent,
                                   ErrorResult& aRv)
@@ -64,22 +76,16 @@ AudioEventTimeline::ValidateEvent(AudioT
     for (uint32_t i = 0; i < aEvent.mCurveLength; ++i) {
       if (!IsValid(aEvent.mCurve[i])) {
         aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
         return false;
       }
     }
   }
 
-  if (aEvent.mType == AudioTimelineEvent::SetTarget &&
-      WebAudioUtils::FuzzyEqual(aEvent.mTimeConstant, 0.0)) {
-    aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
-    return false;
-  }
-
   bool timeAndValueValid = IsValid(aEvent.mValue) &&
                            IsValid(aEvent.mDuration);
   if (!timeAndValueValid) {
     aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     return false;
   }
 
   // Make sure that non-curve events don't fall within the duration of a
--- a/dom/media/webaudio/compiledtest/TestAudioEventTimeline.cpp
+++ b/dom/media/webaudio/compiledtest/TestAudioEventTimeline.cpp
@@ -398,17 +398,17 @@ void TestExponentialRampAtSameTime()
 
 void TestSetTargetZeroTimeConstant()
 {
   Timeline timeline(10.0f);
 
   ErrorResultMock rv;
 
   timeline.SetTargetAtTime(20.0f, 1.0, 0.0, rv);
-  is(rv, NS_ERROR_DOM_SYNTAX_ERR, "Correct error code returned");
+  is(timeline.GetValueAtTime(1.0), 20.0f, "Should get the correct value when t0 == t1");
 }
 
 void TestExponentialInvalidPreviousZeroValue()
 {
   Timeline timeline(0.f);
 
   ErrorResultMock rv;
 
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -61,16 +61,17 @@ tags=capturestream
 [test_AudioParamDevtoolsAPI.html]
 [test_audioParamExponentialRamp.html]
 [test_audioParamGain.html]
 [test_audioParamLinearRamp.html]
 [test_audioParamSetCurveAtTime.html]
 [test_audioParamSetCurveAtTimeTwice.html]
 [test_audioParamSetCurveAtTimeZeroDuration.html]
 [test_audioParamSetTargetAtTime.html]
+[test_audioParamSetTargetAtTimeZeroTimeConstant.html]
 [test_audioParamSetValueAtTime.html]
 [test_audioParamTimelineDestinationOffset.html]
 [test_badConnect.html]
 [test_biquadFilterNode.html]
 [test_biquadFilterNodePassThrough.html]
 [test_biquadFilterNodeWithGain.html]
 [test_bug808374.html]
 [test_bug827541.html]
--- a/dom/media/webaudio/test/test_audioParamSetCurveAtTime.html
+++ b/dom/media/webaudio/test/test_audioParamSetCurveAtTime.html
@@ -11,42 +11,40 @@
 <script class="testbody" type="text/javascript">
 
 var T0 = 0;
 
 var gTest = {
   length: 2048,
   numberOfChannels: 1,
   createGraph: function(context) {
-    var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
-    for (var i = 0; i < 2048; ++i) {
-      sourceBuffer.getChannelData(0)[i] = 1;
-    }
-
-    var source = context.createBufferSource();
-    source.buffer = sourceBuffer;
+    var source = context.createConstantSource();
 
     var gain = context.createGain();
     gain.gain.setValueCurveAtTime(this.curve, T0, this.duration);
-
     source.connect(gain);
 
     source.start(0);
     return gain;
   },
   createExpectedBuffers: function(context) {
     this.duration = 1024 / context.sampleRate;
-    this.curve = new Float32Array(100);
-    for (var i = 0; i < 100; ++i) {
-      this.curve[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
-    }
+    this.curve = new Float32Array([1.0, 0.5, 0.75, 0.25]);
     var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
+    var data = expectedBuffer.getChannelData(0);
     for (var i = 0; i < 2048; ++i) {
-      var t = i / context.sampleRate;
-      expectedBuffer.getChannelData(0)[i] = this.curve[Math.min(99, Math.floor(100 * Math.min(1.0, (t - T0) / this.duration)))];
+      if (i < 256) {
+        data[i] = 1.0 - 0.5*i/256;
+      } else if (i < 512) {
+        data[i] = 0.5 + 0.25*(i - 256)/256;
+      } else if (i < 768) {
+        data[i] = 0.75 - 0.5*(i - 512)/256;
+      } else {
+        data[i] = 0.25;
+      }
     }
     return expectedBuffer;
   },
 };
 
 runTest();
 
 </script>
--- a/dom/media/webaudio/test/test_audioParamSetCurveAtTimeTwice.html
+++ b/dom/media/webaudio/test/test_audioParamSetCurveAtTimeTwice.html
@@ -1,59 +1,67 @@
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Test AudioParam.linearRampToValue</title>
+  <title>Test AudioParam.setValueCurveAtTime twice</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="webaudio.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
+
+function linearInterpolate(t0, v0, t1, v1, t)
+{
+  return v0 + (v1 - v0) * ((t - t0) / (t1 - t0));
+}
+
 var T0 = 0;
 
 var gTest = {
   length: 2048,
   numberOfChannels: 1,
   createGraph: function(context) {
-    var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
-    for (var i = 0; i < 2048; ++i) {
-      sourceBuffer.getChannelData(0)[i] = 1;
-    }
-
     var curve2 = new Float32Array(100);
     for (var i = 0; i < 100; ++i) {
       curve2[i] = Math.sin(220 * 6 * Math.PI * i / context.sampleRate);
     }
 
-    var source = context.createBufferSource();
-    source.buffer = sourceBuffer;
+    var source = context.createConstantSource();
 
     var gain = context.createGain();
     gain.gain.setValueCurveAtTime(curve2, T0, this.duration/2);
-    //Set a diffrent curve from the first one
+    //Set a different curve from the first one
     gain.gain.setValueCurveAtTime(this.curve, T0, this.duration);
 
     source.connect(gain);
 
     source.start(0);
     return gain;
   },
   createExpectedBuffers: function(context) {
     this.duration = 1024 / context.sampleRate;
     this.curve = new Float32Array(100);
     for (var i = 0; i < 100; ++i) {
       this.curve[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
     }
     var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
     for (var i = 0; i < 2048; ++i) {
       var t = i / context.sampleRate;
-      expectedBuffer.getChannelData(0)[i] = this.curve[Math.min(99, Math.floor(100 * Math.min(1.0, (t - T0) / this.duration)))];
+      var current = Math.min(99, Math.floor(100 * Math.min(1.0, (t - T0) / this.duration)));
+      var next = current + 1;
+      if (next < this.curve.length) {
+        var t0 = current / this.curve.length * this.duration;
+        var t1 = next / this.curve.length * this.duration;
+        expectedBuffer.getChannelData(0)[i] = linearInterpolate(t0, this.curve[current], t1, this.curve[next], t);
+      } else {
+        expectedBuffer.getChannelData(0)[i] = this.curve[current];
+      }
     }
     return expectedBuffer;
   },
 };
 
 runTest();
 
 </script>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_audioParamSetTargetAtTimeZeroTimeConstant.html
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test AudioParam.setTargetAtTime with zero time constant</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="webaudio.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+var V0 = 0.9;
+var V1 = 0.1;
+var T0 = 0;
+var TimeConstant = 0;
+
+var gTest = {
+  length: 2048,
+  numberOfChannels: 1,
+  createGraph: function(context) {
+    var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
+    for (var i = 0; i < 2048; ++i) {
+      sourceBuffer.getChannelData(0)[i] = 1;
+    }
+
+    var source = context.createBufferSource();
+    source.buffer = sourceBuffer;
+
+    var gain = context.createGain();
+    gain.gain.value = V0;
+    gain.gain.setTargetAtTime(V1, T0, TimeConstant);
+
+    source.connect(gain);
+
+    source.start(0);
+    return gain;
+  },
+  createExpectedBuffers: function(context) {
+    var T1 = 2048 / context.sampleRate;
+    var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
+    for (var i = 0; i < 2048; ++i) {
+      var t = i / context.sampleRate;
+      expectedBuffer.getChannelData(0)[i] = V1;
+    }
+    return expectedBuffer;
+  },
+};
+
+runTest();
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -273,16 +273,17 @@ nsSMILCSSValueType::ComputeDistance(cons
     &fromWrapper->mCSSValue : nullptr;
   const StyleAnimationValue* toCSSValue = &toWrapper->mCSSValue;
   if (!FinalizeStyleAnimationValues(fromCSSValue, toCSSValue)) {
     return NS_ERROR_FAILURE;
   }
 
   return StyleAnimationValue::ComputeDistance(toWrapper->mPropID,
                                               *fromCSSValue, *toCSSValue,
+                                              nullptr,
                                               aDistance) ?
     NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult
 nsSMILCSSValueType::Interpolate(const nsSMILValue& aStartVal,
                                 const nsSMILValue& aEndVal,
                                 double aUnitDistance,
--- a/dom/webidl/RTCConfiguration.webidl
+++ b/dom/webidl/RTCConfiguration.webidl
@@ -16,17 +16,16 @@ dictionary RTCIceServer {
     (DOMString or sequence<DOMString>) urls;
     DOMString  url; //deprecated
     DOMString username;
     DOMString credential;
     RTCIceCredentialType credentialType = "password";
 };
 
 enum RTCIceTransportPolicy {
-    "none",
     "relay",
     "all"
 };
 
 enum RTCBundlePolicy {
     "balanced",
     "max-compat",
     "max-bundle"
--- a/editor/libeditor/ChangeStyleTransaction.cpp
+++ b/editor/libeditor/ChangeStyleTransaction.cpp
@@ -145,108 +145,101 @@ ChangeStyleTransaction::DoTransaction()
  
   nsAutoString propertyNameString;
   mProperty->ToString(propertyNameString);
 
   mUndoAttributeWasSet = mElement->HasAttr(kNameSpaceID_None,
                                            nsGkAtoms::style);
 
   nsAutoString values;
-  nsresult result = cssDecl->GetPropertyValue(propertyNameString, values);
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = cssDecl->GetPropertyValue(propertyNameString, values);
+  NS_ENSURE_SUCCESS(rv, rv);
   mUndoValue.Assign(values);
 
   // Does this property accept more than one value? (bug 62682)
   bool multiple = AcceptsMoreThanOneValue(*mProperty);
 
   if (mRemoveProperty) {
     nsAutoString returnString;
     if (multiple) {
       // Let's remove only the value we have to remove and not the others
 
       // The two lines below are a workaround because
       // nsDOMCSSDeclaration::GetPropertyCSSValue is not yet implemented (bug
       // 62682)
       RemoveValueFromListOfValues(values, NS_LITERAL_STRING("none"));
       RemoveValueFromListOfValues(values, mValue);
       if (values.IsEmpty()) {
-        result = cssDecl->RemoveProperty(propertyNameString, returnString);
-        NS_ENSURE_SUCCESS(result, result);
+        rv = cssDecl->RemoveProperty(propertyNameString, returnString);
+        NS_ENSURE_SUCCESS(rv, rv);
       } else {
         nsAutoString priority;
         cssDecl->GetPropertyPriority(propertyNameString, priority);
-        result = cssDecl->SetProperty(propertyNameString, values,
-                                      priority);
-        NS_ENSURE_SUCCESS(result, result);
+        rv = cssDecl->SetProperty(propertyNameString, values, priority);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
     } else {
-      result = cssDecl->RemoveProperty(propertyNameString, returnString);
-      NS_ENSURE_SUCCESS(result, result);
+      rv = cssDecl->RemoveProperty(propertyNameString, returnString);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
   } else {
     nsAutoString priority;
     cssDecl->GetPropertyPriority(propertyNameString, priority);
     if (multiple) {
       // Let's add the value we have to add to the others
 
       // The line below is a workaround because
       // nsDOMCSSDeclaration::GetPropertyCSSValue is not yet implemented (bug
       // 62682)
       AddValueToMultivalueProperty(values, mValue);
     } else {
       values.Assign(mValue);
     }
-    result = cssDecl->SetProperty(propertyNameString, values,
-                                  priority);
-    NS_ENSURE_SUCCESS(result, result);
+    rv = cssDecl->SetProperty(propertyNameString, values, priority);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Let's be sure we don't keep an empty style attribute
   uint32_t length;
-  result = cssDecl->GetLength(&length);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = cssDecl->GetLength(&length);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!length) {
-    result = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
-    NS_ENSURE_SUCCESS(result, result);
+    rv = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
+    NS_ENSURE_SUCCESS(rv, rv);
   } else {
     mRedoAttributeWasSet = true;
   }
 
   return cssDecl->GetPropertyValue(propertyNameString, mRedoValue);
 }
 
 nsresult
 ChangeStyleTransaction::SetStyle(bool aAttributeWasSet,
                                  nsAString& aValue)
 {
-  nsresult result = NS_OK;
   if (aAttributeWasSet) {
     // The style attribute was not empty, let's recreate the declaration
     nsAutoString propertyNameString;
     mProperty->ToString(propertyNameString);
 
     nsCOMPtr<nsStyledElement> inlineStyles = do_QueryInterface(mElement);
     NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
     nsCOMPtr<nsICSSDeclaration> cssDecl = inlineStyles->Style();
 
     if (aValue.IsEmpty()) {
       // An empty value means we have to remove the property
       nsAutoString returnString;
-      result = cssDecl->RemoveProperty(propertyNameString, returnString);
-    } else {
-      // Let's recreate the declaration as it was
-      nsAutoString priority;
-      cssDecl->GetPropertyPriority(propertyNameString, priority);
-      result = cssDecl->SetProperty(propertyNameString, aValue, priority);
+      return cssDecl->RemoveProperty(propertyNameString, returnString);
     }
-  } else {
-    result = mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
+    // Let's recreate the declaration as it was
+    nsAutoString priority;
+    cssDecl->GetPropertyPriority(propertyNameString, priority);
+    return cssDecl->SetProperty(propertyNameString, aValue, priority);
   }
-
-  return result;
+  return mElement->UnsetAttr(kNameSpaceID_None, nsGkAtoms::style, true);
 }
 
 NS_IMETHODIMP
 ChangeStyleTransaction::UndoTransaction()
 {
   return SetStyle(mUndoAttributeWasSet, mUndoValue);
 }
 
--- a/editor/libeditor/EditAggregateTransaction.cpp
+++ b/editor/libeditor/EditAggregateTransaction.cpp
@@ -28,63 +28,63 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(EditA
 NS_IMPL_ADDREF_INHERITED(EditAggregateTransaction, EditTransactionBase)
 NS_IMPL_RELEASE_INHERITED(EditAggregateTransaction, EditTransactionBase)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditAggregateTransaction)
 NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
 
 NS_IMETHODIMP
 EditAggregateTransaction::DoTransaction()
 {
-  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
+  // FYI: It's legal (but not very useful) to have an empty child list.
   for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
     nsITransaction *txn = mChildren[i];
     if (!txn) {
       return NS_ERROR_NULL_POINTER;
     }
-    result = txn->DoTransaction();
-    if (NS_FAILED(result)) {
-      break;
+    nsresult rv = txn->DoTransaction();
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditAggregateTransaction::UndoTransaction()
 {
-  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
-  // undo goes through children backwards
+  // FYI: It's legal (but not very useful) to have an empty child list.
+  // Undo goes through children backwards.
   for (uint32_t i = mChildren.Length(); i--; ) {
     nsITransaction *txn = mChildren[i];
     if (!txn) {
       return NS_ERROR_NULL_POINTER;
     }
-    result = txn->UndoTransaction();
-    if (NS_FAILED(result)) {
-      break;
+    nsresult rv = txn->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditAggregateTransaction::RedoTransaction()
 {
-  nsresult result=NS_OK;  // it's legal (but not very useful) to have an empty child list
+  // It's legal (but not very useful) to have an empty child list.
   for (uint32_t i = 0, length = mChildren.Length(); i < length; ++i) {
     nsITransaction *txn = mChildren[i];
     if (!txn) {
       return NS_ERROR_NULL_POINTER;
     }
-    result = txn->RedoTransaction();
-    if (NS_FAILED(result)) {
-      break;
+    nsresult rv = txn->RedoTransaction();
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 EditAggregateTransaction::Merge(nsITransaction* aTransaction,
                                 bool* aDidMerge)
 {
   if (aDidMerge) {
     *aDidMerge = false;
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1446,24 +1446,24 @@ EditorBase::SplitNode(nsIContent& aNode,
     CreateTxnForSplitNode(aNode, aOffset);
   aResult = DoTransaction(transaction);
 
   nsCOMPtr<nsIContent> newNode = aResult.Failed() ? nullptr
                                                   : transaction->GetNewNode();
 
   mRangeUpdater.SelAdjSplitNode(aNode, aOffset, newNode);
 
-  nsresult result = aResult.StealNSResult();
+  nsresult rv = aResult.StealNSResult();
   for (auto& listener : mActionListeners) {
     listener->DidSplitNode(aNode.AsDOMNode(), aOffset, GetAsDOMNode(newNode),
-                           result);
+                           rv);
   }
   // Note: result might be a success code, so we can't use Throw() to
   // set it on aResult.
-  aResult = result;
+  aResult = rv;
 
   return newNode;
 }
 
 NS_IMETHODIMP
 EditorBase::JoinNodes(nsIDOMNode* aLeftNode,
                       nsIDOMNode* aRightNode,
                       nsIDOMNode*)
@@ -1490,32 +1490,32 @@ EditorBase::JoinNodes(nsINode& aLeftNode
   // Find the number of children of the lefthand node
   uint32_t oldLeftNodeLen = aLeftNode.Length();
 
   for (auto& listener : mActionListeners) {
     listener->WillJoinNodes(aLeftNode.AsDOMNode(), aRightNode.AsDOMNode(),
                             parent->AsDOMNode());
   }
 
-  nsresult result = NS_OK;
+  nsresult rv = NS_OK;
   RefPtr<JoinNodeTransaction> transaction =
     CreateTxnForJoinNode(aLeftNode, aRightNode);
   if (transaction)  {
-    result = DoTransaction(transaction);
+    rv = DoTransaction(transaction);
   }
 
   mRangeUpdater.SelAdjJoinNodes(aLeftNode, aRightNode, *parent, offset,
                                 (int32_t)oldLeftNodeLen);
 
   for (auto& listener : mActionListeners) {
     listener->DidJoinNodes(aLeftNode.AsDOMNode(), aRightNode.AsDOMNode(),
-                           parent->AsDOMNode(), result);
-  }
-
-  return result;
+                           parent->AsDOMNode(), rv);
+  }
+
+  return rv;
 }
 
 NS_IMETHODIMP
 EditorBase::DeleteNode(nsIDOMNode* aNode)
 {
   nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
   NS_ENSURE_STATE(node);
   return DeleteNode(node);
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -253,26 +253,26 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
                  nsISelectionController* aSelCon,
                  uint32_t aFlags,
                  const nsAString& aInitialValue)
 {
   NS_PRECONDITION(aDoc && !aSelCon, "bad arg");
   NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
   MOZ_ASSERT(aInitialValue.IsEmpty(), "Non-empty initial values not supported");
 
-  nsresult result = NS_OK, rulesRes = NS_OK;
+  nsresult rulesRv = NS_OK;
 
   {
     // block to scope AutoEditInitRulesTrigger
-    AutoEditInitRulesTrigger rulesTrigger(this, rulesRes);
+    AutoEditInitRulesTrigger rulesTrigger(this, rulesRv);
 
     // Init the plaintext editor
-    result = TextEditor::Init(aDoc, aRoot, nullptr, aFlags, aInitialValue);
-    if (NS_FAILED(result)) {
-      return result;
+    nsresult rv = TextEditor::Init(aDoc, aRoot, nullptr, aFlags, aInitialValue);
+    if (NS_FAILED(rv)) {
+      return rv;
     }
 
     // Init mutation observer
     nsCOMPtr<nsINode> document = do_QueryInterface(aDoc);
     document->AddMutationObserverUnlessExists(this);
 
     // disable Composer-only features
     if (IsMailEditor()) {
@@ -312,19 +312,19 @@ HTMLEditor::Init(nsIDOMDocument* aDoc,
         selection->AddSelectionListener(listener);
       }
       listener = do_QueryInterface(mSelectionListenerP);
       if (listener) {
         selection->AddSelectionListener(listener);
       }
     }
   }
-
-  NS_ENSURE_SUCCESS(rulesRes, rulesRes);
-  return result;
+  NS_ENSURE_SUCCESS(rulesRv, rulesRv);
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLEditor::PreDestroy(bool aDestroyingFrames)
 {
   if (mDidPreDestroy) {
     return NS_OK;
   }
@@ -1548,18 +1548,18 @@ HTMLEditor::InsertElementAtSelection(nsI
         // E.g., inserting an image.  In this case we don't need to delete any
         // inline wrappers before we do the insertion.  Otherwise we let
         // DeleteSelectionAndPrepareToCreateNode do the deletion for us, which
         // calls DeleteSelection with aStripWrappers = eStrip.
         rv = DeleteSelection(nsIEditor::eNone, nsIEditor::eNoStrip);
         NS_ENSURE_SUCCESS(rv, rv);
       }
 
-      nsresult result = DeleteSelectionAndPrepareToCreateNode();
-      NS_ENSURE_SUCCESS(result, result);
+      nsresult rv = DeleteSelectionAndPrepareToCreateNode();
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     // If deleting, selection will be collapsed.
     // so if not, we collapse it
     if (!aDeleteSelection) {
       // Named Anchor is a special case,
       // We collapse to insert element BEFORE the selection
       // For all other tags, we insert AFTER the selection
@@ -3632,17 +3632,16 @@ HTMLEditor::IsTextPropertySetByContent(n
 void
 HTMLEditor::IsTextPropertySetByContent(nsIDOMNode* aNode,
                                        nsIAtom* aProperty,
                                        const nsAString* aAttribute,
                                        const nsAString* aValue,
                                        bool& aIsSet,
                                        nsAString* outValue)
 {
-  nsresult result;
   aIsSet = false;  // must be initialized to false for code below to work
   nsAutoString propName;
   aProperty->ToString(propName);
   nsCOMPtr<nsIDOMNode>node = aNode;
 
   while (node) {
     nsCOMPtr<nsIDOMElement>element;
     element = do_QueryInterface(node);
@@ -3675,18 +3674,17 @@ HTMLEditor::IsTextPropertySetByContent(n
         }
         if (found) {
           aIsSet = true;
           break;
         }
       }
     }
     nsCOMPtr<nsIDOMNode>temp;
-    result = node->GetParentNode(getter_AddRefs(temp));
-    if (NS_SUCCEEDED(result) && temp) {
+    if (NS_SUCCEEDED(node->GetParentNode(getter_AddRefs(temp))) && temp) {
       node = temp;
     } else {
       node = nullptr;
     }
   }
 }
 
 bool
@@ -3755,20 +3753,20 @@ HTMLEditor::CollapseAdjacentTextNodes(ns
   AutoTransactionsConserveSelection dontSpazMySelection(this);
   nsTArray<nsCOMPtr<nsIDOMNode> > textNodes;
   // we can't actually do anything during iteration, so store the text nodes in an array
   // don't bother ref counting them because we know we can hold them for the
   // lifetime of this method
 
 
   // build a list of editable text nodes
-  nsresult result;
+  nsresult rv = NS_ERROR_UNEXPECTED;
   nsCOMPtr<nsIContentIterator> iter =
-    do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &result);
-  NS_ENSURE_SUCCESS(result, result);
+    do_CreateInstance("@mozilla.org/content/subtree-content-iterator;1", &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   iter->Init(aInRange);
 
   while (!iter->IsDone()) {
     nsINode* node = iter->GetCurrentNode();
     if (node->NodeType() == nsIDOMNode::TEXT_NODE &&
         IsEditable(static_cast<nsIContent*>(node))) {
       nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(node);
@@ -3783,32 +3781,31 @@ HTMLEditor::CollapseAdjacentTextNodes(ns
   while (textNodes.Length() > 1) {
     // we assume a textNodes entry can't be nullptr
     nsIDOMNode *leftTextNode = textNodes[0];
     nsIDOMNode *rightTextNode = textNodes[1];
     NS_ASSERTION(leftTextNode && rightTextNode,"left or rightTextNode null in CollapseAdjacentTextNodes");
 
     // get the prev sibling of the right node, and see if its leftTextNode
     nsCOMPtr<nsIDOMNode> prevSibOfRightNode;
-    result =
-      rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode));
-    NS_ENSURE_SUCCESS(result, result);
+    rv = rightTextNode->GetPreviousSibling(getter_AddRefs(prevSibOfRightNode));
+    NS_ENSURE_SUCCESS(rv, rv);
     if (prevSibOfRightNode && prevSibOfRightNode == leftTextNode) {
       nsCOMPtr<nsIDOMNode> parent;
-      result = rightTextNode->GetParentNode(getter_AddRefs(parent));
-      NS_ENSURE_SUCCESS(result, result);
+      rv = rightTextNode->GetParentNode(getter_AddRefs(parent));
+      NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
-      result = JoinNodes(leftTextNode, rightTextNode, parent);
-      NS_ENSURE_SUCCESS(result, result);
+      rv = JoinNodes(leftTextNode, rightTextNode, parent);
+      NS_ENSURE_SUCCESS(rv, rv);
     }
 
     textNodes.RemoveElementAt(0); // remove the leftmost text node from the list
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 HTMLEditor::SetSelectionAtDocumentStart(Selection* aSelection)
 {
   dom::Element* rootElement = GetRoot();
   NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
 
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -341,18 +341,18 @@ RangeUpdater::SelAdjSplitNode(nsIContent
   if (!count) {
     return NS_OK;
   }
 
   nsCOMPtr<nsINode> parent = aOldRightNode.GetParentNode();
   int32_t offset = parent ? parent->IndexOf(&aOldRightNode) : -1;
 
   // first part is same as inserting aNewLeftnode
-  nsresult result = SelAdjInsertNode(parent, offset - 1);
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = SelAdjInsertNode(parent, offset - 1);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // next step is to check for range enpoints inside aOldRightNode
   for (size_t i = 0; i < count; i++) {
     RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == &aOldRightNode) {
       if (item->startOffset > aOffset) {
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -560,110 +560,108 @@ TextEditor::InsertBR(nsCOMPtr<nsIDOMNode
   selection->SetInterlinePosition(true);
   return selection->Collapse(selNode, selOffset+1);
 }
 
 nsresult
 TextEditor::ExtendSelectionForDelete(Selection* aSelection,
                                      nsIEditor::EDirection* aAction)
 {
-  nsresult result = NS_OK;
-
   bool bCollapsed = aSelection->Collapsed();
 
   if (*aAction == eNextWord ||
       *aAction == ePreviousWord ||
       (*aAction == eNext && bCollapsed) ||
       (*aAction == ePrevious && bCollapsed) ||
       *aAction == eToBeginningOfLine ||
       *aAction == eToEndOfLine) {
     nsCOMPtr<nsISelectionController> selCont;
     GetSelectionController(getter_AddRefs(selCont));
     NS_ENSURE_TRUE(selCont, NS_ERROR_NO_INTERFACE);
 
+    nsresult rv;
     switch (*aAction) {
       case eNextWord:
-        result = selCont->WordExtendForDelete(true);
+        rv = selCont->WordExtendForDelete(true);
         // DeleteSelectionImpl doesn't handle these actions
         // because it's inside batching, so don't confuse it:
         *aAction = eNone;
         break;
       case ePreviousWord:
-        result = selCont->WordExtendForDelete(false);
+        rv = selCont->WordExtendForDelete(false);
         *aAction = eNone;
         break;
       case eNext:
-        result = selCont->CharacterExtendForDelete();
+        rv = selCont->CharacterExtendForDelete();
         // Don't set aAction to eNone (see Bug 502259)
         break;
       case ePrevious: {
         // Only extend the selection where the selection is after a UTF-16
         // surrogate pair or a variation selector.
         // For other cases we don't want to do that, in order
         // to make sure that pressing backspace will only delete the last
         // typed character.
         nsCOMPtr<nsIDOMNode> node;
         int32_t offset;
-        result = GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
-        NS_ENSURE_SUCCESS(result, result);
+        rv = GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
+        NS_ENSURE_SUCCESS(rv, rv);
         NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
 
         // node might be anonymous DIV, so we find better text node
         FindBetterInsertionPoint(node, offset);
 
         if (IsTextNode(node)) {
           nsCOMPtr<nsIDOMCharacterData> charData = do_QueryInterface(node);
           if (charData) {
             nsAutoString data;
-            result = charData->GetData(data);
-            NS_ENSURE_SUCCESS(result, result);
+            rv = charData->GetData(data);
+            NS_ENSURE_SUCCESS(rv, rv);
 
             if ((offset > 1 &&
                  NS_IS_LOW_SURROGATE(data[offset - 1]) &&
                  NS_IS_HIGH_SURROGATE(data[offset - 2])) ||
                 (offset > 0 &&
                  gfxFontUtils::IsVarSelector(data[offset - 1]))) {
-              result = selCont->CharacterExtendForBackspace();
+              rv = selCont->CharacterExtendForBackspace();
             }
           }
         }
         break;
       }
       case eToBeginningOfLine:
         selCont->IntraLineMove(true, false);          // try to move to end
-        result = selCont->IntraLineMove(false, true); // select to beginning
+        rv = selCont->IntraLineMove(false, true); // select to beginning
         *aAction = eNone;
         break;
       case eToEndOfLine:
-        result = selCont->IntraLineMove(true, true);
+        rv = selCont->IntraLineMove(true, true);
         *aAction = eNext;
         break;
       default:       // avoid several compiler warnings
-        result = NS_OK;
+        rv = NS_OK;
         break;
     }
+    return rv;
   }
-  return result;
+  return NS_OK;
 }
 
 nsresult
 TextEditor::DeleteSelection(EDirection aAction,
                             EStripWrappers aStripWrappers)
 {
   MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
 
   if (!mRules) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
-  nsresult result;
-
   // delete placeholder txns merge.
   AutoPlaceHolderBatch batch(this, nsGkAtoms::DeleteTxnName);
   AutoRules beginRulesSniffing(this, EditAction::deleteSelection, aAction);
 
   // pre-process
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
 
@@ -671,38 +669,37 @@ TextEditor::DeleteSelection(EDirection a
   //  platforms that use "caret-style" caret positioning collapse the
   //  selection to the  start and then create a new selection.
   //  Platforms that use "selection-style" caret positioning just delete the
   //  existing selection without extending it.
   if (!selection->Collapsed() &&
       (aAction == eNextWord || aAction == ePreviousWord ||
        aAction == eToBeginningOfLine || aAction == eToEndOfLine)) {
     if (mCaretStyle == 1) {
-      result = selection->CollapseToStart();
-      NS_ENSURE_SUCCESS(result, result);
+      nsresult rv = selection->CollapseToStart();
+      NS_ENSURE_SUCCESS(rv, rv);
     } else {
       aAction = eNone;
     }
   }
 
   TextRulesInfo ruleInfo(EditAction::deleteSelection);
   ruleInfo.collapsedAction = aAction;
   ruleInfo.stripWrappers = aStripWrappers;
   bool cancel, handled;
-  result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  NS_ENSURE_SUCCESS(rv, rv);
   if (!cancel && !handled) {
-    result = DeleteSelectionImpl(aAction, aStripWrappers);
+    rv = DeleteSelectionImpl(aAction, aStripWrappers);
   }
   if (!cancel) {
     // post-process
-    result = rules->DidDoAction(selection, &ruleInfo, result);
+    rv = rules->DidDoAction(selection, &ruleInfo, rv);
   }
-
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 TextEditor::InsertText(const nsAString& aStringToInsert)
 {
   if (!mRules) {
     return NS_ERROR_NOT_INITIALIZED;
   }
@@ -1086,25 +1083,25 @@ TextEditor::Undo(uint32_t aCount)
 
   NotifyEditorObservers(eNotifyEditorObserversOfBefore);
 
   AutoRules beginRulesSniffing(this, EditAction::undo, nsIEditor::eNone);
 
   TextRulesInfo ruleInfo(EditAction::undo);
   RefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
-  nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
 
-  if (!cancel && NS_SUCCEEDED(result)) {
-    result = EditorBase::Undo(aCount);
-    result = rules->DidDoAction(selection, &ruleInfo, result);
+  if (!cancel && NS_SUCCEEDED(rv)) {
+    rv = EditorBase::Undo(aCount);
+    rv = rules->DidDoAction(selection, &ruleInfo, rv);
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 TextEditor::Redo(uint32_t aCount)
 {
   // Protect the edit rules object from dying
   nsCOMPtr<nsIEditRules> rules(mRules);
 
@@ -1114,25 +1111,25 @@ TextEditor::Redo(uint32_t aCount)
 
   NotifyEditorObservers(eNotifyEditorObserversOfBefore);
 
   AutoRules beginRulesSniffing(this, EditAction::redo, nsIEditor::eNone);
 
   TextRulesInfo ruleInfo(EditAction::redo);
   RefPtr<Selection> selection = GetSelection();
   bool cancel, handled;
-  nsresult result = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
+  nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
 
-  if (!cancel && NS_SUCCEEDED(result)) {
-    result = EditorBase::Redo(aCount);
-    result = rules->DidDoAction(selection, &ruleInfo, result);
+  if (!cancel && NS_SUCCEEDED(rv)) {
+    rv = EditorBase::Redo(aCount);
+    rv = rules->DidDoAction(selection, &ruleInfo, rv);
   }
 
   NotifyEditorObservers(eNotifyEditorObserversOfEnd);
-  return result;
+  return rv;
 }
 
 bool
 TextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed)
 {
   RefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return false;
--- a/editor/libeditor/TextEditorTest.cpp
+++ b/editor/libeditor/TextEditorTest.cpp
@@ -43,120 +43,122 @@ void TextEditorTest::Run(nsIEditor *aEdi
   if (!aEditor) return;
   mTextEditor = do_QueryInterface(aEditor);
   mEditor = do_QueryInterface(aEditor);
   RunUnitTest(outNumTests, outNumTestsFailed);
 }
 
 nsresult TextEditorTest::RunUnitTest(int32_t *outNumTests, int32_t *outNumTestsFailed)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER);
 
   *outNumTests = 0;
   *outNumTestsFailed = 0;
 
-  result = InitDoc();
-  TEST_RESULT(result);
+  nsresult rv = InitDoc();
+  TEST_RESULT(rv);
   // shouldn't we just bail on error here?
 
   // insert some simple text
-  result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890"));
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
   // insert some more text
-  result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states.  I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham.  Injustice anywhere is a threat to justice everywhere"));
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states.  I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham.  Injustice anywhere is a threat to justice everywhere"));
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
-  result = TestInsertBreak();
-  TEST_RESULT(result);
+  rv = TestInsertBreak();
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
-  result = TestTextProperties();
-  TEST_RESULT(result);
+  rv = TestTextProperties();
+  TEST_RESULT(rv);
   (*outNumTests)++;
-  if (NS_FAILED(result))
+  if (NS_FAILED(rv)) {
     ++(*outNumTestsFailed);
+  }
 
   // get us back to the original document
-  result = mEditor->Undo(12);
-  TEST_RESULT(result);
+  rv = mEditor->Undo(12);
+  TEST_RESULT(rv);
 
-  return result;
+  return rv;
 }
 
 nsresult TextEditorTest::InitDoc()
 {
-  nsresult result = mEditor->SelectAll();
-  TEST_RESULT(result);
-  result = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
-  TEST_RESULT(result);
-  return result;
+  nsresult rv = mEditor->SelectAll();
+  TEST_RESULT(rv);
+  rv = mEditor->DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip);
+  TEST_RESULT(rv);
+  return rv;
 }
 
 nsresult TextEditorTest::TestInsertBreak()
 {
   nsCOMPtr<nsISelection>selection;
-  nsresult result = mEditor->GetSelection(getter_AddRefs(selection));
-  TEST_RESULT(result);
+  nsresult rv = mEditor->GetSelection(getter_AddRefs(selection));
+  TEST_RESULT(rv);
   TEST_POINTER(selection.get());
   nsCOMPtr<nsIDOMNode>anchor;
-  result = selection->GetAnchorNode(getter_AddRefs(anchor));
-  TEST_RESULT(result);
+  rv = selection->GetAnchorNode(getter_AddRefs(anchor));
+  TEST_RESULT(rv);
   TEST_POINTER(anchor.get());
   selection->Collapse(anchor, 0);
   // insert one break
   printf("inserting a break\n");
-  result = mTextEditor->InsertLineBreak();
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertLineBreak();
+  TEST_RESULT(rv);
   mEditor->DebugDumpContent();
 
   // insert a second break adjacent to the first
   printf("inserting a second break\n");
-  result = mTextEditor->InsertLineBreak();
-  TEST_RESULT(result);
+  rv = mTextEditor->InsertLineBreak();
+  TEST_RESULT(rv);
   mEditor->DebugDumpContent();
 
-  return result;
+  return rv;
 }
 
 nsresult TextEditorTest::TestTextProperties()
 {
   nsCOMPtr<nsIDOMDocument>doc;
-  nsresult result = mEditor->GetDocument(getter_AddRefs(doc));
-  TEST_RESULT(result);
+  nsresult rv = mEditor->GetDocument(getter_AddRefs(doc));
+  TEST_RESULT(rv);
   TEST_POINTER(doc.get());
   nsCOMPtr<nsIDOMNodeList>nodeList;
   // XXX This is broken, text nodes are not elements.
   nsAutoString textTag(NS_LITERAL_STRING("#text"));
-  result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
-  TEST_RESULT(result);
+  rv = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
+  TEST_RESULT(rv);
   TEST_POINTER(nodeList.get());
   uint32_t count;
   nodeList->GetLength(&count);
   NS_ASSERTION(0!=count, "there are no text nodes in the document!");
   nsCOMPtr<nsIDOMNode>textNode;
-  result = nodeList->Item(count-1, getter_AddRefs(textNode));
-  TEST_RESULT(result);
+  rv = nodeList->Item(count - 1, getter_AddRefs(textNode));
+  TEST_RESULT(rv);
   TEST_POINTER(textNode.get());
 
   // set the whole text node to bold
   printf("set the whole first text node to bold\n");
   nsCOMPtr<nsISelection>selection;
-  result = mEditor->GetSelection(getter_AddRefs(selection));
-  TEST_RESULT(result);
+  rv = mEditor->GetSelection(getter_AddRefs(selection));
+  TEST_RESULT(rv);
   TEST_POINTER(selection.get());
   nsCOMPtr<nsIDOMCharacterData>textData;
   textData = do_QueryInterface(textNode);
   uint32_t length;
   textData->GetLength(&length);
   selection->Collapse(textNode, 0);
   selection->Extend(textNode, length);
 
@@ -164,98 +166,94 @@ nsresult TextEditorTest::TestTextPropert
   NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE);
 
   bool any = false;
   bool all = false;
   bool first=false;
 
   const nsAFlatString& empty = EmptyString();
 
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(false==first, "first should be false");
   NS_ASSERTION(false==any, "any should be false");
   NS_ASSERTION(false==all, "all should be false");
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
   // remove the bold we just set
   printf("set the whole first text node to not bold\n");
-  result = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->RemoveInlineProperty(nsGkAtoms::b, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(false==first, "first should be false");
   NS_ASSERTION(false==any, "any should be false");
   NS_ASSERTION(false==all, "all should be false");
   mEditor->DebugDumpContent();
 
   // set all but the first and last character to bold
   printf("set the first text node (1, length-1) to bold and italic, and (2, length-1) to underline.\n");
   selection->Collapse(textNode, 1);
   selection->Extend(textNode, length-1);
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::b, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
   // make all that same text italic
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::i, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::i, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::b, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
   // make all the text underlined, except for the first 2 and last 2 characters
-  result = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
-  TEST_RESULT(result);
+  rv = doc->GetElementsByTagName(textTag, getter_AddRefs(nodeList));
+  TEST_RESULT(rv);
   TEST_POINTER(nodeList.get());
   nodeList->GetLength(&count);
   NS_ASSERTION(0!=count, "there are no text nodes in the document!");
-  result = nodeList->Item(count-2, getter_AddRefs(textNode));
-  TEST_RESULT(result);
+  rv = nodeList->Item(count-2, getter_AddRefs(textNode));
+  TEST_RESULT(rv);
   TEST_POINTER(textNode.get());
   textData = do_QueryInterface(textNode);
   textData->GetLength(&length);
   NS_ASSERTION(length==915, "wrong text node");
   selection->Collapse(textNode, 1);
   selection->Extend(textNode, length-2);
-  result = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty);
-  TEST_RESULT(result);
-  result = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first,
-                                         &any, &all);
-  TEST_RESULT(result);
+  rv = htmlEditor->SetInlineProperty(nsGkAtoms::u, empty, empty);
+  TEST_RESULT(rv);
+  rv = htmlEditor->GetInlineProperty(nsGkAtoms::u, empty, empty, &first,
+                                     &any, &all);
+  TEST_RESULT(rv);
   NS_ASSERTION(true==first, "first should be true");
   NS_ASSERTION(true==any, "any should be true");
   NS_ASSERTION(true==all, "all should be true");
   mEditor->DebugDumpContent();
 
-  return result;
+  return rv;
 }
 
-
-
 #endif
-
-
--- a/editor/libeditor/TypeInState.cpp
+++ b/editor/libeditor/TypeInState.cpp
@@ -88,21 +88,21 @@ TypeInState::NotifySelectionChanged(nsID
 
   if (aSelection) {
     int32_t rangeCount = selection->RangeCount();
 
     if (selection->Collapsed() && rangeCount) {
       nsCOMPtr<nsIDOMNode> selNode;
       int32_t selOffset = 0;
 
-      nsresult result =
+      nsresult rv =
         EditorBase::GetStartNodeAndOffset(selection, getter_AddRefs(selNode),
                                           &selOffset);
 
-      NS_ENSURE_SUCCESS(result, result);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       if (selNode &&
           selNode == mLastSelectionContainer &&
           selOffset == mLastSelectionOffset) {
         // We got a bogus selection changed notification!
         return NS_OK;
       }
 
--- a/editor/txmgr/nsTransactionItem.cpp
+++ b/editor/txmgr/nsTransactionItem.cpp
@@ -91,240 +91,247 @@ nsTransactionItem::GetIsBatch(bool *aIsB
   *aIsBatch = !mTransaction;
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetNumberOfChildren(int32_t *aNumChildren)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aNumChildren, NS_ERROR_NULL_POINTER);
 
   *aNumChildren = 0;
 
   int32_t ui = 0;
   int32_t ri = 0;
 
-  result = GetNumberOfUndoItems(&ui);
+  nsresult rv = GetNumberOfUndoItems(&ui);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  result = GetNumberOfRedoItems(&ri);
+  rv = GetNumberOfRedoItems(&ri);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   *aNumChildren = ui + ri;
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::GetChild(int32_t aIndex, nsTransactionItem **aChild)
 {
   NS_ENSURE_TRUE(aChild, NS_ERROR_NULL_POINTER);
 
   *aChild = 0;
 
   int32_t numItems = 0;
-  nsresult result = GetNumberOfChildren(&numItems);
+  nsresult rv = GetNumberOfChildren(&numItems);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
-  NS_ENSURE_SUCCESS(result, result);
-
-  if (aIndex < 0 || aIndex >= numItems)
+  if (aIndex < 0 || aIndex >= numItems) {
     return NS_ERROR_FAILURE;
+  }
 
   // Children are expected to be in the order they were added,
   // so the child first added would be at the bottom of the undo
   // stack, or if there are no items on the undo stack, it would
   // be at the top of the redo stack.
 
-  result = GetNumberOfUndoItems(&numItems);
+  rv = GetNumberOfUndoItems(&numItems);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (numItems > 0 && aIndex < numItems) {
     NS_ENSURE_TRUE(mUndoStack, NS_ERROR_FAILURE);
 
     RefPtr<nsTransactionItem> child = mUndoStack->GetItem(aIndex);
     child.forget(aChild);
     return *aChild ? NS_OK : NS_ERROR_FAILURE;
   }
 
   // Adjust the index for the redo stack:
 
   aIndex -=  numItems;
 
-  result = GetNumberOfRedoItems(&numItems);
+  rv = GetNumberOfRedoItems(&numItems);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ENSURE_TRUE(mRedoStack && numItems != 0 && aIndex < numItems, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> child = mRedoStack->GetItem(aIndex);
   child.forget(aChild);
   return *aChild ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult
 nsTransactionItem::DoTransaction()
 {
-  if (mTransaction)
+  if (mTransaction) {
     return mTransaction->DoTransaction();
+  }
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::UndoTransaction(nsTransactionManager *aTxMgr)
 {
-  nsresult result = UndoChildren(aTxMgr);
+  nsresult rv = UndoChildren(aTxMgr);
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     RecoverFromUndoError(aTxMgr);
-    return result;
+    return rv;
   }
 
-  if (!mTransaction)
+  if (!mTransaction) {
     return NS_OK;
+  }
 
-  result = mTransaction->UndoTransaction();
+  rv = mTransaction->UndoTransaction();
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     RecoverFromUndoError(aTxMgr);
-    return result;
+    return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::UndoChildren(nsTransactionManager *aTxMgr)
 {
   RefPtr<nsTransactionItem> item;
-  nsresult result = NS_OK;
   int32_t sz = 0;
 
   if (mUndoStack) {
     if (!mRedoStack && mUndoStack) {
       mRedoStack = new nsTransactionStack(nsTransactionStack::FOR_REDO);
     }
 
     /* Undo all of the transaction items children! */
     sz = mUndoStack->GetSize();
 
+    nsresult rv = NS_OK;
     while (sz-- > 0) {
       item = mUndoStack->Peek();
 
       if (!item) {
         return NS_ERROR_FAILURE;
       }
 
       nsCOMPtr<nsITransaction> t = item->GetTransaction();
 
       bool doInterrupt = false;
 
-      result = aTxMgr->WillUndoNotify(t, &doInterrupt);
+      rv = aTxMgr->WillUndoNotify(t, &doInterrupt);
 
-      if (NS_FAILED(result)) {
-        return result;
+      if (NS_FAILED(rv)) {
+        return rv;
       }
 
       if (doInterrupt) {
         return NS_OK;
       }
 
-      result = item->UndoTransaction(aTxMgr);
+      rv = item->UndoTransaction(aTxMgr);
 
-      if (NS_SUCCEEDED(result)) {
+      if (NS_SUCCEEDED(rv)) {
         item = mUndoStack->Pop();
         mRedoStack->Push(item.forget());
       }
 
-      nsresult result2 = aTxMgr->DidUndoNotify(t, result);
+      nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
 
-      if (NS_SUCCEEDED(result)) {
-        result = result2;
+      if (NS_SUCCEEDED(rv)) {
+        rv = rv2;
       }
     }
+    // XXX NS_OK if there is no Undo items or all methods work fine, otherwise,
+    //     the result of the last item's UndoTransaction() or
+    //     DidUndoNotify() if UndoTransaction() succeeded.
+    return rv;
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionItem::RedoTransaction(nsTransactionManager *aTxMgr)
 {
-  nsresult result;
-
   nsCOMPtr<nsITransaction> transaction(mTransaction);
   if (transaction) {
-    result = transaction->RedoTransaction();
+    nsresult rv = transaction->RedoTransaction();
 
-    NS_ENSURE_SUCCESS(result, result);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  result = RedoChildren(aTxMgr);
+  nsresult rv = RedoChildren(aTxMgr);
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     RecoverFromRedoError(aTxMgr);
-    return result;
+    return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionItem::RedoChildren(nsTransactionManager *aTxMgr)
 {
   RefPtr<nsTransactionItem> item;
-  nsresult result = NS_OK;
 
-  if (!mRedoStack)
+  if (!mRedoStack) {
     return NS_OK;
+  }
 
   /* Redo all of the transaction items children! */
   int32_t sz = mRedoStack->GetSize();
 
+  nsresult rv = NS_OK;
   while (sz-- > 0) {
     item = mRedoStack->Peek();
 
     if (!item) {
       return NS_ERROR_FAILURE;
     }
 
     nsCOMPtr<nsITransaction> t = item->GetTransaction();
 
     bool doInterrupt = false;
 
-    result = aTxMgr->WillRedoNotify(t, &doInterrupt);
+    rv = aTxMgr->WillRedoNotify(t, &doInterrupt);
 
-    if (NS_FAILED(result)) {
-      return result;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
 
     if (doInterrupt) {
       return NS_OK;
     }
 
-    result = item->RedoTransaction(aTxMgr);
+    rv = item->RedoTransaction(aTxMgr);
 
-    if (NS_SUCCEEDED(result)) {
+    if (NS_SUCCEEDED(rv)) {
       item = mRedoStack->Pop();
       mUndoStack->Push(item.forget());
     }
 
-    nsresult result2 = aTxMgr->DidUndoNotify(t, result);
+    // XXX Shouldn't this DidRedoNotify()? (bug 1311626)
+    nsresult rv2 = aTxMgr->DidUndoNotify(t, rv);
 
-    if (NS_SUCCEEDED(result)) {
-      result = result2;
+    if (NS_SUCCEEDED(rv)) {
+      rv = rv2;
     }
   }
-
-  return result;
+  // XXX NS_OK if there is no Redo items or all methods work fine, otherwise,
+  //     the result of the last item's RedoTransaction() or
+  //     DidUndoNotify() if UndoTransaction() succeeded.
+  return rv;
 }
 
 nsresult
 nsTransactionItem::GetNumberOfUndoItems(int32_t *aNumItems)
 {
   NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
 
   if (!mUndoStack) {
@@ -366,22 +373,21 @@ nsTransactionItem::RecoverFromRedoError(
 {
   //
   // If this method gets called, we already successfully called
   // RedoTransaction() for the transaction item itself. Undo all
   // the children that successfully called RedoTransaction(),
   // then undo the transaction item itself.
   //
 
-  nsresult result;
+  nsresult rv = UndoChildren(aTxMgr);
 
-  result = UndoChildren(aTxMgr);
-
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
-  if (!mTransaction)
+  if (!mTransaction) {
     return NS_OK;
+  }
 
   return mTransaction->UndoTransaction();
 }
 
--- a/editor/txmgr/nsTransactionList.cpp
+++ b/editor/txmgr/nsTransactionList.cpp
@@ -44,46 +44,43 @@ NS_IMETHODIMP nsTransactionList::GetNumI
   NS_ENSURE_TRUE(aNumItems, NS_ERROR_NULL_POINTER);
 
   *aNumItems = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     *aNumItems = mTxnStack->GetSize();
-  else if (mTxnItem)
-    result = mTxnItem->GetNumberOfChildren(aNumItems);
+  } else if (mTxnItem) {
+    return mTxnItem->GetNumberOfChildren(aNumItems);
+  }
 
-  return result;
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsTransactionList::ItemIsBatch(int32_t aIndex, bool *aIsBatch)
 {
   NS_ENSURE_TRUE(aIsBatch, NS_ERROR_NULL_POINTER);
 
   *aIsBatch = false;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetIsBatch(aIsBatch);
 }
 
 NS_IMETHODIMP nsTransactionList::GetData(int32_t aIndex,
                                          uint32_t *aLength,
@@ -93,18 +90,18 @@ NS_IMETHODIMP nsTransactionList::GetData
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
   if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
   } else if (mTxnItem) {
-    nsresult result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-    NS_ENSURE_SUCCESS(result, result);
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCOMArray<nsISupports>& data = item->GetData();
 
   nsISupports** ret = static_cast<nsISupports**>(moz_xmalloc(data.Count() *
     sizeof(nsISupports*)));
 
   for (int32_t i = 0; i < data.Count(); i++) {
@@ -124,24 +121,22 @@ NS_IMETHODIMP nsTransactionList::GetItem
   *aItem = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   *aItem = item->GetTransaction().take();
 
   return NS_OK;
 }
 
@@ -152,24 +147,22 @@ NS_IMETHODIMP nsTransactionList::GetNumC
   *aNumChildren = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   return item->GetNumberOfChildren(aNumChildren);
 }
 
 NS_IMETHODIMP nsTransactionList::GetChildListForItem(int32_t aIndex, nsITransactionList **aTxnList)
 {
@@ -178,28 +171,25 @@ NS_IMETHODIMP nsTransactionList::GetChil
   *aTxnList = 0;
 
   nsCOMPtr<nsITransactionManager> txMgr = do_QueryReferent(mTxnMgr);
 
   NS_ENSURE_TRUE(txMgr, NS_ERROR_FAILURE);
 
   RefPtr<nsTransactionItem> item;
 
-  nsresult result = NS_OK;
-
-  if (mTxnStack)
+  if (mTxnStack) {
     item = mTxnStack->GetItem(aIndex);
-  else if (mTxnItem)
-    result = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
-
-  NS_ENSURE_SUCCESS(result, result);
+  } else if (mTxnItem) {
+    nsresult rv = mTxnItem->GetChild(aIndex, getter_AddRefs(item));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
 
   *aTxnList = (nsITransactionList *)new nsTransactionList(txMgr, item);
 
   NS_ENSURE_TRUE(*aTxnList, NS_ERROR_OUT_OF_MEMORY);
 
   NS_ADDREF(*aTxnList);
 
   return NS_OK;
 }
-
--- a/editor/txmgr/nsTransactionManager.cpp
+++ b/editor/txmgr/nsTransactionManager.cpp
@@ -54,55 +54,53 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsTransactionManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTransactionManager)
 
 NS_IMETHODIMP
 nsTransactionManager::DoTransaction(nsITransaction *aTransaction)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aTransaction, NS_ERROR_NULL_POINTER);
 
   bool doInterrupt = false;
 
-  result = WillDoNotify(aTransaction, &doInterrupt);
+  nsresult rv = WillDoNotify(aTransaction, &doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = BeginTransaction(aTransaction, nullptr);
+  rv = BeginTransaction(aTransaction, nullptr);
 
-  if (NS_FAILED(result)) {
-    DidDoNotify(aTransaction, result);
-    return result;
+  if (NS_FAILED(rv)) {
+    DidDoNotify(aTransaction, rv);
+    return rv;
   }
 
-  result = EndTransaction(false);
+  rv = EndTransaction(false);
 
-  nsresult result2 = DidDoNotify(aTransaction, result);
+  nsresult rv2 = DidDoNotify(aTransaction, rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of EndTransaction() or DidDoNotify() if EndTransaction()
+  //     succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::UndoTransaction()
 {
-  nsresult result       = NS_OK;
-
   // It is illegal to call UndoTransaction() while the transaction manager is
   // executing a  transaction's DoTransaction() method! If this happens,
   // the UndoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
 
   if (!mDoStack.IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
 
@@ -114,47 +112,47 @@ nsTransactionManager::UndoTransaction()
   if (!tx) {
     return NS_OK;
   }
 
   nsCOMPtr<nsITransaction> t = tx->GetTransaction();
 
   bool doInterrupt = false;
 
-  result = WillUndoNotify(t, &doInterrupt);
+  nsresult rv = WillUndoNotify(t, &doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = tx->UndoTransaction(this);
+  rv = tx->UndoTransaction(this);
 
-  if (NS_SUCCEEDED(result)) {
+  if (NS_SUCCEEDED(rv)) {
     tx = mUndoStack.Pop();
     mRedoStack.Push(tx.forget());
   }
 
-  nsresult result2 = DidUndoNotify(t, result);
+  nsresult rv2 = DidUndoNotify(t, rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of UndoTransaction() or DidUndoNotify() if UndoTransaction()
+  //     succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::RedoTransaction()
 {
-  nsresult result       = NS_OK;
-
   // It is illegal to call RedoTransaction() while the transaction manager is
   // executing a  transaction's DoTransaction() method! If this happens,
   // the RedoTransaction() request is ignored, and we return NS_ERROR_FAILURE.
 
   if (!mDoStack.IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
 
@@ -166,139 +164,137 @@ nsTransactionManager::RedoTransaction()
   if (!tx) {
     return NS_OK;
   }
 
   nsCOMPtr<nsITransaction> t = tx->GetTransaction();
 
   bool doInterrupt = false;
 
-  result = WillRedoNotify(t, &doInterrupt);
+  nsresult rv = WillRedoNotify(t, &doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = tx->RedoTransaction(this);
+  rv = tx->RedoTransaction(this);
 
-  if (NS_SUCCEEDED(result)) {
+  if (NS_SUCCEEDED(rv)) {
     tx = mRedoStack.Pop();
     mUndoStack.Push(tx.forget());
   }
 
-  nsresult result2 = DidRedoNotify(t, result);
+  nsresult rv2 = DidRedoNotify(t, rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of RedoTransaction() or DidRedoNotify() if RedoTransaction()
+  //     succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::Clear()
 {
-  nsresult result;
+  nsresult rv = ClearRedoStack();
 
-  result = ClearRedoStack();
-
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
-  result = ClearUndoStack();
-
-  return result;
+  return ClearUndoStack();
 }
 
 NS_IMETHODIMP
 nsTransactionManager::BeginBatch(nsISupports* aData)
 {
-  nsresult result;
-
   // We can batch independent transactions together by simply pushing
   // a dummy transaction item on the do stack. This dummy transaction item
   // will be popped off the do stack, and then pushed on the undo stack
   // in EndBatch().
 
   bool doInterrupt = false;
 
-  result = WillBeginBatchNotify(&doInterrupt);
+  nsresult rv = WillBeginBatchNotify(&doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = BeginTransaction(0, aData);
+  rv = BeginTransaction(0, aData);
 
-  nsresult result2 = DidBeginBatchNotify(result);
+  nsresult rv2 = DidBeginBatchNotify(rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of BeginTransaction() or DidBeginBatchNotify() if
+  //     BeginTransaction() succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::EndBatch(bool aAllowEmpty)
 {
-  nsCOMPtr<nsITransaction> ti;
-  nsresult result;
-
   // XXX: Need to add some mechanism to detect the case where the transaction
   //      at the top of the do stack isn't the dummy transaction, so we can
   //      throw an error!! This can happen if someone calls EndBatch() within
   //      the DoTransaction() method of a transaction.
   //
   //      For now, we can detect this case by checking the value of the
   //      dummy transaction's mTransaction field. If it is our dummy
   //      transaction, it should be nullptr. This may not be true in the
   //      future when we allow users to execute a transaction when beginning
   //      a batch!!!!
 
   RefPtr<nsTransactionItem> tx = mDoStack.Peek();
 
+  nsCOMPtr<nsITransaction> ti;
   if (tx) {
     ti = tx->GetTransaction();
   }
 
   if (!tx || ti) {
     return NS_ERROR_FAILURE;
   }
 
   bool doInterrupt = false;
 
-  result = WillEndBatchNotify(&doInterrupt);
+  nsresult rv = WillEndBatchNotify(&doInterrupt);
 
-  if (NS_FAILED(result)) {
-    return result;
+  if (NS_FAILED(rv)) {
+    return rv;
   }
 
   if (doInterrupt) {
     return NS_OK;
   }
 
-  result = EndTransaction(aAllowEmpty);
+  rv = EndTransaction(aAllowEmpty);
 
-  nsresult result2 = DidEndBatchNotify(result);
+  nsresult rv2 = DidEndBatchNotify(rv);
 
-  if (NS_SUCCEEDED(result)) {
-    result = result2;
+  if (NS_SUCCEEDED(rv)) {
+    rv = rv2;
   }
 
-  return result;
+  // XXX The result of EndTransaction() or DidEndBatchNotify() if
+  //     EndTransaction() succeeded.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTransactionManager::GetNumberOfUndoItems(int32_t *aNumItems)
 {
   *aNumItems = mUndoStack.GetSize();
   return NS_OK;
 }
@@ -465,26 +461,26 @@ nsTransactionManager::BatchTopUndo()
   RefPtr<nsTransactionItem> previousUndo;
 
   lastUndo = mUndoStack.Pop();
   MOZ_ASSERT(lastUndo, "There should be at least two transactions.");
 
   previousUndo = mUndoStack.Peek();
   MOZ_ASSERT(previousUndo, "There should be at least two transactions.");
 
-  nsresult result = previousUndo->AddChild(lastUndo);
+  nsresult rv = previousUndo->AddChild(lastUndo);
 
   // Transfer data from the transactions that is going to be
   // merged to the transaction that it is being merged with.
   nsCOMArray<nsISupports>& lastData = lastUndo->GetData();
   nsCOMArray<nsISupports>& previousData = previousUndo->GetData();
   NS_ENSURE_TRUE(previousData.AppendObjects(lastData), NS_ERROR_UNEXPECTED);
   lastData.Clear();
 
-  return result;
+  return rv;
 }
 
 nsresult
 nsTransactionManager::RemoveTopUndo()
 {
   if (mUndoStack.IsEmpty()) {
     return NS_OK;
   }
@@ -521,280 +517,265 @@ nsTransactionManager::ClearRedoStack()
 {
   mRedoStack.Clear();
   return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillDoNotify(nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillDo(this, aTransaction, aInterrupt);
+    nsresult rv = listener->WillDo(this, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidDoNotify(nsITransaction *aTransaction, nsresult aDoResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidDo(this, aTransaction, aDoResult);
+    nsresult rv = listener->DidDo(this, aTransaction, aDoResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillUndoNotify(nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillUndo(this, aTransaction, aInterrupt);
+    nsresult rv = listener->WillUndo(this, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidUndoNotify(nsITransaction *aTransaction, nsresult aUndoResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidUndo(this, aTransaction, aUndoResult);
+    nsresult rv = listener->DidUndo(this, aTransaction, aUndoResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillRedoNotify(nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillRedo(this, aTransaction, aInterrupt);
+    nsresult rv = listener->WillRedo(this, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidRedoNotify(nsITransaction *aTransaction, nsresult aRedoResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidRedo(this, aTransaction, aRedoResult);
+    nsresult rv = listener->DidRedo(this, aTransaction, aRedoResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillBeginBatchNotify(bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillBeginBatch(this, aInterrupt);
+    nsresult rv = listener->WillBeginBatch(this, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidBeginBatchNotify(nsresult aResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidBeginBatch(this, aResult);
+    nsresult rv = listener->DidBeginBatch(this, aResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillEndBatchNotify(bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillEndBatch(this, aInterrupt);
+    nsresult rv = listener->WillEndBatch(this, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidEndBatchNotify(nsresult aResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidEndBatch(this, aResult);
+    nsresult rv = listener->DidEndBatch(this, aResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::WillMergeNotify(nsITransaction *aTop, nsITransaction *aTransaction, bool *aInterrupt)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
+    nsresult rv = listener->WillMerge(this, aTop, aTransaction, aInterrupt);
 
-    if (NS_FAILED(result) || *aInterrupt) {
-      break;
+    if (NS_FAILED(rv) || *aInterrupt) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::DidMergeNotify(nsITransaction *aTop,
                                      nsITransaction *aTransaction,
                                      bool aDidMerge,
                                      nsresult aMergeResult)
 {
-  nsresult result = NS_OK;
   for (int32_t i = 0, lcount = mListeners.Count(); i < lcount; i++) {
-    nsITransactionListener *listener = mListeners[i];
+    nsITransactionListener* listener = mListeners[i];
 
     NS_ENSURE_TRUE(listener, NS_ERROR_FAILURE);
 
-    result = listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
+    nsresult rv =
+      listener->DidMerge(this, aTop, aTransaction, aDidMerge, aMergeResult);
 
-    if (NS_FAILED(result)) {
-      break;
+    if (NS_FAILED(rv)) {
+      return rv;
     }
   }
 
-  return result;
+  return NS_OK;
 }
 
 nsresult
 nsTransactionManager::BeginTransaction(nsITransaction *aTransaction,
                                        nsISupports *aData)
 {
-  nsresult result = NS_OK;
-
   // XXX: POSSIBLE OPTIMIZATION
   //      We could use a factory that pre-allocates/recycles transaction items.
   RefPtr<nsTransactionItem> tx = new nsTransactionItem(aTransaction);
 
   if (aData) {
     nsCOMArray<nsISupports>& data = tx->GetData();
     data.AppendObject(aData);
   }
 
   if (!tx) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   mDoStack.Push(tx);
 
-  result = tx->DoTransaction();
+  nsresult rv = tx->DoTransaction();
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     tx = mDoStack.Pop();
-    return result;
+    return rv;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsTransactionManager::EndTransaction(bool aAllowEmpty)
 {
-  nsresult result              = NS_OK;
-
   RefPtr<nsTransactionItem> tx = mDoStack.Pop();
 
   if (!tx) {
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsITransaction> tint = tx->GetTransaction();
 
@@ -802,88 +783,84 @@ nsTransactionManager::EndTransaction(boo
     int32_t nc = 0;
 
     // If we get here, the transaction must be a dummy batch transaction
     // created by BeginBatch(). If it contains no children, get rid of it!
 
     tx->GetNumberOfChildren(&nc);
 
     if (!nc) {
-      return result;
+      return NS_OK;
     }
   }
 
   // Check if the transaction is transient. If it is, there's nothing
   // more to do, just return.
 
   bool isTransient = false;
-
+  nsresult rv = NS_OK;
   if (tint) {
-    result = tint->GetIsTransient(&isTransient);
+    rv = tint->GetIsTransient(&isTransient);
   }
 
-  if (NS_FAILED(result) || isTransient || !mMaxTransactionCount) {
+  if (NS_FAILED(rv) || isTransient || !mMaxTransactionCount) {
     // XXX: Should we be clearing the redo stack if the transaction
     //      is transient and there is nothing on the do stack?
-    return result;
+    return rv;
   }
 
   // Check if there is a transaction on the do stack. If there is,
   // the current transaction is a "sub" transaction, and should
   // be added to the transaction at the top of the do stack.
 
   RefPtr<nsTransactionItem> top = mDoStack.Peek();
   if (top) {
-    result = top->AddChild(tx);
-
-    // XXX: What do we do if this fails?
-
-    return result;
+    return top->AddChild(tx); // XXX: What do we do if this fails?
   }
 
   // The transaction succeeded, so clear the redo stack.
 
-  result = ClearRedoStack();
+  rv = ClearRedoStack();
 
-  if (NS_FAILED(result)) {
+  if (NS_FAILED(rv)) {
     // XXX: What do we do if this fails?
   }
 
   // Check if we can coalesce this transaction with the one at the top
   // of the undo stack.
 
   top = mUndoStack.Peek();
 
   if (tint && top) {
     bool didMerge = false;
     nsCOMPtr<nsITransaction> topTransaction = top->GetTransaction();
 
     if (topTransaction) {
 
       bool doInterrupt = false;
 
-      result = WillMergeNotify(topTransaction, tint, &doInterrupt);
+      rv = WillMergeNotify(topTransaction, tint, &doInterrupt);
 
-      NS_ENSURE_SUCCESS(result, result);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       if (!doInterrupt) {
-        result = topTransaction->Merge(tint, &didMerge);
+        rv = topTransaction->Merge(tint, &didMerge);
 
-        nsresult result2 = DidMergeNotify(topTransaction, tint, didMerge, result);
+        nsresult rv2 = DidMergeNotify(topTransaction, tint, didMerge, rv);
 
-        if (NS_SUCCEEDED(result)) {
-          result = result2;
+        if (NS_SUCCEEDED(rv)) {
+          rv = rv2;
         }
 
-        if (NS_FAILED(result)) {
+        if (NS_FAILED(rv)) {
           // XXX: What do we do if this fails?
         }
 
         if (didMerge) {
-          return result;
+          return rv;
         }
       }
     }
   }
 
   // Check to see if we've hit the max level of undo. If so,
   // pop the bottom transaction off the undo stack and release it!
 
@@ -894,9 +871,8 @@ nsTransactionManager::EndTransaction(boo
   }
 
   // Push the transaction on the undo stack:
 
   mUndoStack.Push(tx.forget());
 
   return NS_OK;
 }
-
--- a/editor/txmgr/tests/TestTXMgr.cpp
+++ b/editor/txmgr/tests/TestTXMgr.cpp
@@ -601,31 +601,31 @@ public:
 
   NS_IMETHOD DoTransaction()
   {
     if (mLevel >= mMaxLevel) {
       // Only leaf nodes can throw errors!
       mFlags |= mErrorFlags;
     }
 
-    nsresult result = SimpleTransaction::DoTransaction();
-
-    if (NS_FAILED(result)) {
+    nsresult rv = SimpleTransaction::DoTransaction();
+    if (NS_FAILED(rv)) {
       // fail("QueryInterface() failed for transaction level %d. (%d)\n",
-      //      mLevel, result);
-      return result;
+      //      mLevel, rv);
+      return rv;
     }
 
-    if (mLevel >= mMaxLevel)
+    if (mLevel >= mMaxLevel) {
       return NS_OK;
+    }
 
     if (mFlags & BATCH_FLAG) {
-      result = mTXMgr->BeginBatch(nullptr);
-      if (NS_FAILED(result)) {
-        return result;
+      rv = mTXMgr->BeginBatch(nullptr);
+      if (NS_FAILED(rv)) {
+        return rv;
       }
     }
 
     int32_t cLevel = mLevel + 1;
 
     for (int i = 1; i <= mNumChildrenPerNode; i++) {
       int32_t flags = mErrorFlags & THROWS_DO_ERROR_FLAG;
 
@@ -642,57 +642,54 @@ public:
       flags |= mFlags & BATCH_FLAG;
 
       AggregateTransaction *tximpl =
               new AggregateTransaction(mTXMgr, cLevel, i, mMaxLevel,
                                        mNumChildrenPerNode, flags);
 
       if (!tximpl) {
         fail("Failed to allocate AggregateTransaction %d, level %d. (%d)\n",
-             i, mLevel, result);
+             i, mLevel, rv);
 
         if (mFlags & BATCH_FLAG) {
           mTXMgr->EndBatch(false);
         }
 
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
       nsITransaction *tx = 0;
-      result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-      if (NS_FAILED(result)) {
+      rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+      if (NS_FAILED(rv)) {
         fail("QueryInterface() failed for transaction %d, level %d. (%d)\n",
-             i, mLevel, result);
+             i, mLevel, rv);
 
         if (mFlags & BATCH_FLAG) {
           mTXMgr->EndBatch(false);
         }
-        return result;
+        return rv;
       }
 
-      result = mTXMgr->DoTransaction(tx);
-
-      if (NS_FAILED(result)) {
+      rv = mTXMgr->DoTransaction(tx);
+      if (NS_FAILED(rv)) {
         // fail("Failed to execute transaction %d, level %d. (%d)\n",
-        //      i, mLevel, result);
+        //      i, mLevel, rv);
         tx->Release();
-
         if (mFlags & BATCH_FLAG) {
           mTXMgr->EndBatch(false);
         }
-        return result;
+        return rv;
       }
-
       tx->Release();
     }
 
     if (mFlags & BATCH_FLAG) {
       mTXMgr->EndBatch(false);
     }
-    return result;
+    return rv;
   }
 };
 
 class TestTransactionFactory
 {
 public:
   virtual TestTransaction *create(nsITransactionManager *txmgr, int32_t flags) = 0;
 };
@@ -751,257 +748,246 @@ reset_globals()
 }
 
 /**
  * Test behaviors in non-batch mode.
  **/
 nsresult
 quick_test(TestTransactionFactory *factory)
 {
-  nsresult result;
-
   /*******************************************************************
    *
    * Create a transaction manager implementation:
    *
    *******************************************************************/
 
+  nsresult rv;
   nsCOMPtr<nsITransactionManager> mgr =
-    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
-  if (NS_FAILED(result) || !mgr) {
+    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &rv);
+  if (NS_FAILED(rv) || !mgr) {
     fail("Failed to create Transaction Manager instance.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   passed("Create transaction manager instance");
 
   /*******************************************************************
    *
    * Call DoTransaction() with a null transaction:
    *
    *******************************************************************/
 
-  result = mgr->DoTransaction(0);
-
-  if (result != NS_ERROR_NULL_POINTER) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = mgr->DoTransaction(0);
+  if (rv != NS_ERROR_NULL_POINTER) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call DoTransaction() with null transaction");
 
   /*******************************************************************
    *
    * Call UndoTransaction() with an empty undo stack:
    *
    *******************************************************************/
 
-  result = mgr->UndoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Undo on empty undo stack failed. (%d)\n", result);
-    return result;
+  rv = mgr->UndoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Undo on empty undo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call UndoTransaction() with empty undo stack");
 
   /*******************************************************************
    *
    * Call RedoTransaction() with an empty redo stack:
    *
    *******************************************************************/
 
-  result = mgr->RedoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Redo on empty redo stack failed. (%d)\n", result);
-    return result;
+  rv = mgr->RedoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Redo on empty redo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call RedoTransaction() with empty redo stack");
 
   /*******************************************************************
    *
    * Call SetMaxTransactionCount(-1) with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(-1) failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call SetMaxTransactionCount(-1) with empty undo and redo stacks");
 
   /*******************************************************************
    *
    * Call SetMaxTransactionCount(0) with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(0);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(0);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call SetMaxTransactionCount(0) with empty undo and redo stacks");
 
   /*******************************************************************
    *
    * Call SetMaxTransactionCount(10) with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(10);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(10) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(10);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(10) failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call SetMaxTransactionCount(10) with empty undo and redo stacks");
 
   /*******************************************************************
    *
    * Call Clear() with empty undo and redo stacks:
    *
    *******************************************************************/
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear on empty undo and redo stack failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear on empty undo and redo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call Clear() with empty undo and redo stack");
 
   int32_t numitems;
 
   /*******************************************************************
    *
    * Call GetNumberOfUndoItems() with an empty undo stack:
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call GetNumberOfUndoItems() with empty undo stack");
 
   /*******************************************************************
    *
    * Call GetNumberOfRedoItems() with an empty redo stack:
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call GetNumberOfRedoItems() with empty redo stack");
 
   nsITransaction *tx;
 
   /*******************************************************************
    *
    * Call PeekUndoStack() with an empty undo stack:
    *
    *******************************************************************/
 
   tx = 0;
-  result = mgr->PeekUndoStack(&tx);
+  rv = mgr->PeekUndoStack(&tx);
 
   TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   if (tx) {
-    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", result);
+    fail("PeekUndoStack() on empty undo stack failed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call PeekUndoStack() with empty undo stack");
 
   /*******************************************************************
    *
    * Call PeekRedoStack() with an empty undo stack:
    *
    *******************************************************************/
 
   tx = 0;
-  result = mgr->PeekRedoStack(&tx);
+  rv = mgr->PeekRedoStack(&tx);
 
   TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", rv);
+    return rv;
   }
 
   if (tx) {
-    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", result);
+    fail("PeekRedoStack() on empty redo stack failed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call PeekRedoStack() with empty undo stack");
 
   /*******************************************************************
    *
    * Call AddListener() with a null listener pointer:
    *
    *******************************************************************/
 
-  result = mgr->AddListener(0);
-
-  if (result != NS_ERROR_NULL_POINTER) {
-    fail("AddListener() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = mgr->AddListener(0);
+  if (rv != NS_ERROR_NULL_POINTER) {
+    fail("AddListener() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call AddListener() with null listener");
 
   /*******************************************************************
    *
    * Call RemoveListener() with a null listener pointer:
    *
    *******************************************************************/
 
-  result = mgr->RemoveListener(0);
-
-  if (result != NS_ERROR_NULL_POINTER) {
-    fail("RemoveListener() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = mgr->RemoveListener(0);
+  if (rv != NS_ERROR_NULL_POINTER) {
+    fail("RemoveListener() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   passed("Call RemoveListener() with null listener");
 
   int32_t i;
   TestTransaction *tximpl;
   nsITransaction *u1, *u2;
   nsITransaction *r1, *r2;
@@ -1010,160 +996,155 @@ quick_test(TestTransactionFactory *facto
    *
    * Test coalescing by executing a transaction that can merge any
    * command into itself. Then execute 20 transaction. Afterwards,
    * we should still have the first transaction sitting on the undo
    * stack. Then clear the undo and redo stacks.
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(10);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(10) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(10);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(10) failed. (%d)\n", rv);
+    return rv;
   }
 
 
   tximpl = factory->create(mgr, MERGE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate initial transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
     fail("QueryInterface() failed for initial transaction. (%d)\n",
-         result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("Failed to execute initial transaction. (%d)\n", result);
-    return result;
+         rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute initial transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != tx) {
-    fail("Top of undo stack is different!. (%d)\n", result);
+    fail("Top of undo stack is different!. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r1);
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Test coalescing of transactions");
 
   /*******************************************************************
    *
    * Execute 20 transactions. Afterwards, we should have 10
    * transactions on the undo stack:
@@ -1174,257 +1155,250 @@ quick_test(TestTransactionFactory *facto
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 transactions");
 
   /*******************************************************************
    *
    * Execute 20 transient transactions. Afterwards, we should still
    * have the same 10 transactions on the undo stack:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, TRANSIENT_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 transient transactions");
 
   /*******************************************************************
    *
    * Undo 4 transactions. Afterwards, we should have 6 transactions
    * on the undo stack, and 4 on the redo stack:
    *
    *******************************************************************/
 
   for (i = 1; i <= 4; i++) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 6) {
     fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 4 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 4) {
     fail("GetNumberOfRedoItems() expected 4 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo 4 transactions");
 
   /*******************************************************************
    *
    * Redo 2 transactions. Afterwards, we should have 8 transactions
    * on the undo stack, and 2 on the redo stack:
    *
    *******************************************************************/
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->RedoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to redo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->RedoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to redo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 8 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 8) {
     fail("GetNumberOfUndoItems() expected 8 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Redo 2 transactions");
 
   /*******************************************************************
    *
    * Execute a new transaction. The redo stack should get pruned!
@@ -1435,134 +1409,127 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 9 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 9) {
     fail("GetNumberOfUndoItems() expected 9 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Check if new transactions prune the redo stack");
 
   /*******************************************************************
    *
    * Undo 4 transactions then clear the undo and redo stacks.
    *
    *******************************************************************/
 
   for (i = 1; i <= 4; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 4 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 4) {
     fail("GetNumberOfRedoItems() expected 4 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on cleared undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on cleared redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo 4 transactions then clear the undo and redo stacks");
 
   /*******************************************************************
    *
    * Execute 5 transactions.
@@ -1573,57 +1540,55 @@ quick_test(TestTransactionFactory *facto
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 5 transactions");
 
   /*******************************************************************
    *
    * Test transaction DoTransaction() error:
@@ -1634,105 +1599,102 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction DoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction UndoTransaction() error:
@@ -1743,112 +1705,107 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->UndoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("UndoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->UndoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("UndoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 6) {
     fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction UndoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction RedoTransaction() error:
@@ -1859,29 +1816,28 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
     fail("QueryInterface() failed for RedoErrorTransaction. (%d)\n",
-         result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+         rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   //
   // Execute a normal transaction to be used in a later test:
   //
 
@@ -1889,717 +1845,687 @@ quick_test(TestTransactionFactory *facto
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   //
   // Undo the 2 transactions just executed.
   //
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
   //
   // The RedoErrorTransaction should now be at the top of the redo stack!
   //
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->RedoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("RedoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->RedoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("RedoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 6) {
     fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction RedoTransaction() error");
 
   /*******************************************************************
    *
    * Make sure that setting the transaction manager's max transaction
    * count to zero, clears both the undo and redo stacks, and executes
    * all new commands without pushing them on the undo stack!
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(0);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->SetMaxTransactionCount(0);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   passed("Test max transaction count of zero");
 
   /*******************************************************************
    *
    * Make sure that setting the transaction manager's max transaction
    * count to something greater than the number of transactions on
    * both the undo and redo stacks causes no pruning of the stacks:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(-1) failed. (%d)\n", rv);
+    return rv;
   }
 
   // Push 20 transactions on the undo stack:
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
     if (numitems != i) {
       fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
-           i, numitems, result);
+           i, numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   for (i = 1; i <= 10; i++) {
-
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->SetMaxTransactionCount(25);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(25) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->SetMaxTransactionCount(25);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(25) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test SetMaxTransactionCount() greater than num stack items");
 
   /*******************************************************************
    *
    * Test undo stack pruning by setting the transaction
    * manager's max transaction count to a number lower than the
    * number of transactions on both the undo and redo stacks:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->SetMaxTransactionCount(15);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(15) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->SetMaxTransactionCount(15);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(15) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
-           result);
-    return result;
+           rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test SetMaxTransactionCount() pruning undo stack");
 
   /*******************************************************************
    *
    * Test redo stack pruning by setting the transaction
    * manager's max transaction count to a number lower than the
    * number of transactions on both the undo and redo stacks:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->SetMaxTransactionCount(5);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(5) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->SetMaxTransactionCount(5);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(5) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u2) {
-    fail("Unexpected item at top of undo stack. (%d)\n", result);
+    fail("Unexpected item at top of undo stack. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 0) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 5 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 5) {
     fail("GetNumberOfRedoItems() expected 5 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test SetMaxTransactionCount() pruning redo stack");
 
   /*******************************************************************
    *
    * Release the transaction manager. Any transactions on the undo
    * and redo stack should automatically be released:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(-1) failed. (%d)\n", rv);
+    return rv;
   }
 
   // Push 20 transactions on the undo stack:
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
     if (numitems != i) {
       fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
-           i, numitems, result);
+           i, numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   for (i = 1; i <= 10; i++) {
-
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Release the transaction manager");
 
   /*******************************************************************
    *
    * Make sure number of transactions created matches number of
    * transactions destroyed!
@@ -2680,219 +2606,206 @@ aggregation_test()
 }
 
 /**
  * Test behaviors in batch mode.
  **/
 nsresult
 quick_batch_test(TestTransactionFactory *factory)
 {
-  nsresult result;
-
   /*******************************************************************
    *
    * Create a transaction manager implementation:
    *
    *******************************************************************/
 
+  nsresult rv;
   nsCOMPtr<nsITransactionManager> mgr =
-    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
-  if (NS_FAILED(result) || !mgr) {
+    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &rv);
+  if (NS_FAILED(rv) || !mgr) {
     fail("Failed to create Transaction Manager instance.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   passed("Create transaction manager instance");
 
   int32_t numitems;
 
   /*******************************************************************
    *
    * Make sure an unbalanced call to EndBatch(false) with empty undo stack
    * throws an error!
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("EndBatch(false) returned unexpected status. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("EndBatch(false) returned unexpected status. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test unbalanced EndBatch(false) with empty undo stack");
 
   /*******************************************************************
    *
    * Make sure that an empty batch is not added to the undo stack
    * when it is closed.
    *
    *******************************************************************/
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test empty batch");
 
   int32_t i;
   TestTransaction *tximpl;
   nsITransaction *tx;
 
   /*******************************************************************
    *
    * Execute 20 transactions. Afterwards, we should have 1
    * transaction on the undo stack:
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 0) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 batched transactions");
 
   nsITransaction *u1, *u2;
   nsITransaction *r1, *r2;
 
@@ -2900,706 +2813,669 @@ quick_batch_test(TestTransactionFactory 
    *
    * Execute 20 transient transactions. Afterwards, we should still
    * have the same transaction on the undo stack:
    *
    *******************************************************************/
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, TRANSIENT_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Execute 20 batched transient transactions");
 
   /*******************************************************************
    *
    * Test nested batching. Afterwards, we should have 2 transactions
    * on the undo stack:
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx = 0;
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-  if (NS_FAILED(result)) {
-    fail("Failed to execute transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("Failed to execute transaction. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test nested batched transactions");
 
   /*******************************************************************
    *
    * Undo 2 batch transactions. Afterwards, we should have 0
    * transactions on the undo stack and 2 on the redo stack.
    *
    *******************************************************************/
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo 2 batch transactions");
 
   /*******************************************************************
    *
    * Redo 2 batch transactions. Afterwards, we should have 2
    * transactions on the undo stack and 0 on the redo stack.
    *
    *******************************************************************/
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->RedoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->RedoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Redo 2 batch transactions");
 
   /*******************************************************************
    *
    * Call undo. Afterwards, we should have 1 transaction
    * on the undo stack, and 1 on the redo stack:
    *
    *******************************************************************/
 
-  result = mgr->UndoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Failed to undo transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->UndoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Failed to undo transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Undo a batched transaction that was redone");
 
   /*******************************************************************
    *
    * Make sure an unbalanced call to EndBatch(false) throws an error and
    * doesn't affect the undo and redo stacks!
    *
    *******************************************************************/
 
-  result = mgr->EndBatch(false);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("EndBatch(false) returned unexpected status. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("EndBatch(false) returned unexpected status. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test effect of unbalanced EndBatch(false) on undo and redo stacks");
 
   /*******************************************************************
    *
    * Make sure that an empty batch is not added to the undo stack
    * when it is closed, and that it does not affect the undo and redo
    * stacks.
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test effect of empty batch on undo and redo stacks");
 
   /*******************************************************************
    *
    * Execute a new transaction. The redo stack should get pruned!
    *
    *******************************************************************/
 
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Check if new batched transactions prune the redo stack");
 
   /*******************************************************************
    *
    * Call undo.
    *
    *******************************************************************/
 
   // Move a transaction over to the redo stack, so that we have one
   // transaction on the undo stack, and one on the redo stack!
 
-  result = mgr->UndoTransaction();
-
-  if (NS_FAILED(result)) {
-    fail("Failed to undo transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->UndoTransaction();
+  if (NS_FAILED(rv)) {
+    fail("Failed to undo transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Call undo");
 
   /*******************************************************************
    *
    * Test transaction DoTransaction() error:
@@ -3610,119 +3486,113 @@ quick_batch_test(TestTransactionFactory 
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (rv != NS_ERROR_FAILURE) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 1) {
     fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction DoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction UndoTransaction() error:
@@ -3733,126 +3603,119 @@ quick_batch_test(TestTransactionFactory 
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
   }
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->UndoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("UndoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->UndoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("UndoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction UndoTransaction() error");
 
   /*******************************************************************
    *
    * Test transaction RedoTransaction() error:
@@ -3863,412 +3726,389 @@ quick_batch_test(TestTransactionFactory 
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
     fail("QueryInterface() failed for RedoErrorTransaction. (%d)\n",
-         result);
-    return result;
-  }
-
-  result = mgr->BeginBatch(nullptr);
-
-  if (NS_FAILED(result)) {
-    fail("BeginBatch(nullptr) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+         rv);
+    return rv;
+  }
+
+  rv = mgr->BeginBatch(nullptr);
+  if (NS_FAILED(rv)) {
+    fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
-  result = mgr->EndBatch(false);
-
-  if (NS_FAILED(result)) {
-    fail("EndBatch(false) failed. (%d)\n", result);
-    return result;
+  rv = mgr->EndBatch(false);
+  if (NS_FAILED(rv)) {
+    fail("EndBatch(false) failed. (%d)\n", rv);
+    return rv;
   }
 
   //
   // Execute a normal transaction to be used in a later test:
   //
 
   tximpl = factory->create(mgr, NONE_FLAG);
 
   if (!tximpl) {
     fail("Failed to allocate transaction.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   tx     = 0;
 
-  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-
-  if (NS_FAILED(result)) {
-    fail("QueryInterface() failed for transaction. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->DoTransaction(tx);
-
-  if (NS_FAILED(result)) {
-    fail("DoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
+  rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+  if (NS_FAILED(rv)) {
+    fail("QueryInterface() failed for transaction. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->DoTransaction(tx);
+  if (NS_FAILED(rv)) {
+    fail("DoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
   }
 
   tx->Release();
 
   //
   // Undo the 2 transactions just executed.
   //
 
   for (i = 1; i <= 2; ++i) {
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
 
   //
   // The RedoErrorTransaction should now be at the top of the redo stack!
   //
 
   u1 = u2 = r1 = r2 = 0;
 
-  result = mgr->PeekUndoStack(&u1);
+  rv = mgr->PeekUndoStack(&u1);
 
   TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekUndoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekRedoStack(&r1);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekRedoStack(&r1);
 
   TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Initial PeekRedoStack() failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->RedoTransaction();
-
-  if (result != NS_ERROR_FAILURE) {
-    fail("RedoTransaction() returned unexpected error. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->PeekUndoStack(&u2);
+  if (NS_FAILED(rv)) {
+    fail("Initial PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->RedoTransaction();
+  if (rv != NS_ERROR_FAILURE) {
+    fail("RedoTransaction() returned unexpected error. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->PeekUndoStack(&u2);
 
   TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekUndoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekUndoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (u1 != u2) {
-    fail("Top of undo stack changed. (%d)\n", result);
+    fail("Top of undo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->PeekRedoStack(&r2);
+  rv = mgr->PeekRedoStack(&r2);
 
   TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
 
-  if (NS_FAILED(result)) {
-    fail("Second PeekRedoStack() failed. (%d)\n", result);
-    return result;
+  if (NS_FAILED(rv)) {
+    fail("Second PeekRedoStack() failed. (%d)\n", rv);
+    return rv;
   }
 
   if (r1 != r2) {
-    fail("Top of redo stack changed. (%d)\n", result);
+    fail("Top of redo stack changed. (%d)\n", rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 2) {
     fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   passed("Test transaction RedoTransaction() error");
 
   /*******************************************************************
    *
    * Make sure that setting the transaction manager's max transaction
    * count to zero, clears both the undo and redo stacks, and executes
    * all new commands without pushing them on the undo stack!
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(0);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
-  }
-
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->SetMaxTransactionCount(0);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
+  }
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems) {
     fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->BeginBatch(nullptr);
-
-    if (NS_FAILED(result)) {
-      fail("BeginBatch(nullptr) failed. (%d)\n", result);
-      return result;
+    rv = mgr->BeginBatch(nullptr);
+    if (NS_FAILED(rv)) {
+      fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->EndBatch(false);
-
-    if (NS_FAILED(result)) {
-      fail("EndBatch(false) failed. (%d)\n", result);
-      return result;
+    rv = mgr->EndBatch(false);
+    if (NS_FAILED(rv)) {
+      fail("EndBatch(false) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   passed("Test max transaction count of zero");
 
   /*******************************************************************
    *
    * Release the transaction manager. Any transactions on the undo
    * and redo stack should automatically be released:
    *
    *******************************************************************/
 
-  result = mgr->SetMaxTransactionCount(-1);
-
-  if (NS_FAILED(result)) {
-    fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
-    return result;
+  rv = mgr->SetMaxTransactionCount(-1);
+  if (NS_FAILED(rv)) {
+    fail("SetMaxTransactionCount(0) failed. (%d)\n", rv);
+    return rv;
   }
 
   // Push 20 transactions on the undo stack:
 
   for (i = 1; i <= 20; i++) {
     tximpl = factory->create(mgr, NONE_FLAG);
 
     if (!tximpl) {
       fail("Failed to allocate transaction %d.\n", i);
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     tx = 0;
-    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-    if (NS_FAILED(result)) {
+    rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+    if (NS_FAILED(rv)) {
       fail("QueryInterface() failed for transaction %d. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
-    result = mgr->BeginBatch(nullptr);
-
-    if (NS_FAILED(result)) {
-      fail("BeginBatch(nullptr) failed. (%d)\n", result);
-      return result;
+    rv = mgr->BeginBatch(nullptr);
+    if (NS_FAILED(rv)) {
+      fail("BeginBatch(nullptr) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->DoTransaction(tx);
-    if (NS_FAILED(result)) {
-      fail("Failed to execute transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->DoTransaction(tx);
+    if (NS_FAILED(rv)) {
+      fail("Failed to execute transaction %d. (%d)\n", i, rv);
+      return rv;
     }
 
     tx->Release();
 
-    result = mgr->EndBatch(false);
-
-    if (NS_FAILED(result)) {
-      fail("EndBatch(false) failed. (%d)\n", result);
-      return result;
+    rv = mgr->EndBatch(false);
+    if (NS_FAILED(rv)) {
+      fail("EndBatch(false) failed. (%d)\n", rv);
+      return rv;
     }
 
-    result = mgr->GetNumberOfUndoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfUndoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
-           i, result);
-      return result;
+           i, rv);
+      return rv;
     }
 
     if (numitems != i) {
       fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
-           i, numitems, result);
+           i, numitems, rv);
       return NS_ERROR_FAILURE;
     }
 
-    result = mgr->GetNumberOfRedoItems(&numitems);
-
-    if (NS_FAILED(result)) {
+    rv = mgr->GetNumberOfRedoItems(&numitems);
+    if (NS_FAILED(rv)) {
       fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
-           result);
-      return result;
+           rv);
+      return rv;
     }
 
     if (numitems) {
       fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
-           numitems, result);
+           numitems, rv);
       return NS_ERROR_FAILURE;
     }
   }
 
   for (i = 1; i <= 10; i++) {
-
-    result = mgr->UndoTransaction();
-    if (NS_FAILED(result)) {
-      fail("Failed to undo transaction %d. (%d)\n", i, result);
-      return result;
+    rv = mgr->UndoTransaction();
+    if (NS_FAILED(rv)) {
+      fail("Failed to undo transaction %d. (%d)\n", i, rv);
+      return rv;
     }
   }
-  result = mgr->GetNumberOfUndoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+
+  rv = mgr->GetNumberOfUndoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->GetNumberOfRedoItems(&numitems);
-
-  if (NS_FAILED(result)) {
+  rv = mgr->GetNumberOfRedoItems(&numitems);
+  if (NS_FAILED(rv)) {
     fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
-         result);
-    return result;
+         rv);
+    return rv;
   }
 
   if (numitems != 10) {
     fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
-         numitems, result);
+         numitems, rv);
     return NS_ERROR_FAILURE;
   }
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   passed("Release the transaction manager");
 
   /*******************************************************************
    *
    * Make sure number of transactions created matches number of
    * transactions destroyed!
@@ -4354,27 +4194,26 @@ aggregation_batch_test()
  * do/undo/redo/undo them.
  **/
 nsresult
 stress_test(TestTransactionFactory *factory, int32_t iterations)
 {
   printf("Stress test of %i iterations (may take a while) ... ", iterations);
   fflush(stdout);
 
-  nsresult result;
-
   /*******************************************************************
    *
    * Create a transaction manager:
    *
    *******************************************************************/
 
+  nsresult rv;
   nsCOMPtr<nsITransactionManager> mgr =
-    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
-  if (NS_FAILED(result) || !mgr) {
+    do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &rv);
+  if (NS_FAILED(rv) || !mgr) {
     fail("Failed to create Transaction Manager instance.\n");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   int32_t i, j;
   nsITransaction *tx;
 
   for (i = 1; i <= iterations; i++) {
@@ -4388,89 +4227,89 @@ stress_test(TestTransactionFactory *fact
       TestTransaction *tximpl = factory->create(mgr, NONE_FLAG);
 
       if (!tximpl) {
         fail("Failed to allocate transaction %d-%d.\n", i, j);
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
       tx = 0;
-      result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
-      if (NS_FAILED(result)) {
+      rv = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
+      if (NS_FAILED(rv)) {
         fail("QueryInterface() failed for transaction %d-%d. (%d)\n",
-             i, j, result);
-        return result;
+             i, j, rv);
+        return rv;
       }
 
-      result = mgr->DoTransaction(tx);
-      if (NS_FAILED(result)) {
+      rv = mgr->DoTransaction(tx);
+      if (NS_FAILED(rv)) {
         fail("Failed to execute transaction %d-%d. (%d)\n",
-             i, j, result);
-        return result;
+             i, j, rv);
+        return rv;
       }
 
       tx->Release();
     }
 
     /*******************************************************************
      *
      * Undo all the transactions:
      *
      *******************************************************************/
 
     for (j = 1; j <= i; j++) {
-      result = mgr->UndoTransaction();
-      if (NS_FAILED(result)) {
-        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, result);
-        return result;
+      rv = mgr->UndoTransaction();
+      if (NS_FAILED(rv)) {
+        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, rv);
+        return rv;
       }
     }
 
     /*******************************************************************
      *
      * Redo all the transactions:
      *
      *******************************************************************/
 
     for (j = 1; j <= i; j++) {
-      result = mgr->RedoTransaction();
-      if (NS_FAILED(result)) {
-        fail("Failed to redo transaction %d-%d. (%d)\n", i, j, result);
-        return result;
+      rv = mgr->RedoTransaction();
+      if (NS_FAILED(rv)) {
+        fail("Failed to redo transaction %d-%d. (%d)\n", i, j, rv);
+        return rv;
       }
     }
 
     /*******************************************************************
      *
      * Undo all the transactions again so that they all end up on
      * the redo stack for pruning the next time we execute a new
      * transaction
      *
      *******************************************************************/
 
     for (j = 1; j <= i; j++) {
-      result = mgr->UndoTransaction();
-      if (NS_FAILED(result)) {
-        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, result);
-        return result;
+      rv = mgr->UndoTransaction();
+      if (NS_FAILED(rv)) {
+        fail("Failed to undo transaction %d-%d. (%d)\n", i, j, rv);
+        return rv;
       }
     }
 
     // Trivial feedback not to let the user think the test is stuck.
     if (MOZ_UNLIKELY(j % 100 == 0)) {
       printf("%i ", j);
     }
   } // for, iterations.
 
   printf("passed\n");
 
-  result = mgr->Clear();
-  if (NS_FAILED(result)) {
-    fail("Clear() failed. (%d)\n", result);
-    return result;
+  rv = mgr->Clear();
+  if (NS_FAILED(rv)) {
+    fail("Clear() failed. (%d)\n", rv);
+    return rv;
   }
 
   /* Disabled because the current cycle collector doesn't delete
      cycle collectable objects synchronously.
   if (sConstructorCount != sDestructorCount) {
     fail("Transaction constructor count (%d) != destructor count (%d).\n",
          sConstructorCount, sDestructorCount);
     return NS_ERROR_FAILURE;
@@ -4597,45 +4436,43 @@ aggregation_batch_stress_test()
 int
 main (int argc, char *argv[])
 {
   ScopedXPCOM xpcom("nsITransactionManager");
   if (xpcom.failed()) {
     return 1;
   }
 
-  nsresult result;
-
   //
   // quick_test() part:
   //
 
-  result = simple_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_test();
-  NS_ENSURE_SUCCESS(result, 1);
+  nsresult rv = simple_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_test();
+  NS_ENSURE_SUCCESS(rv, 1);
 
   //
   // quick_batch_test() part:
   //
 
-  result = simple_batch_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_batch_test();
-  NS_ENSURE_SUCCESS(result, 1);
+  rv = simple_batch_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_batch_test();
+  NS_ENSURE_SUCCESS(rv, 1);
 
   //
   // stress_test() part:
   //
 
-  result = simple_stress_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_stress_test();
-  NS_ENSURE_SUCCESS(result, 1);
-
-  result = aggregation_batch_stress_test();
-  NS_ENSURE_SUCCESS(result, 1);
+  rv = simple_stress_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_stress_test();
+  NS_ENSURE_SUCCESS(rv, 1);
+
+  rv = aggregation_batch_stress_test();
+  NS_ENSURE_SUCCESS(rv, 1);
 
   return 0;
 }
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -129,85 +129,84 @@ NS_IMPL_CYCLE_COLLECTION(nsTextServicesD
                          mPrevTextBlock,
                          mNextTextBlock,
                          mExtent,
                          mTxtSvcFilter)
 
 NS_IMETHODIMP
 nsTextServicesDocument::InitWithEditor(nsIEditor *aEditor)
 {
-  nsresult result = NS_OK;
   nsCOMPtr<nsISelectionController> selCon;
   nsCOMPtr<nsIDOMDocument> doc;
 
   NS_ENSURE_TRUE(aEditor, NS_ERROR_NULL_POINTER);
 
   LOCK_DOC(this);
 
   // Check to see if we already have an mSelCon. If we do, it
   // better be the same one the editor uses!
 
-  result = aEditor->GetSelectionController(getter_AddRefs(selCon));
-
-  if (NS_FAILED(result)) {
+  nsresult rv = aEditor->GetSelectionController(getter_AddRefs(selCon));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (!selCon || (mSelCon && selCon != mSelCon)) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
   if (!mSelCon) {
     mSelCon = selCon;
   }
 
   // Check to see if we already have an mDOMDocument. If we do, it
   // better be the same one the editor uses!
 
-  result = aEditor->GetDocument(getter_AddRefs(doc));
-
-  if (NS_FAILED(result)) {
+  rv = aEditor->GetDocument(getter_AddRefs(doc));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (!doc || (mDOMDocument && doc != mDOMDocument)) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
   if (!mDOMDocument) {
     mDOMDocument = doc;
 
-    result = CreateDocumentContentIterator(getter_AddRefs(mIterator));
-
-    if (NS_FAILED(result)) {
+    rv = CreateDocumentContentIterator(getter_AddRefs(mIterator));
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     mIteratorStatus = nsTextServicesDocument::eIsDone;
 
-    result = FirstBlock();
-
-    if (NS_FAILED(result)) {
+    rv = FirstBlock();
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
   }
 
   mEditor = do_GetWeakReference(aEditor);
 
-  result = aEditor->AddEditActionListener(this);
+  rv = aEditor->AddEditActionListener(this);
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::GetDocument(nsIDOMDocument **aDoc)
 {
   NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER);
 
   *aDoc = nullptr; // init out param
@@ -229,79 +228,79 @@ nsTextServicesDocument::SetExtent(nsIDOM
 
   // We need to store a copy of aDOMRange since we don't
   // know where it came from.
 
   mExtent = static_cast<nsRange*>(aDOMRange)->CloneRange();
 
   // Create a new iterator based on our new extent range.
 
-  nsresult result = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
-
-  if (NS_FAILED(result)) {
+  nsresult rv = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   // Now position the iterator at the start of the first block
   // in the range.
 
   mIteratorStatus = nsTextServicesDocument::eIsDone;
 
-  result = FirstBlock();
+  rv = FirstBlock();
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::ExpandRangeToWordBoundaries(nsIDOMRange *aRange)
 {
   NS_ENSURE_ARG_POINTER(aRange);
   RefPtr<nsRange> range = static_cast<nsRange*>(aRange);
 
   // Get the end points of the range.
 
   nsCOMPtr<nsIDOMNode> rngStartNode, rngEndNode;
   int32_t rngStartOffset, rngEndOffset;
 
-  nsresult result =  GetRangeEndPoints(range, getter_AddRefs(rngStartNode),
-                                       &rngStartOffset,
-                                       getter_AddRefs(rngEndNode),
-                                       &rngEndOffset);
-
-  NS_ENSURE_SUCCESS(result, result);
+  nsresult rv = GetRangeEndPoints(range, getter_AddRefs(rngStartNode),
+                                  &rngStartOffset,
+                                  getter_AddRefs(rngEndNode),
+                                  &rngEndOffset);
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Create a content iterator based on the range.
 
   nsCOMPtr<nsIContentIterator> iter;
-  result = CreateContentIterator(range, getter_AddRefs(iter));
-
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Find the first text node in the range.
 
   TSDIteratorStatus iterStatus;
 
-  result = FirstTextNode(iter, &iterStatus);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = FirstTextNode(iter, &iterStatus);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (iterStatus == nsTextServicesDocument::eIsDone) {
     // No text was found so there's no adjustment necessary!
     return NS_OK;
   }
 
   nsINode *firstText = iter->GetCurrentNode();
   NS_ENSURE_TRUE(firstText, NS_ERROR_FAILURE);
 
   // Find the last text node in the range.
 
-  result = LastTextNode(iter, &iterStatus);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = LastTextNode(iter, &iterStatus);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   if (iterStatus == nsTextServicesDocument::eIsDone) {
     // We should never get here because a first text block
     // was found above.
     NS_ASSERTION(false, "Found a first without a last!");
     return NS_ERROR_FAILURE;
   }
 
@@ -321,193 +320,190 @@ nsTextServicesDocument::ExpandRangeToWor
 
   nsCOMPtr<nsIDOMNode> lastTextNode = do_QueryInterface(lastText);
   NS_ENSURE_TRUE(lastTextNode, NS_ERROR_FAILURE);
 
   if (rngEndNode != lastTextNode) {
     // The range includes the end of the last text node!
     rngEndNode = lastTextNode;
     nsAutoString str;
-    result = lastTextNode->GetNodeValue(str);
+    lastTextNode->GetNodeValue(str);
     rngEndOffset = str.Length();
   }
 
   // Create a doc iterator so that we can scan beyond
   // the bounds of the extent range.
 
   nsCOMPtr<nsIContentIterator> docIter;
-  result = CreateDocumentContentIterator(getter_AddRefs(docIter));
-  NS_ENSURE_SUCCESS(result, result);
+  rv = CreateDocumentContentIterator(getter_AddRefs(docIter));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // Grab all the text in the block containing our
   // first text node.
 
-  result = docIter->PositionAt(firstText);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = docIter->PositionAt(firstText);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   iterStatus = nsTextServicesDocument::eValid;
 
   nsTArray<OffsetEntry*> offsetTable;
   nsAutoString blockStr;
 
-  result = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
-                             nullptr, &blockStr);
-  if (NS_FAILED(result)) {
+  rv = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
+                         nullptr, &blockStr);
+  if (NS_FAILED(rv)) {
     ClearOffsetTable(&offsetTable);
-    return result;
+    return rv;
   }
 
   nsCOMPtr<nsIDOMNode> wordStartNode, wordEndNode;
   int32_t wordStartOffset, wordEndOffset;
 
-  result = FindWordBounds(&offsetTable, &blockStr,
-                          rngStartNode, rngStartOffset,
-                          getter_AddRefs(wordStartNode), &wordStartOffset,
-                          getter_AddRefs(wordEndNode), &wordEndOffset);
+  rv = FindWordBounds(&offsetTable, &blockStr,
+                      rngStartNode, rngStartOffset,
+                      getter_AddRefs(wordStartNode), &wordStartOffset,
+                      getter_AddRefs(wordEndNode), &wordEndOffset);
 
   ClearOffsetTable(&offsetTable);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   rngStartNode = wordStartNode;
   rngStartOffset = wordStartOffset;
 
   // Grab all the text in the block containing our
   // last text node.
 
-  result = docIter->PositionAt(lastText);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = docIter->PositionAt(lastText);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   iterStatus = nsTextServicesDocument::eValid;
 
-  result = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
-                             nullptr, &blockStr);
-  if (NS_FAILED(result)) {
+  rv = CreateOffsetTable(&offsetTable, docIter, &iterStatus,
+                         nullptr, &blockStr);
+  if (NS_FAILED(rv)) {
     ClearOffsetTable(&offsetTable);
-    return result;
+    return rv;
   }
 
-  result = FindWordBounds(&offsetTable, &blockStr,
-                          rngEndNode, rngEndOffset,
-                          getter_AddRefs(wordStartNode), &wordStartOffset,
-                          getter_AddRefs(wordEndNode), &wordEndOffset);
+  rv = FindWordBounds(&offsetTable, &blockStr,
+                      rngEndNode, rngEndOffset,
+                      getter_AddRefs(wordStartNode), &wordStartOffset,
+                      getter_AddRefs(wordEndNode), &wordEndOffset);
 
   ClearOffsetTable(&offsetTable);
 
-  NS_ENSURE_SUCCESS(result, result);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   // To prevent expanding the range too much, we only change
   // rngEndNode and rngEndOffset if it isn't already at the start of the
   // word and isn't equivalent to rngStartNode and rngStartOffset.
 
   if (rngEndNode != wordStartNode ||
       rngEndOffset != wordStartOffset ||
       (rngEndNode == rngStartNode && rngEndOffset == rngStartOffset)) {
     rngEndNode = wordEndNode;
     rngEndOffset = wordEndOffset;
   }
 
   // Now adjust the range so that it uses our new
   // end points.
 
-  result = range->SetEnd(rngEndNode, rngEndOffset);
-  NS_ENSURE_SUCCESS(result, result);
+  rv = range->SetEnd(rngEndNode, rngEndOffset);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return range->SetStart(rngStartNode, rngStartOffset);
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::SetFilter(nsITextServicesFilter *aFilter)
 {
   // Hang on to the filter so we can set it into the filtered iterator.
   mTxtSvcFilter = aFilter;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::GetCurrentTextBlock(nsString *aStr)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(aStr, NS_ERROR_NULL_POINTER);
 
   aStr->Truncate();
 
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
-  result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                             mExtent, aStr);
+  nsresult rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                                  mExtent, aStr);
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::FirstBlock()
 {
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
-  nsresult result = FirstTextNode(mIterator, &mIteratorStatus);
-
-  if (NS_FAILED(result)) {
+  nsresult rv = FirstTextNode(mIterator, &mIteratorStatus);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   // Keep track of prev and next blocks, just in case
   // the text service blows away the current block.
 
   if (mIteratorStatus == nsTextServicesDocument::eValid) {
     mPrevTextBlock  = nullptr;
-    result = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
+    rv = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
   } else {
     // There's no text block in the document!
 
     mPrevTextBlock  = nullptr;
     mNextTextBlock  = nullptr;
   }
 
   UNLOCK_DOC(this);
 
-  return result;
+  // XXX Result of FirstTextNode() or GetFirstTextNodeInNextBlock().
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::LastSelectedBlock(TSDBlockSelectionStatus *aSelStatus,
                                           int32_t *aSelOffset,
                                           int32_t *aSelLength)
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(aSelStatus && aSelOffset && aSelLength, NS_ERROR_NULL_POINTER);
 
   LOCK_DOC(this);
 
   mIteratorStatus = nsTextServicesDocument::eIsDone;
 
   *aSelStatus = nsITextServicesDocument::eBlockNotFound;
   *aSelOffset = *aSelLength = -1;
 
   if (!mSelCon || !mIterator) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
   nsCOMPtr<nsISelection> domSelection;
-  result = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
-                                 getter_AddRefs(domSelection));
-  if (NS_FAILED(result)) {
+  nsresult rv = mSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
+                                      getter_AddRefs(domSelection));
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   RefPtr<Selection> selection = domSelection->AsSelection();
 
   bool isCollapsed = selection->IsCollapsed();
 
   nsCOMPtr<nsIContentIterator> iter;
   RefPtr<nsRange> range;
@@ -522,113 +518,115 @@ nsTextServicesDocument::LastSelectedBloc
 
     range = selection->GetRangeAt(0);
 
     if (!range) {
       UNLOCK_DOC(this);
       return NS_ERROR_FAILURE;
     }
 
-    result = range->GetStartContainer(getter_AddRefs(parent));
-
-    if (NS_FAILED(result)) {
+    rv = range->GetStartContainer(getter_AddRefs(parent));
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     if (!parent) {
       UNLOCK_DOC(this);
       return NS_ERROR_FAILURE;
     }
 
-    result = range->GetStartOffset(&offset);
-
-    if (NS_FAILED(result)) {
+    rv = range->GetStartOffset(&offset);
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     if (IsTextNode(parent)) {
       // The caret is in a text node. Find the beginning
       // of the text block containing this text node and
       // return.
 
       nsCOMPtr<nsIContent> content(do_QueryInterface(parent));
 
       if (!content) {
         UNLOCK_DOC(this);
         return NS_ERROR_FAILURE;
       }
 
-      result = mIterator->PositionAt(content);
-
-      if (NS_FAILED(result)) {
+      rv = mIterator->PositionAt(content);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = FirstTextNodeInCurrentBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      rv = FirstTextNodeInCurrentBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
 
-      result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                 mExtent, nullptr);
-
-      if (NS_FAILED(result)) {
+      rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                             mExtent, nullptr);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = GetSelection(aSelStatus, aSelOffset, aSelLength);
-
-      if (NS_FAILED(result)) {
+      rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      if (*aSelStatus == nsITextServicesDocument::eBlockContains)
-        result = SetSelectionInternal(*aSelOffset, *aSelLength, false);
+      if (*aSelStatus == nsITextServicesDocument::eBlockContains) {
+        rv = SetSelectionInternal(*aSelOffset, *aSelLength, false);
+      }
     } else {
       // The caret isn't in a text node. Create an iterator
       // based on a range that extends from the current caret
       // position to the end of the document, then walk forwards
       // till you find a text node, then find the beginning of it's block.
 
-      result = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false, getter_AddRefs(range));
-
-      if (NS_FAILED(result)) {
+      rv = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false,
+                                                      getter_AddRefs(range));
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = range->GetCollapsed(&isCollapsed);
-
-      if (NS_FAILED(result)) {
+      rv = range->GetCollapsed(&isCollapsed);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       if (isCollapsed) {
         // If we get here, the range is collapsed because there is nothing after
         // the caret! Just return NS_OK;
 
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
-      result = CreateContentIterator(range, getter_AddRefs(iter));
-
-      if (NS_FAILED(result)) {
+      rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       iter->First();
 
       nsCOMPtr<nsIContent> content;
       while (!iter->IsDone()) {
         content = do_QueryInterface(iter->GetCurrentNode());
 
@@ -641,64 +639,65 @@ nsTextServicesDocument::LastSelectedBloc
         iter->Next();
       }
 
       if (!content) {
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
-      result = mIterator->PositionAt(content);
-
-      if (NS_FAILED(result)) {
+      rv = mIterator->PositionAt(content);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = FirstTextNodeInCurrentBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      rv = FirstTextNodeInCurrentBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
 
-      result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                 mExtent, nullptr);
-
-      if (NS_FAILED(result)) {
+      rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                             mExtent, nullptr);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = GetSelection(aSelStatus, aSelOffset, aSelLength);
-
-      if (NS_FAILED(result)) {
+      rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
     }
 
     UNLOCK_DOC(this);
 
-    return result;
+    // Result of SetSelectionInternal() in the |if| block or NS_OK.
+    return rv;
   }
 
   // If we get here, we have an uncollapsed selection!
   // Look backwards through each range in the selection till you
   // find the first text node. If you find one, find the
   // beginning of its text block, and make it the current
   // block.
 
-  result = selection->GetRangeCount(&rangeCount);
-
-  if (NS_FAILED(result)) {
+  rv = selection->GetRangeCount(&rangeCount);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   NS_ASSERTION(rangeCount > 0, "Unexpected range count!");
 
   if (rangeCount <= 0) {
     UNLOCK_DOC(this);
     return NS_OK;
   }
@@ -708,68 +707,68 @@ nsTextServicesDocument::LastSelectedBloc
 
   for (int32_t i = rangeCount - 1; i >= 0; i--) {
     // Get the i'th range from the selection.
 
     range = selection->GetRangeAt(i);
 
     if (!range) {
       UNLOCK_DOC(this);
-      return result;
+      return NS_OK; // XXX Really?
     }
 
     // Create an iterator for the range.
 
-    result = CreateContentIterator(range, getter_AddRefs(iter));
-
-    if (NS_FAILED(result)) {
+    rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     iter->Last();
 
     // Now walk through the range till we find a text node.
 
     while (!iter->IsDone()) {
       if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) {
         // We found a text node, so position the document's
         // iterator at the beginning of the block, then get
         // the selection in terms of the string offset.
         nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->AsContent();
 
-        result = mIterator->PositionAt(content);
-
-        if (NS_FAILED(result)) {
+        rv = mIterator->PositionAt(content);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
-        result = FirstTextNodeInCurrentBlock(mIterator);
-
-        if (NS_FAILED(result)) {
+        rv = FirstTextNodeInCurrentBlock(mIterator);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
         mIteratorStatus = nsTextServicesDocument::eValid;
 
-        result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                   mExtent, nullptr);
-
-        if (NS_FAILED(result)) {
+        rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                               mExtent, nullptr);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
-        result = GetSelection(aSelStatus, aSelOffset, aSelLength);
+        rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
 
         UNLOCK_DOC(this);
 
-        return result;
+        return rv;
 
       }
 
       iter->Prev();
     }
   }
 
   // If we get here, we didn't find any text node in the selection!
@@ -779,215 +778,213 @@ nsTextServicesDocument::LastSelectedBloc
 
   range = selection->GetRangeAt(rangeCount - 1);
 
   if (!range) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
-  result = range->GetEndContainer(getter_AddRefs(parent));
-
-  if (NS_FAILED(result)) {
+  rv = range->GetEndContainer(getter_AddRefs(parent));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (!parent) {
     UNLOCK_DOC(this);
     return NS_ERROR_FAILURE;
   }
 
-  result = range->GetEndOffset(&offset);
-
-  if (NS_FAILED(result)) {
+  rv = range->GetEndOffset(&offset);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
-  result = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false, getter_AddRefs(range));
-
-  if (NS_FAILED(result)) {
+  rv = CreateDocumentContentRootToNodeOffsetRange(parent, offset, false,
+                                                  getter_AddRefs(range));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
-  result = range->GetCollapsed(&isCollapsed);
-
-  if (NS_FAILED(result)) {
+  rv = range->GetCollapsed(&isCollapsed);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   if (isCollapsed) {
     // If we get here, the range is collapsed because there is nothing after
     // the current selection! Just return NS_OK;
 
     UNLOCK_DOC(this);
     return NS_OK;
   }
 
-  result = CreateContentIterator(range, getter_AddRefs(iter));
-
-  if (NS_FAILED(result)) {
+  rv = CreateContentIterator(range, getter_AddRefs(iter));
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   iter->First();
 
   while (!iter->IsDone()) {
     if (iter->GetCurrentNode()->NodeType() == nsIDOMNode::TEXT_NODE) {
       // We found a text node! Adjust the document's iterator to point
       // to the beginning of its text block, then get the current selection.
       nsCOMPtr<nsIContent> content = iter->GetCurrentNode()->AsContent();
 
-      result = mIterator->PositionAt(content);
-
-      if (NS_FAILED(result)) {
+      rv = mIterator->PositionAt(content);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = FirstTextNodeInCurrentBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      rv = FirstTextNodeInCurrentBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
 
       mIteratorStatus = nsTextServicesDocument::eValid;
 
-      result = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
-                                 mExtent, nullptr);
-
-      if (NS_FAILED(result)) {
+      rv = CreateOffsetTable(&mOffsetTable, mIterator, &mIteratorStatus,
+                             mExtent, nullptr);
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
-      result = GetSelection(aSelStatus, aSelOffset, aSelLength);
+      rv = GetSelection(aSelStatus, aSelOffset, aSelLength);
 
       UNLOCK_DOC(this);
 
-      return result;
+      return rv;
     }
 
     iter->Next();
   }
 
   // If we get here, we didn't find any block before or inside
   // the selection! Just return OK.
 
   UNLOCK_DOC(this);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::PrevBlock()
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   if (mIteratorStatus == nsTextServicesDocument::eIsDone) {
     return NS_OK;
   }
 
   switch (mIteratorStatus) {
     case nsTextServicesDocument::eValid:
-    case nsTextServicesDocument::eNext:
-
-      result = FirstTextNodeInPrevBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+    case nsTextServicesDocument::eNext: {
+
+      nsresult rv = FirstTextNodeInPrevBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       if (mIterator->IsDone()) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
-
+    }
     case nsTextServicesDocument::ePrev:
 
       // The iterator already points to the previous
       // block, so don't do anything.
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
 
     default:
 
       mIteratorStatus = nsTextServicesDocument::eIsDone;
       break;
   }
 
   // Keep track of prev and next blocks, just in case
   // the text service blows away the current block.
-
+  nsresult rv = NS_OK;
   if (mIteratorStatus == nsTextServicesDocument::eValid) {
-    result = GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
-    result = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
+    GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
+    rv = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
   } else {
     // We must be done!
     mPrevTextBlock = nullptr;
     mNextTextBlock = nullptr;
   }
 
   UNLOCK_DOC(this);
 
-  return result;
+  // XXX The result of GetFirstTextNodeInNextBlock() or NS_OK.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::NextBlock()
 {
-  nsresult result = NS_OK;
-
   NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   if (mIteratorStatus == nsTextServicesDocument::eIsDone) {
     return NS_OK;
   }
 
   switch (mIteratorStatus) {
-    case nsTextServicesDocument::eValid:
+    case nsTextServicesDocument::eValid: {
 
       // Advance the iterator to the next text block.
 
-      result = FirstTextNodeInNextBlock(mIterator);
-
-      if (NS_FAILED(result)) {
+      nsresult rv = FirstTextNodeInNextBlock(mIterator);
+
+      if (NS_FAILED(rv)) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       if (mIterator->IsDone()) {
         mIteratorStatus = nsTextServicesDocument::eIsDone;
         UNLOCK_DOC(this);
         return NS_OK;
       }
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
-
+    }
     case nsTextServicesDocument::eNext:
 
       // The iterator already points to the next block,
       // so don't do anything to it!
 
       mIteratorStatus = nsTextServicesDocument::eValid;
       break;
 
@@ -1000,29 +997,30 @@ nsTextServicesDocument::NextBlock()
     default:
 
       mIteratorStatus = nsTextServicesDocument::eIsDone;
       break;
   }
 
   // Keep track of prev and next blocks, just in case
   // the text service blows away the current block.
-
+  nsresult rv = NS_OK;
   if (mIteratorStatus == nsTextServicesDocument::eValid) {
-    result = GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
-    result = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
+    GetFirstTextNodeInPrevBlock(getter_AddRefs(mPrevTextBlock));
+    rv = GetFirstTextNodeInNextBlock(getter_AddRefs(mNextTextBlock));
   } else {
     // We must be done.
     mPrevTextBlock = nullptr;
     mNextTextBlock = nullptr;
   }
 
   UNLOCK_DOC(this);
 
-  return result;
+  // The result of GetFirstTextNodeInNextBlock() or NS_OK.
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::IsDone(bool *aIsDone)
 {
   NS_ENSURE_TRUE(aIsDone, NS_ERROR_NULL_POINTER);
 
   *aIsDone = false;
@@ -1036,57 +1034,54 @@ nsTextServicesDocument::IsDone(bool *aIs
   UNLOCK_DOC(this);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::SetSelection(int32_t aOffset, int32_t aLength)
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(mSelCon && aOffset >= 0 && aLength >= 0, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
-  result = SetSelectionInternal(aOffset, aLength, true);
+  nsresult rv = SetSelectionInternal(aOffset, aLength, true);
 
   UNLOCK_DOC(this);
 
   //**** KDEBUG ****
   // printf("\n * Sel: (%2d, %4d) (%2d, %4d)\n", mSelStartIndex, mSelStartOffset, mSelEndIndex, mSelEndOffset);
   //**** KDEBUG ****
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::ScrollSelectionIntoView()
 {
-  nsresult result;
-
   NS_ENSURE_TRUE(mSelCon, NS_ERROR_FAILURE);
 
   LOCK_DOC(this);
 
   // After ScrollSelectionIntoView(), the pending notifications might be flushed
   // and PresShell/PresContext/Frames may be dead. See bug 418470.
-  result = mSelCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION,
-                                            nsISelectionController::SCROLL_SYNCHRONOUS);
+  nsresult rv =
+    mSelCon->ScrollSelectionIntoView(
+      nsISelectionController::SELECTION_NORMAL,
+      nsISelectionController::SELECTION_FOCUS_REGION,
+      nsISelectionController::SCROLL_SYNCHRONOUS);
 
   UNLOCK_DOC(this);
 
-  return result;
+  return rv;
 }
 
 NS_IMETHODIMP
 nsTextServicesDocument::DeleteSelection()
 {
-  nsresult result = NS_OK;
-
   // We don't allow deletion during a collapsed selection!
   nsCOMPtr<nsIEditor> editor (do_QueryReferent(mEditor));
   NS_ASSERTION(editor, "DeleteSelection called without an editor present!");
   NS_ASSERTION(SelectionIsValid(), "DeleteSelection called without a valid selection!");
 
   if (!editor || !SelectionIsValid()) {
     return NS_ERROR_FAILURE;
   }
@@ -1105,23 +1100,24 @@ nsTextServicesDocument::DeleteSelection(
   // If we have an mExtent, save off its current set of
   // end points so we can compare them against mExtent's
   // set after the deletion of the content.
 
   nsCOMPtr<nsIDOMNode> origStartNode, origEndNode;
   int32_t origStartOffset = 0, origEndOffset = 0;
 
   if (mExtent) {
-    result = GetRangeEndPoints(mExtent,
-                               getter_AddRefs(origStartNode), &origStartOffset,
-                               getter_AddRefs(origEndNode), &origEndOffset);
-
-    if (NS_FAILED(result)) {
+    nsresult rv =
+      GetRangeEndPoints(mExtent,
+                        getter_AddRefs(origStartNode), &origStartOffset,
+                        getter_AddRefs(origEndNode), &origEndOffset);
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
   }
 
   int32_t selLength;
   OffsetEntry *entry, *newEntry;
 
   for (int32_t i = mSelStartIndex; i <= mSelEndIndex; i++) {
     entry = mOffsetTable[i];
@@ -1143,21 +1139,21 @@ nsTextServicesDocument::DeleteSelection(
       }
 
       if (selLength > 0 && mSelStartOffset > entry->mStrOffset) {
         // Selection doesn't start at the beginning of the
         // text node entry. We need to split this entry into
         // two pieces, the piece before the selection, and
         // the piece inside the selection.
 
-        result = SplitOffsetEntry(i, selLength);
-
-        if (NS_FAILED(result)) {
+        nsresult rv = SplitOffsetEntry(i, selLength);
+
+        if (NS_FAILED(rv)) {
           UNLOCK_DOC(this);
-          return result;
+          return rv;
         }
 
         // Adjust selection indexes to account for new entry:
 
         ++mSelStartIndex;
         ++mSelEndIndex;
         ++i;
 
@@ -1193,21 +1189,21 @@ nsTextServicesDocument::DeleteSelection(
 
         selLength = mSelEndOffset - entry->mStrOffset;
 
         if (selLength > 0 &&
             mSelEndOffset < entry->mStrOffset + entry->mLength) {
           // mStrOffset is guaranteed to be inside the selection, even
           // when mSelStartIndex == mSelEndIndex.
 
-          result = SplitOffsetEntry(i, entry->mLength - selLength);
-
-          if (NS_FAILED(result)) {
+          nsresult rv = SplitOffsetEntry(i, entry->mLength - selLength);
+
+          if (NS_FAILED(rv)) {
             UNLOCK_DOC(this);
-            return result;
+            return rv;
           }
 
           // Update the entry fields:
 
           newEntry = mOffsetTable[i+1];
           newEntry->mNodeOffset = entry->mNodeOffset;
         }
 
@@ -1229,38 +1225,39 @@ nsTextServicesDocument::DeleteSelection(
   }
 
   // Make sure mIterator always points to something valid!
 
   AdjustContentIterator();
 
   // Now delete the actual content!
 
-  result = editor->DeleteSelection(nsIEditor::ePrevious, nsIEditor::eStrip);
-
-  if (NS_FAILED(result)) {
+  nsresult rv =
+    editor->DeleteSelection(nsIEditor::ePrevious, nsIEditor::eStrip);
+
+  if (NS_FAILED(rv)) {
     UNLOCK_DOC(this);
-    return result;
+    return rv;
   }
 
   // Now that we've actually deleted the selected content,
   // check to see if our mExtent has changed, if so, then
   // we have to create a new content iterator!
 
   if (origStartNode && origEndNode) {
     nsCOMPtr<nsIDOMNode> curStartNode, curEndNode;
     int32_t curStartOffset = 0, curEndOffset = 0;
 
-    result = GetRangeEndPoints(mExtent,
-                               getter_AddRefs(curStartNode), &curStartOffset,
-                               getter_AddRefs(curEndNode), &curEndOffset);
-
-    if (NS_FAILED(result)) {
+    rv = GetRangeEndPoints(mExtent,
+                           getter_AddRefs(curStartNode), &curStartOffset,
+                           getter_AddRefs(curEndNode), &curEndOffset);
+
+    if (NS_FAILED(rv)) {
       UNLOCK_DOC(this);
-      return result;
+      return rv;
     }
 
     if (origStartNode != curStartNode || origEndNode != curEndNode) {
       // The range has changed, so we need to create a new content
       // iterator based on the new range.
 
       nsCOMPtr<nsIContent> curContent;
 
@@ -1271,30 +1268,30 @@ nsTextServicesDocument::DeleteSelection(
 
         curContent = mIterator->GetCurrentNode()
                      ? mIterator->GetCurrentNode()->AsContent()
                      : nullptr;
       }
 
       // Create the new iterator.
 
-      result = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
-
-      if (NS_FAILED(result)) {
+      rv = CreateContentIterator(mExtent, getter_AddRefs(mIterator));
+
+      if (NS_FAILED(rv)) {
         UNLOCK_DOC(this);
-        return result;
+        return rv;
       }
 
       // Now make the new iterator point to the content node
       // the old one was pointing at.
 
       if (curContent) {
-        result = mIterator->PositionAt(curContent);
-
-        if (NS_FAILED(result)) {
+        rv = mIterator->PositionAt(curContent);
+
+        if (NS_FAILED(rv)) {
           mIteratorStatus = eIsDone;
         } else {
           mIteratorStatus = eValid;
         }
       }
     }
   }