-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding JS hierarchy information when a StackOverflowException is thro…
…wn in Dev mode Reviewed By: achen1 Differential Revision: D6716309 fbshipit-source-id: 23458cd126d13fec3aa9c09420f7cdd230ec8dd0
- Loading branch information
1 parent
e8893a0
commit 4d3519c
Showing
11 changed files
with
237 additions
and
24 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
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,28 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule JSDevSupportModule | ||
* @flow | ||
*/ | ||
'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]]; | ||
|
||
var result = renderer.getInspectorDataForViewTag(tag); | ||
var path = result.hierarchy.map( (item) => item.name).join(' -> '); | ||
console.error('StackOverflowException rendering JSComponent: ' + path); | ||
require('NativeModules').JSDevSupport.setResult(path, null); | ||
}, | ||
}; | ||
|
||
module.exports = JSDevSupportModule; |
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
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
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
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
70 changes: 70 additions & 0 deletions
70
ReactAndroid/src/main/java/com/facebook/react/devsupport/JSDevSupport.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,70 @@ | ||
// Copyright 2004-present Facebook. All Rights Reserved. | ||
|
||
package com.facebook.react.devsupport; | ||
|
||
import com.facebook.react.bridge.JavaScriptModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.module.annotations.ReactModule; | ||
import javax.annotation.Nullable; | ||
|
||
@ReactModule(name = "JSDevSupport", needsEagerInit = true) | ||
public class JSDevSupport extends ReactContextBaseJavaModule { | ||
|
||
static final String MODULE_NAME = "JSDevSupport"; | ||
|
||
@Nullable | ||
private volatile DevSupportCallback mCurrentCallback = null; | ||
|
||
public interface JSDevSupportModule extends JavaScriptModule { | ||
void getJSHierarchy(String reactTag); | ||
} | ||
|
||
public JSDevSupport(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
public interface DevSupportCallback { | ||
|
||
void onSuccess(String data); | ||
|
||
void onFailure(Exception error); | ||
} | ||
|
||
public synchronized void getJSHierarchy(String reactTag, DevSupportCallback callback) { | ||
if (mCurrentCallback != null) { | ||
callback.onFailure(new RuntimeException("JS Hierarchy download already in progress.")); | ||
return; | ||
} | ||
|
||
JSDevSupportModule | ||
jsDevSupportModule = getReactApplicationContext().getJSModule(JSDevSupportModule.class); | ||
if (jsDevSupportModule == null) { | ||
callback.onFailure(new JSCHeapCapture.CaptureException(MODULE_NAME + | ||
" module not registered.")); | ||
return; | ||
} | ||
mCurrentCallback = callback; | ||
jsDevSupportModule.getJSHierarchy(reactTag); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@ReactMethod | ||
public synchronized void setResult(String data, String error) { | ||
if (mCurrentCallback != null) { | ||
if (error == null) { | ||
mCurrentCallback.onSuccess(data); | ||
} else { | ||
mCurrentCallback.onFailure(new RuntimeException(error)); | ||
} | ||
} | ||
mCurrentCallback = null; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "JSDevSupport"; | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.