Student
Student

Reputation: 28375

Why this script is not running?

I'm trying to add a script to the beggin of my XBL file, but even the following test is not running, any idea why?

<bindings xmlns="http://www.mozilla.org/xbl"
       xmlns:xbl="http://www.mozilla.org/xbl"
       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

 <script language="javascript" type="text/javascript"><![CDATA[
     while(true) {
      dump("OK");
     }
 ]]></script>

</bindings>

--update

This infinite loop is becouse I want a piece of code to keep running. It's a communication with an embedded system.

Upvotes: 1

Views: 118

Answers (3)

Paul Butcher
Paul Butcher

Reputation: 6956

There is no script element in XBL, the documentation is false:

https://bugzilla.mozilla.org/show_bug.cgi?id=58757

Upvotes: 0

philgiese
philgiese

Reputation: 651

I also have no knowledge about XBL, but I also think that the way you have written this, it will block the execution. At the moment everything runs synchronized meaning, that the interpreter will stop at the while end wait for it to end. Now, as it is an infinite loop, this will never happen. What you can do is the following:

window.setTimeout(function() {
    while(true) {
        dump("OK");
    }
}, 1);

This way you start your while in an asynchronous kind of way. This should be non-blocking. Tell me, if it works.

Upvotes: 0

Shadow Wizzard
Shadow Wizzard

Reputation: 66388

Dunno about XBL, but your code has infinite loop without stop condition. Such thing is crashing JavaScript.

Add stop condition or "fail safe" like breaking after 100,000 iterations and it will not freeze the browser.

Upvotes: 1

Related Questions