use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class SetFunctionBreakpointsArguments method setBreakpoints.
public SetFunctionBreakpointsArguments setBreakpoints(List<FunctionBreakpoint> breakpoints) {
final JSONArray json = new JSONArray();
for (FunctionBreakpoint functionBreakpoint : breakpoints) {
json.put(functionBreakpoint.jsonData);
}
jsonData.put("breakpoints", json);
return this;
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class SetFunctionBreakpointsArguments method create.
public static SetFunctionBreakpointsArguments create(List<FunctionBreakpoint> breakpoints) {
final JSONObject json = new JSONObject();
JSONArray breakpointsJsonArr = new JSONArray();
for (FunctionBreakpoint functionBreakpoint : breakpoints) {
breakpointsJsonArr.put(functionBreakpoint.jsonData);
}
json.put("breakpoints", breakpointsJsonArr);
return new SetFunctionBreakpointsArguments(json);
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class Source method getChecksums.
/**
* The checksums associated with this file.
*/
public List<Checksum> getChecksums() {
final JSONArray json = jsonData.optJSONArray("checksums");
if (json == null) {
return null;
}
final List<Checksum> list = new ArrayList<>(json.length());
for (int i = 0; i < json.length(); i++) {
list.add(new Checksum(json.getJSONObject(i)));
}
return Collections.unmodifiableList(list);
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class InspectorRuntime method putResultProperties.
private void putResultProperties(JSONObject json, DebugValue value, Collection<DebugValue> properties, Collection<DebugValue> arrayElements, boolean generatePreview, String objectGroup) {
final String functionLocation = "[[FunctionLocation]]";
JSONArray result = new JSONArray();
JSONArray internals = new JSONArray();
boolean hasArray = !arrayElements.isEmpty();
HashSet<String> storedPropertyNames = (hasArray && properties != null) ? new HashSet<>(properties.size()) : null;
DebugException exception = null;
String nameExc = null;
// Test functionLocation for executable values only
boolean hasFunctionLocation = value == null || !value.canExecute();
try {
boolean isJS = false;
if (properties != null) {
LanguageInfo language = (value != null) ? value.getOriginalLanguage() : null;
isJS = LanguageChecks.isJS(language);
Iterator<DebugValue> propertiesIterator = properties.iterator();
while (propertiesIterator.hasNext()) {
DebugValue v = null;
try {
v = propertiesIterator.next();
if (v.isReadable()) {
if (!v.isInternal()) {
result.put(createPropertyJSON(v, generatePreview, objectGroup));
if (storedPropertyNames != null) {
storedPropertyNames.add(v.getName());
}
} else {
internals.put(createPropertyJSON(v, generatePreview, objectGroup));
}
if (!hasFunctionLocation && functionLocation.equals(v.getName())) {
hasFunctionLocation = true;
}
}
} catch (DebugException ex) {
if (exception == null) {
exception = ex;
nameExc = (v != null) ? v.getName() : "<unknown>";
}
}
}
}
int i = 0;
for (DebugValue v : arrayElements) {
String name = Integer.toString(i++);
try {
if (v.isReadable() && (storedPropertyNames == null || !storedPropertyNames.contains(name))) {
result.put(createPropertyJSON(v, name, generatePreview, objectGroup));
}
} catch (DebugException ex) {
if (exception == null) {
exception = ex;
nameExc = name;
}
}
}
if (isJS) {
// Add __proto__ when in JavaScript:
DebugValue prototype = value.getProperty("__proto__");
if (prototype != null && !prototype.isNull()) {
result.put(createPropertyJSON(prototype, null, generatePreview, true, false, objectGroup, false, null));
}
}
if (value != null && value.hasHashEntries()) {
DebugValue entries = value.getHashEntriesIterator();
JSONObject map2 = createPropertyJSON(entries, "[[Entries]]", false, false, true, objectGroup, true, TypeMark.MAP_ENTRIES);
internals.put(map2);
}
} catch (DebugException ex) {
// From property iterators, etc.
if (exception == null) {
exception = ex;
}
}
if (!hasFunctionLocation) {
SourceSection sourceLocation = null;
try {
sourceLocation = value.getSourceLocation();
} catch (DebugException ex) {
// From property iterators, etc.
if (exception == null) {
exception = ex;
}
}
if (sourceLocation != null) {
int scriptId = slh.getScriptId(sourceLocation.getSource());
if (scriptId >= 0) {
// {"name":"[[FunctionLocation]]","value":{"type":"object","subtype":"internal#location","value":{"scriptId":"87","lineNumber":17,"columnNumber":26},"description":"Object"}}
JSONObject location = new JSONObject();
location.put("name", functionLocation);
JSONObject locationValue = new JSONObject();
locationValue.put("type", "object");
locationValue.put("subtype", "internal#location");
locationValue.put("description", "Object");
locationValue.put("value", new Location(scriptId, sourceLocation.getStartLine(), sourceLocation.getStartColumn()).toJSON());
location.put("value", locationValue);
internals.put(location);
}
}
}
json.put("result", result);
json.put("internalProperties", internals);
if (exception != null) {
fillExceptionDetails(json, exception);
if (exception.isInternalError()) {
PrintWriter err = context.getErr();
if (err != null) {
err.println("Exception while retrieving variable " + nameExc);
exception.printStackTrace(err);
}
}
}
}
use of com.oracle.truffle.tools.utils.json.JSONArray in project graal by oracle.
the class InspectorRuntime method createCodecompletion.
static JSONObject createCodecompletion(DebugValue value, DebugScope scope, InspectorExecutionContext context, boolean resultItems) {
JSONObject result = new JSONObject();
Iterable<DebugValue> properties = null;
try {
if (value != null) {
properties = value.getProperties();
} else {
properties = scope.getDeclaredValues();
}
} catch (DebugException ex) {
fillExceptionDetails(result, ex, context);
if (ex.isInternalError()) {
PrintWriter err = context.getErr();
if (err != null) {
err.println("getProperties(" + ((value != null) ? value.getName() : scope.getName()) + ") has caused: " + ex);
ex.printStackTrace(err);
}
}
}
JSONArray valueArray = new JSONArray();
JSONArray items = new JSONArray();
if (properties != null) {
for (DebugValue property : properties) {
items.put(property.getName());
}
}
if (resultItems) {
JSONObject itemsObj = new JSONObject();
itemsObj.put("items", items);
valueArray.put(itemsObj);
} else {
valueArray.put(items);
}
result.put("type", "object");
result.put("value", valueArray);
return result;
}
Aggregations