Search in sources :

Example 1 with CreateResolvingFunctions

use of com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.CreateResolvingFunctions in project es6draft by anba.

the class PromiseConstructor method construct.

/**
     * 25.4.3.1 Promise ( executor )
     */
@Override
public PromiseObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    Object executor = argument(args, 0);
    /* step 2 */
    if (!IsCallable(executor)) {
        throw newTypeError(calleeContext, Messages.Key.NotCallable);
    }
    /* steps 3-7 */
    PromiseObject promise = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.PromisePrototype, GetPromiseAllocator(calleeContext.getRealm()));
    /* step 8 */
    ResolvingFunctions resolvingFunctions = CreateResolvingFunctions(calleeContext, promise);
    /* steps 9-10 */
    try {
        /* step 9 */
        ((Callable) executor).call(calleeContext, UNDEFINED, resolvingFunctions.getResolve(), resolvingFunctions.getReject());
    } catch (ScriptException e) {
        /* step 10 */
        resolvingFunctions.getReject().call(calleeContext, UNDEFINED, e.getValue());
    }
    /* step 11 */
    return promise;
}
Also used : ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) ResolvingFunctions(com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.ResolvingFunctions) CreateResolvingFunctions(com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.CreateResolvingFunctions) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)1 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)1 CreateResolvingFunctions (com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.CreateResolvingFunctions)1 ResolvingFunctions (com.github.anba.es6draft.runtime.objects.promise.PromiseAbstractOperations.ResolvingFunctions)1 Callable (com.github.anba.es6draft.runtime.types.Callable)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)1