开发者

How to detect syntax errors when debugging Firefox extensions

When working on a large Firefox plugin, I sometimes accidentally make a syntax error not caught by my editor. When this happens, then calling

Components.utils.import("resource://modules/Foo.js")

will simply fail to import or return anything, without any kind of helpful hint as to where in the file to look for the syntax error. Is there any way I can get Firefox to give me some kind of clue when my imports fail?

EDIT: I fixed my own problem, which turned out to be that I was using code which had a global reference to the navigator object. What made this especially annoying was that the code would work when loaded in the browser (as Wladimir suggested below), but would still fail when importing in my extension.

Eventually I resorted to a sort of manual binary search: I'd delete half of the file and then see whether the import still failed. If so, then I'd delete half of what remained and repeat. As soon as it didn't fail, I had a more precise notion of where the problem was, which allowed me to either continue the binary search开发者_Python百科 or scan the smaller area manually looking for the problem.

This is extremely time-consuming and I'd still appreciate any suggestions about how to speed up this debugging process.


The issue here is most likely the one described on https://developer.mozilla.org/en/Exception_logging_in_JavaScript and setting dom.report_all_js_exceptions preference to true should work. I must admit that I haven't tried that however because setting this preference makes the error console very noisy. Instead I use an ugly hack and load the module as a script in a local HTML file - this is enough to show me syntax errors and fortunately isn't something I need to do all too often (it is only an issue with syntax errors, runtime errors are reported as usually).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