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

Unified Diff: runtime/vm/json_stream.cc

Issue 1255003003: Make VM service id handling JSON-RPC 2 compliant. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: cr Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698