ai js promise lambda 2026-09-01

By Xah Lee. Date: .
work in progress

ai js promise lambda 2026-09-01

in js promise constructor, whats the spec for its parameter. show complete spec.

(ai answer)

The Promise constructor is specified as Promise ( executor ) in ECMA-262. The only parameter is executor.

Formal requirement on the parameter

executor must be callable. If IsCallable(executor) is false, the constructor throws a TypeError.

It is invoked synchronously during construction as:

Call(executor, undefined, « resolve, reject »)

If that call completes abruptly (the executor throws), the new promise is rejected with the thrown value. The executor’s return value is ignored.

Complete constructor algorithm (current ECMA-262)

27.2.3.1 Promise ( executor )

This function performs the following steps when called:

  1. If NewTarget is undefined, throw a TypeError exception.
  2. If IsCallable(executor) is false, throw a TypeError exception.
  3. Let promise be ? OrdinaryCreateFromConstructor(NewTarget, "%Promise.prototype%", « [[PromiseState]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]], [[PromiseIsHandled]] »).
  4. Set promise.[[PromiseState]] to pending.
  5. Set promise.[[PromiseResult]] to empty.
  6. Set promise.[[PromiseFulfillReactions]] to a new empty List.
  7. Set promise.[[PromiseRejectReactions]] to a new empty List.
  8. Set promise.[[PromiseIsHandled]] to false.
  9. Let resolvingFunctions be CreateResolvingFunctions(promise).
  10. Let completion be Completion(Call(executor, undefined, « resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]] »)).
  11. If completion is an abrupt completion, then
    1. Perform ? Call(resolvingFunctions.[[Reject]], undefined, « completion.[[Value]] »).
  12. Return promise.

Note
The executor argument must be a function object. It is called for initiating and reporting completion of the possibly deferred action represented by this Promise. The executor is called with two arguments: resolve and reject. These are functions that may be used by the executor function to report eventual completion or failure of the deferred computation. Returning from the executor function does not mean that the deferred action has been completed but only that the request to eventually perform the deferred action has been accepted.

What resolve / reject actually are

They are the pair produced by CreateResolvingFunctions(promise): two anonymous built-in functions that share an alreadyResolved flag. After the first successful call, later calls are no-ops.

That is the complete specified contract for the constructor parameter.