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

View file

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