문제

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.

도움이 되었습니까?

해결책

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

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

다른 팁

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top