Line data Source code
1 : // Copyright 2015 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/inspector/remote-object-id.h"
6 :
7 : #include "src/inspector/protocol/Protocol.h"
8 : #include "src/inspector/string-util.h"
9 :
10 : namespace v8_inspector {
11 :
12 88117 : RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) {}
13 :
14 : std::unique_ptr<protocol::DictionaryValue>
15 88117 : RemoteObjectIdBase::parseInjectedScriptId(const String16& objectId) {
16 : std::unique_ptr<protocol::Value> parsedValue =
17 88117 : protocol::StringUtil::parseJSON(objectId);
18 88117 : if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject)
19 : return nullptr;
20 :
21 : std::unique_ptr<protocol::DictionaryValue> parsedObjectId(
22 : protocol::DictionaryValue::cast(parsedValue.release()));
23 : bool success =
24 176234 : parsedObjectId->getInteger("injectedScriptId", &m_injectedScriptId);
25 88117 : if (success) return parsedObjectId;
26 : return nullptr;
27 : }
28 :
29 68696 : RemoteObjectId::RemoteObjectId() : RemoteObjectIdBase(), m_id(0) {}
30 :
31 68696 : Response RemoteObjectId::parse(const String16& objectId,
32 : std::unique_ptr<RemoteObjectId>* result) {
33 68696 : std::unique_ptr<RemoteObjectId> remoteObjectId(new RemoteObjectId());
34 : std::unique_ptr<protocol::DictionaryValue> parsedObjectId =
35 68696 : remoteObjectId->parseInjectedScriptId(objectId);
36 68696 : if (!parsedObjectId) return Response::Error("Invalid remote object id");
37 :
38 206088 : bool success = parsedObjectId->getInteger("id", &remoteObjectId->m_id);
39 68696 : if (!success) return Response::Error("Invalid remote object id");
40 : *result = std::move(remoteObjectId);
41 68696 : return Response::OK();
42 : }
43 :
44 0 : RemoteCallFrameId::RemoteCallFrameId()
45 19421 : : RemoteObjectIdBase(), m_frameOrdinal(0) {}
46 :
47 19421 : Response RemoteCallFrameId::parse(const String16& objectId,
48 : std::unique_ptr<RemoteCallFrameId>* result) {
49 19421 : std::unique_ptr<RemoteCallFrameId> remoteCallFrameId(new RemoteCallFrameId());
50 : std::unique_ptr<protocol::DictionaryValue> parsedObjectId =
51 19421 : remoteCallFrameId->parseInjectedScriptId(objectId);
52 19421 : if (!parsedObjectId) return Response::Error("Invalid call frame id");
53 :
54 : bool success =
55 58263 : parsedObjectId->getInteger("ordinal", &remoteCallFrameId->m_frameOrdinal);
56 19421 : if (!success) return Response::Error("Invalid call frame id");
57 : *result = std::move(remoteCallFrameId);
58 19421 : return Response::OK();
59 : }
60 :
61 125171 : String16 RemoteCallFrameId::serialize(int injectedScriptId, int frameOrdinal) {
62 625855 : return "{\"ordinal\":" + String16::fromInteger(frameOrdinal) +
63 500684 : ",\"injectedScriptId\":" + String16::fromInteger(injectedScriptId) +
64 375513 : "}";
65 : }
66 :
67 : } // namespace v8_inspector
|