diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index a098624ff1..38976250f0 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -385,9 +385,17 @@ Zotero.Translate.Sandbox = { if(sandbox) return sandbox; } }; - - // TODO security is not super-tight here, as someone could pass something into arg - // that gets evaluated in the wrong scope in Fx < 4. We should wrap this. + + if(Zotero.isFx && Zotero.platformMajorVersion >= 33) { + for(var i in safeTranslator) { + if (typeof(safeTranslator[i]) === "function") { + let func = safeTranslator[i]; + safeTranslator[i] = translate._sandboxManager._makeContentForwarder(function() { + func.apply(safeTranslator, this.args.wrappedJSObject); + }); + } + } + } return safeTranslator; }, @@ -434,7 +442,7 @@ Zotero.Translate.Sandbox = { */ "selectItems":function(translate, items, callback) { function transferObject(obj) { - return Zotero.isFx ? translate._sandboxManager.sandbox.JSON.parse(JSON.stringify(obj)) : obj; + return Zotero.isFx ? translate._sandboxManager._copyObject(obj) : obj; } if(Zotero.Utilities.isEmpty(items)) { diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js index bff1f2d002..151a4e07bd 100644 --- a/chrome/content/zotero/xpcom/translation/translate_firefox.js +++ b/chrome/content/zotero/xpcom/translation/translate_firefox.js @@ -425,6 +425,9 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) { }; this.sandbox.XMLSerializer.__exposedProps__ = {"prototype":"r"}; this.sandbox.XMLSerializer.prototype = {"__exposedProps__":{"serializeToString":"r"}}; + + var expr = "(function(x) { return function() { this.args = arguments; return x.apply(this); }.bind({}); })"; + this._makeContentForwarder = Components.utils.evalInSandbox(expr, this.sandbox); } Zotero.Translate.SandboxManager.prototype = { @@ -447,26 +450,36 @@ Zotero.Translate.SandboxManager.prototype = { "importObject":function(object, passAsFirstArgument, attachTo) { if(!attachTo) attachTo = this.sandbox.Zotero; if(attachTo.wrappedJSObject) attachTo = attachTo.wrappedJSObject; - var newExposedProps = false, - sandbox = this.sandbox, - me = this; - if(!object.__exposedProps__) newExposedProps = {}; - for(var key in (newExposedProps ? object : object.__exposedProps__)) { + var sandbox = this.sandbox, me = this; + for(var key in (object.__exposedProps__ ? object.__exposedProps__ : object)) { let localKey = key; - if(newExposedProps) newExposedProps[localKey] = "r"; var type = typeof object[localKey]; var isFunction = type === "function"; var isObject = typeof object[localKey] === "object"; if(isFunction || isObject) { if(isFunction) { - attachTo[localKey] = function() { - var args = Array.prototype.slice.apply(arguments); - if(passAsFirstArgument) args.unshift(passAsFirstArgument); - return me._copyObject(object[localKey].apply(object, args)); - }; + if (Zotero.platformMajorVersion >= 33) { + attachTo[localKey] = this._makeContentForwarder(function() { + var args = Array.prototype.slice.apply(this.args.wrappedJSObject); + for(var i = 0; i {ec8030f7-c20a-464f-9b0e-13a3a9e97384} - 24.0 - 32.* + 31.0 + 33.* diff --git a/update.rdf b/update.rdf index 0258aeb4c7..d86449b4bd 100644 --- a/update.rdf +++ b/update.rdf @@ -11,8 +11,8 @@ {ec8030f7-c20a-464f-9b0e-13a3a9e97384} - 24.0 - 32.* + 31.0 + 33.* http://download.zotero.org/extension/zotero.xpi sha1: