Add openStackFrameCall to DevServerHelper

Reviewed By: javache

Differential Revision: D4946709

fbshipit-source-id: 059aec70c4a0b230e9280b050601a3bde39f46df
This commit is contained in:
Gerald Monaco 2017-04-27 11:21:04 -07:00 committed by Facebook Github Bot
parent 03d57f2180
commit ee91eb7401
3 changed files with 52 additions and 7 deletions

View File

@ -88,6 +88,7 @@ public class DevServerHelper {
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 class DevServerHelper {
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 class DevServerHelper {
}
}
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 @@ public class DevServerHelper {
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(),

View File

@ -17,6 +17,7 @@ import java.util.regex.Pattern;
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 class StackTraceHelper {
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()));
}
}
/**

View File

@ -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 @@ public interface StackFrame {
* 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();
}