use of com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.PromiseReactionJob in project es6draft by anba.
the class PromisePrototype method PerformPromiseThen.
/**
* 25.4.5.3.1 PerformPromiseThen ( promise, onFulfilled, onRejected, resultCapability )
*
* @param <PROMISE>
* the promise type
* @param cx
* the execution context
* @param promise
* the promise object
* @param onFulfilled
* the onFulfilled handler
* @param onRejected
* the onRejected handler
* @param resultCapability
* the new promise capability record
* @return the new promise object
*/
public static <PROMISE extends ScriptObject> PROMISE PerformPromiseThen(ExecutionContext cx, PromiseObject promise, Object onFulfilled, Object onRejected, PromiseCapability<PROMISE> resultCapability) {
/* step 3 */
if (!IsCallable(onFulfilled)) {
onFulfilled = null;
}
/* step 4 */
if (!IsCallable(onRejected)) {
onRejected = null;
}
ZoneObject currentZone = cx.getRealm().getCurrentZone();
/* step 5 */
PromiseReaction fulfillReaction = new PromiseReaction(resultCapability, PromiseReaction.Type.Fulfill, (Callable) onFulfilled, currentZone);
/* step 6 */
PromiseReaction rejectReaction = new PromiseReaction(resultCapability, PromiseReaction.Type.Reject, (Callable) onRejected, currentZone);
/* step 7 */
if (promise.getState() == PromiseObject.State.Pending) {
promise.addFulfillReaction(fulfillReaction);
promise.addRejectReaction(rejectReaction);
promise.notifyRejectReaction(rejectReaction);
} else /* step 8 */
if (promise.getState() == PromiseObject.State.Fulfilled) {
Object value = promise.getResult();
Realm realm = cx.getRealm();
realm.enqueuePromiseJob(new PromiseReactionJob(realm, fulfillReaction, value));
} else /* step 9 */
{
assert promise.getState() == PromiseObject.State.Rejected;
Object reason = promise.getResult();
Realm realm = cx.getRealm();
realm.enqueuePromiseJob(new PromiseReactionJob(realm, rejectReaction, reason));
promise.notifyRejectReaction(rejectReaction);
}
/* step 11 */
return resultCapability.getPromise();
}
Aggregations