Slightly cleaner fix for #504

This commit is contained in:
Simon Kornblith 2014-06-21 13:16:13 -04:00
parent 28dbfabb4f
commit 76e8ea835f
2 changed files with 15 additions and 9 deletions

View file

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

View file

@ -485,25 +485,32 @@ Zotero.Translate.SandboxManager.prototype = {
}
},
"_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
* @param {Object} obj
* @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);