Permalink
Browse files

Add openStackFrameCall to DevServerHelper

Reviewed By: javache

Differential Revision: D4946709

fbshipit-source-id: 059aec70c4a0b230e9280b050601a3bde39f46df
  • Loading branch information...
devknoll authored and facebook-github-bot committed Apr 27, 2017
1 parent 03d57f2 commit ee91eb74015f6b1befeb58c290fde0f03f3e29d0
@@ -88,6 +88,7 @@
private static final String HEAP_CAPTURE_UPLOAD_URL_FORMAT = "http://%s/jscheapcaptureupload";
private static final String INSPECTOR_DEVICE_URL_FORMAT = "http://%s/inspector/device?name=%s";
private static final String SYMBOLICATE_URL_FORMAT = "http://%s/symbolicate";
private static final String OPEN_STACK_FRAME_URL_FORMAT = "http://%s/open-stack-frame";
private static final String PACKAGER_OK_STATUS = "packager-status:running";
@@ -233,12 +234,7 @@ public void symbolicateStackTrace(
mSettings.getPackagerConnectionSettings().getDebugServerHost());
final JSONArray jsonStackFrames = new JSONArray();
for (final StackFrame stackFrame : stackFrames) {
jsonStackFrames.put(new JSONObject(
MapBuilder.of(
"file", stackFrame.getFile(),
"methodName", stackFrame.getMethod(),
"lineNumber", stackFrame.getLine(),
"column", stackFrame.getColumn())));
jsonStackFrames.put(stackFrame.toJSON());
}
final Request request = new Request.Builder()
.url(symbolicateURL)
@@ -274,6 +270,31 @@ public void onResponse(Call call, final Response response) throws IOException {
}
}
public void openStackFrameCall(StackFrame stackFrame) {
final String openStackFrameURL = createOpenStackFrameURL(
mSettings.getPackagerConnectionSettings().getDebugServerHost());
final Request request = new Request.Builder()
.url(openStackFrameURL)
.post(RequestBody.create(
MediaType.parse("application/json"),
stackFrame.toJSON().toString()))
.build();
Call symbolicateCall = Assertions.assertNotNull(mClient.newCall(request));
symbolicateCall.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
FLog.w(
ReactConstants.TAG,
"Got IOException when attempting to open stack frame: " + e.getMessage());
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
// We don't have a listener for this.
}
});
}
/** Intent action for reloading the JS */
public static String getReloadAppAction(Context context) {
return context.getPackageName() + RELOAD_APP_ACTION_SUFFIX;
@@ -346,6 +367,10 @@ private static String createSymbolicateURL(String host) {
return String.format(Locale.US, SYMBOLICATE_URL_FORMAT, host);
}
private static String createOpenStackFrameURL(String host) {
return String.format(Locale.US, OPEN_STACK_FRAME_URL_FORMAT, host);
}
public String getDevServerBundleURL(final String jsModulePath) {
return createBundleURL(
mSettings.getPackagerConnectionSettings().getDebugServerHost(),
@@ -17,6 +17,7 @@
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.devsupport.interfaces.StackFrame;
import org.json.JSONArray;
@@ -100,6 +101,18 @@ public int getColumn() {
public String getFileName() {
return mFileName;
}
/**
* Convert the stack frame to a JSON representation.
*/
public JSONObject toJSON() {
return new JSONObject(
MapBuilder.of(
"file", getFile(),
"methodName", getMethod(),
"lineNumber", getLine(),
"column", getColumn()));
}
}
/**
@@ -9,6 +9,8 @@
package com.facebook.react.devsupport.interfaces;
import org.json.JSONObject;
/**
* Represents a generic entry in a stack trace, be it originally from JS or Java.
*/
@@ -43,4 +45,9 @@
* name, not the full path. For Java traces there is no difference.
*/
public String getFileName();
}
/**
* Convert the stack frame to a JSON representation.
*/
public JSONObject toJSON();
}

0 comments on commit ee91eb7

Please sign in to comment.