File: NodeJSOuptutParser.cpp

package info (click to toggle)
codelite 12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (59 lines) | stat: -rw-r--r-- 2,278 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "NodeJSOuptutParser.h"

NodeJSOuptutParser::NodeJSOuptutParser() {}

NodeJSOuptutParser::~NodeJSOuptutParser() {}

NodeJSHandle NodeJSOuptutParser::ParseRef(const JSONElement& ref, std::map<int, NodeJSHandle>& handles)
{
    int handleId = ref.namedObject("handle").toInt();
    NodeJSHandle h;
    h.handleID = handleId;
    h.type = ref.namedObject("type").toString();
    if(h.type == "undefined") {
        h.value = "undefined";
    } else if(h.type == "number" || h.type == "boolean") {
        h.value = ref.namedObject("text").toString();
    } else if(h.type == "string") {
        // Make this string repesentable in a single line
        h.value << "\"" << ref.namedObject("text").toString() << "\"";
        h.value.Replace("\n", "\\n");
        h.value.Replace("\t", "\\t");
        h.value.Replace("\r", "\\r");
    } else if(h.type == "script" || h.type == "function") {
        h.value = ref.namedObject("name").toString();
    } else if(h.type == "null") {
        h.value = "null";
    } else if(h.type == "object") {

        if(ref.hasNamedObject("protoObject")) {
            h.properties.push_back(
                std::make_pair(ref.namedObject("protoObject").namedObject("ref").toInt(), "prototype"));
        }

        if(ref.hasNamedObject("className") && ref.namedObject("className").toString() == "Array") {
            h.type = "Array";
            h.value = "[]";
        } else if(ref.hasNamedObject("text")) {
            h.value = ref.namedObject("text").toString();
        } else {
            h.value = "{...}";
        }
        JSONElement props = ref.namedObject("properties");
        int propsCount = props.arraySize();
        for(int n = 0; n < propsCount; ++n) {
            JSONElement prop = props.arrayItem(n);
            wxString propName;
            if(prop.namedObject("name").isString()) {
                propName = prop.namedObject("name").toString();
            } else if(prop.namedObject("name").isNumber()) {
                propName << "[" << prop.namedObject("name").toInt() << "]";
            }

            int propId = prop.namedObject("ref").toInt();
            h.properties.push_back(std::make_pair(propId, propName));
        }
    }
    handles.insert(std::make_pair(handleId, h));
    return h;
}