-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This diff is hooking up cxx error with redbox. Before this diff, cxx errors were only shown in log and there was no visible user feedback. Changelog: [Android] [Added] - Show Redbox for C++ errors. Reviewed By: JoshuaGross Differential Revision: D30421355 fbshipit-source-id: ad473337ba301feb08ba31ee8d82ebaa771ecaeb
- Loading branch information
1 parent
4a96216
commit d6c879e
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ReactAndroid/src/main/java/com/facebook/react/bridge/ReactCxxErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its 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.bridge; | ||
|
||
import com.facebook.common.logging.FLog; | ||
import com.facebook.proguard.annotations.DoNotStrip; | ||
import java.lang.reflect.Method; | ||
|
||
@DoNotStrip | ||
public class ReactCxxErrorHandler { | ||
|
||
private static Method mHandleErrorFunc; | ||
private static Object mObject; | ||
|
||
@DoNotStrip | ||
public static void setHandleErrorFunc(Object object, Method handleErrorFunc) { | ||
mObject = object; | ||
mHandleErrorFunc = handleErrorFunc; | ||
} | ||
|
||
@DoNotStrip | ||
// For use from within the C++ JReactCxxErrorHandler | ||
private static void handleError(final String message) { | ||
if (mHandleErrorFunc != null) { | ||
try { | ||
Object[] parameters = new Object[1]; | ||
parameters[0] = new Exception(message); | ||
mHandleErrorFunc.invoke(mObject, parameters); | ||
} catch (Exception e) { | ||
FLog.e("ReactCxxErrorHandler", "Failed to invole error hanlder function", e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "JReactCxxErrorHandler.h" | ||
|
||
using namespace facebook::react; | ||
|
||
void JReactCxxErrorHandler::handleError(std::string message) { | ||
static const auto handleError = | ||
javaClassStatic()->getStaticMethod<void(std::string message)>( | ||
"handleError"); | ||
|
||
return handleError(javaClassStatic(), message); | ||
} |
25 changes: 25 additions & 0 deletions
25
ReactAndroid/src/main/jni/react/jni/JReactCxxErrorHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <string> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
class JReactCxxErrorHandler : public jni::JavaClass<JReactCxxErrorHandler> { | ||
public: | ||
static constexpr const char *kJavaDescriptor = | ||
"Lcom/facebook/react/bridge/ReactCxxErrorHandler;"; | ||
|
||
static void handleError(std::string message); | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |