commit 250e19364566d05aaab8dfe8734aecea2e05879d
parent 38e25d4756351cb7ffe5956faea98b02f2c8c8dd
Author: Simon Kornblith <simon@simonster.com>
Date: Fri, 17 Jun 2011 07:01:12 +0000
Tweaks to support translation in connector (detection works now, but processDocuments() is still not implemented and no import/export/search translators are Safari/Chrome-compatible, so I haven't tested anything)
Diffstat:
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/chrome/content/zotero/xpcom/connector/translator.js b/chrome/content/zotero/xpcom/connector/translator.js
@@ -295,10 +295,13 @@ Zotero.Translator = function(info) {
}
if(info.code) {
- this.code = info.code;
+ this.code = preprocessCode(info.code);
}
}
+/**
+ * Retrieves code for this translator
+ */
Zotero.Translator.prototype.getCode = function(callback) {
if(this.code) {
callback(true);
@@ -309,7 +312,7 @@ Zotero.Translator.prototype.getCode = function(callback) {
if(!code) {
callback(false);
} else {
- me.code = code;
+ me.code = me.preprocessCode(code);
callback(true);
}
}
@@ -317,6 +320,20 @@ Zotero.Translator.prototype.getCode = function(callback) {
}
}
+/**
+ * Preprocesses code for this translator
+ */
+Zotero.Translator.prototype.preprocessCode = function(code) {
+ if(!Zotero.isFx) {
+ const foreach = /^(\s*)for each\s*\((var )?([^ ]+) in (.*?)\)(\s*){/m;
+ code = code.replace(foreach, "$1var $3_zForEachSubject = $4; "+
+ "for(var $3_zForEachIndex in $4_zForEachSubject)$5{ "+
+ "$2$3 = $3_zForEachSubject[$3_zForEachIndex];", code);
+ Zotero.debug(code);
+ }
+ return code;
+}
+
Zotero.Translator.prototype.__defineGetter__("displayOptions", function() {
return Zotero.Utilities.deepCopy(this._displayOptions);
});
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -744,8 +744,7 @@ Zotero.Translate.Base.prototype = {
}
}
- // TODO maybe this should only be in the web translator
- if(this._waitingForRPC) {
+ if(this._waitingForRPC && this instanceof Zotero.Translate.Web) {
var me = this;
Zotero.Connector.callMethod("detect", {"uri":this.location.toString(),
"cookie":this.document.cookie,
@@ -956,7 +955,8 @@ Zotero.Translate.Base.prototype = {
Zotero.debug("Translate: Parsing code for "+translator.label, 4);
try {
- this._sandboxManager.eval("var translatorInfo = "+translator.code, this._sandbox);
+ this._sandboxManager.eval("var translatorInfo = "+translator.code,
+ ["detect"+this._entryFunctionSuffix, "do"+this._entryFunctionSuffix]);
} catch(e) {
if(translator.logError) {
translator.logError(e.toString());
@@ -1030,7 +1030,10 @@ Zotero.Translate.Base.prototype = {
* @param {Integer} level Log level (1-5, higher numbers are higher priority)
*/
"_debug":function(string, level) {
- if(typeof string === "object") string = new XPCSafeJSObjectWrapper(string);
+ if(typeof string === "object" && Zotero.isFx36) {
+ string = new XPCSafeJSObjectWrapper(string);
+ }
+
if(level !== undefined && typeof level !== "number") {
Zotero.debug("debug: level must be an integer");
return;