Fail-Fast on Redundant Java Callback Invocations

Reviewed By: dcaspi

Differential Revision: D4354731

fbshipit-source-id: d23351f23c8c5962da60af77340166fcb1314d78
This commit is contained in:
Theo Yaung 2016-12-21 10:52:26 -08:00 committed by Facebook Github Bot
parent 8305743725
commit e64618374b
1 changed files with 8 additions and 0 deletions

View File

@ -17,15 +17,23 @@ public final class CallbackImpl implements Callback {
private final CatalystInstance mCatalystInstance;
private final ExecutorToken mExecutorToken;
private final int mCallbackId;
private boolean mInvoked;
public CallbackImpl(CatalystInstance bridge, ExecutorToken executorToken, int callbackId) {
mCatalystInstance = bridge;
mExecutorToken = executorToken;
mCallbackId = callbackId;
mInvoked = false;
}
@Override
public void invoke(Object... args) {
if (mInvoked) {
throw new RuntimeException("Illegal callback invocation from native "+
"module. This callback type only permits a single invocation from "+
"native code.");
}
mCatalystInstance.invokeCallback(mExecutorToken, mCallbackId, Arguments.fromJavaArgs(args));
mInvoked = true;
}
}