I’m writing a Firefox extension and am wondering about the best way to assert my application’s invariants. From what I understand if I set browser.dom.window.dump.enabled = true in about:config, then window.dump() becomes available for logging (is this the recommended way to do the equivalent of console.log()?) but I’m wondering if there is an actual assertions library.
If not it’s easy enough to write a tiny function that logs an error and throws an exception, but a built-in alternative would be cool.
There’s nsIDebug which allows you to generate run-time assertions and aborts, but that may be overkill for what you want.
The recommended way to log is to use Services.console.logStringMessage (or its equivalent in older Firefox versions) or Components.reportError, both of which log to the Error console.