mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Widget: modified widget to throw exception on attempt to call private methods. Fixed #6947 - Attempt to access private member of widget returns jQuery object
This commit is contained in:
parent
ed531ef0d3
commit
c94ec23b26
@ -166,9 +166,11 @@ test( "direct usage", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test( "error handling", function() {
|
test( "error handling", function() {
|
||||||
expect( 2 );
|
expect( 3 );
|
||||||
var error = $.error;
|
var error = $.error;
|
||||||
$.widget( "ui.testWidget", {} );
|
$.widget( "ui.testWidget", {
|
||||||
|
_privateMethod: function () {}
|
||||||
|
});
|
||||||
$.error = function( msg ) {
|
$.error = function( msg ) {
|
||||||
equal( msg, "cannot call methods on testWidget prior to initialization; " +
|
equal( msg, "cannot call methods on testWidget prior to initialization; " +
|
||||||
"attempted to call method 'missing'", "method call before init" );
|
"attempted to call method 'missing'", "method call before init" );
|
||||||
@ -179,6 +181,11 @@ test( "error handling", function() {
|
|||||||
"invalid method call on widget instance" );
|
"invalid method call on widget instance" );
|
||||||
};
|
};
|
||||||
$( "<div>" ).testWidget().testWidget( "missing" );
|
$( "<div>" ).testWidget().testWidget( "missing" );
|
||||||
|
$.error = function ( msg ) {
|
||||||
|
equal( msg, "no such method '_privateMethod' for testWidget widget instance",
|
||||||
|
"invalid method call on widget instance" );
|
||||||
|
};
|
||||||
|
$( "<div>" ).testWidget().testWidget( "_privateMethod" );
|
||||||
$.error = error;
|
$.error = error;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
7
ui/jquery.ui.widget.js
vendored
7
ui/jquery.ui.widget.js
vendored
@ -104,11 +104,6 @@ $.widget.bridge = function( name, object ) {
|
|||||||
$.extend.apply( null, [ true, options ].concat(args) ) :
|
$.extend.apply( null, [ true, options ].concat(args) ) :
|
||||||
options;
|
options;
|
||||||
|
|
||||||
// prevent calls to internal methods
|
|
||||||
if ( isMethodCall && options.charAt( 0 ) === "_" ) {
|
|
||||||
return returnValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( isMethodCall ) {
|
if ( isMethodCall ) {
|
||||||
this.each(function() {
|
this.each(function() {
|
||||||
var instance = $.data( this, name );
|
var instance = $.data( this, name );
|
||||||
@ -116,7 +111,7 @@ $.widget.bridge = function( name, object ) {
|
|||||||
return $.error( "cannot call methods on " + name + " prior to initialization; " +
|
return $.error( "cannot call methods on " + name + " prior to initialization; " +
|
||||||
"attempted to call method '" + options + "'" );
|
"attempted to call method '" + options + "'" );
|
||||||
}
|
}
|
||||||
if ( !$.isFunction( instance[options] ) ) {
|
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
|
||||||
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
|
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
|
||||||
}
|
}
|
||||||
var methodValue = instance[ options ].apply( instance, args );
|
var methodValue = instance[ options ].apply( instance, args );
|
||||||
|
Loading…
Reference in New Issue
Block a user