Stage 1 Draft / November 18, 2025

Await Dictionary

27 Control Abstraction Objects

27.2 Promise Objects

27.2.1 Promise Abstract Operations

27.2.1.10 CreateKeyedPromiseCombinatorResultObject ( keys, values )

The abstract operation CreateKeyedPromiseCombinatorResultObject takes arguments keys (a List of property keys) and values (a List of ECMAScript language values) and returns an Object. It performs the following steps when called:

  1. Assert: The number of elements in keys is the same as the number of elements in values.
  2. Let obj be OrdinaryObjectCreate(null).
  3. For each integer i such that 0 ≤ i < the number of elements in keys, in ascending order, do
    1. Perform ! CreateDataPropertyOrThrow(obj, keys[i], values[i]).
  4. Return obj.

27.2.4 Properties of the Promise Constructor

The Promise constructor:

  • has a [[Prototype]] internal slot whose value is %Function.prototype%.
  • has the following properties:

27.2.4.1 Promise.allKeyed ( promises )

This method performs the following steps when called:

  1. Let C be the this value.
  2. Let promiseCapability be ? NewPromiseCapability(C).
  3. Let promiseResolve be Completion(GetPromiseResolve(C)).
  4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
  5. If promises is not an Object, then
    1. Let error be a newly created TypeError object.
    2. Perform ? Call(promiseCapability.[[Reject]], undefined, « error »).
    3. Return promiseCapability.[[Promise]].
  6. Let result be Completion(PerformPromiseAllKeyed(all, promises, C, promiseCapability, promiseResolve)).
  7. IfAbruptRejectPromise(result, promiseCapability).
  8. Return promiseCapability.[[Promise]].
Note

This function requires its this value to be a constructor function that supports the parameter conventions of the Promise constructor.

27.2.4.1.1 PerformPromiseAllKeyed ( variant, promises, constructor, resultCapability, promiseResolve )

The abstract operation PerformPromiseAllKeyed takes arguments variant (all or all-settled), promises (an Object), constructor (a constructor), resultCapability (a PromiseCapability Record), and promiseResolve (a function object) and returns either a normal completion containing an ECMAScript language value or a throw completion. It performs the following steps when called:

  1. Let allKeys be ? promises.[[OwnPropertyKeys]]().
  2. Let keys be a new empty List.
  3. Let values be a new empty List.
  4. Let remainingElementsCount be the Record { [[Value]]: 1 }.
  5. Let index be 0.
  6. For each element key of allKeys, do
    1. Let desc be ? promises.[[GetOwnProperty]](key).
    2. If desc is not undefined and desc.[[Enumerable]] is true, then
      1. Let value be ? Get(promises, key).
      2. Append key to keys.
      3. Append undefined to values.
      4. Let nextPromise be ? Call(promiseResolve, constructor, « value »).
      5. Let alreadyCalled be the Record { [[Value]]: false }.
      6. Let onFulfilled be a new Abstract Closure with parameters (x) that captures variant, alreadyCalled, index, keys, values, resultCapability, and remainingElementsCount and performs the following steps when called:
        1. If alreadyCalled.[[Value]] is true, return undefined.
        2. Set alreadyCalled.[[Value]] to true.
        3. If variant is all, then
          1. Set values[index] to x.
        4. Else,
          1. Assert: variant is all-settled.
          2. Let obj be OrdinaryObjectCreate(%Object.prototype%).
          3. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled").
          4. Perform ! CreateDataPropertyOrThrow(obj, "value", x).
          5. Set values[index] to obj.
        5. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
        6. If remainingElementsCount.[[Value]] = 0, then
          1. Let result be CreateKeyedPromiseCombinatorResultObject(keys, values).
          2. Return ? Call(resultCapability.[[Resolve]], undefined, « result »).
        7. Return undefined.
      7. Set onFulfilled.[[Length]] to 1.
      8. If variant is all, then
        1. Let onRejected be resultCapability.[[Reject]].
      9. Else,
        1. Assert: variant is all-settled.
        2. Let onRejected be a new Abstract Closure with parameters (x) that captures alreadyCalled, index, keys, values, resultCapability, and remainingElementsCount and performs the following steps when called:
          1. If alreadyCalled.[[Value]] is true, return undefined.
          2. Set alreadyCalled.[[Value]] to true.
          3. Let obj be OrdinaryObjectCreate(%Object.prototype%).
          4. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected").
          5. Perform ! CreateDataPropertyOrThrow(obj, "reason", x).
          6. Set values[index] to obj.
          7. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
          8. If remainingElementsCount.[[Value]] = 0, then
            1. Let result be CreateKeyedPromiseCombinatorResultObject(keys, values).
            2. Return ? Call(resultCapability.[[Resolve]], undefined, « result »).
          9. Return undefined.
        3. Set onRejected.[[Length]] to 1.
      10. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
      11. Perform ? Invoke(nextPromise, "then", « onFulfilled, onRejected »).
      12. Set index to index + 1.
  7. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
  8. If remainingElementsCount.[[Value]] = 0, then
    1. NOTE: This can happen even if keys was non-empty if an ill-behaved thenable synchronously invoked the callback passed to its "then" method.
    2. Let result be CreateKeyedPromiseCombinatorResultObject(keys, values).
    3. Perform ? Call(resultCapability.[[Resolve]], undefined, « result »).
  9. Return resultCapability.[[Promise]].

27.2.4.2 Promise.allSettledKeyed ( promises )

This method performs the following steps when called:

  1. Let C be the this value.
  2. Let promiseCapability be ? NewPromiseCapability(C).
  3. Let promiseResolve be Completion(GetPromiseResolve(C)).
  4. IfAbruptRejectPromise(promiseResolve, promiseCapability).
  5. If promises is not an Object, then
    1. Let error be a newly created TypeError object.
    2. Perform ? Call(promiseCapability.[[Reject]], undefined, « error »).
    3. Return promiseCapability.[[Promise]].
  6. Let result be Completion(PerformPromiseAllKeyed(all-settled, promises, C, promiseCapability, promiseResolve)).
  7. IfAbruptRejectPromise(result, promiseCapability).
  8. Return promiseCapability.[[Promise]].
Note

This function requires its this value to be a constructor function that supports the parameter conventions of the Promise constructor.

Copyright & Software License

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.