| OLD | NEW |
| 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 389 |
| 390 | 390 |
| 391 void JSONStream::PrintValue(const char* s) { | 391 void JSONStream::PrintValue(const char* s) { |
| 392 PrintCommaIfNeeded(); | 392 PrintCommaIfNeeded(); |
| 393 buffer_.AddChar('"'); | 393 buffer_.AddChar('"'); |
| 394 AddEscapedUTF8String(s); | 394 AddEscapedUTF8String(s); |
| 395 buffer_.AddChar('"'); | 395 buffer_.AddChar('"'); |
| 396 } | 396 } |
| 397 | 397 |
| 398 | 398 |
| 399 bool JSONStream::PrintValueStr(const String& s, intptr_t limit) { | 399 bool JSONStream::PrintValueStr(const String& s, |
| 400 intptr_t offset, |
| 401 intptr_t count) { |
| 400 PrintCommaIfNeeded(); | 402 PrintCommaIfNeeded(); |
| 401 buffer_.AddChar('"'); | 403 buffer_.AddChar('"'); |
| 402 bool did_truncate = AddDartString(s, limit); | 404 bool did_truncate = AddDartString(s, offset, count); |
| 403 buffer_.AddChar('"'); | 405 buffer_.AddChar('"'); |
| 404 return did_truncate; | 406 return did_truncate; |
| 405 } | 407 } |
| 406 | 408 |
| 407 | 409 |
| 408 void JSONStream::PrintValueNoEscape(const char* s) { | 410 void JSONStream::PrintValueNoEscape(const char* s) { |
| 409 PrintCommaIfNeeded(); | 411 PrintCommaIfNeeded(); |
| 410 buffer_.Printf("%s", s); | 412 buffer_.Printf("%s", s); |
| 411 } | 413 } |
| 412 | 414 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 void JSONStream::PrintPropertyBase64(const char* name, | 529 void JSONStream::PrintPropertyBase64(const char* name, |
| 528 const uint8_t* b, | 530 const uint8_t* b, |
| 529 intptr_t len) { | 531 intptr_t len) { |
| 530 PrintPropertyName(name); | 532 PrintPropertyName(name); |
| 531 PrintValueBase64(b, len); | 533 PrintValueBase64(b, len); |
| 532 } | 534 } |
| 533 | 535 |
| 534 | 536 |
| 535 bool JSONStream::PrintPropertyStr(const char* name, | 537 bool JSONStream::PrintPropertyStr(const char* name, |
| 536 const String& s, | 538 const String& s, |
| 537 intptr_t limit) { | 539 intptr_t offset, |
| 540 intptr_t count) { |
| 538 PrintPropertyName(name); | 541 PrintPropertyName(name); |
| 539 return PrintValueStr(s, limit); | 542 return PrintValueStr(s, offset, count); |
| 540 } | 543 } |
| 541 | 544 |
| 542 | 545 |
| 543 void JSONStream::PrintPropertyNoEscape(const char* name, const char* s) { | 546 void JSONStream::PrintPropertyNoEscape(const char* name, const char* s) { |
| 544 PrintPropertyName(name); | 547 PrintPropertyName(name); |
| 545 PrintValueNoEscape(s); | 548 PrintValueNoEscape(s); |
| 546 } | 549 } |
| 547 | 550 |
| 548 | 551 |
| 549 void JSONStream::PrintProperty(const char* name, const ServiceEvent* event) { | 552 void JSONStream::PrintProperty(const char* name, const ServiceEvent* event) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 int32_t ch_len = Utf8::Decode(&s8[i], len - i, &ch); | 698 int32_t ch_len = Utf8::Decode(&s8[i], len - i, &ch); |
| 696 ASSERT(ch_len != 0); | 699 ASSERT(ch_len != 0); |
| 697 buffer_.EscapeAndAddCodeUnit(ch); | 700 buffer_.EscapeAndAddCodeUnit(ch); |
| 698 // Move i forward. | 701 // Move i forward. |
| 699 i += ch_len; | 702 i += ch_len; |
| 700 } | 703 } |
| 701 ASSERT(i == len); | 704 ASSERT(i == len); |
| 702 } | 705 } |
| 703 | 706 |
| 704 | 707 |
| 705 bool JSONStream::AddDartString(const String& s, intptr_t limit) { | 708 bool JSONStream::AddDartString(const String& s, |
| 706 bool did_truncate = false; | 709 intptr_t offset, |
| 710 intptr_t count) { |
| 707 intptr_t length = s.Length(); | 711 intptr_t length = s.Length(); |
| 708 if (limit == -1) { | 712 ASSERT(offset >= 0); |
| 709 limit = length; | 713 if (offset > length) { |
| 714 offset = length; |
| 710 } | 715 } |
| 711 if (length <= limit) { | 716 if (!Utils::RangeCheck(offset, count, length)) { |
| 712 limit = length; | 717 count = length - offset; |
| 713 } else { | |
| 714 did_truncate = true; | |
| 715 } | 718 } |
| 716 | 719 intptr_t limit = offset + count; |
| 717 for (intptr_t i = 0; i < limit; i++) { | 720 for (intptr_t i = offset; i < limit; i++) { |
| 718 intptr_t code_unit = s.CharAt(i); | 721 intptr_t code_unit = s.CharAt(i); |
| 719 buffer_.EscapeAndAddCodeUnit(code_unit); | 722 buffer_.EscapeAndAddCodeUnit(code_unit); |
| 720 } | 723 } |
| 721 return did_truncate; | 724 // Return value indicates whether the string is truncated. |
| 725 return (offset > 0) || (limit < length); |
| 722 } | 726 } |
| 723 | 727 |
| 724 | 728 |
| 725 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { | 729 JSONObject::JSONObject(const JSONArray* arr) : stream_(arr->stream_) { |
| 726 stream_->OpenObject(); | 730 stream_->OpenObject(); |
| 727 } | 731 } |
| 728 | 732 |
| 729 | 733 |
| 730 void JSONObject::AddFixedServiceId(const char* format, ...) const { | 734 void JSONObject::AddFixedServiceId(const char* format, ...) const { |
| 731 // Mark that this id is fixed. | 735 // Mark that this id is fixed. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 839 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 836 va_end(args); | 840 va_end(args); |
| 837 ASSERT(len == len2); | 841 ASSERT(len == len2); |
| 838 stream_->buffer_.AddChar('"'); | 842 stream_->buffer_.AddChar('"'); |
| 839 stream_->AddEscapedUTF8String(p); | 843 stream_->AddEscapedUTF8String(p); |
| 840 stream_->buffer_.AddChar('"'); | 844 stream_->buffer_.AddChar('"'); |
| 841 free(p); | 845 free(p); |
| 842 } | 846 } |
| 843 | 847 |
| 844 } // namespace dart | 848 } // namespace dart |
| OLD | NEW |