Fix document wrapping issues in translation-server

Fixes https://github.com/zotero/translation-server/issues/26
This commit is contained in:
Dan Stillman 2016-08-28 03:27:38 -04:00
parent 649ce58726
commit ad45c3e51a
2 changed files with 22 additions and 14 deletions

View file

@ -242,10 +242,9 @@ Zotero.Translate.Sandbox = {
};
safeTranslator.setDocument = function(arg) {
if (Zotero.isFx && !Zotero.isBookmarklet) {
if (arg.wrappedJSObject && arg.wrappedJSObject.__wrappedObject) {
arg = arg.wrappedJSObject.__wrappedObject;
}
return translation.setDocument(new XPCNativeWrapper(arg));
return translation.setDocument(
Zotero.Translate.DOMWrapper.wrap(arg, arg.__wrapperOverrides)
);
} else {
return translation.setDocument(arg);
}
@ -1774,11 +1773,15 @@ Zotero.Translate.Web.prototype._getSandboxLocation = function() {
* Pass document and location to detect* and do* functions
*/
Zotero.Translate.Web.prototype._getParameters = function() {
if (Zotero.Translate.DOMWrapper &&
Zotero.Translate.DOMWrapper.isWrapped(this.document) &&
Zotero.platformMajorVersion >= 35) {
return [this._sandboxManager.wrap(Zotero.Translate.DOMWrapper.unwrap(this.document), null,
this.document.__wrapperOverrides), this.location];
if (Zotero.Translate.DOMWrapper && Zotero.Translate.DOMWrapper.isWrapped(this.document)) {
return [
this._sandboxManager.wrap(
Zotero.Translate.DOMWrapper.unwrap(this.document),
null,
this.document.__wrapperOverrides
),
this.location
];
} else {
return [this.document, this.location];
}

View file

@ -222,7 +222,11 @@ Zotero.Translate.DOMWrapper = new function() {
get(target, prop, receiver) {
if (prop === "__wrappedObject")
return this.wrappedObject;
if (prop == "__wrapperOverrides") {
return this.overrides;
}
if (prop in this.overrides) {
return this.overrides[prop];
}
@ -256,11 +260,11 @@ Zotero.Translate.DOMWrapper = new function() {
return { value: this.wrappedObject, writeable: true,
configurable: true, enumerable: false };
}
if (name == "__wrapperOverrides") {
if (prop == "__wrapperOverrides") {
return { value: this.overrides, writeable: false, configurable: false, enumerable: false };
}
// Handle __exposedProps__.
if (name == "__exposedProps__") {
if (prop == "__exposedProps__") {
return { value: ExposedPropsWaiver, writable: false, configurable: false, enumerable: false };
}
@ -426,6 +430,7 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) {
};
wrappedRet.get = function(x, prop, receiver) {
if (prop === "__wrappedObject") return target;
if (prop === "__wrapperOverrides") return overrides;
if (prop === "__wrappingManager") return me;
var y = overrides.hasOwnProperty(prop) ? overrides[prop] : target[prop];
if (y === null || (typeof y !== "object" && typeof y !== "function")) return y;
@ -607,8 +612,8 @@ Zotero.Translate.ChildSandboxManager.prototype = {
"_makeContentForwarder":function(f) {
return this._parent._makeContentForwarder(f);
},
"wrap":function(x) {
return this._parent.wrap(x);
"wrap": function (target, x, overrides) {
return this._parent.wrap(target, x, overrides);
}
}