Fix passing all arrays to sandbox
This commit is contained in:
parent
22c083fe6b
commit
e806925844
1 changed files with 11 additions and 24 deletions
|
@ -149,7 +149,8 @@ Zotero.Translate.SandboxManager.prototype = {
|
|||
*/
|
||||
"importObject":function(object, passAsFirstArgument, attachTo) {
|
||||
if(!attachTo) attachTo = this.sandbox.Zotero;
|
||||
var newExposedProps = false;
|
||||
var newExposedProps = false,
|
||||
sandbox = this.sandbox;
|
||||
if(!object.__exposedProps__) newExposedProps = {};
|
||||
for(var key in (newExposedProps ? object : object.__exposedProps__)) {
|
||||
let localKey = key;
|
||||
|
@ -160,30 +161,16 @@ Zotero.Translate.SandboxManager.prototype = {
|
|||
var isObject = typeof object[localKey] === "object";
|
||||
if(isFunction || isObject) {
|
||||
if(isFunction) {
|
||||
if(Zotero.isFx4) {
|
||||
if(passAsFirstArgument) {
|
||||
attachTo[localKey] = object[localKey].bind(object, passAsFirstArgument);
|
||||
} else {
|
||||
attachTo[localKey] = object[localKey].bind(object);
|
||||
}
|
||||
} else {
|
||||
attachTo[localKey] = function() {
|
||||
if(passAsFirstArgument) {
|
||||
var args = new Array(arguments.length+1);
|
||||
args[0] = passAsFirstArgument;
|
||||
var offset = 1;
|
||||
} else {
|
||||
var args = new Array(arguments.length);
|
||||
var offset = 0;
|
||||
var args = Array.prototype.slice.apply(arguments);
|
||||
if(passAsFirstArgument) args.unshift(passAsFirstArgument);
|
||||
var out = object[localKey].apply(object, args);
|
||||
if(out instanceof Array) {
|
||||
// Copy to sandbox
|
||||
out = sandbox.Array.prototype.slice.apply(out);
|
||||
}
|
||||
|
||||
for(var i=0, nArgs=arguments.length; i<nArgs; i++) {
|
||||
args[i+offset] = arguments[i];
|
||||
}
|
||||
|
||||
return object[localKey].apply(object, args);
|
||||
return out;
|
||||
};
|
||||
}
|
||||
} else {
|
||||
attachTo[localKey] = {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue