Whats wrong with this code?

Discussion in 'Javascript' started by hiqu, Jun 12, 2008.

  1. hiqu

    hiqu Guest

    This issue is driving me nuts and not able to figure out whats wrong.
    I've this code in my firefox extension. Firefox always hangs and
    reports the script is busy.

    if I introduce a break statement in the for(;;) loop below, then
    no issue.

    Any help would be appreciated!

    function getStuff()
    {
    try
    {
    httpReq = new XMLHttpRequest();


    httpReq.onreadystatechange = function(evt)
    {
    if (httpReq.readyState == 4)
    {
    if (httpReq.status == 200)
    {
    getList(httpReq.responseText);
    }
    }
    }


    httpReq.open("GET", "http://www.mysite.com", true);
    httpReq.send(null);
    }catch(ex)
    {
    Components.utils.reportError(ex);
    }
    }


    function getList(htmlText)
    {
    for(;;)
    {
    }
    }
     
    hiqu, Jun 12, 2008
    #1
    1. Advertising

  2. hiqu

    hiqu Guest

    On Jun 12, 9:54 am, hiqu <> wrote:
    > This issue is driving me nuts and not able to figure out whats wrong.
    > I've this code in my firefox extension. Firefox always hangs and
    > reports the script is busy.
    >
    > if I introduce a break statement in the for(;;) loop below, then
    > no issue.
    >
    > Any help would be appreciated!
    >
    > function getStuff()
    > {
    >     try
    >     {
    >         httpReq = new XMLHttpRequest();
    >
    >         httpReq.onreadystatechange = function(evt)
    >         {
    >             if (httpReq.readyState == 4)
    >             {
    >                 if (httpReq.status == 200)
    >                 {
    >                     getList(httpReq.responseText);
    >                 }
    >             }
    >         }
    >
    >         httpReq.open("GET", "http://www.mysite.com", true);
    >         httpReq.send(null);
    >     }catch(ex)
    >     {
    >         Components.utils.reportError(ex);
    >     }
    >
    > }
    >
    > function getList(htmlText)
    > {
    >     for(;;)
    >     {
    >     }
    >
    >
    >
    > }- Hide quoted text -
    >
    > - Show quoted text -


    actually, let me post the correct code. I do some stuff in the for
    loop.
     
    hiqu, Jun 12, 2008
    #2
    1. Advertising

  3. hiqu

    Erwin Moller Guest

    hiqu schreef:
    > On Jun 12, 9:54 am, hiqu <> wrote:
    >> This issue is driving me nuts and not able to figure out whats wrong.
    >> I've this code in my firefox extension. Firefox always hangs and
    >> reports the script is busy.
    >>
    >> if I introduce a break statement in the for(;;) loop below, then
    >> no issue.
    >>
    >> Any help would be appreciated!
    >>
    >> function getStuff()
    >> {
    >> try
    >> {
    >> httpReq = new XMLHttpRequest();
    >>
    >> httpReq.onreadystatechange = function(evt)
    >> {
    >> if (httpReq.readyState == 4)
    >> {
    >> if (httpReq.status == 200)
    >> {
    >> getList(httpReq.responseText);
    >> }
    >> }
    >> }
    >>
    >> httpReq.open("GET", "http://www.mysite.com", true);
    >> httpReq.send(null);
    >> }catch(ex)
    >> {
    >> Components.utils.reportError(ex);
    >> }
    >>
    >> }
    >>
    >> function getList(htmlText)
    >> {
    >> for(;;)
    >> {
    >> }
    >>
    >>
    >>
    >> }- Hide quoted text -
    >>
    >> - Show quoted text -

    >
    > actually, let me post the correct code. I do some stuff in the for
    > loop.


    What is your question?
    I am afraid I cannot follow your line of thought at all. :-/

    Regards,
    Erwin Moller
     
    Erwin Moller, Jun 13, 2008
    #3
  4. hiqu escribió:
    > function getStuff()
    > {
    > try
    > {
    > httpReq = new XMLHttpRequest();


    Since httpReq is global, every time you getStuff() you'll destroy any
    other AJAX call that may be executing. Is that the desired effect?


    > function getList(htmlText)
    > {
    > for(;;)
    > {
    > }
    > }


    Well, this is pretty obvious xD



    --
    -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    -- Mi sitio sobre programación web: http://bits.demogracia.com
    -- Mi web de humor al baño María: http://www.demogracia.com
    --
     
    Álvaro G. Vicario, Jun 13, 2008
    #4
  5. hiqu

    GArlington Guest

    On Jun 12, 5:54 pm, hiqu <> wrote:
    > This issue is driving me nuts and not able to figure out whats wrong.
    > I've this code in my firefox extension. Firefox always hangs and
    > reports the script is busy.
    >
    > if I introduce a break statement in the for(;;) loop below, then
    > no issue.

    <snap>
    >
    > function getList(htmlText)
    > {
    > for(;;)
    > {
    > }
    >
    > }

    The above is never ending loop, this is an equivalent of telling your
    CPU to do nothing (NOP) but be BUSY all the time...
     
    GArlington, Jun 13, 2008
    #5
  6. hiqu

    GArlington Guest

    On Jun 12, 6:10 pm, hiqu <> wrote:
    > On Jun 12, 9:54 am, hiqu <> wrote:
    >

    <snap>
    >
    > actually, let me post the correct code. I do some stuff in the for
    > loop.


    Please do (post the correct code), because the posted code does
    EXACTLY what you can expect it to do - hangs you machine...
     
    GArlington, Jun 13, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    726
  2. Tinus

    Whats wrong in this code??

    Tinus, Sep 2, 2003, in forum: HTML
    Replies:
    2
    Views:
    523
    Samuël van Laere
    Sep 3, 2003
  3. Robert Smith

    whats wrong with this simple code?

    Robert Smith, Apr 27, 2004, in forum: C++
    Replies:
    2
    Views:
    333
    Christopher Benson-Manica
    Apr 28, 2004
  4. Matthew Wilson

    Whats wrong with this crc32 code?

    Matthew Wilson, Feb 16, 2004, in forum: C Programming
    Replies:
    1
    Views:
    535
    Jack Klein
    Feb 17, 2004
  5. Vineeth V

    whats wrong with this code???

    Vineeth V, Feb 19, 2007, in forum: VHDL
    Replies:
    2
    Views:
    427
    R Quijano
    Feb 19, 2007
Loading...

Share This Page