mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Log SoftExceptions when the legacy NativeModule system is used
Summary: When ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse is true, we will log a SoftException, whenever: 1. A Java/Cxx NativeModule is created by the legacy system. 2. Any method on the Java NativeModule is executed, including getConstants(). NOTE: Logs to CXXModule use incoming. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D30252953 fbshipit-source-id: 570929624d0114bb298c593ba909e5cdbd54bd6c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2b427f8692
commit
f93d95e079
@@ -15,6 +15,7 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -43,6 +44,7 @@ public class JavaModuleWrapper {
|
||||
private final ModuleHolder mModuleHolder;
|
||||
private final ArrayList<NativeModule.NativeMethod> mMethods;
|
||||
private final ArrayList<MethodDescriptor> mDescs;
|
||||
private static final String TAG = JavaModuleWrapper.class.getSimpleName();
|
||||
|
||||
public JavaModuleWrapper(JSInstance jsInstance, ModuleHolder moduleHolder) {
|
||||
mJSInstance = jsInstance;
|
||||
@@ -113,6 +115,17 @@ public class JavaModuleWrapper {
|
||||
|
||||
@DoNotStrip
|
||||
public @Nullable NativeMap getConstants() {
|
||||
if (ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse) {
|
||||
ReactSoftExceptionLogger.logSoftException(
|
||||
TAG,
|
||||
new ReactNoCrashSoftException(
|
||||
"Calling getConstants() on Java NativeModule (name = \""
|
||||
+ mModuleHolder.getName()
|
||||
+ "\", className = "
|
||||
+ mModuleHolder.getClassName()
|
||||
+ ")."));
|
||||
}
|
||||
|
||||
if (!mModuleHolder.getHasConstants()) {
|
||||
return null;
|
||||
}
|
||||
@@ -144,10 +157,34 @@ public class JavaModuleWrapper {
|
||||
|
||||
@DoNotStrip
|
||||
public void invoke(int methodId, ReadableNativeArray parameters) {
|
||||
if (ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse) {
|
||||
ReactSoftExceptionLogger.logSoftException(
|
||||
TAG,
|
||||
new ReactNoCrashSoftException(
|
||||
"Calling method on Java NativeModule (name = \""
|
||||
+ mModuleHolder.getName()
|
||||
+ "\", className = "
|
||||
+ mModuleHolder.getClassName()
|
||||
+ ")."));
|
||||
}
|
||||
|
||||
if (mMethods == null || methodId >= mMethods.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ReactFeatureFlags.warnOnLegacyNativeModuleSystemUse) {
|
||||
ReactSoftExceptionLogger.logSoftException(
|
||||
TAG,
|
||||
new ReactNoCrashSoftException(
|
||||
"Calling "
|
||||
+ mDescs.get(methodId).name
|
||||
+ "() on Java NativeModule (name = \""
|
||||
+ mModuleHolder.getName()
|
||||
+ "\", className = "
|
||||
+ mModuleHolder.getClassName()
|
||||
+ ")."));
|
||||
}
|
||||
|
||||
mMethods.get(methodId).invoke(mJSInstance, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user