| 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 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/json_stream.h" | 7 #include "vm/json_stream.h" |
| 8 | 8 |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 free(p); | 107 free(p); |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 void JSONStream::PrintValue(const Object& o, bool ref) { | 111 void JSONStream::PrintValue(const Object& o, bool ref) { |
| 112 PrintCommaIfNeeded(); | 112 PrintCommaIfNeeded(); |
| 113 o.PrintToJSONStream(this, ref); | 113 o.PrintToJSONStream(this, ref); |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 void JSONStream::PrintValue(const Field& field, |
| 118 const Instance& instance, |
| 119 bool ref) { |
| 120 PrintCommaIfNeeded(); |
| 121 field.PrintToJSONStreamWithInstance(this, instance, ref); |
| 122 } |
| 123 |
| 124 |
| 117 void JSONStream::PrintPropertyBool(const char* name, bool b) { | 125 void JSONStream::PrintPropertyBool(const char* name, bool b) { |
| 118 PrintPropertyName(name); | 126 PrintPropertyName(name); |
| 119 PrintValueBool(b); | 127 PrintValueBool(b); |
| 120 } | 128 } |
| 121 | 129 |
| 122 | 130 |
| 123 void JSONStream::PrintProperty(const char* name, intptr_t i) { | 131 void JSONStream::PrintProperty(const char* name, intptr_t i) { |
| 124 PrintPropertyName(name); | 132 PrintPropertyName(name); |
| 125 PrintValue(i); | 133 PrintValue(i); |
| 126 } | 134 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); | 212 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); |
| 205 } | 213 } |
| 206 | 214 |
| 207 | 215 |
| 208 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { | 216 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { |
| 209 stream_->OpenObject(); | 217 stream_->OpenObject(); |
| 210 } | 218 } |
| 211 | 219 |
| 212 | 220 |
| 213 void JSONObject::AddPropertyF(const char* name, | 221 void JSONObject::AddPropertyF(const char* name, |
| 214 const char* format, ...) const { | 222 const char* format, ...) const { |
| 215 stream_->PrintPropertyName(name); | 223 stream_->PrintPropertyName(name); |
| 216 va_list args; | 224 va_list args; |
| 217 va_start(args, format); | 225 va_start(args, format); |
| 218 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 226 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 219 va_end(args); | 227 va_end(args); |
| 220 char* p = reinterpret_cast<char*>(malloc(len+1)); | 228 char* p = reinterpret_cast<char*>(malloc(len+1)); |
| 221 va_start(args, format); | 229 va_start(args, format); |
| 222 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 230 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 223 va_end(args); | 231 va_end(args); |
| 224 ASSERT(len == len2); | 232 ASSERT(len == len2); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 240 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 248 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 241 va_end(args); | 249 va_end(args); |
| 242 ASSERT(len == len2); | 250 ASSERT(len == len2); |
| 243 stream_->buffer_.AddChar('"'); | 251 stream_->buffer_.AddChar('"'); |
| 244 stream_->buffer_.AddEscapedString(p); | 252 stream_->buffer_.AddEscapedString(p); |
| 245 stream_->buffer_.AddChar('"'); | 253 stream_->buffer_.AddChar('"'); |
| 246 free(p); | 254 free(p); |
| 247 } | 255 } |
| 248 | 256 |
| 249 } // namespace dart | 257 } // namespace dart |
| 250 | |
| OLD | NEW |