Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
json_stream.cc File Reference
#include "platform/assert.h"
#include "include/dart_native_api.h"
#include "platform/unicode.h"
#include "vm/dart_entry.h"
#include "vm/debugger.h"
#include "vm/heap/safepoint.h"
#include "vm/json_stream.h"
#include "vm/message.h"
#include "vm/metrics.h"
#include "vm/object.h"
#include "vm/service.h"
#include "vm/service_event.h"
#include "vm/timeline.h"

Go to the source code of this file.

Namespaces

namespace  dart
 

Macros

#define PRIVATE_NAME_CHECK()    if (!IsAllowableKey(name) || ignore_object_depth_ > 0) return
 

Functions

 dart::DECLARE_FLAG (bool, trace_service)
 
static const char * dart::GetJSONRpcErrorMessage (intptr_t code)
 
static void dart::PrintRequest (JSONObject *obj, JSONStream *js)
 
static void dart::Finalizer (void *isolate_callback_data, void *buffer)
 

Macro Definition Documentation

◆ PRIVATE_NAME_CHECK

#define PRIVATE_NAME_CHECK ( )     if (!IsAllowableKey(name) || ignore_object_depth_ > 0) return

Definition at line 376 of file json_stream.cc.

378 {
380 PrintPropertyName(name);
381 PrintValue(event);
382}
383
384void JSONStream::PrintProperty(const char* name, Breakpoint* bpt) {
386 PrintPropertyName(name);
387 PrintValue(bpt);
388}
389
390void JSONStream::PrintProperty(const char* name, TokenPosition tp) {
392 PrintPropertyName(name);
393 PrintValue(tp);
394}
395
396void JSONStream::PrintProperty(const char* name, Metric* metric) {
398 PrintPropertyName(name);
399 PrintValue(metric);
400}
401
402void JSONStream::PrintProperty(const char* name, MessageQueue* queue) {
404 PrintPropertyName(name);
405 PrintValue(queue);
406}
407
408void JSONStream::PrintProperty(const char* name, Isolate* isolate) {
410 PrintPropertyName(name);
411 PrintValue(isolate);
412}
413
414void JSONStream::PrintProperty(const char* name, IsolateGroup* isolate_group) {
416 PrintPropertyName(name);
417 PrintValue(isolate_group);
418}
419
420void JSONStream::PrintProperty(const char* name,
421 const TimelineEvent* timeline_event) {
423 PrintPropertyName(name);
424 PrintValue(timeline_event);
425}
426
427void JSONStream::PrintProperty(const char* name,
428 const TimelineEventBlock* timeline_event_block) {
430 PrintPropertyName(name);
431 PrintValue(timeline_event_block);
432}
433
434void JSONStream::PrintfProperty(const char* name, const char* format, ...) {
436 va_list args;
438 writer_.VPrintfProperty(name, format, args);
439 va_end(args);
440}
441
442void JSONStream::set_reply_port(Dart_Port port) {
443 reply_port_ = port;
444}
445
446intptr_t JSONStream::NumObjectParameters() const {
447 if (parameter_keys_ == nullptr) {
448 return 0;
449 }
450 ASSERT(parameter_keys_ != nullptr);
451 ASSERT(parameter_values_ != nullptr);
452 return parameter_keys_->Length();
453}
454
455ObjectPtr JSONStream::GetObjectParameterKey(intptr_t i) const {
456 ASSERT((i >= 0) && (i < NumObjectParameters()));
457 return parameter_keys_->At(i);
458}
459
460ObjectPtr JSONStream::GetObjectParameterValue(intptr_t i) const {
461 ASSERT((i >= 0) && (i < NumObjectParameters()));
462 return parameter_values_->At(i);
463}
464
465ObjectPtr JSONStream::LookupObjectParam(const char* c_key) const {
466 const String& key = String::Handle(String::New(c_key));
467 Object& test = Object::Handle();
468 const intptr_t num_object_parameters = NumObjectParameters();
469 for (intptr_t i = 0; i < num_object_parameters; i++) {
470 test = GetObjectParameterKey(i);
471 if (test.IsString() && String::Cast(test).Equals(key)) {
472 return GetObjectParameterValue(i);
473 }
474 }
475 return Object::null();
476}
477
478void JSONStream::SetParams(const char** param_keys,
479 const char** param_values,
480 intptr_t num_params) {
481 param_keys_ = param_keys;
482 param_values_ = param_values;
483 num_params_ = num_params;
484}
485
486void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) {
488 PrintPropertyName(name);
489 PrintValue(o, ref);
490}
491
492void JSONStream::PrintPropertyVM(const char* name, bool ref) {
494 PrintPropertyName(name);
495 PrintValueVM(ref);
496}
497
498JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) {
499 stream_->OpenObject();
500}
501
502void JSONObject::AddFixedServiceId(const char* format, ...) const {
503 // Mark that this id is fixed.
504 AddProperty("fixedId", true);
505 // Add the id property.
506 va_list args;
508 stream_->VPrintfProperty("id", format, args);
509 va_end(args);
510}
511
512void JSONObject::AddServiceId(const char* format, ...) const {
513 // Add the id property.
514 va_list args;
516 stream_->VPrintfProperty("id", format, args);
517 va_end(args);
518}
519
520void JSONObject::AddLocation(const Script& script,
521 TokenPosition token_pos,
522 TokenPosition end_token_pos) const {
523 JSONObject location(this, "location");
524 location.AddProperty("type", "SourceLocation");
525 location.AddProperty("script", script);
526 location.AddProperty("tokenPos", token_pos);
527 if (end_token_pos.IsReal()) {
528 location.AddProperty("endTokenPos", end_token_pos);
529 }
530 intptr_t line = -1;
531 intptr_t column = -1;
532 // Add line and column information if token_pos is real.
533 if (script.GetTokenLocation(token_pos, &line, &column)) {
534 location.AddProperty("line", line);
535 location.AddProperty("column", column);
536 }
537}
538
539void JSONObject::AddLocation(const BreakpointLocation* bpt_loc) const {
540 ASSERT(bpt_loc->IsResolved());
541
542 Zone* zone = Thread::Current()->zone();
543 Script& script = Script::Handle(zone);
544 TokenPosition token_pos = TokenPosition::kNoSource;
545 bpt_loc->GetCodeLocation(&script, &token_pos);
546 AddLocation(script, token_pos);
547}
548
549void JSONObject::AddLocationLine(const Script& script, intptr_t line) const {
550 JSONObject location(this, "location");
551 location.AddProperty("type", "SourceLocation");
552 location.AddProperty("script", script);
553 location.AddProperty("tokenPos", TokenPosition::kNoSource);
554 if (line > 0) {
555 location.AddProperty("line", line);
556 }
557}
558
559void JSONObject::AddUnresolvedLocation(
560 const BreakpointLocation* bpt_loc) const {
561 ASSERT(!bpt_loc->IsResolved());
562
563 Zone* zone = Thread::Current()->zone();
564 Script& script = Script::Handle(zone);
565 TokenPosition token_pos = TokenPosition::kNoSource;
566 bpt_loc->GetCodeLocation(&script, &token_pos);
567
568 JSONObject location(this, "location");
569 location.AddProperty("type", "UnresolvedSourceLocation");
570 if (!script.IsNull()) {
571 location.AddProperty("script", script);
572 } else {
573 const String& scriptUri = String::Handle(zone, bpt_loc->url());
574 location.AddPropertyStr("scriptUri", scriptUri);
575 }
576 if (bpt_loc->requested_line_number() >= 0) {
577 // This unresolved breakpoint was specified at a particular line.
578 location.AddProperty("line", bpt_loc->requested_line_number());
579 if (bpt_loc->requested_column_number() >= 0) {
580 location.AddProperty("column", bpt_loc->requested_column_number());
581 }
582 } else {
583 // This unresolved breakpoint was requested at some function entry.
584 location.AddProperty("tokenPos", token_pos);
585 }
586}
587
588void JSONObject::AddPropertyF(const char* name, const char* format, ...) const {
589 va_list args;
591 stream_->VPrintfProperty(name, format, args);
592 va_end(args);
593}
594
595void JSONArray::AddValueF(const char* format, ...) const {
596 va_list args;
598 stream_->VPrintfValue(format, args);
599 va_end(args);
600}
601
602void JSONBase64String::AppendBytes(const uint8_t* bytes, intptr_t length) {
603 ASSERT(bytes != nullptr);
604
605 if (num_queued_bytes_ > 0) {
606 while (length > 0) {
607 queued_bytes_[num_queued_bytes_++] = bytes[0];
608 bytes++;
609 length--;
610 if (num_queued_bytes_ == 3) {
611 break;
612 }
613 }
614 if (num_queued_bytes_ < 3) {
615 return;
616 }
617 stream_->AppendBytesInBase64(queued_bytes_, 3);
618 num_queued_bytes_ = 0;
619 }
620
621 intptr_t length_mod_3 = length % 3;
622 intptr_t largest_multiple_of_3_less_than_or_equal_to_length =
623 length - length_mod_3;
624 if (largest_multiple_of_3_less_than_or_equal_to_length > 0) {
625 stream_->AppendBytesInBase64(
626 bytes, largest_multiple_of_3_less_than_or_equal_to_length);
627 }
628
629 for (intptr_t i = 0; i < length_mod_3; ++i) {
630 queued_bytes_[i] =
631 bytes[largest_multiple_of_3_less_than_or_equal_to_length + i];
632 }
633 num_queued_bytes_ = length_mod_3;
634}
635
636#endif // !PRODUCT
637
638} // namespace dart
int64_t Dart_Port
Definition dart_api.h:1524
#define ASSERT(E)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent * event
uint32_t uint32_t * format
const char * name
Definition fuchsia.cc:50
#define PRIVATE_NAME_CHECK()
size_t length
va_start(args, format)
va_end(args)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
Definition switches.h:87