njs_promise_capability_executor(njs_vm_t *vm, njs_value_t *args,
    njs_uint_t nargs, njs_index_t unused)
{
    njs_promise_context_t     *context;
    njs_promise_capability_t  *capability;

    context = vm->top_frame->function->context;
    capability = context->capability;

    if (njs_slow_path(capability == NULL)) {
        njs_type_error(vm, "failed to get function capability");
        return NJS_ERROR;
    }

    if (!njs_is_undefined(&capability->resolve)) {
        njs_type_error(vm, "capability resolve slot is not undefined");
        return NJS_ERROR;
    }

    if (!njs_is_undefined(&capability->reject)) {
        njs_type_error(vm, "capability reject slot is not undefined");
        return NJS_ERROR;
    }

    capability->resolve = *njs_arg(args, nargs, 1);
    capability->reject = *njs_arg(args, nargs, 2);

    njs_vm_retval_set(vm, &njs_value_undefined);

    return NJS_OK;
}
njs_promise_capability_executor(njs_vm_t *vm, njs_value_t *args,
    njs_uint_t nargs, njs_index_t unused)
{
    njs_promise_context_t     *context;
    njs_promise_capability_t  *capability;

    context = vm->top_frame->function->context;
    capability = context->capability;

    if (njs_slow_path(capability == NULL)) {
        njs_type_error(vm, "failed to get function capability");
        return NJS_ERROR;
    }

    if (!njs_is_undefined(&capability->resolve)) {
        njs_type_error(vm, "capability resolve slot is not undefined");
        return NJS_ERROR;
    }

    if (!njs_is_undefined(&capability->reject)) {
        njs_type_error(vm, "capability reject slot is not undefined");
        return NJS_ERROR;
    }

    capability->resolve = *njs_arg(args, nargs, 1);
    capability->reject = *njs_arg(args, nargs, 2);

    njs_vm_retval_set(vm, &njs_value_undefined);

    return NJS_OK;
}