• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
RemoteObjectIdBase()12 RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) {}
13 
14 std::unique_ptr<protocol::DictionaryValue>
parseInjectedScriptId(const String16 & objectId)15 RemoteObjectIdBase::parseInjectedScriptId(const String16& objectId) {
16   std::unique_ptr<protocol::Value> parsedValue =
17       protocol::StringUtil::parseJSON(objectId);
18   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       parsedObjectId->getInteger("injectedScriptId", &m_injectedScriptId);
25   if (success) return parsedObjectId;
26   return nullptr;
27 }
28 
RemoteObjectId()29 RemoteObjectId::RemoteObjectId() : RemoteObjectIdBase(), m_id(0) {}
30 
parse(const String16 & objectId,std::unique_ptr<RemoteObjectId> * result)31 Response RemoteObjectId::parse(const String16& objectId,
32                                std::unique_ptr<RemoteObjectId>* result) {
33   std::unique_ptr<RemoteObjectId> remoteObjectId(new RemoteObjectId());
34   std::unique_ptr<protocol::DictionaryValue> parsedObjectId =
35       remoteObjectId->parseInjectedScriptId(objectId);
36   if (!parsedObjectId) return Response::Error("Invalid remote object id");
37 
38   bool success = parsedObjectId->getInteger("id", &remoteObjectId->m_id);
39   if (!success) return Response::Error("Invalid remote object id");
40   *result = std::move(remoteObjectId);
41   return Response::OK();
42 }
43 
RemoteCallFrameId()44 RemoteCallFrameId::RemoteCallFrameId()
45     : RemoteObjectIdBase(), m_frameOrdinal(0) {}
46 
parse(const String16 & objectId,std::unique_ptr<RemoteCallFrameId> * result)47 Response RemoteCallFrameId::parse(const String16& objectId,
48                                   std::unique_ptr<RemoteCallFrameId>* result) {
49   std::unique_ptr<RemoteCallFrameId> remoteCallFrameId(new RemoteCallFrameId());
50   std::unique_ptr<protocol::DictionaryValue> parsedObjectId =
51       remoteCallFrameId->parseInjectedScriptId(objectId);
52   if (!parsedObjectId) return Response::Error("Invalid call frame id");
53 
54   bool success =
55       parsedObjectId->getInteger("ordinal", &remoteCallFrameId->m_frameOrdinal);
56   if (!success) return Response::Error("Invalid call frame id");
57   *result = std::move(remoteCallFrameId);
58   return Response::OK();
59 }
60 
serialize(int injectedScriptId,int frameOrdinal)61 String16 RemoteCallFrameId::serialize(int injectedScriptId, int frameOrdinal) {
62   return "{\"ordinal\":" + String16::fromInteger(frameOrdinal) +
63          ",\"injectedScriptId\":" + String16::fromInteger(injectedScriptId) +
64          "}";
65 }
66 
67 }  // namespace v8_inspector
68