Search in sources :

Example 81 with JSONArray

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;
}
Also used : JSONArray(com.oracle.truffle.tools.utils.json.JSONArray)

Example 82 with JSONArray

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);
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray)

Example 83 with JSONArray

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);
}
Also used : JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) ArrayList(java.util.ArrayList)

Example 84 with JSONArray

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);
            }
        }
    }
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) DebugException(com.oracle.truffle.api.debug.DebugException) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) SourceSection(com.oracle.truffle.api.source.SourceSection) Location(com.oracle.truffle.tools.chromeinspector.types.Location) PrintWriter(java.io.PrintWriter)

Example 85 with JSONArray

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;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray) DebugException(com.oracle.truffle.api.debug.DebugException) PrintWriter(java.io.PrintWriter)

Aggregations

JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)195 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)85 ArrayList (java.util.ArrayList)74 DebugValue (com.oracle.truffle.api.debug.DebugValue)8 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)8 Collection (java.util.Collection)7 List (java.util.List)7 DebugException (com.oracle.truffle.api.debug.DebugException)6 Source (com.oracle.truffle.api.source.Source)5 SourceSection (com.oracle.truffle.api.source.SourceSection)4 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)4 HashMap (java.util.HashMap)4 Location (com.oracle.truffle.tools.chromeinspector.types.Location)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3 CPUSampler (com.oracle.truffle.tools.profiler.CPUSampler)3 CPUSamplerData (com.oracle.truffle.tools.profiler.CPUSamplerData)3 PrintWriter (java.io.PrintWriter)3 Map (java.util.Map)3 TruffleContext (com.oracle.truffle.api.TruffleContext)2 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)2