Web Inspector: Switch to type-safe JSON ConsoleMessage.cpp, InspectorDOMAgent.cpp...
[WebKit-https.git] / Source / WebCore / inspector / InspectorDOMAgent.cpp
index cf42314802cacaab6c48f8f41447d57feb88ed26..bf08f3c4f1cb5bae72706fcf3aed0b25057912e9 100644 (file)
@@ -1125,8 +1125,6 @@ String InspectorDOMAgent::documentURLString(Document* document)
 
 PassRefPtr<InspectorObject> InspectorDOMAgent::buildObjectForNode(Node* node, int depth, NodeToIdMap* nodesMap)
 {
-    RefPtr<InspectorObject> value = InspectorObject::create();
-
     int id = bind(node, nodesMap);
     String nodeName;
     String localName;
@@ -1155,15 +1153,16 @@ PassRefPtr<InspectorObject> InspectorDOMAgent::buildObjectForNode(Node* node, in
         break;
     }
 
-    value->setNumber("nodeId", id);
-    value->setNumber("nodeType", node->nodeType());
-    value->setString("nodeName", nodeName);
-    value->setString("localName", localName);
-    value->setString("nodeValue", nodeValue);
+    RefPtr<TypeBuilder::DOM::Node> value = TypeBuilder::DOM::Node::create()
+        .setNodeId(id)
+        .setNodeType(node->nodeType())
+        .setNodeName(nodeName)
+        .setLocalName(localName)
+        .setNodeValue(nodeValue);
 
     if (node->nodeType() == Node::ELEMENT_NODE || node->nodeType() == Node::DOCUMENT_NODE || node->nodeType() == Node::DOCUMENT_FRAGMENT_NODE) {
         int nodeCount = innerChildNodeCount(node);
-        value->setNumber("childNodeCount", nodeCount);
+        value->setChildNodeCount(nodeCount);
         RefPtr<InspectorArray> children = buildArrayForContainerChildren(node, depth, nodesMap);
         if (children->length() > 0)
             value->setArray("children", children.release());
@@ -1173,22 +1172,22 @@ PassRefPtr<InspectorObject> InspectorDOMAgent::buildObjectForNode(Node* node, in
             value->setArray("attributes", buildArrayForElementAttributes(element));
             if (node->isFrameOwnerElement()) {
                 HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerElement*>(node);
-                value->setString("documentURL", documentURLString(frameOwner->contentDocument()));
+                value->setDocumentURL(documentURLString(frameOwner->contentDocument()));
             }
         } else if (node->nodeType() == Node::DOCUMENT_NODE) {
             Document* document = static_cast<Document*>(node);
-            value->setString("documentURL", documentURLString(document));
-            value->setString("xmlVersion", document->xmlVersion());
+            value->setDocumentURL(documentURLString(document));
+            value->setXmlVersion(document->xmlVersion());
         }
     } else if (node->nodeType() == Node::DOCUMENT_TYPE_NODE) {
         DocumentType* docType = static_cast<DocumentType*>(node);
-        value->setString("publicId", docType->publicId());
-        value->setString("systemId", docType->systemId());
-        value->setString("internalSubset", docType->internalSubset());
+        value->setPublicId(docType->publicId());
+        value->setSystemId(docType->systemId());
+        value->setInternalSubset(docType->internalSubset());
     } else if (node->nodeType() == Node::ATTRIBUTE_NODE) {
         Attr* attribute = static_cast<Attr*>(node);
-        value->setString("name", attribute->name());
-        value->setString("value", attribute->value());
+        value->setName(attribute->name());
+        value->setValue(attribute->value());
     }
     return value.release();
 }
@@ -1235,19 +1234,19 @@ PassRefPtr<InspectorArray> InspectorDOMAgent::buildArrayForContainerChildren(Nod
 PassRefPtr<InspectorObject> InspectorDOMAgent::buildObjectForEventListener(const RegisteredEventListener& registeredEventListener, const AtomicString& eventType, Node* node)
 {
     RefPtr<EventListener> eventListener = registeredEventListener.listener;
-    RefPtr<InspectorObject> value = InspectorObject::create();
-    value->setString("type", eventType);
-    value->setBoolean("useCapture", registeredEventListener.useCapture);
-    value->setBoolean("isAttribute", eventListener->isAttribute());
-    value->setNumber("nodeId", pushNodePathToFrontend(node));
-    value->setString("handlerBody", eventListenerHandlerBody(node->document(), eventListener.get()));
+    RefPtr<TypeBuilder::DOM::EventListener> value = TypeBuilder::DOM::EventListener::create()
+        .setType(eventType)
+        .setUseCapture(registeredEventListener.useCapture)
+        .setIsAttribute(eventListener->isAttribute())
+        .setNodeId(pushNodePathToFrontend(node))
+        .setHandlerBody(eventListenerHandlerBody(node->document(), eventListener.get()));
     String sourceName;
     int lineNumber;
     if (eventListenerHandlerLocation(node->document(), eventListener.get(), sourceName, lineNumber)) {
-        RefPtr<InspectorObject> location = InspectorObject::create();
-        location->setString("scriptId", sourceName);
-        location->setNumber("lineNumber", lineNumber);
-        value->setObject("location", location);
+        RefPtr<TypeBuilder::Debugger::Location> location = TypeBuilder::Debugger::Location::create()
+            .setScriptId(sourceName)
+            .setLineNumber(lineNumber);
+        value->setLocation(location);
     }
     return value.release();
 }