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:

  1. Let fullfilledCount be 0.

  2. Let rejected be false.

  3. Let rejectionHandlerSteps be the following steps given arg:

    1. If rejected is true, abort these steps.

    2. Set rejected to true.

    3. Perform failureSteps given arg.

  4. Let rejectionHandler be CreateBuiltinFunction(rejectionHandlerSteps, 1, "", « »):

  5. Let total be promises’s size.

  6. If total is 0, then:

    1. Queue a microtask to perform successSteps given « ».

    2. Return.

  7. Let index be 0.

  8. Let result be a list containing total null values.

  9. For each promise of promises:

    1. Let promiseIndex be index.

    2. Let fulfillmentHandler be the following steps given arg:

      1. Set result[promiseIndex] to arg.

      2. Set fullfilledCount to fullfilledCount + 1.

      3. If fullfilledCount equals total, then perform successSteps given result.

    3. Let fulfillmentHandler be CreateBuiltinFunction(fulfillmentHandler, 1, "", « »):

    4. Perform PerformPromiseThen(promise, fulfillmentHandler, rejectionHandler).

    5. Set index to index + 1.