Unresponsive script...

General discussion about the NoScript extension for Firefox
Locked
luntrus
Senior Member
Posts: 237
Joined: Sat Mar 21, 2009 6:29 pm

Unresponsive script...

Post by luntrus »

Hi forum friends,

On a download I get an alert for an unresponsive script halted at line 306. It is in firefox/Firefox Portable/Hpp Firefox/ firefox/modules/XPCCMUtils.jsm

Code: Select all

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * vim: sw=2 ts=2 sts=2 et filetype=javascript
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Mozilla code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2004
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *    Alex Fritze <alex@croczilla.com> (original author)
 *    Nickolay Ponomarev <asqueella@gmail.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

/**
 * Utilities for JavaScript components loaded by the JS component
 * loader.
 *
 * Import into a JS component using
 * 'Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");'
 *
 * Exposing a JS 'class' as a component using these utility methods consists
 * of several steps:
 * 0. Import XPCOMUtils, as described above.
 * 1. Declare the 'class' (or multiple classes) implementing the component(s):
 *  function MyComponent() {
 *    // constructor
 *  }
 *  MyComponent.prototype = {
 *    // properties required for XPCOM registration:
 *    classDescription: "unique text description",
 *    classID:          Components.ID("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"),
 *    contractID:       "@example.com/xxx;1",
 *
 *    // [optional] custom factory (an object implementing nsIFactory). If not
 *    // provided, the default factory is used, which returns
 *    // |(new MyComponent()).QueryInterface(iid)| in its createInstance().
 *    _xpcom_factory: { ... },
 *
 *    // [optional] an array of categories to register this component in.
 *    _xpcom_categories: [{
 *      // Each object in the array specifies the parameters to pass to
 *      // nsICategoryManager.addCategoryEntry(). 'true' is passed for
 *      // both aPersist and aReplace params.
 *      category: "some-category",
 *      // optional, defaults to the object's classDescription
 *      entry: "entry name",
 *      // optional, defaults to the object's contractID (unless
 *      // 'service' is specified)
 *      value: "...",
 *      // optional, defaults to false. When set to true, and only if 'value'
 *      // is not specified, the concatenation of the string "service," and the
 *      // object's contractID is passed as aValue parameter of addCategoryEntry.
 *      service: true
 *    }],
 *
 *    // QueryInterface implementation, e.g. using the generateQI helper
 *    QueryInterface: XPCOMUtils.generateQI(
 *      [Components.interfaces.nsIObserver,
 *       Components.interfaces.nsIMyInterface,
 *       "nsIFoo",
 *       "nsIBar" ]),
 *
 *    // ...component implementation...
 *  };
 *
 * 2. Create an array of component constructors (like the one
 * created in step 1):
 *  var components = [MyComponent];
 *
 * 3. Define the NSGetModule entry point:
 *  function NSGetModule(compMgr, fileSpec) {
 *    // components is the array created in step 2.
 *    return XPCOMUtils.generateModule(components);
 *  }
 */


var EXPORTED_SYMBOLS = [ "XPCOMUtils" ];

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;

