为什么这个脚本没有运行?
我正在尝试将脚本添加到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不知道 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.
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
我对 XBL 也一无所知,但我也认为你这样写的方式会阻止执行。目前,所有内容都运行同步,这意味着解释器将在
while
结束时停止,等待其结束。现在,由于它是无限循环,因此这种情况永远不会发生。您可以执行以下操作:这样您就可以以异步方式启动
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:This way you start your
while
in an asynchronous kind of way. This should be non-blocking. Tell me, if it works.