crash gracefully on fatal js errors (take two)

Reviewed By: AaaChiuuu

Differential Revision: D2773513

fb-gh-sync-id: f8e50ad12e808caf1d85c6c7859c04fcabdaaeae
This commit is contained in:
Felix Oghina
2016-01-04 13:16:58 -08:00
committed by facebook-github-bot-7
parent f2bdb79782
commit 4866ec2767
3 changed files with 33 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ import android.app.Application;
import android.content.Intent;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
@@ -159,6 +160,7 @@ public abstract class ReactInstanceManager {
protected boolean mUseDeveloperSupport;
protected @Nullable LifecycleState mInitialLifecycleState;
protected @Nullable UIImplementationProvider mUIImplementationProvider;
protected @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
protected Builder() {
}
@@ -242,6 +244,16 @@ public abstract class ReactInstanceManager {
return this;
}
/**
* Set the exception handler for all native module calls. If not set, the default
* {@link DevSupportManager} will be used, which shows a redbox in dev mode and rethrows
* (crashes the app) in prod mode.
*/
public Builder setNativeModuleCallExceptionHandler(NativeModuleCallExceptionHandler handler) {
mNativeModuleCallExceptionHandler = handler;
return this;
}
/**
* Instantiates a new {@link ReactInstanceManagerImpl}.
* Before calling {@code build}, the following must be called:
@@ -274,7 +286,8 @@ public abstract class ReactInstanceManager {
mUseDeveloperSupport,
mBridgeIdleDebugListener,
Assertions.assertNotNull(mInitialLifecycleState, "Initial lifecycle state was not set"),
mUIImplementationProvider);
mUIImplementationProvider,
mNativeModuleCallExceptionHandler);
}
}
}