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

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

Issue 2059883003: DevFS initial implementation (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6
7 #include "vm/dart_entry.h" 7 #include "vm/dart_entry.h"
8 #include "vm/debugger.h" 8 #include "vm/debugger.h"
9 #include "vm/json_stream.h" 9 #include "vm/json_stream.h"
10 #include "vm/message.h" 10 #include "vm/message.h"
(...skipping 28 matching lines...) Expand all
39 39
40 DECLARE_FLAG(bool, trace_service); 40 DECLARE_FLAG(bool, trace_service);
41 41
42 JSONStream::JSONStream(intptr_t buf_size) 42 JSONStream::JSONStream(intptr_t buf_size)
43 : open_objects_(0), 43 : open_objects_(0),
44 buffer_(buf_size), 44 buffer_(buf_size),
45 default_id_zone_(), 45 default_id_zone_(),
46 id_zone_(&default_id_zone_), 46 id_zone_(&default_id_zone_),
47 reply_port_(ILLEGAL_PORT), 47 reply_port_(ILLEGAL_PORT),
48 seq_(NULL), 48 seq_(NULL),
49 parameter_keys_(NULL),
50 parameter_values_(NULL),
49 method_(""), 51 method_(""),
50 param_keys_(NULL), 52 param_keys_(NULL),
51 param_values_(NULL), 53 param_values_(NULL),
52 num_params_(0), 54 num_params_(0),
53 offset_(0), 55 offset_(0),
54 count_(-1) { 56 count_(-1) {
55 ObjectIdRing* ring = NULL; 57 ObjectIdRing* ring = NULL;
56 Isolate* isolate = Isolate::Current(); 58 Isolate* isolate = Isolate::Current();
57 if (isolate != NULL) { 59 if (isolate != NULL) {
58 ring = isolate->object_id_ring(); 60 ring = isolate->object_id_ring();
59 } 61 }
60 default_id_zone_.Init(ring, ObjectIdRing::kAllocateId); 62 default_id_zone_.Init(ring, ObjectIdRing::kAllocateId);
61 } 63 }
62 64
63 65
64 JSONStream::~JSONStream() { 66 JSONStream::~JSONStream() {
65 } 67 }
66 68
67 69
68 void JSONStream::Setup(Zone* zone, 70 void JSONStream::Setup(Zone* zone,
69 Dart_Port reply_port, 71 Dart_Port reply_port,
70 const Instance& seq, 72 const Instance& seq,
71 const String& method, 73 const String& method,
72 const Array& param_keys, 74 const Array& param_keys,
73 const Array& param_values) { 75 const Array& param_values,
76 bool parameters_are_dart_objects) {
74 set_reply_port(reply_port); 77 set_reply_port(reply_port);
75 seq_ = &Instance::ZoneHandle(seq.raw()); 78 seq_ = &Instance::ZoneHandle(seq.raw());
76 method_ = method.ToCString(); 79 method_ = method.ToCString();
77 80
78 String& string_iterator = String::Handle(); 81 if (parameters_are_dart_objects) {
79 if (param_keys.Length() > 0) { 82 parameter_keys_ = &Array::ZoneHandle(param_keys.raw());
83 parameter_values_ = &Array::ZoneHandle(param_values.raw());
84 ASSERT(parameter_keys_->Length() == parameter_values_->Length());
85 } else if (param_keys.Length() > 0) {
86 String& string_iterator = String::Handle();
80 ASSERT(param_keys.Length() == param_values.Length()); 87 ASSERT(param_keys.Length() == param_values.Length());
81 const char** param_keys_native = 88 const char** param_keys_native =
82 zone->Alloc<const char*>(param_keys.Length()); 89 zone->Alloc<const char*>(param_keys.Length());
83 const char** param_values_native = 90 const char** param_values_native =
84 zone->Alloc<const char*>(param_keys.Length()); 91 zone->Alloc<const char*>(param_keys.Length());
85 for (intptr_t i = 0; i < param_keys.Length(); i++) { 92 for (intptr_t i = 0; i < param_keys.Length(); i++) {
86 string_iterator ^= param_keys.At(i); 93 string_iterator ^= param_keys.At(i);
87 param_keys_native[i] = 94 param_keys_native[i] =
88 zone->MakeCopyOfString(string_iterator.ToCString()); 95 zone->MakeCopyOfString(string_iterator.ToCString());
89 string_iterator ^= param_values.At(i); 96 string_iterator ^= param_values.At(i);
90 param_values_native[i] = 97 param_values_native[i] =
91 zone->MakeCopyOfString(string_iterator.ToCString()); 98 zone->MakeCopyOfString(string_iterator.ToCString());
92 } 99 }
93 SetParams(param_keys_native, param_values_native, param_keys.Length()); 100 SetParams(param_keys_native, param_values_native, param_keys.Length());
94 } 101 }
102
95 if (FLAG_trace_service) { 103 if (FLAG_trace_service) {
96 Isolate* isolate = Isolate::Current(); 104 Isolate* isolate = Isolate::Current();
97 ASSERT(isolate != NULL); 105 ASSERT(isolate != NULL);
98 const char* isolate_name = isolate->name(); 106 const char* isolate_name = isolate->name();
99 setup_time_micros_ = OS::GetCurrentTimeMicros(); 107 setup_time_micros_ = OS::GetCurrentTimeMicros();
100 OS::Print("[+%" Pd64 "ms] Isolate %s processing service request %s\n", 108 OS::Print("[+%" Pd64 "ms] Isolate %s processing service request %s\n",
101 Dart::timestamp(), isolate_name, method_); 109 Dart::timestamp(), isolate_name, method_);
102 } 110 }
103 buffer_.Printf("{\"jsonrpc\":\"2.0\", \"result\":"); 111 buffer_.Printf("{\"jsonrpc\":\"2.0\", \"result\":");
104 } 112 }
(...skipping 18 matching lines...) Expand all
123 case kInternalError: 131 case kInternalError:
124 return "Internal error"; 132 return "Internal error";
125 case kFeatureDisabled: 133 case kFeatureDisabled:
126 return "Feature is disabled"; 134 return "Feature is disabled";
127 case kCannotAddBreakpoint: 135 case kCannotAddBreakpoint:
128 return "Cannot add breakpoint"; 136 return "Cannot add breakpoint";
129 case kIsolateMustBeRunnable: 137 case kIsolateMustBeRunnable:
130 return "Isolate must be runnable"; 138 return "Isolate must be runnable";
131 case kIsolateMustBePaused: 139 case kIsolateMustBePaused:
132 return "Isolate must be paused"; 140 return "Isolate must be paused";
141 case kIsolateIsReloading:
142 return "Isolate is reloading";
143 case kFileSystemAlreadyExists:
144 return "File system already exists";
145 case kFileSystemDoesNotExist:
146 return "File system does not exist";
147 case kFileDoesNotExist:
148 return "File does not exist";
133 default: 149 default:
134 return "Extension error"; 150 return "Extension error";
135 } 151 }
136 } 152 }
137 153
138 154
139 static void PrintRequest(JSONObject* obj, JSONStream* js) { 155 static void PrintRequest(JSONObject* obj, JSONStream* js) {
140 JSONObject jsobj(obj, "request"); 156 JSONObject jsobj(obj, "request");
141 jsobj.AddProperty("method", js->method()); 157 jsobj.AddProperty("method", js->method());
142 { 158 {
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 *buffer_length = buffer_.length(); 676 *buffer_length = buffer_.length();
661 *buffer = buffer_.Steal(); 677 *buffer = buffer_.Steal();
662 } 678 }
663 679
664 680
665 void JSONStream::set_reply_port(Dart_Port port) { 681 void JSONStream::set_reply_port(Dart_Port port) {
666 reply_port_ = port; 682 reply_port_ = port;
667 } 683 }
668 684
669 685
686 intptr_t JSONStream::NumObjectParameters() const {
687 if (parameter_keys_ == NULL) {
688 return 0;
689 }
690 ASSERT(parameter_keys_ != NULL);
691 ASSERT(parameter_values_ != NULL);
692 return parameter_keys_->Length();
693 }
694
695
696 RawObject* JSONStream::GetObjectParameterKey(intptr_t i) const {
697 ASSERT((i >= 0) && (i < NumObjectParameters()));
698 return parameter_keys_->At(i);
699 }
700
701
702 RawObject* JSONStream::GetObjectParameterValue(intptr_t i) const {
703 ASSERT((i >= 0) && (i < NumObjectParameters()));
704 return parameter_values_->At(i);
705 }
706
707
708 RawObject* JSONStream::LookupObjectParam(const char* c_key) const {
709 const String& key = String::Handle(String::New(c_key));
710 Object& test = Object::Handle();
711 const intptr_t num_object_parameters = NumObjectParameters();
712 for (intptr_t i = 0; i < num_object_parameters; i++) {
713 test = GetObjectParameterKey(i);
714 if (test.IsString() && String::Cast(test).Equals(key)) {
715 return GetObjectParameterValue(i);
716 }
717 }
718 return Object::null();
719 }
720
721
670 void JSONStream::SetParams(const char** param_keys, 722 void JSONStream::SetParams(const char** param_keys,
671 const char** param_values, 723 const char** param_values,
672 intptr_t num_params) { 724 intptr_t num_params) {
673 param_keys_ = param_keys; 725 param_keys_ = param_keys;
674 param_values_ = param_values; 726 param_values_ = param_values;
675 num_params_ = num_params; 727 num_params_ = num_params;
676 } 728 }
677 729
678 730
679 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) { 731 void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 ASSERT(len == len2); 943 ASSERT(len == len2);
892 stream_->buffer_.AddChar('"'); 944 stream_->buffer_.AddChar('"');
893 stream_->AddEscapedUTF8String(p); 945 stream_->AddEscapedUTF8String(p);
894 stream_->buffer_.AddChar('"'); 946 stream_->buffer_.AddChar('"');
895 free(p); 947 free(p);
896 } 948 }
897 949
898 #endif // !PRODUCT 950 #endif // !PRODUCT
899 951
900 } // namespace dart 952 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698