This is implemented by creating a Promise object internally and
forwarding the .then() call to it. Any further callbacks passed to
future .then() calls will be added as callbacks on the same internal
promise object. We also take care of resolving or rejecting the promise
if the success/error event of the DOMRequest object has been fired
before .then() is called.
Without special handling CallbackObject subclasses will fall into the "nsISupports but not nsWrapperCache" case which goes through an XPConnect wrapping path that has no idea how to cope with a CallbackObject. We need both the CallbackObject overload and the EnableIf bit in the template because the template will bind to the subclass and thus be preferred to the CallbackObject overload which requires an implicit conversion to the base class.
Before this patch nsTArray<T*> will eventually try to ToJSValue a T* which will select the boolean overload. Thanks C++! The new template overload that takes a T and attempts to dereference it will be preferred because it can bind to the type directly and does not require the implicit (and terrible!) conversion to bool. This template is written in terms of T and not T* so we can test to see if T is a pointer type (and not merely something that can be coerced to a T*, such as a T[N]).
Apart from moving the methods, I made the following changes:
1) Renamed them to ToJSValue.
2) Inlined the boolean overload.
3) Added overloads that take integer types.
4) Changed the order of the aCx and aArgument arguments so aCx comes first.
5) Renamed "abv" to "obj" in the typed array overload.