-
8 Feb 2013 6:19 AM #1
getPlugin fails if plugins is not declared as an array
getPlugin fails if plugins is not declared as an array
Related forum post here, I'm copying my last post from that thread since it really should have been a bug report.
REQUIRED INFORMATION
Ext version tested:- Ext 4.1.1
Browser versions tested against:- FF18
DOCTYPE tested against:- Unrelated?
Description:- The getPlugin method throws an exception if the component's plugin array is not manually initialized
Steps to reproduce the problem:- http://jsfiddle.net/LMaaM/ shows initializing a component without a plugins array and then calling getPlugin and having it throw an exception.
The result that was expected:- getPlugin should simply return null or undefined
The result that occurs instead:- It throws an exception because it checks the plugins.length when plugins is undefined
Test Case:
See JSFiddle above.
Additional information:
This is based on 4.1.1 (not 4.1.3) which is latest. The test is obviously pretty contrived. However, I think it still illustrates the bug since in one case it works fine and in the other case it fails. This has to do with the fact that the code for the getPlugins code in Ext.AbstractComponent is:
My developer's thought is that the plugins.length check fails since plugins doesn't exist. Plugins isn't obligated to be defined.Code:/** * Retrieves a plugin by its `pluginId` which has been bound to this component. * @param {String} pluginId * @return {Ext.AbstractPlugin} plugin instance. */ getPlugin: function(pluginId) { var i = 0, plugins = this.plugins, ln = plugins.length; //problematic for (; i < ln; i++) { if (plugins[i].pluginId === pluginId) { return plugins[i]; } } },
The AbstractComponent.constructPlugins method isn't obligated to assign an array to plugins or return an array that would be assign to plugins from any calls while initializing the component. The configuration option isn't defined as an array by default (wisely) either.
I'd say there's two options to repair:
- getPlugins (and any other methods utilizing the plugins member variable) could guard against the case that the plugins array is undefined.
- plugins could be initialized as an empty array by default, reducing the need to check
I'd guess the latter would be the better choice from a future proofing standpoint.
-
8 Feb 2013 10:24 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
Thanks for the report! I have opened a bug in our bug tracker.
-
11 Feb 2013 11:06 AM #3
Success! Looks like we've fixed this one. According to our records the fix was applied for
EXTJSIV-8568
in
4.2.1.744.


Reply With Quote