package o;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CancellationException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.js, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public abstract class AbstractC1618js extends Nc0 {
    public int n;

    public AbstractC1618js(int i) {
        super(false, 0L);
        this.n = i;
    }

    public abstract InterfaceC0220Im c();

    public Throwable d(Object obj) {
        C2075oj c2075oj = obj instanceof C2075oj ? (C2075oj) obj : null;
        if (c2075oj != null) {
            return c2075oj.a;
        }
        return null;
    }

    public final void g(Throwable th) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        AbstractC1155f00.t(new C0143Fn("Fatal exception in coroutines machinery for " + this + ". Please read KDoc to 'handleFatalException' method and report this incident to maintainers", th), c().h());
    }

    public abstract Object i();

    @Override // java.lang.Runnable
    public final void run() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        try {
            C1428hs c1428hs = (C1428hs) c();
            AbstractC0298Lm abstractC0298Lm = c1428hs.p;
            Object obj = c1428hs.r;
            InterfaceC2747vn interfaceC2747vnH = abstractC0298Lm.h();
            Object objI = AbstractC1155f00.I(interfaceC2747vnH, obj);
            TI ti = null;
            Jh0 jh0G = objI != AbstractC1155f00.g ? C2887xC.G(abstractC0298Lm, interfaceC2747vnH, objI) : null;
            try {
                InterfaceC2747vn interfaceC2747vnH2 = abstractC0298Lm.h();
                Object objI2 = i();
                Throwable thD = d(objI2);
                if (thD == null) {
                    int i = this.n;
                    boolean z = true;
                    if (i != 1 && i != 2) {
                        z = false;
                    }
                    if (z) {
                        ti = (TI) interfaceC2747vnH2.m(C0669Zu.K);
                    }
                }
                if (ti != null && !ti.b()) {
                    CancellationException cancellationExceptionZ = ti.z();
                    b(cancellationExceptionZ);
                    abstractC0298Lm.resumeWith(new H20(cancellationExceptionZ));
                } else if (thD != null) {
                    abstractC0298Lm.resumeWith(new H20(thD));
                } else {
                    abstractC0298Lm.resumeWith(f(objI2));
                }
                if (jh0G != null && !jh0G.n0()) {
                    return;
                }
                AbstractC1155f00.C(interfaceC2747vnH, objI);
            } catch (Throwable th) {
                if (jh0G == null || jh0G.n0()) {
                    AbstractC1155f00.C(interfaceC2747vnH, objI);
                }
                throw th;
            }
        } catch (Throwable th2) {
            g(th2);
        }
    }

    public void b(CancellationException cancellationException) {
    }

    public Object f(Object obj) {
        return obj;
    }
}
