Unit test bustage fix - port bug 645922 to comm-central (Remove nsIJSON.encode/decode, because their functionality is subsumed by JSON.parse and JSON.stringify, and their idiosyncrasies are hindering code improvements). r=bustage fix
authorMark Banner <bugzilla@standard8.plus.com>
Wed, 06 Jul 2011 09:03:02 +0100
changeset 8513 69de1b1f58f7264ba2952c9f9a8e320541d804ad
parent 8512 7e3a06ce86c8c465b39fbdba4860942c6fb308d8
child 8514 3ac94faeeb559a7b41afe1710e83e7e8262f68bb
push id158
push userbugzilla@standard8.plus.com
push dateTue, 27 Sep 2011 19:18:14 +0000
treeherdercomm-beta@e47b99c61e4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage
bugs645922
Unit test bustage fix - port bug 645922 to comm-central (Remove nsIJSON.encode/decode, because their functionality is subsumed by JSON.parse and JSON.stringify, and their idiosyncrasies are hindering code improvements). r=bustage fix
mail/base/content/folderPane.js
mail/components/addrbook/content/abTrees.js
mailnews/db/gloda/modules/datastore.js
mailnews/db/gloda/modules/gloda.js
mailnews/import/test/unit/resources/import_helper.js
suite/common/places/tests/unit/test_leftpane_corruption_handling.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -187,18 +187,17 @@ let gFolderTreeView = {
         fstream.init(file, -1, 0, 0);
         sstream.init(fstream);
 
         while (sstream.available())
           data += sstream.read(4096);
 
         sstream.close();
         fstream.close();
-        let JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-        this._persistOpenMap = JSON.decode(data);
+        this._persistOpenMap = JSON.parse(data);
       }
     }
 
     // Load our data
     this._rebuild();
     // And actually draw the tree
     aTree.view = this;
 
