Search in sources :

Example 1 with TypeMark

use of com.oracle.truffle.tools.chromeinspector.types.RemoteObject.TypeMark 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);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) TypeMark(com.oracle.truffle.tools.chromeinspector.types.RemoteObject.TypeMark) DebugValue(com.oracle.truffle.api.debug.DebugValue) ArrayList(java.util.ArrayList) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException) DebugException(com.oracle.truffle.api.debug.DebugException) DebugScope(com.oracle.truffle.api.debug.DebugScope) RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) Collection(java.util.Collection)

Aggregations

DebugException (com.oracle.truffle.api.debug.DebugException)1 DebugScope (com.oracle.truffle.api.debug.DebugScope)1 DebugValue (com.oracle.truffle.api.debug.DebugValue)1 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException)1 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)1 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)1 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)1 TypeMark (com.oracle.truffle.tools.chromeinspector.types.RemoteObject.TypeMark)1 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)1 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1