Components.results is a read-only object whose properties are the names listed as the first parameters of the macros in js/xpconnect/src/xpc.msg (also at Table Of Errors), with the value of each corresponding to that constant's value.


Components.results is an object whose properties are the names of well-known XPCOM result codes, with each value being that of the corresponding result code. Elements in this array can be used to test against unknown nsresult variables or they can be 'thrown' to indicate failure...

     throw Components.results.NS_ERROR_UNEXPECTED;

The elements of the Components.results object can be enumerated using a for-in loop.


Implementing nsISupports

The standard nsISupports is usually implemented in JavaScript by using Components.results to get a failure return value if does not implement the given interface. Note the common use of an abbreviation for Components.results, Cr:

const Ci = Components.interfaces, Cr = Components.results;

function Class()
  /* ... */
Class.prototype =
  /* ... */
  QueryInterface: function(id)
    if (id.equals(Ci.IMyInterface))
      return this;