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