File tree Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,23 @@ test( "direct usage", function() {
120
120
equals ( instance . getterSetterVal , 30 , "getter/setter can act as setter" ) ;
121
121
} ) ;
122
122
123
+ test ( "error handling" , function ( ) {
124
+ expect ( 2 ) ;
125
+ var error = $ . error ;
126
+ $ . widget ( "ui.testWidget" , { } ) ;
127
+ $ . error = function ( msg ) {
128
+ equal ( msg , "cannot call methods on testWidget prior to initialization; " +
129
+ "attempted to call method 'missing'" , "method call before init" ) ;
130
+ } ;
131
+ $ ( "<div>" ) . testWidget ( "missing" ) ;
132
+ $ . error = function ( msg ) {
133
+ equal ( msg , "no such method 'missing' for testWidget widget instance" ,
134
+ "invalid method call on widget instance" ) ;
135
+ } ;
136
+ $ ( "<div>" ) . testWidget ( ) . testWidget ( "missing" ) ;
137
+ $ . error = error ;
138
+ } ) ;
139
+
123
140
test ( "merge multiple option arguments" , function ( ) {
124
141
expect ( 1 ) ;
125
142
$ . widget ( "ui.testWidget" , {
Original file line number Diff line number Diff line change @@ -96,19 +96,15 @@ $.widget.bridge = function( name, object ) {
96
96
97
97
if ( isMethodCall ) {
98
98
this . each ( function ( ) {
99
- var instance = $ . data ( this , name ) ,
100
- methodValue = instance && $ . isFunction ( instance [ options ] ) ?
101
- instance [ options ] . apply ( instance , args ) :
102
- instance ;
103
- // TODO: add this back in 1.9 and use $.error() (see #5972)
104
- // if ( !instance ) {
105
- // throw "cannot call methods on " + name + " prior to initialization; " +
106
- // "attempted to call method '" + options + "'";
107
- // }
108
- // if ( !$.isFunction( instance[options] ) ) {
109
- // throw "no such method '" + options + "' for " + name + " widget instance";
110
- // }
111
- // var methodValue = instance[ options ].apply( instance, args );
99
+ var instance = $ . data ( this , name ) ;
100
+ if ( ! instance ) {
101
+ return $ . error ( "cannot call methods on " + name + " prior to initialization; " +
102
+ "attempted to call method '" + options + "'" ) ;
103
+ }
104
+ if ( ! $ . isFunction ( instance [ options ] ) ) {
105
+ return $ . error ( "no such method '" + options + "' for " + name + " widget instance" ) ;
106
+ }
107
+ var methodValue = instance [ options ] . apply ( instance , args ) ;
112
108
if ( methodValue !== instance && methodValue !== undefined ) {
113
109
returnValue = methodValue ;
114
110
return false ;
You can’t perform that action at this time.
0 commit comments