Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 665280: Content script using XPathResult constants fails r=myk
Browse files Browse the repository at this point in the history
  • Loading branch information
ochameau committed Jun 28, 2011
1 parent ab15440 commit 3ef0d9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/api-utils/lib/content/content-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 19 additions & 0 deletions packages/api-utils/tests/test-content-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down

0 comments on commit 3ef0d9b

Please # to comment.