Search in sources :

Example 81 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class ObjectPreview method createEntryPreview.

private static JSONObject createEntryPreview(DebugValue entry, boolean allowToStringSideEffects, LanguageInfo language, PrintWriter err) {
    List<DebugValue> entryArray = entry.getArray();
    DebugValue key = entryArray.get(0);
    DebugValue value = entryArray.get(1);
    // Setup the object with a language-specific value
    if (language != null) {
        key = key.asInLanguage(language);
        value = value.asInLanguage(language);
    }
    JSONObject json = new JSONObject();
    json.put("key", create(key, allowToStringSideEffects, language, err, true));
    json.put("value", create(value, allowToStringSideEffects, language, err, true));
    return json;
}
Also used : DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 82 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class ObjectPreview method create.

private static JSONObject create(DebugValue debugValue, TYPE type, SUBTYPE subtype, boolean allowToStringSideEffects, LanguageInfo language, PrintWriter err, boolean isMapEntryKV) {
    JSONObject json = new JSONObject();
    json.put("type", type.getId());
    if (subtype != null) {
        json.put("subtype", subtype.getId());
    }
    boolean isArray = debugValue.isArray();
    boolean isMap = debugValue.hasHashEntries();
    if (isMapEntryKV) {
        String valueStr = RemoteObject.toString(debugValue, allowToStringSideEffects, err);
        json.putOpt("description", valueStr);
    } else {
        DebugValue metaObject = RemoteObject.getMetaObject(debugValue, language, err);
        String metaType = null;
        if (metaObject != null) {
            metaType = RemoteObject.toMetaName(metaObject, err);
            if (isArray) {
                metaType += "(" + debugValue.getArray().size() + ")";
            } else if (isMap) {
                metaType += "(" + debugValue.getHashSize() + ")";
            }
        }
        json.putOpt("description", metaType);
    }
    boolean overflow;
    JSONArray properties = new JSONArray();
    JSONArray entries = new JSONArray();
    if (isArray) {
        List<DebugValue> array = debugValue.getArray();
        int size = array.size();
        overflow = size > OVERFLOW_LIMIT_ARRAY_ELEMENTS;
        int n = Math.min(size, OVERFLOW_LIMIT_ARRAY_ELEMENTS);
        for (int i = 0; i < n; i++) {
            try {
                properties.put(createPropertyPreview(array.get(i), allowToStringSideEffects, language, err));
            } catch (DebugException ex) {
                overflow = true;
                break;
            }
        }
    } else if (isMap && !isMapEntryKV) {
        DebugValue entriesIter = debugValue.getHashEntriesIterator();
        overflow = false;
        while (entriesIter.hasIteratorNextElement()) {
            DebugValue entry = entriesIter.getIteratorNextElement();
            JSONObject entryPreview;
            try {
                entryPreview = createEntryPreview(entry, allowToStringSideEffects, language, err);
            } catch (DebugException ex) {
                overflow = true;
                break;
            }
            if (entryPreview != null) {
                if (entries.length() == OVERFLOW_LIMIT_PROPERTIES) {
                    overflow = true;
                    break;
                }
                entries.put(entryPreview);
            }
        }
    } else {
        Collection<DebugValue> valueProperties = debugValue.getProperties();
        if (valueProperties != null) {
            Iterator<DebugValue> propertyIterator = valueProperties.iterator();
            overflow = false;
            while (propertyIterator.hasNext()) {
                DebugValue property = propertyIterator.next();
                if (!property.isInternal() && !property.hasReadSideEffects() && property.isReadable()) {
                    if (properties.length() == OVERFLOW_LIMIT_PROPERTIES) {
                        overflow = true;
                        break;
                    }
                    try {
                        properties.put(createPropertyPreview(property, allowToStringSideEffects, language, err));
                    } catch (DebugException ex) {
                        overflow = true;
                        break;
                    }
                }
            }
        } else {
            overflow = false;
        }
    }
    json.put("overflow", overflow);
    json.put("properties", properties);
    if (isMap && !isMapEntryKV) {
        json.put("entries", entries);
    }
    return json;
}
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) Iterator(java.util.Iterator) Collection(java.util.Collection) DebugException(com.oracle.truffle.api.debug.DebugException)

Example 83 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class ProfileNode method toJSON.

private JSONObject toJSON() {
    JSONObject json = new JSONObject();
    json.put("id", id);
    json.put("callFrame", callFrame.toJSON());
    json.put("hitCount", hitCount);
    JSONArray array = new JSONArray();
    children.forEach(i -> {
        array.put(i.intValue());
    });
    json.put("children", array);
    return json;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) JSONArray(com.oracle.truffle.tools.utils.json.JSONArray)

Example 84 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class Scope method createJSON.

private JSONObject createJSON() {
    JSONObject json = new JSONObject();
    json.put("type", type);
    json.put("object", object.toJSON());
    json.putOpt("name", name);
    if (startLocation != null) {
        json.put("startLocation", startLocation.toJSON());
    }
    if (endLocation != null) {
        json.put("endLocation", endLocation.toJSON());
    }
    return json;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Example 85 with JSONObject

use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.

the class ScriptCoverage method toJSON.

public JSONObject toJSON() {
    JSONObject json = new JSONObject();
    json.put("scriptId", Integer.toString(scriptId));
    json.put("url", url);
    json.put("functions", FunctionCoverage.toJSON(functions));
    return json;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject)

Aggregations

JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)318 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)71 ArrayList (java.util.ArrayList)20 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)18 DebugValue (com.oracle.truffle.api.debug.DebugValue)14 DebugException (com.oracle.truffle.api.debug.DebugException)11 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)10 SourceSection (com.oracle.truffle.api.source.SourceSection)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Collection (java.util.Collection)7 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)6 Source (com.oracle.truffle.api.source.Source)6 Map (java.util.Map)6 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException)5 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)5 JSONTokener (com.oracle.truffle.tools.utils.json.JSONTokener)5 Test (org.junit.Test)5 Location (com.oracle.truffle.tools.chromeinspector.types.Location)4