To wait for all with a list of
Promise<T> values promises, with success steps
successSteps that take a list of T values and failure steps failureSteps that take a
rejection reason any value, perform the following steps:
Let fullfilledCount be 0.
Let rejected be false.
Let rejectionHandlerSteps be the following steps given arg:
If rejected is true, abort these steps.
Set rejected to true.
Perform failureSteps given arg.
Let rejectionHandler be CreateBuiltinFunction(rejectionHandlerSteps, 1, "", « »):
Let total be promises’s size.
If total is 0, then:
Queue a microtask to perform successSteps given « ».
Return.
Let index be 0.
Let result be a list containing total null values.
For each promise of promises:
Let promiseIndex be index.
Let fulfillmentHandler be the following steps given arg:
Set result[promiseIndex] to arg.
Set fullfilledCount to fullfilledCount + 1.
If fullfilledCount equals total, then perform successSteps given result.
Let fulfillmentHandler be CreateBuiltinFunction(fulfillmentHandler, 1, "", « »):
Perform PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler).
Set index to index + 1.