diff --git a/packages/api-utils/lib/content/content-proxy.js b/packages/api-utils/lib/content/content-proxy.js index d1a37c5ec..db0dc9ec3 100644 --- a/packages/api-utils/lib/content/content-proxy.js +++ b/packages/api-utils/lib/content/content-proxy.js @@ -467,6 +467,17 @@ function handlerMaker(obj) { return getProxyForFunction(f, NativeFunctionWrapper(f)); } + // Fix XPathResult's constants being undefined on XrayWrappers + // these constants are defined here: + // http://mxr.mozilla.org/mozilla-central/source/dom/interfaces/xpath/nsIDOMXPathResult.idl + // and are only numbers. + // See bug 665279 for platform fix progress + if (!o && typeof obj == "object" && name in Ci.nsIDOMXPathResult) { + let value = Ci.nsIDOMXPathResult[name]; + if (typeof value == "number" && value === obj.wrappedJSObject[name]) + return value; + } + // Generic case return wrap(o, obj, name); diff --git a/packages/api-utils/tests/test-content-proxy.js b/packages/api-utils/tests/test-content-proxy.js index 68033abef..788ea00d2 100644 --- a/packages/api-utils/tests/test-content-proxy.js +++ b/packages/api-utils/tests/test-content-proxy.js @@ -196,6 +196,25 @@ exports.testProxy = function (test) { // that may break our proxy code test.assert(wrapped.XMLHttpRequest(), "we are able to instantiate XMLHttpRequest object"); + // Check XPathResult bug with constants being undefined on + // XPCNativeWrapper + let value = + win.XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE; + let xpcXPathResult = XPCNativeWrapper(win).XPathResult; + test.assertEqual(xpcXPathResult.wrappedJSObject. + UNORDERED_NODE_SNAPSHOT_TYPE, + value, + "XPathResult's constants are valid on unwrapped node"); + // The following test will fail if platform is fixed, + // so we will be able to know when to remove the work around. + test.assertEqual(xpcXPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, + undefined, + "XPathResult's constants are undefined on " + + "XPCNativeWrapper (platform bug #)"); + // Check that our work around is working: + test.assertEqual(wrapped.XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, + value, "XPathResult works correctly on Proxies"); + // Verify that inherited prototype function like initEvent // are handled correctly. (e2.type will return an error if it's not the case) let event1 = document.createEvent( 'MouseEvents' );