tc39 / proposal-promise-any

ECMAScript proposal: Promise.any
https://tc39.es/proposal-promise-any/
200 stars 27 forks source link

PerformPromiseAny calls `then` incorrectly. #25

Closed raulsebastianmihaila closed 5 years ago

raulsebastianmihaila commented 5 years ago

During a quick read I saw line 8.r. of PerformPromiseAny:

Perform ? Invoke(nextPromise, "then", « resultCapability, rejectElement[[Reject]] »).

Shouldn't that be?:

Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
mathiasbynens commented 5 years ago

What makes you say so?

For context, the current PerformPromiseAny spec matches PerformPromiseAll:

Perform ? Invoke(nextPromise, "then", « resolveElement, resultCapability.[[Reject]] »).

PerformPromiseRace does something else:

Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).

PerformPromiseAllSettled does:

Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
raulsebastianmihaila commented 5 years ago

Are we looking in the same place? See 8.r.: https://tc39.es/proposal-promise-any/#sec-performpromiseany

mathiasbynens commented 5 years ago

Yes? It says:

Perform ? Invoke(nextPromise, "then", « resultCapability, rejectElement[[Reject]] »).

...which I pointed out matches PerformPromiseAll. I'm probably missing something here -- could you please elaborate on why you'd go with a different approach?

raulsebastianmihaila commented 5 years ago

I don't think it matches PerformPromiseAll. PerformPromiseAll does, as you pointed out:

Perform ? Invoke(nextPromise, "then", « resolveElement, resultCapability.[[Reject]] »).

Compare that to:

Perform ? Invoke(nextPromise, "then", « resultCapability, rejectElement[[Reject]] »).

As you can see, PerformPromiseAll calls then with a resolveElement, which is a function, and with a resultCapability.[[Reject]], which is also a function. PerformPromiseAny calls then with a promise capability record, which is not a function, and with rejectElement[[Reject]] which is incorrect even syntactically. Syntactically it should be rejectElement.[[Reject]], but then it would be semantically incorrect, because rejectElement is a function, not a record.

mathiasbynens commented 5 years ago

Thanks for clarifying that. Would you mind submitting a PR to fix this?

mathiasbynens commented 5 years ago

Addressed by #26.