Results 1 to 3 of 3

Thread: getPlugin fails if plugins is not declared as an array

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-8568 in a recent build.
  1. #1
    Sencha Premium Member
    Join Date
    Mar 2007
    Vote Rating

    Default 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.


    Ext version tested:
    • Ext 4.1.1

    Browser versions tested against:
    • FF18

    DOCTYPE tested against:
    • Unrelated?

    • The getPlugin method throws an exception if the component's plugin array is not manually initialized

    Steps to reproduce the problem:
    • 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:

         * 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];
    My developer's thought is that the plugins.length check fails since plugins doesn't exist. Plugins isn't obligated to be defined.

    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:

    1. getPlugins (and any other methods utilizing the plugins member variable) could guard against the case that the plugins array is undefined.
    2. 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.

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Thanks for the report! I have opened a bug in our bug tracker.

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2007
    Vote Rating


    Awesome, thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts