mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-06 22:38:37 +08:00
Capture StackOverflowExceptions triggered when drawing a ReactViewGroup or ReactRootView
Reviewed By: achen1 Differential Revision: D6653395 fbshipit-source-id: 849b1a2ed6ab9bc057414d451e97a673178c30dd
This commit is contained in:
committed by
Facebook Github Bot
parent
877f1cde2e
commit
1aac962378
@@ -12,6 +12,7 @@ package com.facebook.react;
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -40,6 +41,7 @@ import com.facebook.react.modules.appregistry.AppRegistry;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
import com.facebook.react.uimanager.IllegalViewOperationException;
|
||||
import com.facebook.react.uimanager.JSTouchDispatcher;
|
||||
import com.facebook.react.uimanager.MeasureSpecProvider;
|
||||
import com.facebook.react.uimanager.PixelUtil;
|
||||
@@ -201,6 +203,17 @@ public class ReactRootView extends SizeMonitoringFrameLayout
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
try {
|
||||
super.dispatchDraw(canvas);
|
||||
} catch (StackOverflowError e) {
|
||||
// Adding special exception management for StackOverflowError for logging purposes.
|
||||
// This will be removed in the future.
|
||||
handleException(new IllegalViewOperationException("StackOverflowError", e));
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatchJSTouchEvent(MotionEvent event) {
|
||||
if (mReactInstanceManager == null || !mIsAttachedToInstance ||
|
||||
mReactInstanceManager.getCurrentReactContext() == null) {
|
||||
@@ -496,6 +509,15 @@ public class ReactRootView extends SizeMonitoringFrameLayout
|
||||
mRootViewTag = rootViewTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleException(Exception e) {
|
||||
if (mReactInstanceManager != null && mReactInstanceManager.getCurrentReactContext() != null) {
|
||||
mReactInstanceManager.getCurrentReactContext().handleException(e);
|
||||
} else {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ReactInstanceManager getReactInstanceManager() {
|
||||
return mReactInstanceManager;
|
||||
|
||||
Reference in New Issue
Block a user