From d0441d334e79e99e11e166a295d16cec81b8883d Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 6 Jun 2010 03:11:24 +0000 Subject: [PATCH] commit Rintze's changes to translate.js for Scaffold compatibility --- chrome/content/zotero/xpcom/translate.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/translate.js b/chrome/content/zotero/xpcom/translate.js index 380b5d677..2a0d61009 100644 --- a/chrome/content/zotero/xpcom/translate.js +++ b/chrome/content/zotero/xpcom/translate.js @@ -179,8 +179,15 @@ Zotero.Translators = new function() { var destFile = Zotero.getTranslatorsDirectory(); destFile.append(fileName); - var nsIJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); - var metadataJSON = nsIJSON.encode(metadata); + var metadataJSON; + + // JSON.stringify (FF 3.5.4 and up) has the benefit of indenting JSON + if (typeof JSON != "undefined" && 'function' == typeof JSON.stringify) { + metadataJSON = JSON.stringify(metadata,null,8); + } else { + var nsIJSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); + metadataJSON = nsIJSON.encode(metadata); + } var str = metadataJSON + "\n\n" + code; @@ -813,7 +820,11 @@ Zotero.Translate.prototype._parseCode = function(translator) { Components.utils.evalInSandbox("var translatorInfo = "+translator.code, this._sandbox); return true; } catch(e) { - translator.logError(e.toString()); + if('function' == typeof translator.logError) { + translator.logError(e.toString()); + } else { + Components.utils.reportError(e); + } this._debug(e+' in parsing code for '+translator.label, 3); return false; } @@ -1102,7 +1113,7 @@ Zotero.Translate.prototype._translationComplete = function(returnValue, error) { if(!returnValue) { // report error to console - if(this.translator[0]) { + if(typeof this.translator[0] != "undefined" && 'function' == typeof this.translator[0].logError) { this.translator[0].logError(error.toString(), "exception"); } else { Components.utils.reportError(error);