use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class MultiEngineTest method checkSuspendAndResume.
private static void checkSuspendAndResume(String path) throws Exception {
CountDownLatch closed = new CountDownLatch(1);
AtomicBoolean paused = new AtomicBoolean(false);
AtomicReference<Exception> exception = new AtomicReference<>(null);
final String url = "ws://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + PORT + "/" + path;
WebSocketClient wsc = new WebSocketClient(new URI(url)) {
@Override
public void onOpen(ServerHandshake sh) {
}
@Override
public void onMessage(String message) {
JSONObject msg = new JSONObject(message);
if ("Debugger.paused".equals(msg.opt("method"))) {
paused.set(true);
send("{\"id\":5,\"method\":\"Debugger.resume\"}");
}
}
@Override
public void onClose(int i, String message, boolean bln) {
closed.countDown();
}
@Override
public void onError(Exception excptn) {
excptn.printStackTrace();
exception.set(excptn);
}
};
final boolean connectionSucceeded = wsc.connectBlocking();
assertTrue("Connection has not succeeded: " + url, connectionSucceeded);
for (String message : INITIAL_MESSAGES) {
wsc.send(message);
}
closed.await();
wsc.close();
if (exception.get() != null) {
throw exception.get();
}
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class BreakpointsHandler method createURLBreakpoint.
Params createURLBreakpoint(Object url, int line, int column, String condition) {
JSONArray locations = new JSONArray();
long id;
LoadScriptListener scriptListener;
synchronized (bpIDs) {
id = ++lastID;
scriptListener = script -> {
if (url instanceof Pattern ? ((Pattern) url).matcher(script.getUrl()).matches() : ScriptsHandler.compareURLs((String) url, script.getUrl())) {
Breakpoint bp = createBuilder(script.getSourceLoaded(), line, column).resolveListener(resolvedHandler).build();
if (condition != null && !condition.isEmpty()) {
bp.setCondition(condition);
}
bp = ds.install(bp);
synchronized (bpIDs) {
bpIDs.put(bp, id);
SourceSection section = resolvedBreakpoints.remove(bp);
if (section != null) {
Location resolvedLocation = new Location(script.getId(), section.getStartLine(), section.getStartColumn());
locations.put(resolvedLocation.toJSON());
}
}
}
};
scriptListeners.put(id, scriptListener);
}
slh.addLoadScriptListener(scriptListener);
JSONObject json = new JSONObject();
json.put("breakpointId", Long.toString(id));
json.put("locations", locations);
return new Params(json);
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class BreakpointsHandler method createFunctionBreakpoint.
Params createFunctionBreakpoint(DebugValue functionValue, String condition) {
SourceSection functionLocation = functionValue.getSourceLocation();
Breakpoint.Builder builder;
if (functionLocation != null) {
builder = Breakpoint.newBuilder(functionLocation);
} else {
builder = Breakpoint.newBuilder((URI) null);
}
builder.rootInstance(functionValue);
builder.sourceElements(SourceElement.ROOT);
Breakpoint bp = builder.build();
if (condition != null && !condition.isEmpty()) {
bp.setCondition(condition);
}
ds.install(bp);
long id;
synchronized (bpIDs) {
id = ++lastID;
bpIDs.put(bp, id);
}
JSONObject json = new JSONObject();
json.put("breakpointId", Long.toString(id));
return new Params(json);
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class InspectorRuntime method putMapEntries.
private void putMapEntries(JSONObject json, DebugValue value, RemoteObject.IndexRange indexRange, boolean generatePreview, String objectGroup) {
int start = 0;
int end = Integer.MAX_VALUE;
if (indexRange != null && !indexRange.isNamed()) {
start = indexRange.start();
end = indexRange.end();
}
JSONArray result = new JSONArray();
for (int index = 0; value.hasIteratorNextElement() && index < end; index++) {
DebugValue next = value.getIteratorNextElement();
if (index < start) {
continue;
}
String name = Integer.toString(index);
JSONObject jsonEntry = createPropertyJSON(next, name, generatePreview, objectGroup, TypeMark.MAP_ENTRY);
result.put(jsonEntry);
}
json.put("result", result);
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class InspectorRuntime method getProperties.
@Override
public Params getProperties(String objectId, boolean ownProperties, boolean accessorPropertiesOnly, boolean generatePreview) throws CommandProcessException {
if (objectId == null) {
throw new CommandProcessException("An objectId required.");
}
RemoteObject object = context.getRemoteObjectsHandler().getRemote(objectId);
String objectGroup = context.getRemoteObjectsHandler().getObjectGroupOf(objectId);
JSONObject json = new JSONObject();
if (object != null) {
DebugValue value = object.getDebugValue();
RemoteObject.IndexRange indexRange = object.getIndexRange();
try {
if (value != null) {
context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {
@Override
public Void executeCommand() throws CommandProcessException {
TypeMark typeMark = object.getTypeMark();
if (typeMark != null) {
switch(typeMark) {
case MAP_ENTRIES:
putMapEntries(json, value, indexRange, generatePreview, objectGroup);
break;
case MAP_ENTRY:
putMapEntry(json, value, generatePreview, objectGroup);
break;
default:
throw new CommandProcessException("Unknown type mark " + typeMark);
}
return null;
}
Collection<DebugValue> properties = null;
if (!value.hasHashEntries()) {
properties = value.getProperties();
}
if (properties == null) {
properties = Collections.emptyList();
} else if (indexRange != null && indexRange.isNamed()) {
List<DebugValue> list = new ArrayList<>(properties);
properties = list.subList(indexRange.start(), indexRange.end());
}
Collection<DebugValue> array;
if (!value.isArray()) {
array = Collections.emptyList();
} else if (indexRange != null && !indexRange.isNamed()) {
List<DebugValue> arr = value.getArray();
array = arr.subList(indexRange.start(), indexRange.end());
} else {
array = value.getArray();
}
putResultProperties(json, value, properties, array, generatePreview, objectGroup);
return null;
}
@Override
public Void processException(DebugException ex) {
fillExceptionDetails(json, ex);
return null;
}
});
} else {
final DebugScope scope = object.getScope();
context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {
@Override
public Void executeCommand() throws CommandProcessException {
Collection<DebugValue> properties = new ArrayList<>();
DebugValue scopeReceiver = object.getScopeReceiver();
if (scopeReceiver != null) {
properties.add(scopeReceiver);
}
for (DebugValue p : scope.getDeclaredValues()) {
properties.add(p);
}
putResultProperties(json, null, properties, Collections.emptyList(), generatePreview, objectGroup);
return null;
}
@Override
public Void processException(DebugException ex) {
fillExceptionDetails(json, ex);
return null;
}
});
}
} catch (NoSuspendedThreadException ex) {
// Not suspended, no properties
json.put("result", new JSONArray());
}
}
return new Params(json);
}
Aggregations