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

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

Issue 19870006: Support stacktrace and objecthistogram service commands (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
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 #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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 buffer_->Printf("%f", d); 77 buffer_->Printf("%f", d);
78 } 78 }
79 79
80 80
81 void JSONStream::PrintValue(const char* s) { 81 void JSONStream::PrintValue(const char* s) {
82 PrintCommaIfNeeded(); 82 PrintCommaIfNeeded();
83 buffer_->Printf("\"%s\"", s); 83 buffer_->Printf("\"%s\"", s);
84 } 84 }
85 85
86 86
87 void JSONStream::PrintfValue(const char* format, ...) {
88 PrintCommaIfNeeded();
89
90 va_list args;
91 va_start(args, format);
92 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
93 va_end(args);
94 char* p = reinterpret_cast<char*>(malloc(len+1));
95 va_start(args, format);
96 intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
97 va_end(args);
98 ASSERT(len == len2);
99 buffer_->Printf("\"%s\"", p);
100 free(p);
101 }
102
103
87 void JSONStream::PrintValue(const Object& o, bool ref) { 104 void JSONStream::PrintValue(const Object& o, bool ref) {
88 PrintCommaIfNeeded(); 105 PrintCommaIfNeeded();
89 o.PrintToJSONStream(this, ref); 106 o.PrintToJSONStream(this, ref);
90 } 107 }
91 108
92 109
93 void JSONStream::PrintPropertyBool(const char* name, bool b) { 110 void JSONStream::PrintPropertyBool(const char* name, bool b) {
94 PrintPropertyName(name); 111 PrintPropertyName(name);
95 PrintValueBool(b); 112 PrintValueBool(b);
96 } 113 }
(...skipping 10 matching lines...) Expand all
107 PrintValue(d); 124 PrintValue(d);
108 } 125 }
109 126
110 127
111 void JSONStream::PrintProperty(const char* name, const char* s) { 128 void JSONStream::PrintProperty(const char* name, const char* s) {
112 PrintPropertyName(name); 129 PrintPropertyName(name);
113 PrintValue(s); 130 PrintValue(s);
114 } 131 }
115 132
116 133
134 void JSONStream::PrintfProperty(const char* name, const char* format, ...) {
135 PrintPropertyName(name);
136 va_list args;
137 va_start(args, format);
138 intptr_t len = OS::VSNPrint(NULL, 0, format, args);
139 va_end(args);
140 char* p = reinterpret_cast<char*>(malloc(len+1));
141 va_start(args, format);
142 intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
143 va_end(args);
144 ASSERT(len == len2);
145 buffer_->Printf("\"%s\"", p);
146 free(p);
147 }
148
149
117 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) { 150 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) {
118 PrintPropertyName(name); 151 PrintPropertyName(name);
119 PrintValue(o, ref); 152 PrintValue(o, ref);
120 } 153 }
121 154
122 155
123 void JSONStream::PrintPropertyName(const char* name) { 156 void JSONStream::PrintPropertyName(const char* name) {
124 ASSERT(name != NULL); 157 ASSERT(name != NULL);
125 PrintCommaIfNeeded(); 158 PrintCommaIfNeeded();
126 buffer_->Printf("\"%s\":", name); 159 buffer_->Printf("\"%s\":", name);
(...skipping 12 matching lines...) Expand all
139 intptr_t length = buffer_->length(); 172 intptr_t length = buffer_->length();
140 if (length == 0) { 173 if (length == 0) {
141 return false; 174 return false;
142 } 175 }
143 char ch = buffer[length-1]; 176 char ch = buffer[length-1];
144 return ch != '[' && ch != '{' && ch != ':' && ch != ','; 177 return ch != '[' && ch != '{' && ch != ':' && ch != ',';
145 } 178 }
146 179
147 } // namespace dart 180 } // namespace dart
148 181
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698