From ffd671ce7b4408e4898f29d2587bbf1b884cb905 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Mon, 11 Jul 2011 22:37:37 +0000 Subject: [PATCH] - Remove references to Zotero.JSON - Add deprecation warning in case any external code makes use of Zotero.JSON - Fix some strict mode warnings in zotero.js --- chrome/content/zotero/exportOptions.js | 4 ++-- chrome/content/zotero/xpcom/integration.js | 14 +++++++------- .../content/zotero/xpcom/translation/translator.js | 4 ++-- chrome/content/zotero/xpcom/zotero.js | 14 +++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/chrome/content/zotero/exportOptions.js b/chrome/content/zotero/exportOptions.js index 325c786717..d3c1852844 100644 --- a/chrome/content/zotero/exportOptions.js +++ b/chrome/content/zotero/exportOptions.js @@ -121,7 +121,7 @@ var Zotero_File_Interface_Export = new function() { if(optionString) { try { - var options = Zotero.JSON.unserialize(optionString); + var options = JSON.parse(optionString); } catch(e) {} } @@ -211,7 +211,7 @@ var Zotero_File_Interface_Export = new function() { } // save options - var optionString = Zotero.JSON.serialize(displayOptions); + var optionString = JSON.stringify(displayOptions); Zotero.Prefs.set("export.translatorSettings", optionString); } diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 2f5bfb92ea..035e3fdef5 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -1273,15 +1273,15 @@ Zotero.Integration.Session.prototype.unserializeCitation = function(arg, index) // get JSON try { - var citation = Zotero.JSON.unserialize(arg); + var citation = JSON.parse(arg); } catch(e) { // fix for corrupted fields (corrupted by Word, somehow) try { - var citation = Zotero.JSON.unserialize(arg.substr(0, arg.length-1)); + var citation = JSON.parse(arg.substr(0, arg.length-1)); } catch(e) { // another fix for corrupted fields (corrupted by 2.1b1) try { - var citation = Zotero.JSON.unserialize(arg.replace(/{{((?:\s*,?"unsorted":(?:true|false)|\s*,?"custom":"(?:(?:\\")?[^"]*\s*)*")*)}}/, "{$1}")); + var citation = JSON.parse(arg.replace(/{{((?:\s*,?"unsorted":(?:true|false)|\s*,?"custom":"(?:(?:\\")?[^"]*\s*)*")*)}}/, "{$1}")); } catch(e) { throw new Zotero.Integration.CorruptFieldException(arg); } @@ -1574,10 +1574,10 @@ Zotero.Integration.Session.prototype.restoreProcessorState = function() { */ Zotero.Integration.Session.prototype.loadBibliographyData = function(json) { try { - var documentData = Zotero.JSON.unserialize(json); + var documentData = JSON.parse(json); } catch(e) { try { - var documentData = Zotero.JSON.unserialize(json.substr(0, json.length-1)); + var documentData = JSON.parse(json.substr(0, json.length-1)); } catch(e) { throw new Zotero.Integration.CorruptFieldException(json); } @@ -1683,7 +1683,7 @@ Zotero.Integration.Session.prototype.getBibliographyData = function() { for(id in this.customBibliographyText)]; if(bibliographyData.uncited || bibliographyData.custom) { - return Zotero.JSON.serialize(bibliographyData); + return JSON.stringify(bibliographyData); } else { return ""; // nothing } @@ -1729,7 +1729,7 @@ Zotero.Integration.Session.prototype.editCitation = function(index, noteIndex, c } // create object to hold citation - io.citation = (citation ? Zotero.JSON.unserialize(Zotero.JSON.serialize(citation)) : {"citationItems":{}, "properties":{}}); + io.citation = (citation ? JSON.parse(JSON.stringify(citation)) : {"citationItems":{}, "properties":{}}); io.citation.properties.zoteroIndex = parseInt(index, 10); io.citation.properties.noteIndex = parseInt(noteIndex, 10); // assign preview function diff --git a/chrome/content/zotero/xpcom/translation/translator.js b/chrome/content/zotero/xpcom/translation/translator.js index c931f507f9..c138ffb999 100644 --- a/chrome/content/zotero/xpcom/translation/translator.js +++ b/chrome/content/zotero/xpcom/translation/translator.js @@ -434,7 +434,7 @@ Zotero.Translator = function(file, json, code) { var fStream, cStream; if(json) { - var info = Zotero.JSON.unserialize(json); + var info = JSON.parse(json); } else { fStream = Components.classes["@mozilla.org/network/file-input-stream;1"]. createInstance(Components.interfaces.nsIFileInputStream); @@ -467,7 +467,7 @@ Zotero.Translator = function(file, json, code) { this.metadataString = m[0]; try { - var info = Zotero.JSON.unserialize(this.metadataString); + var info = JSON.parse(this.metadataString); } catch(e) { this.logError("Invalid or missing translator metadata JSON object in " + file.leafName); fStream.close(); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 1a4f7baced..05f4b826e2 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -421,7 +421,7 @@ if(appInfo.platformVersion[0] >= 2) { // DEBUG: handle more startup errors else { throw (e); - return; + return false; } } @@ -449,7 +449,7 @@ if(appInfo.platformVersion[0] >= 2) { while(_waitingForInitComplete && !Zotero.closing) { Zotero.mainThread.processNextEvent(true); } - if(Zotero.closing) return; + if(Zotero.closing) return false; } Zotero.Repo.init(); @@ -508,7 +508,7 @@ if(appInfo.platformVersion[0] >= 2) { } } - if(!_initDB()) return; + if(!_initDB()) return false; // Add notifier queue callbacks to the DB layer Zotero.DB.addCallback('begin', Zotero.Notifier.begin); @@ -2375,13 +2375,13 @@ Zotero.WebProgressFinishListener = function(onFinish) { * Saves or loads JSON objects. */ Zotero.JSON = new function() { - var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON); - this.serialize = function(arg) { - return nativeJSON.encode(arg); + Zotero.debug("WARNING: Zotero.JSON.serialize() is deprecated; use JSON.stringify()"); + return JSON.stringify(arg); } this.unserialize = function(arg) { - return nativeJSON.decode(arg); + Zotero.debug("WARNING: Zotero.JSON.unserialize() is deprecated; use JSON.parse()"); + return JSON.parse(arg); } }