Closed Bug 852220 Opened 7 years ago Closed 7 years ago

nsIConsoleService does not work properly

Categories

(Core :: General, defect)

21 Branch
x86_64
Windows 7
defect
Not set

Tracking

()

RESOLVED WONTFIX

People

(Reporter: alice0775, Unassigned)

References

Details

(Keywords: addon-compat, regression)

Build Identifier:
http://hg.mozilla.org/mozilla-central/rev/b03bb3ce8cee
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20130318 Firefox/22.0 ID:20130318030947

Executing the following code in ScratchPad(chrome privilege) should appear an alert box.
However since Aurora20.0a2, alert box does not pop up anymore.

//begin---------------------------
function myLogToConsole(aMessage, aSourceName, aSourceLine, aLineNumber,
                        aColumnNumber, aFlags, aCategory) {
  var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
                                 .getService(Components.interfaces.nsIConsoleService);
  var scriptError = Components.classes["@mozilla.org/scripterror;1"]
                              .createInstance(Components.interfaces.nsIScriptError);
  scriptError.init(aMessage, aSourceName, aSourceLine, aLineNumber,
                   aColumnNumber, aFlags, aCategory);
  consoleService.logMessage(scriptError);
}

var errorListener = {
  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIConsoleListener,
                                         Components.interfaces.nsISupports]),
  observe: function(message) {
    if ("QueryInterface" in message) {
      var error = message.QueryInterface(Components.interfaces.nsIScriptError);
      alert(error.errorMessage);
    }
  }
}

var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
                     .getService(Components.interfaces.nsIConsoleService);
consoleService.registerListener(errorListener);

myLogToConsole("my message", "", "", "",  "", 1, "myerror");

consoleService.unregisterListener(errorListener);
//end---------------------------



If I changed last line
>> consoleService.unregisterListener(errorListener);
to
>> setTimeout(function(){ consoleService.unregisterListener(errorListener);}, 0);

then it works as expected.
Err
s/However since Aurora20.0a2/However since Aurora21.0a2/
This was a purposeful change with bug 831428.  See in particular bug 831428 comment 9.

I believe this bug as filed is wontfix.
Hmm.  We didn't have any addon messaging about this, did we?  We probably should.
Flags: needinfo?(jorge)
Flags: needinfo?(benjamin)
Keywords: addon-compat
(In reply to Boris Zbarsky (:bz) from comment #4)
> Hmm.  We didn't have any addon messaging about this, did we?  We probably
> should.

Not yet, no. I flagged bug 831428 for addon-compat and we will definitely include it in our messaging.
Flags: needinfo?(jorge)
Yes, this was an intentional change. I didn't expect that anything other than unit tests could possibly depend on the current behavior, but apparently they do!
Status: NEW → RESOLVED
Closed: 7 years ago
Flags: needinfo?(benjamin)
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.