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/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" |
(...skipping 12 matching lines...) Expand all Loading... |
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_(), | 26 default_id_zone_(), |
27 id_zone_(&default_id_zone_), | 27 id_zone_(&default_id_zone_), |
28 reply_port_(ILLEGAL_PORT), | 28 reply_port_(ILLEGAL_PORT), |
29 seq_(NULL), | 29 seq_(NULL), |
30 method_(""), | 30 method_(""), |
31 param_keys_(NULL), | 31 param_keys_(NULL), |
32 param_values_(NULL), | 32 param_values_(NULL), |
33 num_params_(0) { | 33 num_params_(0), |
| 34 offset_(0), |
| 35 count_(-1) { |
34 ObjectIdRing* ring = NULL; | 36 ObjectIdRing* ring = NULL; |
35 Isolate* isolate = Isolate::Current(); | 37 Isolate* isolate = Isolate::Current(); |
36 if (isolate != NULL) { | 38 if (isolate != NULL) { |
37 ring = isolate->object_id_ring(); | 39 ring = isolate->object_id_ring(); |
38 } | 40 } |
39 default_id_zone_.Init(ring, ObjectIdRing::kAllocateId); | 41 default_id_zone_.Init(ring, ObjectIdRing::kAllocateId); |
40 } | 42 } |
41 | 43 |
42 | 44 |
43 JSONStream::~JSONStream() { | 45 JSONStream::~JSONStream() { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 240 |
239 | 241 |
240 bool JSONStream::ParamIs(const char* key, const char* value) const { | 242 bool JSONStream::ParamIs(const char* key, const char* value) const { |
241 ASSERT(key); | 243 ASSERT(key); |
242 ASSERT(value); | 244 ASSERT(value); |
243 const char* key_value = LookupParam(key); | 245 const char* key_value = LookupParam(key); |
244 return (key_value != NULL) && (strcmp(key_value, value) == 0); | 246 return (key_value != NULL) && (strcmp(key_value, value) == 0); |
245 } | 247 } |
246 | 248 |
247 | 249 |
| 250 void JSONStream::ComputeOffsetAndCount(intptr_t length, |
| 251 intptr_t* offset, |
| 252 intptr_t* count) { |
| 253 // This function is written to avoid adding (count + offset) in case |
| 254 // that triggers an integer overflow. |
| 255 *offset = offset_; |
| 256 if (*offset > length) { |
| 257 *offset = length; |
| 258 } |
| 259 intptr_t remaining = length - *offset; |
| 260 *count = count_; |
| 261 if (*count < 0 || *count > remaining) { |
| 262 *count = remaining; |
| 263 } |
| 264 } |
| 265 |
248 void JSONStream::Clear() { | 266 void JSONStream::Clear() { |
249 buffer_.Clear(); | 267 buffer_.Clear(); |
250 open_objects_ = 0; | 268 open_objects_ = 0; |
251 } | 269 } |
252 | 270 |
253 | 271 |
254 void JSONStream::OpenObject(const char* property_name) { | 272 void JSONStream::OpenObject(const char* property_name) { |
255 PrintCommaIfNeeded(); | 273 PrintCommaIfNeeded(); |
256 open_objects_++; | 274 open_objects_++; |
257 if (property_name != NULL) { | 275 if (property_name != NULL) { |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 824 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
807 va_end(args); | 825 va_end(args); |
808 ASSERT(len == len2); | 826 ASSERT(len == len2); |
809 stream_->buffer_.AddChar('"'); | 827 stream_->buffer_.AddChar('"'); |
810 stream_->AddEscapedUTF8String(p); | 828 stream_->AddEscapedUTF8String(p); |
811 stream_->buffer_.AddChar('"'); | 829 stream_->buffer_.AddChar('"'); |
812 free(p); | 830 free(p); |
813 } | 831 } |
814 | 832 |
815 } // namespace dart | 833 } // namespace dart |
OLD | NEW |