Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Components.returnCode

Components.returnCode is a property which can hold an XPCOM return code additionally to the value returned by the return statement.

Note that Components.returnCode is currently non-functional due to bug 287107. This problem was introduced in Mozilla 1.4.

Usage

Components.returnCode is a property that can be used to indicate to an XPCOM caller of the JavaScript method that the method is returning a specific nsresult code.

Generally, XPConnect does a fine job of making it unnecessary for JavaScript code to worry about nsresult codes. By default the successful completion of the JavaScript method will cause XPConnect to return a result code of NS_OK to the caller. If the JavaScript code needs to signal failure then that is done by throwing an exception. However, there are a very few XPCOM interfaces that specify success code return values. Components.returnCode exists in order to make it possible to implement these rare interfaces in JavaScript.

Example

var foo = {
  bar: function(i) {
    if (yada_yada)
      Components.returnCode = 5;

    return i * 2;
  }
};

Document Tags and Contributors

 Contributors to this page: teoli, Mgjbot, Andreas Wuest, Nickolay
 Last updated by: Mgjbot,