var XPCOMUtils = {
  /**
   * Generate a QueryInterface implementation. The returned function must be
   * assigned to the 'QueryInterface' property of a JS object. When invoked on
   * that object, it checks if the given iid is listed in the |interfaces|
   * param, and if it is, returns |this| (the object it was called on).
   */
  generateQI: function(interfaces) {
    /* Note that Ci[Ci.x] == Ci.x for all x */
    return makeQI([Ci[i].name for each (i in interfaces) if (Ci[i])]);
  },

  /**
   * Generate the NSGetModule function (along with the module definition).
   * See the parameters to generateModule.
   */
  generateNSGetModule: function(componentsArray, postRegister, preUnregister) {
    return function NSGetModule(compMgr, fileSpec) {
      return XPCOMUtils.generateModule(componentsArray,
                                       postRegister,
                                       preUnregister);
    }
  },

  /**
   * Generate a module implementation.
   *
   * @param componentsArray  Array of component constructors. See the comment
   *                         at the top of this file for details.
   * @param postRegister  optional post-registration function with
   *                      signature 'postRegister(nsIComponentManager,
   *                                              nsIFile, componentsArray)'
   * @param preUnregister optional pre-unregistration function with
   *                      signature 'preUnregister(nsIComponentManager,
   *                                               nsIFile, componentsArray)'
   */
  generateModule: function(componentsArray, postRegister, preUnregister) {
    let classes = [];
    for each (let component in componentsArray) {
      classes.push({
        cid:          component.prototype.classID,
        className:    component.prototype.classDescription,
        contractID:   component.prototype.contractID,
        factory:      this._getFactory(component),
        categories:   component.prototype._xpcom_categories
      });
    }

    return { // nsIModule impl.
      getClassObject: function(compMgr, cid, iid) {
        // We only support nsIFactory queries, not nsIClassInfo
        if (!iid.equals(Ci.nsIFactory))
          throw Cr.NS_ERROR_NOT_IMPLEMENTED;

        for each (let classDesc in classes) {
          if (classDesc.cid.equals(cid))
            return classDesc.factory;
        }

        throw Cr.NS_ERROR_FACTORY_NOT_REGISTERED;
      },

      registerSelf: function(compMgr, fileSpec, location, type) {
        var componentCount = 0;
        debug("*** registering " + fileSpec.leafName + ": [ ");
        compMgr.QueryInterface(Ci.nsIComponentRegistrar);

        for each (let classDesc in classes) {
          debug((componentCount++ ? ", " : "") + classDesc.className);
          compMgr.registerFactoryLocation(classDesc.cid,
                                          classDesc.className,
                                          classDesc.contractID,
                                          fileSpec,
                                          location,
                                          type);
          if (classDesc.categories) {
            let catMan = XPCOMUtils.categoryManager;
            for each (let cat in classDesc.categories) {
              let defaultValue = (cat.service ? "service," : "") +
                                 classDesc.contractID;
              catMan.addCategoryEntry(cat.category,
                                      cat.entry || classDesc.className,
                                      cat.value || defaultValue,
                                      true, true);
            }
          }
        }

        if (postRegister)
          postRegister(compMgr, fileSpec, componentsArray);
        debug(" ]\n");
      },

      unregisterSelf: function(compMgr, fileSpec, location) {
        var componentCount = 0;
        debug("*** unregistering " + fileSpec.leafName + ": [ ");
        compMgr.QueryInterface(Ci.nsIComponentRegistrar);
        if (preUnregister)
          preUnregister(compMgr, fileSpec, componentsArray);

        for each (let classDesc in classes) {
          debug((componentCount++ ? ", " : "") + classDesc.className);
          if (classDesc.categories) {
            let catMan = XPCOMUtils.categoryManager;
            for each (let cat in classDesc.categories) {
              catMan.deleteCategoryEntry(cat.category,
                                         cat.entry || classDesc.className,
                                         true);
            }
          }
          compMgr.unregisterFactoryLocation(classDesc.cid, fileSpec);
        }
        debug(" ]\n");
      },

      canUnload: function(compMgr) {
        return true;
      }
    };
  },

  /**
   * Defines a getter on a specified object that will be created upon first use.
   *
   * @param aObject
   *        The object to define the lazy getter on.
   * @param aName
   *        The name of the getter to define on aObject.
   * @param aLambda
   *        A function that returns what the getter should return.  This will
   *        only ever be called once.
   */
  defineLazyGetter: function XPCU_defineLazyGetter(aObject, aName, aLambda)
  {
    aObject.__defineGetter__(aName, function() {
      delete aObject[aName];
      return aObject[aName] = aLambda.apply(aObject);
    });
  },

  /**
   * Defines a getter on a specified object for a service.  The service will not
   * be obtained until first use.
   *
   * @param aObject
   *        The object to define the lazy getter on.
   * @param aName
   *        The name of the getter to define on aObject for the service.
   * @param aContract
   *        The contract used to obtain the service.
   * @param aInterfaceName
   *        The name of the interface to query the service to.
   */
  defineLazyServiceGetter: function XPCU_defineLazyServiceGetter(aObject, aName,
                                                                 aContract,
                                                                 aInterfaceName)
  {
    this.defineLazyGetter(aObject, aName, function XPCU_serviceLambda() {
      return Cc[aContract].getService(Ci[aInterfaceName]);
    });
  },

  /**
   * Convenience access to category manager
   */
  get categoryManager() {
    return Components.classes["@mozilla.org/categorymanager;1"]
           .getService(Ci.nsICategoryManager);
  },

  /**
   * Returns an nsIFactory for |component|.
   */
  _getFactory: function(component) {
    var factory = component.prototype._xpcom_factory;
    if (!factory) {
      factory = {
        createInstance: function(outer, iid) {
          if (outer)
            throw Cr.NS_ERROR_NO_AGGREGATION;
          return (new component()).QueryInterface(iid);
        }
      }
    }
    return factory;
  }
};

/**
 * Helper for XPCOMUtils.generateQI to avoid leaks - see bug 381651#c1
 */
function makeQI(interfaceNames) {
  return function XPCOMUtils_QueryInterface(iid) {
    if (iid.equals(Ci.nsISupports))
      return this;
    for each(let interfaceName in interfaceNames) {
      if (Ci[interfaceName].equals(iid))
        return this;
    }

    throw Cr.NS_ERROR_NO_INTERFACE;
  };
}

Anyone on why a JPG file download is halted by the script. Is it related to my NS install?

Could this be fixed in the usual way for unresponsive scripts, where one need to access the hidden configuration page in Firefox. Give in about:config in the address bar and in the 'Filter' box, type dom.max_script_run_time. This will narrow the options till only the dom.max_script_run_time option remains. Right-click it and choose Modify. A box pops up. Change the number to something bigger like 20. This is the maximum time a script can run before Firefox considers it 'unresponsive',

