Bug 1454023 - Port |Bug 1431050 - "remove NS_ASSERT / debug.js"| to SeaMonkey trunk. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Thu, 06 Feb 2020 02:45:10 +0100
changeset 38073 000158b2aa701f94ae4b73ff88855a7d1d737237
parent 38072 d56158f2a5925c00acbb3b0e84ec71b6747c9392
child 38074 652e57af2d8a502d8f30faa53e7cb9f90b4510cc
push id398
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:10:28 +0000
reviewersfrg
bugs1454023, 1431050
Bug 1454023 - Port |Bug 1431050 - "remove NS_ASSERT / debug.js"| to SeaMonkey trunk. r=frg
suite/components/feeds/FeedConverter.js
suite/components/places/content/bookmarkProperties.js
suite/components/places/content/controller.js
suite/components/places/content/places.js
suite/components/places/content/tree.xml
suite/components/places/content/treeView.js
suite/components/sessionstore/nsSessionStore.js
--- a/suite/components/feeds/FeedConverter.js
+++ b/suite/components/feeds/FeedConverter.js
@@ -1,16 +1,15 @@
 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
-ChromeUtils.import("resource://gre/modules/debug.js");
 
 const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
 const TYPE_MAYBE_VIDEO_FEED = "application/vnd.mozilla.maybe.video.feed";
 const TYPE_MAYBE_AUDIO_FEED = "application/vnd.mozilla.maybe.audio.feed";
 const TYPE_ANY = "*/*";
 
 const FEEDHANDLER_URI = "about:feeds";
 
@@ -411,42 +410,46 @@ FeedResultService.prototype = {
 
     }
   },
 
   /**
    * See nsIFeedResultService.idl
    */
   addFeedResult: function addFeedResult(feedResult) {
-    NS_ASSERT(feedResult != null, "null feedResult!");
-    NS_ASSERT(feedResult.uri != null, "null URI!");
+    if (feedResult == null)
+      throw new Error("null feedResult!");
+    if (feedResult.uri == null)
+      throw new Error("null URI!");
     var spec = feedResult.uri.spec;
     if (!this._results[spec])
       this._results[spec] = [];
     this._results[spec].push(feedResult);
   },
 
   /**
    * See nsIFeedResultService.idl
    */
   getFeedResult: function getFeedResult(uri) {
-    NS_ASSERT(uri != null, "null URI!");
+    if (uri == null)
+      throw new Error("null URI!");
     var resultList = this._results[uri.spec];
     for (let i = 0; i < resultList.length; ++i) {
       if (resultList[i].uri == uri)
         return resultList[i];
     }
     return null;
   },
 
   /**
    * See nsIFeedResultService.idl
    */
   removeFeedResult: function removeFeedResult(uri) {
-    NS_ASSERT(uri != null, "null URI!");
+    if (uri == null)
+      throw new Error("null URI!");
     var resultList = this._results[uri.spec];
     if (!resultList)
       return;
     var deletions = 0;
     for (let i = 0; i < resultList.length; ++i) {
       if (resultList[i].uri == uri) {
         delete resultList[i];
         ++deletions;
--- a/suite/components/places/content/bookmarkProperties.js
+++ b/suite/components/places/content/bookmarkProperties.js
@@ -127,17 +127,18 @@ var BookmarkPropertiesPanel = {
   _getDialogTitle: function BPP__getDialogTitle() {
     if (this._action == ACTION_ADD) {
       if (this._itemType == BOOKMARK_ITEM)
         return this._strings.getString("dialogTitleAddBookmark");
       if (this._itemType == LIVEMARK_CONTAINER)
         return this._strings.getString("dialogTitleAddLivemark");
 
       // add folder
-      NS_ASSERT(this._itemType == BOOKMARK_FOLDER, "Unknown item type");
+      if (this._itemType != BOOKMARK_FOLDER)
+        throw new Error("Unknown item type");
       if (this._URIs.length)
         return this._strings.getString("dialogTitleAddMulti");
 
       return this._strings.getString("dialogTitleAddFolder");
     }
     if (this._action == ACTION_EDIT) {
       return this._strings.getFormattedString("dialogTitleEdit", [this._title]);
     }
@@ -147,17 +148,18 @@ var BookmarkPropertiesPanel = {
   /**
    * Determines the initial data for the item edited or added by this dialog
    */
   async _determineItemInfo() {
     let dialogInfo = window.arguments[0];
     this._action = dialogInfo.action == "add" ? ACTION_ADD : ACTION_EDIT;
     this._hiddenRows = dialogInfo.hiddenRows ? dialogInfo.hiddenRows : [];
     if (this._action == ACTION_ADD) {
-      NS_ASSERT("type" in dialogInfo, "missing type property for add action");
+      if (!("type" in dialogInfo))
+        throw new Error("missing type property for add action");
 
       if ("title" in dialogInfo)
         this._title = dialogInfo.title;
 
       if ("defaultInsertionPoint" in dialogInfo) {
         this._defaultInsertionPoint = dialogInfo.defaultInsertionPoint;
       } else {
         this._defaultInsertionPoint =
@@ -166,18 +168,18 @@ var BookmarkPropertiesPanel = {
             parentGuid: PlacesUtils.bookmarks.menuGuid
           });
       }
 
       switch (dialogInfo.type) {
         case "bookmark":
           this._itemType = BOOKMARK_ITEM;
           if ("uri" in dialogInfo) {
-            NS_ASSERT(dialogInfo.uri instanceof Ci.nsIURI,
-                      "uri property should be a uri object");
+            if (!(dialogInfo.uri instanceof Ci.nsIURI))
+              throw new Error("uri property should be a uri object");
             this._uri = dialogInfo.uri;
             if (typeof(this._title) != "string") {
               this._title = await PlacesUtils.history.fetch(this._uri) ||
                             this._uri.spec;
             }
           } else {
             this._uri = Services.io.newURI("about:blank");
             this._title = this._strings.getString("newBookmarkDefault");
--- a/suite/components/places/content/controller.js
+++ b/suite/components/places/content/controller.js
@@ -646,25 +646,16 @@ PlacesController.prototype = {
 
     PlacesUIUtils.showBookmarkDialog({ action: "edit",
                                        node,
                                        hiddenRows: [ "folderPicker" ]
                                      }, window.top);
   },
 
   /**
-   * This method can be run on a URI parameter to ensure that it didn't
-   * receive a string instead of an nsIURI object.
-   */
-  _assertURINotString: function PC__assertURINotString(value) {
-    NS_ASSERT((typeof(value) == "object") && !(value instanceof String),
-           "This method should be passed a URI as a nsIURI object, not as a string.");
-  },
-
-  /**
    * Reloads the selected livemark if any.
    */
   reloadSelectedLivemark: function PC_reloadSelectedLivemark() {
     var selectedNode = this._view.selectedNode;
     if (selectedNode) {
       let itemId = selectedNode.itemId;
       PlacesUtils.livemarks.getLivemark({ id: itemId })
         .then(aLivemark => {
@@ -786,17 +777,18 @@ PlacesController.prototype = {
    *          An array of nodes to remove. Should all be adjacent.
    * @param   [out] transactions
    *          An array of transactions.
    * @param   [optional] removedFolders
    *          An array of folder nodes that have already been removed.
    * @return {Integer} The total number of items affected.
    */
   async _removeRange(range, transactions, removedFolders) {
-    NS_ASSERT(transactions instanceof Array, "Must pass a transactions array");
+    if (!(transactions instanceof Array))
+      throw new Error("Must pass a transactions array");
     if (!removedFolders)
       removedFolders = [];
 
     let bmGuidsToRemove = [];
     let totalItems = 0;
 
     for (var i = 0; i < range.length; ++i) {
       var node = range[i];
@@ -854,22 +846,17 @@ PlacesController.prototype = {
       }
     }
     if (bmGuidsToRemove.length) {
       transactions.push(PlacesTransactions.Remove({ guids: bmGuidsToRemove }));
     }
     return totalItems;
   },
 
-  /**
-   * Removes the set of selected ranges from bookmarks.
-   * @param   txnName
-   *          See |remove|.
-   */
-  async _removeRowsFromBookmarks(txnName) {
+  async _removeRowsFromBookmarks() {
     let ranges = this._view.removableSelectionRanges;
     let transactions = [];
     let removedFolders = [];
     let totalItems = 0;
 
     for (let range of ranges) {
       totalItems += await this._removeRange(range, transactions, removedFolders);
     }
@@ -914,53 +901,48 @@ PlacesController.prototype = {
     if (PlacesUtils.nodeIsHost(aContainerNode)) {
       // Site container.
       PlacesUtils.history.removePagesFromHost(aContainerNode.title, true);
     } else if (PlacesUtils.nodeIsDay(aContainerNode)) {
       // Day container.
       let query = aContainerNode.getQueries()[0];
       let beginTime = query.beginTime;
       let endTime = query.endTime;
-      NS_ASSERT(query && beginTime && endTime,
-                "A valid date container query should exist!");
+      if (!query || !beginTime || !endTime)
+        throw new Error("A valid date container query should exist!");
       // We want to exclude beginTime from the removal because
       // removePagesByTimeframe includes both extremes, while date containers
       // exclude the lower extreme.  So, if we would not exclude it, we would
       // end up removing more history than requested.
       PlacesUtils.history.removePagesByTimeframe(beginTime + 1, endTime);
     }
   },
 
   /**
    * Removes the selection
-   * @param   aTxnName
-   *          A name for the transaction if this is being performed
-   *          as part of another operation.
    */
-  async remove(aTxnName) {
+  async remove() {
     if (!this._hasRemovableSelection())
       return;
 
-    NS_ASSERT(aTxnName !== undefined, "Must supply Transaction Name");
-
     var root = this._view.result.root;
 
     if (PlacesUtils.nodeIsFolder(root)) {
-      await this._removeRowsFromBookmarks(aTxnName);
+      await this._removeRowsFromBookmarks();
     } else if (PlacesUtils.nodeIsQuery(root)) {
       var queryType = PlacesUtils.asQuery(root).queryOptions.queryType;
       if (queryType == Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS) {
-        await this._removeRowsFromBookmarks(aTxnName);
+        await this._removeRowsFromBookmarks();
       } else if (queryType == Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY) {
         this._removeRowsFromHistory();
       } else {
-        NS_ASSERT(false, "implement support for QUERY_TYPE_UNIFIED");
+        throw new Error("implement support for QUERY_TYPE_UNIFIED");
       }
     } else
-      NS_ASSERT(false, "unexpected root");
+      throw new Error("unexpected root");
   },
 
   /**
    * Fills a DataTransfer object with the content of the selection that can be
    * dropped elsewhere.
    * @param   aEvent
    *          The dragstart event.
    */
@@ -1246,17 +1228,18 @@ PlacesController.prototype = {
   },
 
   /**
    * Checks if we can insert into a container.
    * @param   container
    *          The container were we are want to drop
    */
   disallowInsertion(container) {
-    NS_ASSERT(container, "empty container");
+    if (!container)
+      throw new Error("empty container");
     // Allow dropping into Tag containers and editable folders.
     return !PlacesUtils.nodeIsTagQuery(container) &&
            (!PlacesUtils.nodeIsFolder(container) ||
             PlacesUIUtils.isFolderReadOnly(container, this._view));
   },
 
   /**
    * Determines if a node can be moved.
--- a/suite/components/places/content/places.js
+++ b/suite/components/places/content/places.js
@@ -962,31 +962,31 @@ var ViewMenu = {
    *          item only.
    *          Must be contained by popup. Can be null (in which case all
    *          items until the end of the popup will be removed). Ignored
    *          if startID is null.
    * @returns The element for the caller to insert new items before,
    *          null if the caller should just append to the popup.
    */
   _clean: function VM__clean(popup, startID, endID) {
-    if (endID)
-      NS_ASSERT(startID, "meaningless to have valid endID and null startID");
+    if (endID && !startID)
+      throw new Error("meaningless to have valid endID and null startID");
     if (startID) {
       var startElement = document.getElementById(startID);
-      NS_ASSERT(startElement.parentNode ==
-                popup, "startElement is not in popup");
-      NS_ASSERT(startElement,
-                "startID does not correspond to an existing element");
+      if (!startElement)
+        throw new Error("startID does not correspond to an existing element");
+      if (startElement.parentNode != popup)
+        throw new Error("startElement is not in popup");
       var endElement = null;
       if (endID) {
         endElement = document.getElementById(endID);
-        NS_ASSERT(endElement.parentNode == popup,
-                  "endElement is not in popup");
-        NS_ASSERT(endElement,
-                  "endID does not correspond to an existing element");
+        if (!endElement)
+          throw new Error("endID does not correspond to an existing element");
+        if (endElement.parentNode != popup)
+          throw new Error("endElement is not in popup");
       }
       while (startElement.nextSibling != endElement)
         popup.removeChild(startElement.nextSibling);
       return endElement;
     }
     while (popup.hasChildNodes()) {
       popup.firstChild.remove();
     }
--- a/suite/components/places/content/tree.xml
+++ b/suite/components/places/content/tree.xml
@@ -198,17 +198,17 @@
 
             if (!wasOpen)
               container.containerOpen = false;
 
             return null;
           }
 
           var container = this.result.root;
-          NS_ASSERT(container, "No result, cannot select place URI!");
+          console.assert(container, "No result, cannot select place URI!");
           if (!container)
             return;
 
           var child = findNode(container, []);
           if (child)
             this.selectNode(child);
           else {
             // If the specified child could not be located, clear the selection
@@ -468,17 +468,17 @@
       <method name="_getInsertionPoint">
         <parameter name="index"/>
         <parameter name="orientation"/>
         <body><![CDATA[
           var result = this.result;
           var resultview = this.view;
           var container = result.root;
           var dropNearNode = null;
-          NS_ASSERT(container, "null container");
+          console.assert(container, "null container");
           // When there's no selection, assume the container is the container
           // the view is populated from (i.e. the result's itemId).
           if (index != -1) {
             var lastSelected = resultview.nodeForTreeIndex(index);
             if (resultview.isContainer(index) && orientation == Ci.nsITreeView.DROP_ON) {
               // If the last selected item is an open container, append _into_
               // it, rather than insert adjacent to it.
               container = lastSelected;
--- a/suite/components/places/content/treeView.js
+++ b/suite/components/places/content/treeView.js
@@ -646,17 +646,17 @@ PlacesTreeView.prototype = {
       case Ci.nsINavHistoryQueryOptions.SORT_BY_TAGS_DESCENDING:
         return [this.COLUMN_TYPE_TAGS, true];
     }
     return [this.COLUMN_TYPE_UNKNOWN, false];
   },
 
   // nsINavHistoryResultObserver
   nodeInserted: function PTV_nodeInserted(aParentNode, aNode, aNewIndex) {
-    NS_ASSERT(this._result, "Got a notification but have no result!");
+    console.assert(this._result, "Got a notification but have no result!");
     if (!this._tree || !this._result)
       return;
 
     // Bail out for hidden separators.
     if (PlacesUtils.nodeIsSeparator(aNode) && this.isSorted())
       return;
 
     let parentRow;
@@ -720,17 +720,17 @@ PlacesTreeView.prototype = {
    * removed but the node it is collapsed with is not being removed (this then
    * just swap out the removee with its collapsing partner). The only time
    * when we really remove things is when deleting URIs, which will apply to
    * all collapsees. This function is called sometimes when resorting items.
    * However, we won't do this when sorted by date because dates will never
    * change for visits, and date sorting is the only time things are collapsed.
    */
   nodeRemoved: function PTV_nodeRemoved(aParentNode, aNode, aOldIndex) {
-    NS_ASSERT(this._result, "Got a notification but have no result!");
+    console.assert(this._result, "Got a notification but have no result!");
     if (!this._tree || !this._result)
       return;
 
     // XXX bug 517701: We don't know what to do when the root node is removed.
     if (aNode == this._rootNode)
       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
 
     // Bail out for hidden separators.
@@ -775,17 +775,17 @@ PlacesTreeView.prototype = {
     // Restore selection.
     let rowToSelect = Math.min(oldRow, this._rows.length - 1);
     if (rowToSelect != -1)
       this.selection.rangedSelect(rowToSelect, rowToSelect, true);
   },
 
   nodeMoved:
   function PTV_nodeMoved(aNode, aOldParent, aOldIndex, aNewParent, aNewIndex) {
-    NS_ASSERT(this._result, "Got a notification but have no result!");
+    console.assert(this._result, "Got a notification but have no result!");
     if (!this._tree || !this._result)
       return;
 
     // Bail out for hidden separators.
     if (PlacesUtils.nodeIsSeparator(aNode) && this.isSorted())
       return;
 
     // Note that at this point the node has already been moved by the backend,
@@ -824,17 +824,17 @@ PlacesTreeView.prototype = {
     if (nodesToReselect.length > 0) {
       this._restoreSelection(nodesToReselect, aNewParent);
       this.selection.selectEventsSuppressed = false;
     }
   },
 
   _invalidateCellValue: function PTV__invalidateCellValue(aNode,
                                                           aColumnType) {
-    NS_ASSERT(this._result, "Got a notification but have no result!");
+    console.assert(this._result, "Got a notification but have no result!");
     if (!this._tree || !this._result)
       return;
 
     // Nothing to do for the root node.
     if (aNode == this._rootNode)
       return;
 
     let row = this._getRowForNode(aNode);
@@ -971,17 +971,17 @@ PlacesTreeView.prototype = {
               aLivemark.unregisterForUpdates(aNode);
             }
           }, () => undefined);
       }
     }
   },
 
   invalidateContainer: function PTV_invalidateContainer(aContainer) {
-    NS_ASSERT(this._result, "Need to have a result to update");
+    console.assert(this._result, "Need to have a result to update");
     if (!this._tree)
       return;
 
     // If we are currently editing, don't invalidate the container until we
     // finish.
     if (this._tree.element.getAttribute("editing")) {
       if (!this._editingObservers) {
         this._editingObservers = new Map();
--- a/suite/components/sessionstore/nsSessionStore.js
+++ b/suite/components/sessionstore/nsSessionStore.js
@@ -75,18 +75,16 @@ const CAPABILITIES = [
 ];
 
 // These are tab events that we listen to.
 const TAB_EVENTS = ["TabOpen", "TabClose", "TabSelect", "TabShow", "TabHide"];
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
-// debug.js adds NS_ASSERT. cf. bug 669196
-const {debug} = ChromeUtils.import("resource://gre/modules/debug.js");
 
 XPCOMUtils.defineLazyServiceGetter(this, "SecMan",
   "@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager");
 XPCOMUtils.defineLazyServiceGetter(this, "gScreenManager",
   "@mozilla.org/gfx/screenmanager;1", "nsIScreenManager");
 XPCOMUtils.defineLazyServiceGetter(this, "uuidGenerator",
   "@mozilla.org/uuid-generator;1", "nsIUUIDGenerator");
 
@@ -1471,18 +1469,18 @@ SessionStoreService.prototype = {
         // try-catch, we'll update history to where it breaks, assert for
         // non-release builds, and still save sessionstore.js. We'll track if
         // we've shown the assert for this tab so we only show it once.
         // cf. bug 669196.
         if (!aTab.__SS_broken_history) {
           // First Focus the window & tab we're having trouble with.
           aTab.ownerDocument.defaultView.focus();
           aTab.ownerDocument.defaultView.getBrowser().selectedTab = aTab;
-          NS_ASSERT(false, "SessionStore failed gathering complete history " +
-                           "for the focused window/tab. See bug 669196.");
+          debug("SessionStore failed gathering complete history " +
+                "for the focused window/tab. See bug 669196.");
           aTab.__SS_broken_history = true;
         }
       }
       tabData.index = history.index + 1;
 
       // make sure not to cache privacy sensitive data which shouldn't get out
       if (!aFullData)
         browser.__SS_data = tabData;