29 id_zone_(&default_id_zone_),
32 parameter_keys_(nullptr),
33 parameter_values_(nullptr),
36 param_values_(nullptr),
40 include_private_members_(
true),
41 ignore_object_depth_(0) {
44 if (isolate !=
nullptr) {
54 const Array& param_keys,
55 const Array& param_values,
56 bool parameters_are_dart_objects) {
59 method_ =
method.ToCString();
61 if (parameters_are_dart_objects) {
68 const char** param_keys_native =
70 const char** param_values_native =
72 for (intptr_t i = 0; i <
param_keys.Length(); i++) {
74 param_keys_native[i] =
77 param_values_native[i] =
83 if (FLAG_trace_service) {
85 ASSERT(isolate !=
nullptr);
86 int64_t main_port =
static_cast<int64_t
>(isolate->
main_port());
87 const char* isolate_name = isolate->
name();
90 ") %s processing service "
94 const char* kIncludePrivateMembersKey =
"_includePrivateMembers";
95 if (
HasParam(kIncludePrivateMembersKey)) {
96 include_private_members_ =
ParamIs(kIncludePrivateMembersKey,
"true");
109 return "Parse error";
111 return "Invalid Request";
113 return "Method not found";
115 return "Invalid params";
117 return "Internal error";
119 return "Feature is disabled";
121 return "Cannot add breakpoint";
123 return "Stream already subscribed";
125 return "Stream not subscribed";
127 return "Isolate must be runnable";
129 return "Isolate must be paused";
131 return "Cannot resume execution";
133 return "Isolate is reloading";
135 return "Isolate cannot be reloaded";
137 return "Isolate must have reloaded";
139 return "File system already exists";
141 return "File system does not exist";
143 return "File does not exist";
145 return "The timeline related request could not be completed due to the "
146 "current configuration";
148 return "Extension error";
157 for (intptr_t i = 0; i < js->num_params(); i++) {
158 params.AddProperty(js->GetParamKey(i), js->GetParamValue(i));
171 if (details_format !=
nullptr) {
172 va_list measure_args;
173 va_start(measure_args, details_format);
174 intptr_t len =
Utils::VSNPrint(
nullptr, 0, details_format, measure_args);
175 va_end(measure_args);
179 va_start(print_args, details_format);
187void JSONStream::PostNullReply(
Dart_Port port) {
200 if (seq_->IsString()) {
201 const String& str = String::Cast(*seq_);
203 }
else if (seq_->IsInteger()) {
204 const Integer& integer = Integer::Cast(*seq_);
206 }
else if (seq_->IsDouble()) {
207 const Double& dbl = Double::Cast(*seq_);
208 PrintProperty(
"id", dbl.
value());
209 }
else if (seq_->
IsNull()) {
216 OS::PrintErr(
"-----\nDropping reply:\n%s\n-----\n", cstr);
241 elements[0] = &bytes;
244 message.value.as_array.length = 1;
245 message.value.as_array.values = elements;
253 if (FLAG_trace_service) {
255 ASSERT(isolate !=
nullptr);
256 int64_t main_port =
static_cast<int64_t
>(isolate->
main_port());
257 const char* isolate_name = isolate->
name();
261 ") %s processed service request %s (%" Pd64 "us)\n",
266 ") %s processed service request %s (%" Pd64 "us) FAILED\n",
275 if (strcmp(
key, param_keys_[i]) == 0) {
276 return param_values_[i];
291 return (key_value !=
nullptr) && (strcmp(key_value,
value) == 0);
305 if (*count < 0 || *count > remaining) {
309void JSONStream::PrintfValue(
const char*
format, ...) {
316void JSONStream::PrintValue(
const Object& o,
bool ref) {
318 o.PrintJSON(
this, ref);
321void JSONStream::PrintValue(Breakpoint* bpt) {
323 bpt->PrintJSON(
this);
326void JSONStream::PrintValue(TokenPosition tp) {
328 PrintValue(
static_cast<intptr_t
>(tp.Serialize()));
331void JSONStream::PrintValue(
const ServiceEvent*
event) {
333 event->PrintJSON(
this);
336void JSONStream::PrintValue(Metric* metric) {
338 metric->PrintJSON(
this);
341void JSONStream::PrintValue(MessageQueue* queue) {
343 queue->PrintJSON(
this);
346void JSONStream::PrintValue(Isolate* isolate,
bool ref) {
348 isolate->PrintJSON(
this, ref);
351void JSONStream::PrintValue(IsolateGroup* isolate_group,
bool ref) {
353 isolate_group->PrintJSON(
this, ref);
356void JSONStream::PrintValue(
const TimelineEvent* timeline_event) {
358 timeline_event->PrintJSON(
this);
361void JSONStream::PrintValue(
const TimelineEventBlock* timeline_event_block) {
363 timeline_event_block->PrintJSON(
this);
366void JSONStream::PrintValueVM(
bool ref) {
371void JSONStream::PrintServiceId(
const Object& o) {
372 ASSERT(id_zone_ !=
nullptr);
376#define PRIVATE_NAME_CHECK() \
377 if (!IsAllowableKey(name) || ignore_object_depth_ > 0) return
379void JSONStream::PrintProperty(
const char*
name,
const ServiceEvent*
event) {
381 PrintPropertyName(
name);
385void JSONStream::PrintProperty(
const char*
name, Breakpoint* bpt) {
387 PrintPropertyName(
name);
391void JSONStream::PrintProperty(
const char*
name, TokenPosition tp) {
393 PrintPropertyName(
name);
397void JSONStream::PrintProperty(
const char*
name, Metric* metric) {
399 PrintPropertyName(
name);
403void JSONStream::PrintProperty(
const char*
name, MessageQueue* queue) {
405 PrintPropertyName(
name);
409void JSONStream::PrintProperty(
const char*
name, Isolate* isolate) {
411 PrintPropertyName(
name);
415void JSONStream::PrintProperty(
const char*
name, IsolateGroup* isolate_group) {
417 PrintPropertyName(
name);
418 PrintValue(isolate_group);
421void JSONStream::PrintProperty(
const char*
name,
422 const TimelineEvent* timeline_event) {
424 PrintPropertyName(
name);
425 PrintValue(timeline_event);
428void JSONStream::PrintProperty(
const char*
name,
429 const TimelineEventBlock* timeline_event_block) {
431 PrintPropertyName(
name);
432 PrintValue(timeline_event_block);
435void JSONStream::PrintfProperty(
const char*
name,
const char*
format, ...) {
448 if (parameter_keys_ ==
nullptr) {
451 ASSERT(parameter_keys_ !=
nullptr);
452 ASSERT(parameter_values_ !=
nullptr);
453 return parameter_keys_->
Length();
458 return parameter_keys_->
At(i);
463 return parameter_values_->
At(i);
470 for (intptr_t i = 0; i < num_object_parameters; i++) {
472 if (
test.IsString() && String::Cast(
test).Equals(
key)) {
480 const char** param_values,
481 intptr_t num_params) {
487void JSONStream::PrintProperty(
const char*
name,
const Object& o,
bool ref) {
489 PrintPropertyName(
name);
493void JSONStream::PrintPropertyVM(
const char*
name,
bool ref) {
495 PrintPropertyName(
name);
500 stream_->OpenObject();
528 if (end_token_pos.
IsReal()) {
529 location.
AddProperty(
"endTokenPos", end_token_pos);
532 intptr_t column = -1;
534 if (script.GetTokenLocation(token_pos, &line, &column)) {
554 location.
AddProperty(
"tokenPos", TokenPosition::kNoSource);
570 location.
AddProperty(
"type",
"UnresolvedSourceLocation");
571 if (!script.IsNull()) {
606 if (num_queued_bytes_ > 0) {
608 queued_bytes_[num_queued_bytes_++] = bytes[0];
611 if (num_queued_bytes_ == 3) {
615 if (num_queued_bytes_ < 3) {
618 stream_->AppendBytesInBase64(queued_bytes_, 3);
619 num_queued_bytes_ = 0;
622 intptr_t length_mod_3 =
length % 3;
623 intptr_t largest_multiple_of_3_less_than_or_equal_to_length =
625 if (largest_multiple_of_3_less_than_or_equal_to_length > 0) {
626 stream_->AppendBytesInBase64(
627 bytes, largest_multiple_of_3_less_than_or_equal_to_length);
630 for (intptr_t i = 0; i < length_mod_3; ++i) {
632 bytes[largest_multiple_of_3_less_than_or_equal_to_length + i];
634 num_queued_bytes_ = length_mod_3;
ObjectPtr At(intptr_t index) const
intptr_t Printf(const char *format,...) PRINTF_ATTRIBUTE(2
intptr_t requested_column_number() const
void GetCodeLocation(Script *script, TokenPosition *token_pos) const
intptr_t requested_line_number() const
static int64_t UptimeMillis()
virtual int64_t AsInt64Value() const
static Isolate * Current()
ObjectIdRing * EnsureObjectIdRing()
Dart_Port main_port() const
const char * name() const
void AddValueF(const char *format,...) const PRINTF_ATTRIBUTE(2
void AppendBytes(const uint8_t *bytes, intptr_t length)
void void void AddLocation(const Script &script, TokenPosition token_pos, TokenPosition end_token_pos=TokenPosition::kNoSource) const
void AddProperty(const char *name, bool b) const
void AddServiceId(const Object &o) const
void AddUnresolvedLocation(const BreakpointLocation *bpt_loc) const
bool AddPropertyStr(const char *name, const String &s, intptr_t offset=0, intptr_t count=-1) const
void AddFixedServiceId(const char *format,...) const PRINTF_ATTRIBUTE(2
JSONObject(JSONStream *stream)
void AddPropertyF(const char *name, const char *format,...) const PRINTF_ATTRIBUTE(3
void AddLocationLine(const Script &script, intptr_t line) const
void Setup(Zone *zone, Dart_Port reply_port, const Instance &seq, const String &method, const Array ¶m_keys, const Array ¶m_values, bool parameters_are_dart_objects=false)
void PrintCommaIfNeeded()
intptr_t num_params() const
ObjectPtr GetObjectParameterKey(intptr_t i) const
ObjectPtr LookupObjectParam(const char *key) const
bool ParamIs(const char *key, const char *value) const
void ComputeOffsetAndCount(intptr_t length, intptr_t *offset, intptr_t *count)
Dart_Port reply_port() const
bool HasParam(const char *key) const
const char ** param_values() const
void set_reply_port(Dart_Port port)
const char ** param_keys() const
JSONStream(intptr_t buf_size=256)
intptr_t NumObjectParameters() const
void PrintError(intptr_t code, const char *details_format,...) PRINTF_ATTRIBUTE(3
ObjectPtr GetObjectParameterValue(intptr_t i) const
void Steal(char **buffer, intptr_t *buffer_length)
const char * LookupParam(const char *key) const
const char * method() const
void SetParams(const char **param_keys, const char **param_values, intptr_t num_params)
void void VPrintfProperty(const char *name, const char *format, va_list args)
static std::unique_ptr< Message > New(Args &&... args)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static int64_t GetCurrentTimeMicros()
static Object & ZoneHandle()
static bool PostMessage(std::unique_ptr< Message > message, bool before_events=false)
void Init(ObjectIdRing *ring, ObjectIdRing::IdPolicy policy)
virtual char * GetServiceId(const Object &obj)=0
static void PrintJSONForVM(JSONStream *js, bool ref)
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
static const char * ToCString(Thread *thread, StringPtr ptr)
static Thread * Current()
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
char * MakeCopyOfString(const char *str)
ElementType * Alloc(intptr_t length)
@ Dart_CObject_kExternalTypedData
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
uint32_t uint32_t * format
#define DECLARE_FLAG(type, name)
#define PRIVATE_NAME_CHECK()
static const char * GetJSONRpcErrorMessage(intptr_t code)
DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject *message)
static int8_t data[kExtLength]
static void PrintRequest(JSONObject *obj, JSONStream *js)
@ kIsolateMustHaveReloaded
@ kStreamAlreadySubscribed
@ kFileSystemDoesNotExist
@ kFileSystemAlreadyExists
@ kInvalidTimelineRequest
Dart_HandleFinalizer callback
union _Dart_CObject::@86 value
struct _Dart_CObject::@86::@91 as_external_typed_data