Skip to main content

Search and Top Navigation

#6947 closed feature (fixed)

Opened February 05, 2011 10:24AM UTC

Closed February 16, 2011 01:11PM UTC

Attempt to access private member of widget returns jQuery object

Reported by: wkmanire Owned by:
Priority: major Milestone: 1.9.0
Component: ui.widget Version: 1.8.9
Keywords: Cc:
Blocked by: Blocking:
Description

I'm submitting this as a bug, but I think this could be classified as an enhancement.

ui.widget's bridge method protects against calling pseudo-private methods that start with an underscore by immediately returning "this". In my opinion, it should instead throw an exception to inform the developer that the widget is not being used properly. I can see the potential for a hard to detect bug going into production code as a result of the current behavior.

// starting on line 73 of jquery.ui.widget.js
var isMethodCall = typeof options === "string",
  args = slice.call( arguments, 1 ),
  returnValue = this;

// then on line 83 returnValue remains "this"

// prevent calls to internal methods
if ( isMethodCall && options.charAt( 0 ) === "_" ) {
  // perhaps instead at this point $.error('jquery.ui.widget: Attempt to access private member ' + options);
  return returnValue;
}

Attachments (0)
Change History (5)

Changed February 06, 2011 12:22AM UTC by scottgonzalez comment:1

priority: minormajor
status: newopen
type: bugfeature

We should treat this the same as non-existant methods. See #5972 for a related change.

Changed February 06, 2011 06:39AM UTC by wkmanire comment:2

I just submitted a pull request for this. I goofed up and accidently copied another unit test on my first commit so there are actually two commits. The first commit has the fix, a unit test, and an erroneous copy paste. The second removes the erroneous copy paste.

1st: https://github.com/wkmanire/jquery-ui/tree/f331db7e7d57416b65954c88a6c8e7c007313f8f

2nd: https://github.com/wkmanire/jquery-ui/commit/42068d5b1e6ea89f2f10ae5dcb1fd1e2b4b9cc6a

Changed February 07, 2011 06:27PM UTC by wkmanire comment:3

I took another stab at this according to scott.gonzalez's direction. Should I submit another pull request? I read the guidelines but I'm still not completely familiar with this process.

Here is the commit:

https://github.com/wkmanire/jquery-ui/commit/ddb24adbe9a2648083614fcf1dbfd6880a54e93b

Changed February 16, 2011 08:50AM UTC by wkmanire comment:4

Next pull request is ready. Attempts to execute private methods are treated the same as missing methods. Unit test code integrated into errors test.

Here is the commit for it: https://github.com/wkmanire/jquery-ui/commit/c94ec23b263464af3dfa4533eff45fc0d6fef954

Changed February 16, 2011 01:11PM UTC by William Kevin Manire comment:5

resolution: → fixed
status: openclosed

Widget: modified widget to throw exception on attempt to call private methods. Fixed #6947 - Attempt to access private member of widget returns jQuery object

Changeset: c94ec23b263464af3dfa4533eff45fc0d6fef954