mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-05 07:07:26 +08:00
Display JS component stack in native view exceptions
Reviewed By: mdvacca Differential Revision: D7578033 fbshipit-source-id: 4dc393cddf8487db58cc3a9fefbff220983ba9da
This commit is contained in:
committed by
Facebook Github Bot
parent
c4ab03a18e
commit
ff9b3c6517
@@ -9,16 +9,25 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var JSDevSupportModule = {
|
||||
getJSHierarchy: function (tag: string) {
|
||||
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
||||
const renderers = hook._renderers;
|
||||
const keys = Object.keys(renderers);
|
||||
const renderer = renderers[keys[0]];
|
||||
const JSDevSupport = require('NativeModules').JSDevSupport;
|
||||
const ReactNative = require('ReactNative');
|
||||
|
||||
var result = renderer.getInspectorDataForViewTag(tag);
|
||||
var path = result.hierarchy.map( (item) => item.name).join(' -> ');
|
||||
require('NativeModules').JSDevSupport.setResult(path, null);
|
||||
const JSDevSupportModule = {
|
||||
getJSHierarchy: function (tag: number) {
|
||||
try {
|
||||
const {computeComponentStackForErrorReporting} =
|
||||
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
||||
const componentStack = computeComponentStackForErrorReporting(tag);
|
||||
if (!componentStack) {
|
||||
JSDevSupport.onFailure(
|
||||
JSDevSupport.ERROR_CODE_VIEW_NOT_FOUND,
|
||||
'Component stack doesn\'t exist for tag ' + tag);
|
||||
} else {
|
||||
JSDevSupport.onSuccess(componentStack);
|
||||
}
|
||||
} catch (e) {
|
||||
JSDevSupport.onFailure(JSDevSupport.ERROR_CODE_EXCEPTION, e.message);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user