OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 class ServiceTestMessageHandler : public MessageHandler { | 27 class ServiceTestMessageHandler : public MessageHandler { |
28 public: | 28 public: |
29 ServiceTestMessageHandler() : _msg(NULL) {} | 29 ServiceTestMessageHandler() : _msg(NULL) {} |
30 | 30 |
31 ~ServiceTestMessageHandler() { free(_msg); } | 31 ~ServiceTestMessageHandler() { free(_msg); } |
32 | 32 |
33 MessageStatus HandleMessage(Message* message) { | 33 MessageStatus HandleMessage(Message* message) { |
34 if (_msg != NULL) { | 34 if (_msg != NULL) { |
35 free(_msg); | 35 free(_msg); |
| 36 _msg = NULL; |
36 } | 37 } |
37 | 38 |
38 // Parse the message. | 39 // Parse the message. |
39 Object& response_obj = Object::Handle(); | 40 Object& response_obj = Object::Handle(); |
40 if (message->IsRaw()) { | 41 if (message->IsRaw()) { |
41 response_obj = message->raw_obj(); | 42 response_obj = message->raw_obj(); |
42 } else { | 43 } else { |
43 Thread* thread = Thread::Current(); | 44 Thread* thread = Thread::Current(); |
44 MessageSnapshotReader reader(message->data(), message->len(), thread); | 45 MessageSnapshotReader reader(message->data(), message->len(), thread); |
45 response_obj = reader.ReadObject(); | 46 response_obj = reader.ReadObject(); |
46 } | 47 } |
47 if (response_obj.IsString()) { | 48 if (response_obj.IsString()) { |
48 String& response = String::Handle(); | 49 String& response = String::Handle(); |
49 response ^= response_obj.raw(); | 50 response ^= response_obj.raw(); |
50 _msg = strdup(response.ToCString()); | 51 _msg = strdup(response.ToCString()); |
51 } else { | 52 } else { |
52 ASSERT(response_obj.IsArray()); | 53 ASSERT(response_obj.IsArray()); |
53 Array& response_array = Array::Handle(); | 54 Array& response_array = Array::Handle(); |
54 response_array ^= response_obj.raw(); | 55 response_array ^= response_obj.raw(); |
55 ASSERT(response_array.Length() == 1); | 56 ASSERT(response_array.Length() == 1); |
56 ExternalTypedData& response = ExternalTypedData::Handle(); | 57 ExternalTypedData& response = ExternalTypedData::Handle(); |
57 response ^= response_array.At(0); | 58 response ^= response_array.At(0); |
58 _msg = strdup(reinterpret_cast<char*>(response.DataAddr(0))); | 59 _msg = strdup(reinterpret_cast<char*>(response.DataAddr(0))); |
59 } | 60 } |
60 | 61 |
| 62 delete message; |
| 63 |
61 return kOK; | 64 return kOK; |
62 } | 65 } |
63 | 66 |
64 const char* msg() const { return _msg; } | 67 const char* msg() const { return _msg; } |
65 | 68 |
66 virtual Isolate* isolate() const { return Isolate::Current(); } | 69 virtual Isolate* isolate() const { return Isolate::Current(); } |
67 | 70 |
68 private: | 71 private: |
69 char* _msg; | 72 char* _msg; |
70 }; | 73 }; |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 789 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
787 // Expect error. | 790 // Expect error. |
788 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 791 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
789 } | 792 } |
790 | 793 |
791 #endif // !defined(TARGET_ARCH_ARM64) | 794 #endif // !defined(TARGET_ARCH_ARM64) |
792 | 795 |
793 #endif // !PRODUCT | 796 #endif // !PRODUCT |
794 | 797 |
795 } // namespace dart | 798 } // namespace dart |
OLD | NEW |