Skip to content

Commit 1e28040

Browse files
committed
Widget: Throw errors when calling non-existent methods or methods on uninistantiated widgets. Fixes #5972 - Widget: Throw error for non-existent method calls.
1 parent 52a052b commit 1e28040

File tree

6 files changed

+12
-38
lines changed

6 files changed

+12
-38
lines changed

tests/unit/accordion/accordion_methods.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ test("init", function() {
1818
$('<div></div>').appendTo('body').remove().accordion().remove();
1919
ok(true, '.accordion() called on disconnected DOMElement - removed');
2020

21-
$('<div></div>').accordion().accordion("foo").remove();
22-
ok(true, 'arbitrary method called after init');
23-
2421
var el = $('<div></div>').accordion();
2522
var foo = el.accordion("option", "foo");
2623
el.remove();

tests/unit/dialog/dialog_core.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,6 @@ function margin(el, side) {
8888

8989
module("dialog: core");
9090

91-
test("element types", function() {
92-
var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form'
93-
+ ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr'
94-
+ ',acronym,code,samp,kbd,var,img,object,hr'
95-
+ ',input,button,label,select,iframe').split(',');
96-
97-
$.each(typeNames, function(i) {
98-
var typeName = typeNames[i];
99-
el = $(document.createElement(typeName)).appendTo('body');
100-
(typeName == 'table' && el.append("<tr><td>content</td></tr>"));
101-
el.dialog();
102-
ok(true, '$("&lt;' + typeName + '/&gt").dialog()');
103-
el.dialog("destroy");
104-
el.remove();
105-
});
106-
});
107-
10891
test("title id", function() {
10992
expect(3);
11093

tests/unit/dialog/dialog_methods.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module("dialog: methods", {
1010
});
1111

1212
test("init", function() {
13-
expect(7);
13+
expect(6);
1414

1515
$("<div></div>").appendTo('body').dialog().remove();
1616
ok(true, '.dialog() called on element');
@@ -24,9 +24,6 @@ test("init", function() {
2424
$('<div></div>').appendTo('body').remove().dialog().remove();
2525
ok(true, '.dialog() called on disconnected DOMElement - removed');
2626

27-
$('<div></div>').dialog().dialog("foo").remove();
28-
ok(true, 'arbitrary method called after init');
29-
3027
el = $('<div></div>').dialog();
3128
var foo = el.dialog("option", "foo");
3229
el.remove();
@@ -46,9 +43,6 @@ test("destroy", function() {
4643
$('<div></div>').dialog().dialog("destroy").remove();
4744
ok(true, '.dialog("destroy") called on disconnected DOMElement');
4845

49-
$('<div></div>').dialog().dialog("destroy").dialog("foo").remove();
50-
ok(true, 'arbitrary method called after destroy');
51-
5246
var expected = $('<div></div>').dialog(),
5347
actual = expected.dialog('destroy');
5448
equals(actual, expected, 'destroy is chainable');

tests/unit/slider/slider.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
1616
<script type="text/javascript" src="../../../external/qunit.js"></script>
1717
<script type="text/javascript" src="../../jquery.simulate.js"></script>
18+
<script type="text/javascript" src="../testsuite.js"></script>
1819

1920
<script type="text/javascript" src="slider_core.js"></script>
2021
<script type="text/javascript" src="slider_defaults.js"></script>

tests/unit/slider/slider_methods.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module("slider: methods");
77

88
test("init", function() {
9-
expect(6);
9+
expect(5);
1010

1111
$("<div></div>").appendTo('body').slider().remove();
1212
ok(true, '.slider() called on element');
@@ -17,9 +17,6 @@ test("init", function() {
1717
$('<div></div>').slider().remove();
1818
ok(true, '.slider() called on disconnected DOMElement');
1919

20-
$('<div></div>').slider().slider("foo").remove();
21-
ok(true, 'arbitrary method called after init');
22-
2320
var el = $('<div></div>').slider();
2421
var foo = el.slider("option", "foo");
2522
el.remove();
@@ -39,9 +36,6 @@ test("destroy", function() {
3936
$('<div></div>').appendTo('body').remove().slider().slider("destroy").remove();
4037
ok(true, '.slider("destroy") called on disconnected DOMElement');
4138

42-
$('<div></div>').slider().slider("destroy").slider("foo").remove();
43-
ok(true, 'arbitrary method called after destroy');
44-
4539
var expected = $('<div></div>').slider(),
4640
actual = expected.slider('destroy');
4741
equals(actual, expected, 'destroy is chainable');

ui/jquery.ui.widget.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ $.widget.bridge = function( name, object ) {
8686

8787
if ( isMethodCall ) {
8888
this.each(function() {
89-
var instance = $.data( this, name ),
90-
methodValue = instance && $.isFunction( instance[options] ) ?
91-
instance[ options ].apply( instance, args ) :
92-
instance;
89+
var instance = $.data( this, name );
90+
if ( !instance ) {
91+
throw "cannot call methods on " + name + " prior to initialization; " +
92+
"attempted to call method '" + options + "'";
93+
}
94+
if ( !$.isFunction( instance[options] ) ) {
95+
throw "no such method '" + options + "' for " + name + " widget instance";
96+
}
97+
var methodValue = instance[ options ].apply( instance, args );
9398
if ( methodValue !== instance && methodValue !== undefined ) {
9499
returnValue = methodValue;
95100
return false;

0 commit comments

Comments
 (0)