Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: runtime/vm/json_stream.cc

Issue 1255003003: Make VM service id handling JSON-RPC 2 compliant. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: cr Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/debugger.h" 8 #include "vm/debugger.h"
9 #include "vm/json_stream.h" 9 #include "vm/json_stream.h"
10 #include "vm/message.h" 10 #include "vm/message.h"
11 #include "vm/metrics.h" 11 #include "vm/metrics.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/service_event.h" 13 #include "vm/service_event.h"
14 #include "vm/service.h" 14 #include "vm/service.h"
15 #include "vm/timeline.h" 15 #include "vm/timeline.h"
16 #include "vm/unicode.h" 16 #include "vm/unicode.h"
17 17
18 18
19 namespace dart { 19 namespace dart {
20 20
21 DECLARE_FLAG(bool, trace_service); 21 DECLARE_FLAG(bool, trace_service);
22 22
23 JSONStream::JSONStream(intptr_t buf_size) 23 JSONStream::JSONStream(intptr_t buf_size)
24 : open_objects_(0), 24 : open_objects_(0),
25 buffer_(buf_size), 25 buffer_(buf_size),
26 default_id_zone_(Isolate::Current()->object_id_ring(), 26 default_id_zone_(Isolate::Current()->object_id_ring(),
27 ObjectIdRing::kAllocateId), 27 ObjectIdRing::kAllocateId),
28 id_zone_(&default_id_zone_), 28 id_zone_(&default_id_zone_),
29 reply_port_(ILLEGAL_PORT), 29 reply_port_(ILLEGAL_PORT),
30 seq_(""), 30 seq_(Instance::Handle(Instance::null())),
31 method_(""), 31 method_(""),
32 param_keys_(NULL), 32 param_keys_(NULL),
33 param_values_(NULL), 33 param_values_(NULL),
34 num_params_(0) { 34 num_params_(0) {
35 } 35 }
36 36
37 37
38 JSONStream::~JSONStream() { 38 JSONStream::~JSONStream() {
39 } 39 }
40 40
41 41
42 void JSONStream::Setup(Zone* zone, 42 void JSONStream::Setup(Zone* zone,
43 Dart_Port reply_port, 43 Dart_Port reply_port,
44 const String& seq, 44 const Instance& seq,
45 const String& method, 45 const String& method,
46 const Array& param_keys, 46 const Array& param_keys,
47 const Array& param_values) { 47 const Array& param_values) {
48 set_reply_port(reply_port); 48 set_reply_port(reply_port);
49 seq_ = seq.ToCString(); 49 seq_ ^= seq.raw();
50 method_ = method.ToCString(); 50 method_ = method.ToCString();
51 51
52 String& string_iterator = String::Handle(); 52 String& string_iterator = String::Handle();
53 if (param_keys.Length() > 0) { 53 if (param_keys.Length() > 0) {
54 ASSERT(param_keys.Length() == param_values.Length()); 54 ASSERT(param_keys.Length() == param_values.Length());
55 const char** param_keys_native = 55 const char** param_keys_native =
56 zone->Alloc<const char*>(param_keys.Length()); 56 zone->Alloc<const char*>(param_keys.Length());
57 const char** param_values_native = 57 const char** param_values_native =
58 zone->Alloc<const char*>(param_keys.Length()); 58 zone->Alloc<const char*>(param_keys.Length());
59 for (intptr_t i = 0; i < param_keys.Length(); i++) { 59 for (intptr_t i = 0; i < param_keys.Length(); i++) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 156
157 void JSONStream::PostReply() { 157 void JSONStream::PostReply() {
158 Dart_Port port = reply_port(); 158 Dart_Port port = reply_port();
159 ASSERT(port != ILLEGAL_PORT); 159 ASSERT(port != ILLEGAL_PORT);
160 set_reply_port(ILLEGAL_PORT); // Prevent double replies. 160 set_reply_port(ILLEGAL_PORT); // Prevent double replies.
161 int64_t process_delta_micros = 0; 161 int64_t process_delta_micros = 0;
162 if (FLAG_trace_service) { 162 if (FLAG_trace_service) {
163 process_delta_micros = OS::GetCurrentTimeMicros() - setup_time_micros_; 163 process_delta_micros = OS::GetCurrentTimeMicros() - setup_time_micros_;
164 } 164 }
165 // TODO(turnidge): Handle non-string sequence numbers. 165
166 buffer_.Printf(", \"id\":\"%s\"}", seq()); 166 if (seq_.IsString()) {
167 const String& str = String::Cast(seq_);
168 PrintProperty("id", str.ToCString());
169 } else if (seq_.IsInteger()) {
170 const Integer& integer = Integer::Cast(seq_);
171 PrintProperty64("id", integer.AsInt64Value());
172 } else if (seq_.IsDouble()) {
173 const Double& dbl = Double::Cast(seq_);
174 PrintProperty("id", dbl.value());
175 } else if (seq_.IsNull()) {
176 // JSON-RPC 2.0 says that a request with a null ID shouldn't get a reply.
177 return;
178 }
179 buffer_.AddChar('}');
180
167 const String& reply = String::Handle(String::New(ToCString())); 181 const String& reply = String::Handle(String::New(ToCString()));
168 ASSERT(!reply.IsNull()); 182 ASSERT(!reply.IsNull());
169 183
170 uint8_t* data = NULL; 184 uint8_t* data = NULL;
171 MessageWriter writer(&data, &allocator, false); 185 MessageWriter writer(&data, &allocator, false);
172 writer.WriteMessage(reply); 186 writer.WriteMessage(reply);
173 bool result = PortMap::PostMessage(new Message(port, data, 187 bool result = PortMap::PostMessage(new Message(port, data,
174 writer.BytesWritten(), 188 writer.BytesWritten(),
175 Message::kNormalPriority)); 189 Message::kNormalPriority));
176 if (FLAG_trace_service) { 190 if (FLAG_trace_service) {
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); 701 intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
688 va_end(args); 702 va_end(args);
689 ASSERT(len == len2); 703 ASSERT(len == len2);
690 stream_->buffer_.AddChar('"'); 704 stream_->buffer_.AddChar('"');
691 stream_->AddEscapedUTF8String(p); 705 stream_->AddEscapedUTF8String(p);
692 stream_->buffer_.AddChar('"'); 706 stream_->buffer_.AddChar('"');
693 free(p); 707 free(p);
694 } 708 }
695 709
696 } // namespace dart 710 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698