Bug 763341 - Handle wrappers in new dom binding QI. r=bz

The |ok| parent check goes away because it's ill-conceived. All it's really checking is that proxies are parented to the global, and it's impossible to port to SpecialPowers, because SpecialPowers will think that the proxy is parented to the SpecialPowers global. I don't think this check is very important, so I removed it.
This commit is contained in:
Bobby Holley 2012-06-12 15:44:21 +02:00
parent a2a3845832
commit 50c7e8bc6b
3 changed files with 24 additions and 9 deletions

View File

@ -338,7 +338,13 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
if (thisv == JSVAL_NULL)
return false;
JSObject* obj = JSVAL_TO_OBJECT(thisv);
// Get the object. It might be a security wrapper, in which case we do a checked
// unwrap.
JSObject* origObj = JSVAL_TO_OBJECT(thisv);
JSObject* obj = js::UnwrapObjectChecked(cx, origObj);
if (!obj)
return false;
JSClass* clasp = js::GetObjectJSClass(obj);
if (!IsDOMClass(clasp) ||
!DOMJSClass::FromJSClass(clasp)->mDOMObjectIsISupports) {
@ -371,9 +377,9 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
return Throw<true>(cx, rv);
}
return WrapObject(cx, obj, ci, &NS_GET_IID(nsIClassInfo), vp);
return WrapObject(cx, origObj, ci, &NS_GET_IID(nsIClassInfo), vp);
}
// Lie, otherwise we need to check classinfo or QI
*vp = thisv;
return true;

View File

@ -67,6 +67,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=500931
// Test getter/setter lookup on Xray wrappers.
ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document');
ok(Object.prototype.__lookupGetter__.call(win.document, 'title'), 'found getter on document');
// Test QI on new dom bindings.
var contentXHR = XPCNativeWrapper(win.wrappedJSObject.xhr);
try {
var QIed = contentXHR.QueryInterface(Components.interfaces.nsIClassInfo);
ok(QIed, "Successfully QI-ed on wrapper");
} catch(e) {
ok(false, "Threw while QI-ing on wrapper");
}
}
SimpleTest.waitForExplicitFinish();

View File

@ -3,20 +3,17 @@
<script>
function check_wrapper(ok, wrapper, expected, note) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var utils = SpecialPowers.DOMWindowUtils;
ok(utils.getClassName(wrapper) === expected, note);
}
function check_parent(ok, obj, expected, note) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
var utils = SpecialPowers.DOMWindowUtils;
ok(utils.getParent(obj) === expected, note);
}
function run_test(ok, xpcnw, sjow) {
// both wrappers should point to our window: XOW
check_wrapper(ok, ok, "Proxy", "functions are wrapped properly")
check_parent(ok, ok, window, "ok is parented correctly");
check_wrapper(ok, xpcnw, "Proxy", "XPCNWs are transformed correctly");
check_wrapper(ok, sjow, "Proxy", "SJOWs are transformed correctly");
@ -29,6 +26,8 @@
// defprop2 = {}; disabled because the test doesn't work
}
window.xhr = new XMLHttpRequest();
</script>
</head>
<body>