mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 04:24:15 +00:00
crash gracefully on fatal js errors
Reviewed By: AaaChiuuu Differential Revision: D2739392 fb-gh-sync-id: bcc1171c076a4f6425184e7b9ffed204f5ce6f0e
This commit is contained in:
parent
4cb04315e7
commit
7871abf907
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import com.facebook.react.bridge.JavaScriptExecutor;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.JavaScriptModulesConfig;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
|
||||
import com.facebook.react.bridge.NativeModuleRegistry;
|
||||
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
|
||||
import com.facebook.react.bridge.ProxyJavaScriptExecutor;
|
||||
@ -100,6 +101,7 @@ import com.facebook.systrace.Systrace;
|
||||
private volatile boolean mHasStartedCreatingInitialContext = false;
|
||||
private final UIImplementationProvider mUIImplementationProvider;
|
||||
private final MemoryPressureRouter mMemoryPressureRouter;
|
||||
private final @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
|
||||
|
||||
private final ReactInstanceDevCommandsHandler mDevInterface =
|
||||
new ReactInstanceDevCommandsHandler() {
|
||||
@ -195,7 +197,8 @@ import com.facebook.systrace.Systrace;
|
||||
boolean useDeveloperSupport,
|
||||
@Nullable NotThreadSafeBridgeIdleDebugListener bridgeIdleDebugListener,
|
||||
LifecycleState initialLifecycleState,
|
||||
UIImplementationProvider uiImplementationProvider) {
|
||||
UIImplementationProvider uiImplementationProvider,
|
||||
NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler) {
|
||||
initializeSoLoaderIfNecessary(applicationContext);
|
||||
|
||||
mApplicationContext = applicationContext;
|
||||
@ -216,6 +219,7 @@ import com.facebook.systrace.Systrace;
|
||||
mLifecycleState = initialLifecycleState;
|
||||
mUIImplementationProvider = uiImplementationProvider;
|
||||
mMemoryPressureRouter = new MemoryPressureRouter(applicationContext);
|
||||
mNativeModuleCallExceptionHandler = nativeModuleCallExceptionHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -652,13 +656,16 @@ import com.facebook.systrace.Systrace;
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
NativeModuleCallExceptionHandler exceptionHandler = mNativeModuleCallExceptionHandler != null
|
||||
? mNativeModuleCallExceptionHandler
|
||||
: mDevSupportManager;
|
||||
CatalystInstanceImpl.Builder catalystInstanceBuilder = new CatalystInstanceImpl.Builder()
|
||||
.setCatalystQueueConfigurationSpec(CatalystQueueConfigurationSpec.createDefault())
|
||||
.setJSExecutor(jsExecutor)
|
||||
.setRegistry(nativeModuleRegistry)
|
||||
.setJSModulesConfig(javaScriptModulesConfig)
|
||||
.setJSBundleLoader(jsBundleLoader)
|
||||
.setNativeModuleCallExceptionHandler(mDevSupportManager);
|
||||
.setNativeModuleCallExceptionHandler(exceptionHandler);
|
||||
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createCatalystInstance");
|
||||
CatalystInstance catalystInstance;
|
||||
|
Loading…
x
Reference in New Issue
Block a user