Fix check for if we are ready to make js calls

Reviewed By: mhorowitz

Differential Revision: D3485010

fbshipit-source-id: 5a3ce9be6a88f02478fb711fd09c57e4b2ccfc0d
This commit is contained in:
Chris Hopman 2016-06-24 19:18:31 -07:00 коммит произвёл Facebook Github Bot 6
Родитель f8c486f03c
Коммит d055ab548e
1 изменённых файлов: 13 добавлений и 2 удалений

Просмотреть файл

@ -75,6 +75,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
private final NativeModuleRegistry mJavaRegistry;
private final NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
private boolean mInitialized = false;
private volatile boolean mAcceptCalls = false;
private boolean mJSBundleHasLoaded;
@ -165,6 +166,10 @@ public class CatalystInstanceImpl implements CatalystInstance {
@Override
public void runJSBundle() {
// This should really be done when we post the task that runs the JS bundle
// (don't even need to wait for it to finish). Since that is currently done
// synchronously, marking it here is fine.
mAcceptCalls = true;
Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!");
mJSBundleHasLoaded = true;
// incrementPendingJSCalls();
@ -191,8 +196,8 @@ public class CatalystInstanceImpl implements CatalystInstance {
FLog.w(ReactConstants.TAG, "Calling JS function after bridge has been destroyed.");
return;
}
if (!mInitialized) {
throw new RuntimeException("Attempt to call JS function before instance initialization.");
if (!mAcceptCalls) {
throw new RuntimeException("Attempt to call JS function before JS bundle is loaded.");
}
callJSFunction(executorToken, module, method, arguments, tracingName);
@ -253,6 +258,12 @@ public class CatalystInstanceImpl implements CatalystInstance {
Assertions.assertCondition(
!mInitialized,
"This catalyst instance has already been initialized");
// We assume that the instance manager blocks on running the JS bundle. If
// that changes, then we need to set mAcceptCalls just after posting the
// task that will run the js bundle.
Assertions.assertCondition(
mAcceptCalls,
"RunJSBundle hasn't completed.");
mInitialized = true;
mJavaRegistry.notifyCatalystInstanceInitialized();
}