resolve()/reject() on Promise subclasses and @@species
Boris Zbarsky
bzbarsky at mit.edu
Thu Oct 29 02:51:25 UTC 2015
I was just implementing subclassing of Promise in Gecko, when I realized
that given a Promise subclass MyPromise these two calls:
MyPromise.race([])
MyPromise.all([])
will take MyPromise[@@species] into account when creating the return
value, but these two calls:
MyPromise.resolve()
MyPromise.reject()
will not; they will invoke MyPromise itself, not MyPromise[@@species].
This is because
http://www.ecma-international.org/ecma-262/6.0/#sec-promise.all and
http://www.ecma-international.org/ecma-262/6.0/#sec-promise.race do the
whole @@species thing but
http://www.ecma-international.org/ecma-262/6.0/#sec-promise.reject and
http://www.ecma-international.org/ecma-262/6.0/#sec-promise.resolve do not.
Is this behavior intentional? If so, I'd really like to understand the
reason for it.
-Boris
More information about the es-discuss
mailing list