- 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
This commit is contained in:
Simon Kornblith 2011-07-11 22:37:37 +00:00
parent 4783051f4e
commit ffd671ce7b
4 changed files with 18 additions and 18 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -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();

View file

@ -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);
}
}