Revert sandboxing changes

This commit is contained in:
Simon Kornblith 2012-10-09 18:29:06 -04:00
parent 0c2b8e6016
commit 1ad5b9fd63

View file

@ -456,34 +456,22 @@ Zotero.Translate.SandboxManager.prototype = {
*/ */
"importObject":function(object, passAsFirstArgument, attachTo) { "importObject":function(object, passAsFirstArgument, attachTo) {
if(!attachTo) attachTo = this.sandbox.Zotero; if(!attachTo) attachTo = this.sandbox.Zotero;
var me = this; var newExposedProps = false;
if("__exposedProps__" in object) { if(!object.__exposedProps__) newExposedProps = {};
var newExposedProps = false, for(var key in (newExposedProps ? object : object.__exposedProps__)) {
exposedProps = object.__exposedProps__,
iterate = object.__exposedProps__;
} else {
var newExposedProps = true,
exposedProps = {},
iterate = object;
}
for(var key in iterate) {
let localKey = key; let localKey = key;
if(newExposedProps) exposedProps[localKey] = "r"; if(newExposedProps) newExposedProps[localKey] = "r";
var type = typeof object[localKey]; var type = typeof object[localKey];
var isFunction = type === "function"; var isFunction = type === "function";
var isObject = typeof object[localKey] === "object"; var isObject = typeof object[localKey] === "object";
if(isFunction || isObject) { if(isFunction || isObject) {
if(isFunction) { if(isFunction) {
attachTo[localKey] = function() { if(passAsFirstArgument) {
var args = Array.prototype.slice.apply(arguments); attachTo[localKey] = object[localKey].bind(object, passAsFirstArgument);
if(passAsFirstArgument) args.unshift(passAsFirstArgument); } else {
var retval = object[localKey].apply(object, args); attachTo[localKey] = object[localKey].bind(object);
if(typeof retval !== "object" || retval === null }
|| "__exposedProps__" in retval) return retval;
return me._copyObject(retval);
};
} else { } else {
attachTo[localKey] = {}; attachTo[localKey] = {};
} }
@ -497,40 +485,11 @@ Zotero.Translate.SandboxManager.prototype = {
} }
} }
attachTo.__exposedProps__ = exposedProps; if(newExposedProps) {
}, attachTo.__exposedProps__ = newExposedProps;
} else {
/** attachTo.__exposedProps__ = object.__exposedProps__;
* Copies a JavaScript object to this sandbox
* @param {Object} obj
* @return {Object}
*/
"_copyObject":function(obj, wm) {
var str = Object.prototype.toString.call(obj);
if(!obj.hasOwnProperty || (str !== "[object Object]" && str !== "[object Array]")) {
return obj;
} }
Zotero.debug(str);
if(!wm) wm = new WeakMap();
var obj2 = (obj instanceof Array ? new this.sandbox.Array() : new this.sandbox.Object());
obj2.__proto__ = obj.__proto__;
for(var i in obj) {
if(!obj.hasOwnProperty(i)) continue;
var prop1 = obj[i];
if(typeof prop1 === "object" && prop1 !== null) {
var prop2 = wm.get(prop1);
if(prop2 === undefined) {
prop2 = this._copyObject(prop1, wm);
wm.set(prop1, prop2);
}
obj2[i] = prop2;
} else {
obj2[i] = prop1;
}
}
return obj2;
} }
} }