commit 76e8ea835f1024beb52e2f260ddb4b5e12f05d1f
parent 28dbfabb4f6c2d14ac35539a2eb481f6dc0b9a57
Author: Simon Kornblith <simon@simonster.com>
Date: Sat, 21 Jun 2014 13:16:13 -0400
Slightly cleaner fix for #504
Diffstat:
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js
@@ -2242,8 +2242,7 @@ Zotero.Translate.Search.prototype.complete = function(returnValue, error) {
*/
Zotero.Translate.Search.prototype._getParameters = function() {
if(Zotero.isFx) {
- return [this._sandboxManager._copyObject(this.search.wrappedJSObject ?
- this.search.wrappedJSObject : this.search)];
+ return [this._sandboxManager._copyObject(this.search)];
}
return [this.search];
};
diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js
@@ -484,6 +484,17 @@ Zotero.Translate.SandboxManager.prototype = {
attachTo.__exposedProps__ = object.__exposedProps__;
}
},
+
+ "_canCopy":function(obj) {
+ if(typeof obj !== "object" || obj === null) return false;
+ var proto = Object.getPrototypeOf(obj),
+ global = Components.utils.getGlobalForObject(obj);
+ if((proto !== global.Object.prototype && proto !== global.Array.prototype) ||
+ "__exposedProps__" in obj) {
+ return false;
+ }
+ return true;
+ },
/**
* Copies a JavaScript object to this sandbox
@@ -491,19 +502,15 @@ Zotero.Translate.SandboxManager.prototype = {
* @return {Object}
*/
"_copyObject":function(obj, wm) {
- if(typeof obj !== "object" || obj === null
- || (obj.constructor.name !== "Object" && obj.constructor.name !== "Array")
- || "__exposedProps__" in obj) {
- return obj;
- }
+ if(!this._canCopy(obj)) return obj
if(!wm) wm = new WeakMap();
var obj2 = (obj instanceof Array ? this.sandbox.Array() : this.sandbox.Object());
+ if(obj2.wrappedJSObject) obj2 = obj2.wrappedJSObject;
for(var i in obj) {
if(!obj.hasOwnProperty(i)) continue;
var prop1 = obj[i];
- if(typeof prop1 === "object" && prop1 !== null
- && (prop1.constructor.name === "Object" || prop1.constructor.name === "Array")) {
+ if(this._canCopy(prop1)) {
var prop2 = wm.get(prop1);
if(prop2 === undefined) {
prop2 = this._copyObject(prop1, wm);