mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Convert ExceptionManagerModule to Kotlin (#45812)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45812 # Changelog: [Internal] - As in the title. Reviewed By: mdvacca Differential Revision: D60446630 fbshipit-source-id: 9d27e13735c7d2ae6f1d0e3259ef962513665050
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3735cb3d4f
commit
395f46c847
-92
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.core;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.fbreact.specs.NativeExceptionsManagerSpec;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.common.JavascriptException;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.util.ExceptionDataHelper;
|
||||
import com.facebook.react.util.JSStackTrace;
|
||||
|
||||
@ReactModule(name = NativeExceptionsManagerSpec.NAME)
|
||||
public class ExceptionsManagerModule extends NativeExceptionsManagerSpec {
|
||||
|
||||
private final DevSupportManager mDevSupportManager;
|
||||
|
||||
public ExceptionsManagerModule(DevSupportManager devSupportManager) {
|
||||
super(null);
|
||||
mDevSupportManager = devSupportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportFatalException(String message, ReadableArray stack, double idDouble) {
|
||||
int id = (int) idDouble;
|
||||
|
||||
JavaOnlyMap data = new JavaOnlyMap();
|
||||
data.putString("message", message);
|
||||
data.putArray("stack", stack);
|
||||
data.putInt("id", id);
|
||||
data.putBoolean("isFatal", true);
|
||||
reportException(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportSoftException(String message, ReadableArray stack, double idDouble) {
|
||||
int id = (int) idDouble;
|
||||
|
||||
JavaOnlyMap data = new JavaOnlyMap();
|
||||
data.putString("message", message);
|
||||
data.putArray("stack", stack);
|
||||
data.putInt("id", id);
|
||||
data.putBoolean("isFatal", false);
|
||||
reportException(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportException(ReadableMap data) {
|
||||
String message = data.hasKey("message") ? data.getString("message") : "";
|
||||
ReadableArray stack = data.hasKey("stack") ? data.getArray("stack") : Arguments.createArray();
|
||||
boolean isFatal = data.hasKey("isFatal") ? data.getBoolean("isFatal") : false;
|
||||
|
||||
String extraDataAsJson = ExceptionDataHelper.getExtraDataAsJson(data);
|
||||
if (isFatal) {
|
||||
JavascriptException ex = new JavascriptException(JSStackTrace.format(message, stack));
|
||||
ex.setExtraDataAsJson(extraDataAsJson);
|
||||
throw ex;
|
||||
} else {
|
||||
FLog.e(ReactConstants.TAG, JSStackTrace.format(message, stack));
|
||||
if (extraDataAsJson != null) {
|
||||
FLog.d(ReactConstants.TAG, "extraData: %s", extraDataAsJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateExceptionMessage(
|
||||
String title, ReadableArray details, double exceptionIdDouble) {
|
||||
int exceptionId = (int) exceptionIdDouble;
|
||||
|
||||
if (mDevSupportManager.getDevSupportEnabled()) {
|
||||
mDevSupportManager.updateJSError(title, details, exceptionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissRedbox() {
|
||||
if (mDevSupportManager.getDevSupportEnabled()) {
|
||||
mDevSupportManager.hideRedboxDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.core
|
||||
|
||||
import com.facebook.common.logging.FLog
|
||||
import com.facebook.fbreact.specs.NativeExceptionsManagerSpec
|
||||
import com.facebook.react.bridge.Arguments
|
||||
import com.facebook.react.bridge.JavaOnlyMap
|
||||
import com.facebook.react.bridge.ReadableArray
|
||||
import com.facebook.react.bridge.ReadableMap
|
||||
import com.facebook.react.common.JavascriptException
|
||||
import com.facebook.react.common.ReactConstants
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager
|
||||
import com.facebook.react.module.annotations.ReactModule
|
||||
import com.facebook.react.util.ExceptionDataHelper.getExtraDataAsJson
|
||||
import com.facebook.react.util.JSStackTrace.format
|
||||
|
||||
@ReactModule(name = NativeExceptionsManagerSpec.NAME)
|
||||
public open class ExceptionsManagerModule(private val devSupportManager: DevSupportManager) :
|
||||
NativeExceptionsManagerSpec(null) {
|
||||
override fun reportFatalException(message: String?, stack: ReadableArray?, idDouble: Double) {
|
||||
val id = idDouble.toInt()
|
||||
val data = JavaOnlyMap()
|
||||
data.putString("message", message)
|
||||
data.putArray("stack", stack)
|
||||
data.putInt("id", id)
|
||||
data.putBoolean("isFatal", true)
|
||||
reportException(data)
|
||||
}
|
||||
|
||||
override fun reportSoftException(message: String?, stack: ReadableArray?, idDouble: Double) {
|
||||
val id = idDouble.toInt()
|
||||
val data = JavaOnlyMap()
|
||||
data.putString("message", message)
|
||||
data.putArray("stack", stack)
|
||||
data.putInt("id", id)
|
||||
data.putBoolean("isFatal", false)
|
||||
reportException(data)
|
||||
}
|
||||
|
||||
override fun reportException(data: ReadableMap) {
|
||||
val message = data.getString("message").orEmpty()
|
||||
val stack = data.getArray("stack") ?: Arguments.createArray()
|
||||
val isFatal = if (data.hasKey("isFatal")) data.getBoolean("isFatal") else false
|
||||
val extraDataAsJson = getExtraDataAsJson(data)
|
||||
if (isFatal) {
|
||||
val ex = JavascriptException(format(message, stack))
|
||||
ex.extraDataAsJson = extraDataAsJson
|
||||
throw ex
|
||||
} else {
|
||||
FLog.e(ReactConstants.TAG, format(message, stack))
|
||||
if (extraDataAsJson != null) {
|
||||
FLog.d(ReactConstants.TAG, "extraData: %s", extraDataAsJson)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateExceptionMessage(
|
||||
title: String?,
|
||||
details: ReadableArray?,
|
||||
exceptionIdDouble: Double
|
||||
) {
|
||||
val exceptionId = exceptionIdDouble.toInt()
|
||||
if (devSupportManager.devSupportEnabled) {
|
||||
devSupportManager.updateJSError(title, details, exceptionId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun dismissRedbox() {
|
||||
if (devSupportManager.devSupportEnabled) {
|
||||
devSupportManager.hideRedboxDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user