Awesome
Status
This proposal has progressed to the Draft ECMAScript 6 Specification, which is available for review on the official ECMAScript wiki. When referencing the promises specification, you should reference the draft ECMAScript 6 spec, and not this repository.
We are still using this repository as a way to fix the remaining issues with the promises specification, and as such it may be slightly ahead of the draft specification as we perform that work. However, we must emphasize it is only a staging ground.
Promise Objects
A Promise is an object that is used as a placeholder for the eventual results of a deferred (and possibly asynchronous) computation.
Any Promise object is in one of three mutually exclusive states: fulfilled, rejected, and pending:
- A promise
p
is fulfilled ifp.then(f, r)
will immediately enqueue a Task to call the functionf
. - A promise
p
is rejected ifp.then(f, r)
will immediately enqueue a Task to call the functionr
. - A promise is pending if it is neither fulfilled nor rejected.
A promise said to be settled if it is not pending, i.e. if it is either fulfilled or rejected.
A promise is resolved if it is settled or if it has been "locked in" match the state of another promise. Attempting to resolve or reject a resolved promise has no effect. A promise is unresolved if it is not resolved. An unresolved promise is always in the pending state. A resolved promise may be pending, fullfilled, or rejected.
Promise Abstract Operations
PromiseCapability Records
A PromiseCapability is a Record value used to encapsulate a promise object along with the functions that are capable of resolving or rejecting that promise object. PromiseCapability records are produced by the NewPromiseCapability abstract operation.
PromiseCapability Records have the fields listed in this table.
<table> <caption>PromiseCapability Record Fields</caption> <thead> <tr> <th>Field Name</th> <th>Value</th> <th>Meaning</th> </tr> </thead> <tbody> <tr> <td>[[Promise]]</td> <td>An object</td> <td>An object that is usable as a promise.</td> </tr> <tr> <td>[[Resolve]]</td> <td>A function object</td> <td>The function that is used to resolve the given promise object.</td> </tr> <tr> <td>[[Reject]]</td> <td>A function object</td> <td>The function that is used to reject the given promise object.</td> </tr> </tbody> </table>IfAbruptRejectPromise ( value, capability )
IfAbruptRejectPromise is a short hand for a sequence of algorithm steps that use a PromiseCapability record. An algorithm step of the form:
- IfAbruptRejectPromise(value, capability).
means the same things as:
- If value is an abrupt completion,
- Let rejectResult be the result of calling the [[Call]] internal method of capability.[[Reject]] with undefined as thisArgument and (value.[[value]]) as argumentsList.
- ReturnIfAbrupt(rejectResult).
- Return capability.[[Promise]].
- Else if value is a Completion Record, then let value be value.[[value]].
PromiseReaction Records
The PromiseReaction is a Record value used to store information about how a promise should react when it becomes resolved or rejected with a given value. PromiseReaction records are created by the then
method of the Promise prototype, and are used by a PromiseReactionTask.
PromiseReaction records have the fields listed in this table.
<table> <caption>PromiseReaction Record Fields</caption> <thead> <tr> <th>Field Name</th> <th>Value</th> <th>Meaning</th> </tr> </thead> <tbody> <tr> <td>[[Capabilities]]</td> <td>A PromiseCapability record</td> <td>The capabilities of the promise for which this record provides a reaction handler.</td> </tr> <tr> <td>[[Handler]]</td> <td>A function object, or a String</td> <td>The function that should be applied to the incoming value, and whose return value will govern what happens to the derived promise. If [[Handled]] is <code>"Identity"</code> it is equivalent to a function that simply returns its first argument. If [[Handler]] is <code>"Thrower"</code> it is equivalent to a function that throws its first argument as an exception.</td> </tr> </tbody> </table>CreateResolvingFunctions ( promise )
When CreateResolvingFunctions is performed with argument promise, the following steps are taken:
- Let alreadyResolved be a new Record { [[value]]: false }.
- Let resolve be a new built-in function object as defined in Promise Resolve Functions.
- Set the [[Promise]] internal slot of resolve to promise.
- Set the [[AlreadyResolved]] internal slot of resolve to alreadyResolved.
- Let reject be a new built-in function object as defined in Promise Reject Functions.
- Set the [[Promise]] internal slot of reject to promise.
- Set the [[AlreadyResolved]] internal slot of reject to alreadyResolved.
- Return a new Record { [[Resolve]]: resolve, [[Reject]]: reject }.
Promise Reject Functions
A promise reject function is an anonymous built-in function that has [[Promise]] and [[AlreadyResolved]] internal slots.
When a promise reject function F is called with argument reason, the following steps are taken:
- Assert: F has a [[Promise]] internal slot whose value is an Object.
- Let promise be the value of F's [[Promise]] internal slot.
- Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot.
- If alreadyResolved.[[value]] is true, then return undefined.
- Set alreadyResolved.[[value]] to true.
- Return RejectPromise(promise, reason).
Promise Resolve Functions
A promise resolve function is an anonymous built-in function that has [[Promise]] and [[AlreadyResolved]] internal slots.
When a promise resolve function F is called with argument resolution, the following steps are taken:
- Assert: F has a [[Promise]] internal slot whose value is an Object.
- Let promise be the value of F's [[Promise]] internal slot.
- Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot.
- If alreadyResolved.[[value]] is true, then return undefined.
- Set alreadyResolved.[[value]] to true.
- If SameValue(resolution, promise) is true, then
- Let selfResolutionError be a newly-created TypeError object.
- Return RejectPromise(promise, selfResolutionError).
- If Type(resolution) is not Object, then
- Return FulfillPromise(promise, resolution).
- Let then be Get(resolution,
"then"
). - If then is an abrupt completion, then
- Return RejectPromise(promise, then.[[value]]).
- Let then be then.[[value]].
- If IsCallable(then) is false, then
- Return FulfillPromise(promise, resolution).
- Perform EnqueueTask(
"PromiseTasks"
, ResolvePromiseViaThenableTask, (promise, resolution, then)). - Return undefined.
FulfillPromise ( promise, value )
- Assert: the value of promise's [[PromiseState]] internal slot is
"pending"
. - Let reactions be the value of promise's [[PromiseFulfillReactions]] internal slot.
- Set the value of promise's [[PromiseResult]] internal slot to value.
- Set the value of promise's [[PromiseFulfillReactions]] internal slot to undefined.
- Set the value of promise's [[PromiseRejectReactions]] internal slot to undefined.
- Set the value of promise's [[PromiseState]] internal slot to
"fulfilled"
. - Return TriggerPromiseReactions(reactions, value).
NewPromiseCapability ( C )
The abstract operation NewPromiseCapability takes a constructor function, and attempts to use that constructor function in the fashion of the built-in Promise
constructor to create a Promise object and extract its resolve and reject functions. The promise plus the resolve and reject functions are used to initialise a new PromiseCapability record which is returned as the value of this abstract operation.
- If IsConstructor(C) is false, throw a TypeError.
- Assert: C is a constructor function that supports the parameter conventions of the
Promise
constructor. - Let promise be CreateFromConstructor(C).
- ReturnIfAbrupt(promise).
- If Type(promise) is not Object, then throw a TypeError exception.
- Return CreatePromiseCapabilityRecord(promise, C).
NOTE: This abstract operation supports Promise subclassing, as it is generic on any constructor that calls a passed executor function argument in the same way as the Promise constructor. It is used to generalize static methods of the Promise constructor to any subclass.
CreatePromiseCapabilityRecord ( promise, constructor )
- Assert: promise is an uninitialized object created as if by invoking @@create on constructor.
- Let promiseCapability be a new PromiseCapability { [[Promise]]: promise, [[Resolve]]: undefined, [[Reject]]: undefined }.
- Let executor be a new built-in function object as defined in GetCapabilitiesExecutor Functions.
- Set the [[Capability]] internal slot of executor to promiseCapability.
- Let constructorResult be the result of calling the [[Call]] internal method of constructor, passing promise and (executor) as the arguments.
- ReturnIfAbrupt(constructorResult).
- If IsCallable(promiseCapability.[[Resolve]]) is false, then throw a TypeError exception.
- If IsCallable(promiseCapability.[[Reject]]) is false, then throw a TypeError exception.
- If Type(constructorResult) is Object and SameValue(promise, constructorResult) is false, then throw a TypeError exception.
- Return promiseCapability.
GetCapabilitiesExecutor Functions
A GetCapabilitiesExecutor function is an anonymous built-in function that has a [[Capability]] internal slot.
When a GetCapabilitiesExecutor function F is called with arguments resolve and reject the following steps are taken:
- Assert: F has a [[Capability]] internal slot whose value is a PromiseCapability Record.
- Let promiseCapability be the value of F's [[Capability]] internal slot.
- If promiseCapability.[[Resolve]] is not undefined, then throw a TypeError exception.
- If promiseCapability.[[Reject]] is not undefined, then throw a TypeError exception.
- Set promiseCapability.[[Resolve]] to resolve.
- Set promiseCapability.[[Reject]] to reject.
- Return undefined.
RejectPromise ( promise, reason )
- Assert: the value of promise's [[PromiseState]] internal slot is
"pending"
. - Let reactions be the value of promise's [[PromiseRejectReactions]] internal slot.
- Set the value of promise's [[PromiseResult]] internal slot to reason.
- Set the value of promise's [[PromiseFulfillReactions]] internal slot to undefined.
- Set the value of promise's [[PromiseRejectReactions]] internal slot to undefined.
- Set the value of promise's [[PromiseState]] internal slot to
"rejected"
. - Return TriggerPromiseReactions(reactions, reason).
IsPromise ( x )
The abstract operation IsPromise checks for the promise brand on an object.
- If Type(x) is not Object, return false.
- If x does not have a [[PromiseState]] internal slot, return false.
- If the value of x's [[PromiseState]] internal slot is undefined, return false.
- Return true.
TriggerPromiseReactions ( reactions, argument )
The abstract operation TriggerPromiseReactions takes a collection of functions to trigger in the next Task, and calls them, passing each the given argument. Typically, these reactions will modify a previously-returned promise, possibly calling in to a user-supplied handler before doing so.
- Repeat for each reaction in reactions, in original insertion order
- Perform EnqueueTask(
"PromiseTasks"
, PromiseReactionTask, (reaction, argument)).
- Perform EnqueueTask(
- Return undefined.
Promise Tasks
PromiseReactionTask ( reaction, argument )
The task PromiseReactionTask with parameters reaction and argument applies the appropriate handler to the incoming value, and uses the handler's return value to resolve or reject the derived promise associated with that handler.
- Assert: reaction is a PromiseReaction Record.
- Let promiseCapability be reaction.[[Capabilities]].
- Let handler be reaction.[[Handler]].
- If handler is
"Identity"
, then let handlerResult be NormalCompletion(argument). - Else if handler is
"Thrower"
, then let handlerResult be Completion{ [[type]]: throw, [[value]]: argument, [[target]]: empty }. - Else, let handlerResult be the result of calling the [[Call]] internal method of handler passing undefined as thisArgument and (argument) as argumentsList.
- If handlerResult is an abrupt completion, then
- Let status be the result of calling the [[Call]] internal method of promiseCapability.[[Reject]] passing undefined as thisArgument and (handlerResult.[[value]]) as argumentsList.
- NextTask status.
- Let handlerResult be handlerResult.[[value]].
- Let status be the result of calling the [[Call]] internal method of promiseCapability.[[Resolve]] passing undefined as thisArgument and (handlerResult) as argumentsList.
- NextTask status.
ResolvePromiseViaThenableTask ( promiseToResolve, thenable, then )
The task ResolvePromiseViaThenableTask with parameters promiseToResolve, thenable, and then uses the supplied thenable and its then
method to resolve the given promise. This process must take place in an enqueued task to ensure that code inside the then
method cannot disrupt the invariants of surrounding code.
- Let resolvingFunctions be CreateResolvingFunctions(promiseToResolve).
- Let thenCallResult be the result of calling the [[Call]] internal method of then passing thenable as thisArgument and (resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]) as argumentsList.
- If thenCallResult is an abrupt completion,
- Let status be the result of calling the [[Call]] internal method of resolvingFunctions.[[Reject]] passing undefined as thisArgument and (thenCallResult.[[value]]) as argumentsList.
- NextTask status.
- NextTask thenCallResult.
The Promise Constructor
The Promise constructor is the %Promise% intrinsic object and the initial value of the Promise
property of the global object. When Promise
is called as a function rather than as a constructor, it initialises its this value with the internal state necessary to support the Promise.prototype
methods.
The Promise
constructor is designed to be subclassable. It may be used as the value in an extends
clause of a class definition. Subclass constructors that intend to inherit the specified Promise
behaviour must include a super
call to Promise
.
Promise ( executor )
When the Promise
function is called with argument executor the following steps are taken:
- Let promise be the this value.
- If Type(promise) is not Object, then throw a TypeError exception.
- If promise does not have a [[PromiseState]] internal slot, then throw a TypeError exception.
- If promise's [[PromiseState]] internal slot is not undefined, then throw a TypeError exception.
- If IsCallable(executor) is false, then throw a TypeError exception.
- Return InitialisePromise(promise, executor).
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 object. 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.
The resolve function that is passed to an executor function accepts a single argument. The executor code may eventually call the resolve function to indicate that it wishes to resolve the associated Promise object. The argument passed to the resolve function represents the eventual value of the deferred action and can be either the actual fulfillment value or another Promise object which will provide the value if it is fullfilled.
The reject function that is passed to an executor function accepts a single argument. The executor code may eventually call the reject function to indicate that the associated Promise is rejected and will never be fulfilled. The argument passed to the reject function is used as the rejection value of the promise. Typically it will be an Error
object.
The resolve and reject functions passed to an executor function by the Promise constructor have the capability to actually resolve and reject the associated promise. Subclasses may have different constructor behaviour that passes in customized values for resolve and reject.
InitialisePromise ( promise, executor )
The abstract operation InitialisePromise initialises a newly allocated promise object using an executor function.
- Assert: promise has a [[PromiseState]] internal slot and its value is undefined.
- Assert: IsCallable(executor) is true.
- Set promise's [[PromiseState]] internal slot to
"pending"
. - Set promise's [[PromiseFulfillReactions]] internal slot to a new empty List.
- Set promise's [[PromiseRejectReactions]] internal slot to a new empty List.
- Let resolvingFunctions be CreateResolvingFunctions(promise).
- Let completion be the result of calling the [[Call]] internal method of executor with undefined as thisArgument and (resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]) as argumentsList.
- If completion is an abrupt completion, then
- Let status be the result of calling the [[Call]] internal method of resolvingFunctions.[[Reject]] with undefined as thisArgument and (completion.[[value]]) as argumentsList.
- ReturnIfAbrupt(status).
- Return promise.
new Promise ( ... argumentsList )
When Promise
is called as part of a new
expression it is a constructor: it initialises a newly created object.
Promise
called as part of a new expression with argument list argumentsList performs the following steps:
- Let F be the
Promise
function object on which thenew
operator was applied. - Let argumentsList be the argumentsList argument of the [[Construct]] internal method that was invoked by the
new
operator. - Return Construct(F, argumentsList).
If Promise is implemented as an ECMAScript function object, its [[Construct]] internal method will perform the above steps.
Properties of the Promise Constructor
The value of the [[Prototype]] internal slot of the Promise
constructor is the Function
prototype object.
Besides the length
property (whose value is 1), the Promise constructor has the following properties:
Promise.all ( iterable )
The all
function returns a new promise which is fulfilled with an array of fulfillment values for the passed promises, or rejects with the reason of the first passed promise that rejects. It resolves all elements of the passed iterable to promises as it runs this algorithm.
- Let C be the this value.
- Let promiseCapability be NewPromiseCapability(C).
- ReturnIfAbrupt(promiseCapability).
- Let iterator be GetIterator(iterable).
- IfAbruptRejectPromise(iterator, promiseCapability).
- Let values be ArrayCreate(0).
- Let remainingElementsCount be a new Record { [[value]]: 1 }.
- Let index be 0.
- Repeat
- Let next be IteratorStep(iterator).
- IfAbruptRejectPromise(next, promiseCapability).
- If next is false,
- Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] - 1.
- If remainingElementsCount.[[value]] is 0,
- Let resolveResult be the result of calling the [[Call]] internal method of promiseCapability.[[Resolve]] with undefined as thisArgument and (values) as argumentsList.
- ReturnIfAbrupt(resolveResult).
- Return promiseCapability.[[Promise]].
- Let nextValue be IteratorValue(next).
- IfAbruptRejectPromise(nextValue, promiseCapability).
- Let nextPromise be Invoke(C,
"resolve"
, (nextValue)). - IfAbruptRejectPromise(nextPromise, promiseCapability).
- Let resolveElement be a new built-in function object as defined in Promise.all Resolve Element Functions.
- Set the [[AlreadyCalled]] internal slot of resolveElement to false.
- Set the [[Index]] internal slot of resolveElement to index.
- Set the [[Values]] internal slot of resolveElement to values.
- Set the [[Capabilities]] internal slot of resolveElement to promiseCapabilities.
- Set the [[RemainingElements]] internal slot of resolveElement to remainingElementsCount.
- Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] + 1.
- Let result be Invoke(nextPromise,
"then"
, (resolveElement, promiseCapability.[[Reject]])). - IfAbruptRejectPromise(result, promiseCapability).
- Set index to index + 1.
Note: The all
function requires its this value to be a constructor function that supports the parameter conventions of the Promise
constructor.
Promise.all Resolve Element Functions
A Promise.all resolve element function is an anonymous built-in function that is used to resolve a specific Promise.all element. Each Promise.all resolve element function has [[Index]], [[Values]], [[Capabilities]], [[RemainingElements]], and [[AlreadyCalled]] internal slots.
When a Promise.all resolve element function F is called with argument x, the following steps are taken:
- If the value of F's [[AlreadyCalled]] internal slot is true, then return undefined.
- Set the [[AlreadyCalled]] internal slot of F to true.
- Let index be the value of F's [[Index]] internal slot.
- Let values be the value of F's [[Values]] internal slot.
- Let promiseCapability be the value of F's [[Capabilities]] internal slot.
- Let remainingElementsCount be the value of F's [[RemainingElements]] internal slot.
- Let result be CreateDataProperty(values, ToString(index), x).
- IfAbruptRejectPromise(result, promiseCapability).
- Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] - 1.
- If remainingElementsCount.[[value]] is 0,
- Return the result of calling the [[Call]] internal method of promiseCapability.[[Resolve]] with undefined as thisArgument and (values) as argumentsList.
- Return undefined.
Promise.prototype
The initial value of Promise.prototype
is the Promise prototype object.
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.
Promise.race ( iterable )
The race
function returns a new promise which is settled in the same way as the first passed promise to settle. It resolves all elements of the passed iterable to promises as it runs this algorithm.
- Let C be the this value.
- Let promiseCapability be NewPromiseCapability(C).
- ReturnIfAbrupt(promiseCapability).
- Let iterator be GetIterator(iterable).
- IfAbruptRejectPromise(iterator, promiseCapability).
- Repeat
- Let next be IteratorStep(iterator).
- IfAbruptRejectPromise(next, promiseCapability).
- If next is false, return promiseCapability.[[Promise]].
- Let nextValue be IteratorValue(next).
- IfAbruptRejectPromise(nextValue, promiseCapability).
- Let nextPromise be Invoke(C,
"resolve"
, (nextValue)). - IfAbruptRejectPromise(nextPromise, promiseCapability).
- Let result be Invoke(nextPromise,
"then"
, (promiseCapability.[[Resolve]], promiseCapability.[[Reject]])). - IfAbruptRejectPromise(result, promiseCapability).
Note: The race
function requires its this value to be a constructor function that supports the parameter conventions of the Promise
constructor. It also requires that its this value provides a resolve
method.
Promise.reject ( r )
The reject
function returns a new promise rejected with the passed argument.
- Let C be the this value.
- Let promiseCapability be NewPromiseCapability(C).
- ReturnIfAbrupt(promiseCapability).
- Let rejectResult be the result of calling the [[Call]] internal method of promiseCapability.[[Reject]] with undefined as thisArgument and (r) as argumentsList.
- ReturnIfAbrupt(rejectResult).
- Return promiseCapability.[[Promise]].
Note: The reject
function requires its this value to be a constructor function that supports the parameter conventions of the Promise
constructor.
Promise.resolve ( x )
The resolve
function returns a new promise resolved with the passed argument, or returns the argument if it is already a promise branded with the correct type.
- Let C be the this value.
- If IsPromise(x) is true,
- Let constructor be the value of x's [[PromiseConstructor]] internal slot.
- If SameValue(constructor, C) is true, return x.
- Let promiseCapability be NewPromiseCapability(C).
- ReturnIfAbrupt(promiseCapability).
- Let resolveResult be the result of calling the [[Call]] internal method of promiseCapability.[[Resolve]] with undefined as thisArgument and (x) as argumentsList.
- ReturnIfAbrupt(resolveResult).
- Return promiseCapability.[[Promise]].
Note: The resolve
function requires its this value to be a constructor function that supports the parameter conventions of the Promise
constructor.
Promise [ @@create ] ( )
The @@create method of a Promise function object F performs the following steps:
- Let F be the this value.
- Return AllocatePromise(F).
The value of the name
property of this function is "[Symbol.create]"
.
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
AllocatePromise ( constructor )
The abstract operation AllocatePromise allocates a new promise object using the constructor argument.
- Let obj be OrdinaryCreateFromConstructor(constructor,
"%PromisePrototype%"
, ([[PromiseState]], [[PromiseConstructor]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]])). - Set obj's [[PromiseConstructor]] internal slot to constructor.
- Return obj.
Properties of the Promise Prototype Object
The value of the [[Prototype]] internal slot of the Promise prototype object is the standard built-in Object prototype object. The Promise prototype object is an ordinary object. It does not have a [[PromiseState]] internal slot or any of the other internal slots of Promise instances.
Promise.prototype.catch ( onRejected )
When the catch
method is called with argument onRejected the following steps are taken:
- Let promise be the this value.
- Return Invoke(promise,
"then"
, (undefined, onRejected)).
Promise.prototype.constructor
The initial value of Promise.prototype.constructor
is the standard built-in Promise
constructor.
Promise.prototype.then ( onFulfilled , onRejected )
When the then
method is called with arguments onFulfilled and onRejected the following steps are taken:
- Let promise be the this value.
- If IsPromise(promise) is false, throw a TypeError exception.
- If IsCallable(onFulfilled) is false, then
- Let onFulfilled be
"Identity"
.
- Let onFulfilled be
- If IsCallable(onRejected) is false, then
- Let onRejected be
"Thrower"
.
- Let onRejected be
- Let C be Get(promise, "constructor").
- ReturnIfAbrupt(C).
- Let promiseCapability be NewPromiseCapability(C).
- ReturnIfAbrupt(promiseCapability).
- Let fulfillReaction be the PromiseReaction { [[Capabilities]]: promiseCapability, [[Handler]]: onFulfilled }.
- Let rejectReaction be the PromiseReaction { [[Capabilities]]: promiseCapability, [[Handler]]: onRejected }.
- If the value of promise's [[PromiseState]] internal slot is
"pending"
,- Append fulfillReaction as the last element of the List that is the value of promise's [[PromiseFulfillReactions]] internal slot.
- Append rejectReaction as the last element of the List that is the value of promise's [[PromiseRejectReactions]] internal slot.
- Else if the value of promise's [[PromiseState]] internal slot is
"fulfilled"
,- Let value be the value of promise's [[PromiseResult]] internal slot.
- Call EnqueueTask(
"PromiseTasks"
, PromiseReactionTask, (fulfillReaction, value)).
- Else if the value of promise's [[PromiseState]] internal slot is
"rejected"
,- Let reason be the value of promise's [[PromiseResult]] internal slot.
- Call EnqueueTask(
"PromiseTasks"
, (rejectReaction, reason)).
- Return promiseCapability.[[Promise]].
Promise.prototype [ @@toStringTag ]
The initial value of the @@toStringTag property is the string value "Promise"
.
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
Properties of Promise Instances
Promise instances are ordinary objects that inherit properties from the Promise prototype object (the intrinsic, %PromisePrototype%). Promise instances are initially created with the internal slots described in this table.
<table> <caption>Internal Slots of Promise Instances</caption> <thead> <tr> <th>Internal Slot</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>[[PromiseState]]</td> <td>A string value that governs how a promise will react to incoming calls to its <code>then</code> method. The possible values are: <b>undefined</b>, <code>"pending"</code>, <code>"fulfilled"</code>, and <code>"rejected"</code>.</td> </tr> <tr> <td>[[PromiseConstructor]]</td> <td>The function object that was used to construct this promise. Checked by the <code>resolve</code> method of the <code>Promise</code> constructor.</td> </tr> <tr> <td>[[PromiseResult]]</td> <td>The value with which the promise has been fulfilled or rejected, if any. Only meaningful if [[PromiseState]] is not <code>"pending"</code>.</td> </tr> <tr> <td>[[PromiseFulfillReactions]]</td> <td>A List of PromiseReaction records to be processed when/if the promise transitions from the <code>"pending"</code> state to the <code>"fulfilled"</code> state.</td> </tr> <tr> <td>[[PromiseRejectReactions]]</td> <td>A List of PromiseReaction records to be processed when/if the promise transitions from the <code>"pending"</code> state to the <code>"rejected"</code> state.</td> </tr> </tbody> </table>Deltas to Other Areas of the Spec
Well-Known Intrinsic Objects Table
Add the following rows:
<table> <tr> <td>%Promise%</td> <td>The initial value of the global object property named <code>"Promise"</code>.</td> </tr> <tr> <td>%PromisePrototype%</td> <td>The initial value of the <code>"prototype"</code> data property of the intrinsic %Promise%.</td> </tr> </table><p xmlns:dct="http://purl.org/dc/terms/" xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"> <a rel="license" href="http://creativecommons.org/publicdomain/zero/1.0/"> <img src="http://i.creativecommons.org/p/zero/1.0/88x31.png" style="border-style: none;" alt="CC0" /> </a> <br /> To the extent possible under law, <a rel="dct:publisher" href="http://domenicdenicola.com"><span property="dct:title">Domenic Denicola</span></a> has waived all copyright and related or neighboring rights to <span property="dct:title">promises-unwrapping</span>.
This work is published from:
<span property="vcard:Country" datatype="dct:ISO3166" content="US" about="http://domenicdenicola.com">
United States
</span>.
</p>