@@ -218,18 +217,17 @@ let gFolderTreeView = {
 
     // Remove our listener
     let session = Cc["@mozilla.org/messenger/services/session;1"]
                      .getService(Ci.nsIMsgMailSession);
     session.RemoveFolderListener(this);
 
     if (aJSONFile) {
       // Write out our json file...
-      let JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-      let data = JSON.encode(this._persistOpenMap);
+      let data = JSON.stringify(this._persistOpenMap);
       let file = Cc["@mozilla.org/file/directory_service;1"]
                     .getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
       file.append(aJSONFile);
       let foStream = Cc["@mozilla.org/network/file-output-stream;1"]
                         .createInstance(Ci.nsIFileOutputStream);
 
       foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
       foStream.write(data, data.length);
--- a/mail/components/addrbook/content/abTrees.js
+++ b/mail/components/addrbook/content/abTrees.js
@@ -128,34 +128,32 @@ directoryTreeView.prototype = {
         fstream.init(file, -1, 0, 0);
         sstream.init(fstream);
 
         while (sstream.available())
           data += sstream.read(4096);
 
         sstream.close();
         fstream.close();
-        let JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-        this._persistOpenMap = JSON.decode(data);
+        this._persistOpenMap = JSON.parse(data);
       }
     }
 
     this._rebuild();
     aTree.view = this;
   },
 
   shutdown: function dtv_shutdown(aJSONFile) {
     const Cc = Components.classes;
     const Ci = Components.interfaces;
 
     // Write out the persistOpenMap to our JSON file
     if (aJSONFile) {
       // Write out our json file...
-      let JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-      let data = JSON.encode(this._persistOpenMap);
+      let data = JSON.stringify(this._persistOpenMap);
       let file = Cc["@mozilla.org/file/directory_service;1"]
                  .getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
       file.append(aJSONFile);
       let foStream = Cc["@mozilla.org/network/file-output-stream;1"]
                     .createInstance(Ci.nsIFileOutputStream);
 
       foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
       foStream.write(data, data.length);
--- a/mailnews/db/gloda/modules/datastore.js
+++ b/mailnews/db/gloda/modules/datastore.js
@@ -945,21 +945,20 @@ var GlodaDatastore = {
    */
   _prefBranch: null,
 
   /**
    * Initialize logging, create the database if it doesn't exist, "upgrade" it
    *  if it does and it's not up-to-date, fill our authoritative folder uri/id
    *  mapping.
    */
-  _init: function gloda_ds_init(aNsJSON, aNounIDToDef) {
+  _init: function gloda_ds_init(aNounIDToDef) {
     this._log = Log4Moz.repository.getLogger("gloda.datastore");
     this._log.debug("Beginning datastore initialization.");
 
-    this._json = aNsJSON;
     this._nounIDToDef = aNounIDToDef;
 
     let prefService = Cc["@mozilla.org/preferences-service;1"].
                         getService(Ci.nsIPrefService);
     let branch = prefService.getBranch("mailnews.database.global.datastore.");
     this._prefBranch = branch.QueryInterface(Ci.nsIPrefBranch2);
 
     // Not sure the weak reference really makes a difference given that we are a
@@ -3442,17 +3441,17 @@ var GlodaDatastore = {
     //  the json pass has already been performed
     if (!aItem.NOUN_DEF.allowsArbitraryAttrs || !aItem._jsonText || hadDeps) {
       if (hasDeps)
         aItem._deps = deps;
       return hasDeps;
     }
 
     //this._log.debug(" load json: " + aItem._jsonText);
-    let jsonDict = this._json.decode(aItem._jsonText);
+    let jsonDict = JSON.parse(aItem._jsonText);
     delete aItem._jsonText;
 
     // Iterate over the attributes on the item
     for each (let [attribId, jsonValue] in Iterator(jsonDict)) {
       // It is technically impossible for attribute ids to go away at this
       //  point in time.  This would require someone to monkey around with
       //  our schema.  But we will introduce this functionality one day, so
       //  prepare for it now.
--- a/mailnews/db/gloda/modules/gloda.js
+++ b/mailnews/db/gloda/modules/gloda.js
@@ -164,18 +164,17 @@ var Gloda = {
    *  current user (based on accounts).
    *
    * Additional nouns and the core attribute providers are initialized by the
    *  everybody.js module which ensures all of those dependencies are loaded
    *  (and initialized).
    */
   _init: function gloda_ns_init() {
     this._initLogging();
-    this._json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-    GlodaDatastore._init(this._json, this._nounIDToDef);
+    GlodaDatastore._init(this._nounIDToDef);
     this._initAttributes();
     this._initMyIdentities();
   },
 
   _log: null,
   /**
    * Initialize logging; the error console window gets Warning/Error, and stdout
    *  (via dump) gets everything.
@@ -2119,17 +2118,17 @@ var Gloda = {
       // remove the empty set marker if there should have been one
       if (!value.length && attrib.emptySetIsSignificant)
         removeDBAttribs.push([GlodaDatastore.kEmptySetAttrId, attribDB.id]);
       // delete these from the old item, as the old item is canonical, and
       //  should no longer have these values
       delete aOldItem[key];
     }
 
-    aItem._jsonText = this._json.encode(jsonDict);
+    aItem._jsonText = JSON.stringify(jsonDict);
     this._log.debug("  json text: " + aItem._jsonText);
 
     if (aIsRecordNew) {
       this._log.debug(" inserting item");
       itemNounDef.objInsert.call(itemNounDef.datastore, aItem);
     }
     else {
       this._log.debug(" updating item");
--- a/mailnews/import/test/unit/resources/import_helper.js
+++ b/mailnews/import/test/unit/resources/import_helper.js
@@ -261,14 +261,13 @@ AbImportHelper.prototype =
     var str = {};
     // get the entire file into the json string
     while(istream.readString(4096, str) != 0)
       json += str.value;
     // close the input streams
     istream.close();
     fis.close();
     // decode the JSON and get the array of cards
-    var nsIJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-    var arr = nsIJSON.decode(json)[aName];
+    var arr = JSON.parse(json)[aName];
     do_check_true(arr && arr.length > 0);
     return arr;
   }
 }
--- a/suite/common/places/tests/unit/test_leftpane_corruption_handling.js
+++ b/suite/common/places/tests/unit/test_leftpane_corruption_handling.js
@@ -186,19 +186,18 @@ function folderToJSON(aItemId) {
   return writer.value;
 }
 
 /**
  * Compare the JSON representation of 2 nodes, skipping everchanging properties
  * like dates.
  */
 function compareJSON(aNodeJSON_1, aNodeJSON_2) {
-  let JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
-  node1 = JSON.decode(aNodeJSON_1);
-  node2 = JSON.decode(aNodeJSON_2);
+  node1 = JSON.parse(aNodeJSON_1);
+  node2 = JSON.parse(aNodeJSON_2);
 
   // List of properties we should not compare (expected to be different).
   const SKIP_PROPS = ["dateAdded", "lastModified", "id"];
 
   function compareObjects(obj1, obj2) {
     function count(o) { var n = 0; for (let p in o) n++; return n; }
     do_check_eq(count(obj1), count(obj2));
     for (let prop in obj1) {