toolkit/devtools/tests/unit/head_devtools.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 "use strict";
     2 const Cc = Components.classes;
     3 const Ci = Components.interfaces;
     4 const Cu = Components.utils;
     5 const Cr = Components.results;
     7 Cu.import("resource://gre/modules/devtools/Loader.jsm");
     8 Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm");
    10 // Register a console listener, so console messages don't just disappear
    11 // into the ether.
    12 let errorCount = 0;
    13 let listener = {
    14   observe: function (aMessage) {
    15     errorCount++;
    16     try {
    17       // If we've been given an nsIScriptError, then we can print out
    18       // something nicely formatted, for tools like Emacs to pick up.
    19       var scriptError = aMessage.QueryInterface(Ci.nsIScriptError);
    20       dump(aMessage.sourceName + ":" + aMessage.lineNumber + ": " +
    21            scriptErrorFlagsToKind(aMessage.flags) + ": " +
    22            aMessage.errorMessage + "\n");
    23       var string = aMessage.errorMessage;
    24     } catch (x) {
    25       // Be a little paranoid with message, as the whole goal here is to lose
    26       // no information.
    27       try {
    28         var string = "" + aMessage.message;
    29       } catch (x) {
    30         var string = "<error converting error message to string>";
    31       }
    32     }
    34     // Make sure we exit all nested event loops so that the test can finish.
    35     while (DebuggerServer.xpcInspector.eventLoopNestLevel > 0) {
    36       DebuggerServer.xpcInspector.exitNestedEventLoop();
    37     }
    38     do_throw("head_dbg.js got console message: " + string + "\n");
    39   }
    40 };
    42 let consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
    43 consoleService.registerListener(listener);

mercurial