Bug 1186696. Event handlers on JS-implemented webidl interfaces should have the same behavior as other event handlers: accept all values, convert non-objects to null. r=smaug

This commit is contained in:
Boris Zbarsky 2015-07-28 12:35:39 -04:00
parent 6e916540f5
commit 89016f2d0c
6 changed files with 71 additions and 3 deletions

View File

@ -14305,6 +14305,9 @@ class CallbackMember(CGNativeMember):
self.descriptorProvider,
exceptionCode=self.exceptionCode,
isCallbackReturnValue=isCallbackReturnValue,
# Allow returning a callback type that
# allows non-callable objects.
allowTreatNonCallableAsNull=True,
sourceDescription=sourceDescription),
replacements)
assignRetval = string.Template(

View File

@ -156,6 +156,13 @@ TestInterfaceJS.prototype = {
});
},
get onsomething() {
return this.__DOM_IMPL__.getEventHandler("onsomething");
},
set onsomething(val) {
this.__DOM_IMPL__.setEventHandler("onsomething", val);
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestInterfaceJS])

View File

@ -64,4 +64,6 @@ skip-if = debug == false
[test_unforgeablesonexpando.html]
[test_crossOriginWindowSymbolAccess.html]
[test_bug1123516_maplikesetlike.html]
skip-if = debug == false
skip-if = debug == false
[test_jsimplemented_eventhandler.html]
skip-if = debug == false

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1186696
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1186696</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 1186696 **/
SimpleTest.waitForExplicitFinish();
function doTest() {
var values = [ function() {}, 5, null, undefined, "some string", {} ];
while (values.length != 0) {
var value = values.pop();
var t = new TestInterfaceJS();
t.onsomething = value;
var gottenValue = t.onsomething;
if (typeof value == "object" || typeof value == "function") {
is(gottenValue, value, "Should get back the object-or-null we put in");
} else {
is(gottenValue, null, "Should get back null");
}
}
SimpleTest.finish();
}
SpecialPowers.pushPrefEnv({set: [['dom.expose_test_interfaces', true]]},
doTest);
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1186696">Mozilla Bug 1186696</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View File

@ -32,8 +32,14 @@ interface EventTarget {
// Mozilla extensions for use by JS-implemented event targets to
// implement on* properties.
partial interface EventTarget {
// The use of [TreatNonCallableAsNull] here is a bit of a hack: it just makes
// the codegen check whether the type involved is either
// [TreatNonCallableAsNull] or [TreatNonObjectAsNull] and if it is handle it
// accordingly. In particular, it will NOT actually treat a non-null
// non-callable object as null here.
[ChromeOnly, Throws]
void setEventHandler(DOMString type, EventHandler handler);
void setEventHandler(DOMString type,
[TreatNonCallableAsNull] EventHandler handler);
[ChromeOnly]
EventHandler getEventHandler(DOMString type);

View File

@ -12,7 +12,7 @@ dictionary TestInterfaceJSUnionableDictionary {
[JSImplementation="@mozilla.org/dom/test-interface-js;1",
Pref="dom.expose_test_interfaces",
Constructor(optional any anyArg, optional object objectArg, optional TestInterfaceJSDictionary dictionaryArg)]
interface TestInterfaceJS {
interface TestInterfaceJS : EventTarget {
readonly attribute any anyArg;
readonly attribute object objectArg;
[Cached, Pure] readonly attribute TestInterfaceJSDictionary dictionaryArg;
@ -78,4 +78,7 @@ interface TestInterfaceJS {
Promise<void> testPromiseWithThrowingChromeThenable();
Promise<void> testPromiseWithThrowingContentThenable(object thenable);
Promise<void> testPromiseWithDOMExceptionThrowingThenable();
// Event handler tests
attribute EventHandler onsomething;
};