Stage 1 Draft / March 12, 2026

MaybeDeferredResolvePromise (name TBD)

You'll notice the spec looks a bit 'playful' -- this is because I don't want to give too much of an impression that this is perfection, done, or even entirely thought through deeply. This spec text is a sketch, intended for discussion not implementation.

1 MaybeDeferredPromiseResolve Abstract Operations

These operations provide a mechanism for resolving promises without risk of synchronously executing arbitrary user code. When the resolution value is an object that could trigger user code (such as a Proxy, a thenable, or an object with accessor properties), the actual resolution is deferred to a future job.

1.1 RequiresDeferredPromiseResolution ( value )

The abstract operation RequiresDeferredPromiseResolution takes argument value (an ECMAScript language value) and returns either a normal completion containing a Boolean or a throw completion. It determines whether resolving a promise with value might execute user code that should be deferred to avoid running user code It performs the following steps when called:

  1. Let o be value.
  2. While o is defined, Repeat:
    1. If value is not an Object, return false.
    2. If value has a [[ProxyHandler]] internal slot, return true.
    3. Let desc be o.[[GetOwnProperty]]("then").
    4. If desc is not undefined and IsAccessorDescriptor(desc) is true, return true.
    5. Set o to o.[[GetPrototypeOf]]().
  3. Let constructorDesc be ? value.[[GetOwnProperty]]("constructor").
  4. If constructorDesc is not undefined, then
    1. If IsAccessorDescriptor(constructorDesc) is true, return true.
  5. Return false.
Note

I've sketched this assuming that [[GetPrototypeOf]] cannot trap on a getter, but I'm not 100% sure of this

Also, the lookup of "constructor" needs also to be a loop of similar shape to the lookup for 'then'

1.2 DoTheRestOfThePromiseResolveStuffWithoutAccidentallyCreatingAnotherJob ( promiseToResolve, resolution )

The abstract operation DoTheRestOfThePromiseResolveStuffWithoutAccidentallyCreatingAnotherJob takes arguments promiseToResolve (a Promise) and resolution (an ECMAScript language value). Basically a nicely layered version of PromiseResolve that doesn't accidentally force another tick. It performs the following steps when called:

  1. Do ? PromiseResolve(promiseToResolve, resolution), but without accidentally introducing another tick.

1.3 NewDeferredSafeResolveJob ( promiseToResolve, resolution, realm )

The abstract operation NewDeferredSafeResolveJob takes arguments promiseToResolve (a Promise), resolution (an ECMAScript language value), and realm (a Realm Record) and returns a Record with fields [[Job]] (a Job Abstract Closure) and [[Realm]] (a Realm Record). It returns a Job that performs deferred promise resolution in a microtask. It performs the following steps when called:

  1. Let job be a new Job Abstract Closure with no parameters that captures promiseToResolve and resolution and performs the following steps when called:
    1. Return ? DoTheRestOfThePromiseResolveStuffWithoutAccidentallyCreatingAnotherJob(promiseToResolve, resolution).
  2. Return the Record { [[Job]]: job, [[Realm]]: realm }.

1.4 MaybeDeferredPromiseResolve ( promise, resolution )

The abstract operation MaybeDeferredPromiseResolve takes arguments promise (a Promise) and resolution (an ECMAScript language value) and returns either a normal completion containing undefined or a throw completion. It resolves promise with resolution, deferring to a microtask if resolution might execute user code. It performs the following steps when called:

  1. Assert: promise is a Promise.
  2. Assert: promise.[[PromiseState]] is pending.
  3. Let requiresDeferred be ? RequiresDeferredPromiseResolution(resolution).
  4. If requiresDeferred is true, then
    1. Set promise.[[PromiseState]] to deferred.
    2. Let callerRealm be the current Realm Record.
    3. Let job be NewDeferredSafeResolveJob(promise, resolution, callerRealm).
    4. Perform HostEnqueuePromiseJob(job.[[Job]], job.[[Realm]]).
    5. Return undefined.
  5. Return ? PromiseResolve(promise, resolution).
Note

deferred is a new state that I've not run through the rest of the spec, but the intention is that it prevents future resolutions from overriding the resolution applied here.

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.