Stage 2 Draft / December 12, 2023

ES Promise.withResolvers (2023)


This is the formal specification for a proposed Promise.withResolvers method in JavaScript. It modifies the original ECMAScript specification with several new or revised clauses. See the proposal's explainer for the proposal's background, motivation, and usage examples.

1 Control Abstraction Objects

1.1 Promise Objects

1.1.1 Properties of the Promise Constructor Promise.withResolvers ( )

This function returns an object with three properties: a new promise plus the resolve and reject functions associated with that promise.

  1. Let C be the this value.
  2. Let promiseCapability be ? NewPromiseCapability(C).
  3. Let obj be OrdinaryObjectCreate(%Object.prototype%).
  4. Perform ! CreateDataPropertyOrThrow(obj, "promise", promiseCapability.[[Promise]]).
  5. Perform ! CreateDataPropertyOrThrow(obj, "resolve", promiseCapability.[[Resolve]]).
  6. Perform ! CreateDataPropertyOrThrow(obj, "reject", promiseCapability.[[Reject]]).
  7. Return obj.