crash gracefully on fatal js errors

Reviewed By: AaaChiuuu

Differential Revision: D2739392

fb-gh-sync-id: bcc1171c076a4f6425184e7b9ffed204f5ce6f0e
This commit is contained in:
Felix Oghina
2015-12-15 08:19:53 -08:00
committed by facebook-github-bot-6
parent 4cb04315e7
commit 7871abf907
2 changed files with 23 additions and 3 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);
}
}
}