Chromium Code Reviews| Index: runtime/vm/json_stream.cc |
| diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc |
| index 96dfb0d605d2d0c6d4da01921c03e772adc65b86..4ad36094b467bb086ad95941983548f434a77068 100644 |
| --- a/runtime/vm/json_stream.cc |
| +++ b/runtime/vm/json_stream.cc |
| @@ -27,7 +27,7 @@ JSONStream::JSONStream(intptr_t buf_size) |
| ObjectIdRing::kAllocateId), |
| id_zone_(&default_id_zone_), |
| reply_port_(ILLEGAL_PORT), |
| - seq_(""), |
| + seq_(Instance::Handle(Instance::null())), |
| method_(""), |
| param_keys_(NULL), |
| param_values_(NULL), |
| @@ -41,12 +41,12 @@ JSONStream::~JSONStream() { |
| void JSONStream::Setup(Zone* zone, |
| Dart_Port reply_port, |
| - const String& seq, |
| + const Instance& seq, |
| const String& method, |
| const Array& param_keys, |
| const Array& param_values) { |
| set_reply_port(reply_port); |
| - seq_ = seq.ToCString(); |
| + seq_ ^= seq.raw(); |
| method_ = method.ToCString(); |
| String& string_iterator = String::Handle(); |
| @@ -162,8 +162,23 @@ void JSONStream::PostReply() { |
| if (FLAG_trace_service) { |
| process_delta_micros = OS::GetCurrentTimeMicros() - setup_time_micros_; |
| } |
| - // TODO(turnidge): Handle non-string sequence numbers. |
| - buffer_.Printf(", \"id\":\"%s\"}", seq()); |
| + |
| + Instance& id = seq(); |
|
Cutch
2015/07/27 21:10:10
just use seq_ directly here OR:
Instance& id = In
nweiz
2015/07/27 21:17:35
Done.
|
| + if (id.IsString()) { |
| + const String& str = String::Cast(id); |
| + PrintProperty("id", str.ToCString()); |
| + } else if (id.IsInteger()) { |
| + const Integer& integer = Integer::Cast(id); |
| + PrintProperty64("id", integer.AsInt64Value()); |
| + } else if (id.IsDouble()) { |
| + const Double& dbl = Double::Cast(id); |
| + PrintProperty("id", dbl.value()); |
| + } else if (id.IsNull()) { |
| + // JSON-RPC 2.0 says that a request with a null ID shouldn't get a reply. |
| + return; |
| + } |
| + buffer_.AddChar('}'); |
| + |
| const String& reply = String::Handle(String::New(ToCString())); |
| ASSERT(!reply.IsNull()); |