@samitouri / QOS-React-2 / commits / b0757c5182

Assert that event listeners are real functions

Fixes #1028.

Ben Alpert committed Feb 12, 2014 at 23:21 UTC b0757c51828fc95ad88505fbebebcfdb3f631994
3 files changed +17 -1
src/browser/dom/components/LinkedValueUtils.js
+4 -1
@@ -19,6 +19,8 @@
19
20 "use strict";
21
22 +var ReactPropTypes = require('ReactPropTypes');
23 +
24 var invariant = require('invariant');
25
26 var hasReadOnlyValue = {
@@ -106,7 +108,8 @@ var LinkedValueUtils = {
108 );
109 }
110 }
109 - }
111 + },
112 + onChange: ReactPropTypes.func
113 }
114 },
115
src/event/EventPluginHub.js
+5
@@ -155,6 +155,11 @@ var EventPluginHub = {
155 ExecutionEnvironment.canUseDOM,
156 'Cannot call putListener() in a non-DOM environment.'
157 );
158 + invariant(
159 + !listener || typeof listener === 'function',
160 + 'Expected %s listener to be a function, instead got type %s',
161 + registrationName, typeof listener
162 + );
163
164 if (__DEV__) {
165 // IE8 has no API for event capturing and the `onScroll` event doesn't
src/event/__tests__/EventPluginHub-test.js
+8
@@ -42,4 +42,12 @@ describe('EventPluginHub', function() {
42 );
43 });
44
45 + it("should prevent non-function listeners", function() {
46 + expect(function() {
47 + EventPluginHub.putListener(1, 'onClick', 'not a function');
48 + }).toThrow(
49 + 'Invariant Violation: Expected onClick listener to be a function, ' +
50 + 'instead got type string'
51 + );
52 + });
53 });