package com.eclipsesource.v8;

import com.tencent.matrix.trace.core.AppMethodBeat;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

class V8ContextWrapper implements InvocationHandler {
    private static final String TAG = "V8ContextWrapper";
    private final MultiContextV8 multiContextV8;
    private final V8Context proxy = ((V8Context) Proxy.newProxyInstance(V8ContextWrapper.class.getClassLoader(), new Class[]{V8Context.class}, this));
    private final V8ContextImpl v8ContextImpl;
    private final long v8ContextPtr;

    V8ContextWrapper(MultiContextV8 multiContextV8, long j) {
        AppMethodBeat.i(75487);
        this.multiContextV8 = multiContextV8;
        this.v8ContextPtr = j;
        enterContext();
        this.v8ContextImpl = new V8ContextImpl(this, j);
        AppMethodBeat.o(75487);
    }

    public V8Context context() {
        return this.proxy;
    }

    /* Access modifiers changed, original: protected */
    public long getPtr() {
        return this.v8ContextPtr;
    }

    private void enterContext() {
        AppMethodBeat.i(75488);
        this.multiContextV8.enterContext(this);
        AppMethodBeat.o(75488);
    }

    public boolean equals(Object obj) {
        AppMethodBeat.i(75489);
        if (this == obj) {
            AppMethodBeat.o(75489);
            return true;
        } else if (obj == null || getClass() != obj.getClass()) {
            AppMethodBeat.o(75489);
            return false;
        } else {
            if (this.v8ContextPtr == ((V8ContextWrapper) obj).v8ContextPtr) {
                AppMethodBeat.o(75489);
                return true;
            }
            AppMethodBeat.o(75489);
            return false;
        }
    }

    public int hashCode() {
        return (int) (this.v8ContextPtr ^ (this.v8ContextPtr >>> 32));
    }

    public Object invoke(Object obj, Method method, Object[] objArr) {
        AppMethodBeat.i(75490);
        if (!method.getName().equals("isReleased")) {
            this.v8ContextImpl.checkReleased();
            enterContext();
        }
        try {
            Object invoke = method.invoke(this.v8ContextImpl, objArr);
            AppMethodBeat.o(75490);
            return invoke;
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            AppMethodBeat.o(75490);
            throw cause;
        }
    }
}
