Index: runtime/vm/json_stream.cc |
diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc |
index 96dfb0d605d2d0c6d4da01921c03e772adc65b86..6fc9e924ecec2606ea5c746eeb058204229ab484 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,22 @@ 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()); |
+ |
+ if (seq_.IsString()) { |
+ const String& str = String::Cast(seq_); |
+ PrintProperty("id", str.ToCString()); |
+ } else if (seq_.IsInteger()) { |
+ const Integer& integer = Integer::Cast(seq_); |
+ PrintProperty64("id", integer.AsInt64Value()); |
+ } else if (seq_.IsDouble()) { |
+ const Double& dbl = Double::Cast(seq_); |
+ PrintProperty("id", dbl.value()); |
+ } else if (seq_.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()); |