Fix for bug 827546 (|non editable element|.QueryInterface(Components.interfaces.nsIDOMNSEditableElement) does not throw anymore) - throw on QI failure. r=bz.

This commit is contained in:
Peter Van der Beken 2013-01-14 11:29:49 +01:00
parent 806c76d9f1
commit 0bf1bbaec2
3 changed files with 48 additions and 1 deletions

View File

@ -592,7 +592,12 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
return WrapObject(cx, origObj, ci, &NS_GET_IID(nsIClassInfo), vp);
}
// Lie, otherwise we need to check classinfo or QI
nsCOMPtr<nsISupports> unused;
nsresult rv = native->QueryInterface(*iid->GetID(), getter_AddRefs(unused));
if (NS_FAILED(rv)) {
return Throw<true>(cx, rv);
}
*vp = thisv;
return true;
}

View File

@ -65,6 +65,7 @@ MOCHITEST_FILES := \
test_bug742191.html \
test_namedNoIndexed.html \
test_bug759621.html \
test_queryInterface.html \
$(NULL)
MOCHITEST_CHROME_FILES = \

View File

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=827546
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 827546</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 827546 **/
var notEditable = document.createElement("div");
var thrown;
try {
thrown = false;
SpecialPowers.do_QueryInterface(notEditable, "nsIDOMNSEditableElement");
} catch (e) {
thrown = true;
}
ok(thrown,
"QI to nsIDOMNSEditableElement on a non-editable element should fail");
var editable = document.createElement("input");
ok(SpecialPowers.do_QueryInterface(editable, "nsIDOMNSEditableElement"),
"Editable element needs to support QI to nsIDOMNSEditableElement");
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=827546">Mozilla Bug 827546</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>