为什么这个脚本没有运行?

发布于 2024-10-02 08:03:17 字数 491 浏览 0 评论 0原文

我正在尝试将脚本添加到 XBL 文件的开头,但即使以下测试也没有运行,知道为什么吗?

<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

这个无限循环是因为我想让一段代码继续运行。这是与嵌入式系统的通信。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最单纯的乌龟 2024-10-09 08:03:17

不知道 XBL,但您的代码有无限循环,没有停止条件。这样的事情会导致 JavaScript 崩溃。

添加停止条件或“故障安全”,例如在 100,000 次迭代后中断,并且不会冻结浏览器。

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.

锦爱 2024-10-09 08:03:17

XBL 中没有脚本元素,文档是错误的:

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

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

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

郁金香雨 2024-10-09 08:03:17

我对 XBL 也一无所知,但我也认为你这样写的方式会阻止执行。目前,所有内容都运行同步,这意味着解释器将在 while 结束时停止,等待其结束。现在,由于它是无限循环,因此这种情况永远不会发生。您可以执行以下操作:

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

这样您就可以以异步方式启动 while 。这应该是非阻塞的。告诉我,如果有效的话。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文