luntrus
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.3a1pre) Gecko/20090929 Minefield/3.7a1pre
User avatar
therube
Ambassador
Posts: 7929
Joined: Thu Mar 19, 2009 4:17 pm
Location: Maryland USA

Re: Unresponsive script...

Post by therube »

URL or website where this occurs?

FF has two JavaScript (whateveryoucallthem). If you switch to the other, does it still occur.
(I think if you about:config, a search for 'JIT' will find it.)
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball NoScript FlashGot AdblockPlus
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090825 SeaMonkey/1.1.18
User avatar
GµårÐïåñ
Lieutenant Colonel
Posts: 3365
Joined: Fri Mar 20, 2009 5:19 am
Location: PST - USA
Contact:

Re: Unresponsive script...

Post by GµårÐïåñ »

I have been getting alot of these and they come and go as often as there are NS releases almost. I have always since 1.8.x been experiencing it and on different setups and machines and configurations, so I know the only common thread is Fx+NS and I have been able to rig a solution by making the dom configuration for the delay unreasonable long but still experience this. So there has to be something with either Fx core or how NS captures and uses it. My money is on Fx but what the hell do I know, I have too much to do to sit there and dissect the code and spend hours on Bugzilla trying to defend it and then have it be ignored or done some other way. I did my part on the early releases and found quickly there is a herd behavior and truth is the lowest part of the agenda, its who can say the most and convince the most to go with their pet project, not really fixing the problems. This has become even worst in the more recent releases of Fx starting with 3.x
~.:[ Lï£ê ï§ å Lêmðñ åñÐ Ì Wåñ† M¥ Mðñê¥ ßå¢k ]:.~
________________ .: [ Major Mike's ] :. ________________
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
luntrus
Senior Member
Posts: 237
Joined: Sat Mar 21, 2009 6:29 pm

Re: Unresponsive script...

Post by luntrus »

Hi GµårÐïåñ ,

I would not doubt your words one bit and take your explanation as authoritative, because I assume it is genuine and factual. Would the dissecting that you talk about not go bit in the line as it is described here: http://elegantcode.com/2009/06/15/disse ... uery-text/ OK, other code similar line of dissecting....
Sometimes one should follow one's convictions when it is not given in by any herd-and-hive mentality, fanboyism or being part of a certain clique circle. I agree with you here that truth finding and an independent point of view that stools on facts is sometimes hard to find these days. Good we have you here, GµårÐïåñ,

luntrus
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2a1) Gecko/20090806 Namoroka/3.6a1
User avatar
GµårÐïåñ
Lieutenant Colonel
Posts: 3365
Joined: Fri Mar 20, 2009 5:19 am
Location: PST - USA
Contact:

Re: Unresponsive script...

Post by GµårÐïåñ »

I do not want to hijack this thread and get too far off topic and I apologize for that wholeheartedly but just to reply to your comments, I wanted to see this through.

Thank you my friend but it wasn't so much that I gave up on it but rather I felt that I was putting a small amount of energy (comparative to the whole community) and it was getting swallowed in the waves of discontent and overwhelmed lack of proper infrastructure and it seems a futile waste of time. IF they revamp the system, put checks and balances that are not based on volunteers and their moods and personal agendas fueled by their affiliations, then yeah I would bend over backwards to contribute, not the way it is now though. Plus, I know of friends like the magnificent Giorgio who put their time, expertise and reputation on the line every day to little appreciation or credit who continue to do it for the sake of the principle for which I am supremely grateful. This is why I do the little I can to help him here because I know what he does and goes through out there.

Now back to the technical issue of dissecting the code, the example you provided is a good example but in large code bases, you have a choice to adopt a piece of the code (a module, a function, a library, a routine, etc) and make it better hoping your coding is consistent with the REST of the herd and it works, when not the holes occur. However, to be most effective, like my involvement and experience with Windows, Visual Studio, and a few other private projects, I have worked extensively to look at the code, in the nude if you will, completely raw and see the full interaction of ALL parts. That takes commitment that the current disorganized model cannot provide and that's the waste. Say you work your ass off to fix or better something that someone else is already working on and when it comes to release it, its obsolete and moot, that is disheartening. If better communication, tracking and cohesiveness was achieved, this wouldn't' happen or people could pair up to work on similar projects rather than spin their wheels.

That being said, I have peeked enough into it to make sure I know enough generalized information to be able to effectively support it without necessarily being a self anointed know it all and guru or authority. I even tried at coming back and supporting the new model implemented to work on new addons but found it quickly disorganized and in its infancy and I didn't want to disadvantage it by not being able to dedicate enough time to it, so I stepped out when the problems I submitted were finalized and fixed. I felt that I saw it through and can step away now without jeopardizing the project. As for being here, its my pleasure and duty to a friend and until the day Giorgio throws me out on my ass with a Ciao, I shall do my part to help him anyway I can, along with it the community that relies on us.
~.:[ Lï£ê ï§ å Lêmðñ åñÐ Ì Wåñ† M¥ Mðñê¥ ßå¢k ]:.~
________________ .: [ Major Mike's ] :. ________________
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
Locked