| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 285 } |
| 286 | 286 |
| 287 | 287 |
| 288 void JSONStream::PrintValueBool(bool b) { | 288 void JSONStream::PrintValueBool(bool b) { |
| 289 PrintCommaIfNeeded(); | 289 PrintCommaIfNeeded(); |
| 290 buffer_.Printf("%s", b ? "true" : "false"); | 290 buffer_.Printf("%s", b ? "true" : "false"); |
| 291 } | 291 } |
| 292 | 292 |
| 293 | 293 |
| 294 void JSONStream::PrintValue(intptr_t i) { | 294 void JSONStream::PrintValue(intptr_t i) { |
| 295 EnsureIntegerIsRepresentableInJavaScript(static_cast<int64_t>(i)); |
| 295 PrintCommaIfNeeded(); | 296 PrintCommaIfNeeded(); |
| 296 buffer_.Printf("%" Pd "", i); | 297 buffer_.Printf("%" Pd "", i); |
| 297 } | 298 } |
| 298 | 299 |
| 299 | 300 |
| 300 void JSONStream::PrintValue64(int64_t i) { | 301 void JSONStream::PrintValue64(int64_t i) { |
| 302 EnsureIntegerIsRepresentableInJavaScript(i); |
| 301 PrintCommaIfNeeded(); | 303 PrintCommaIfNeeded(); |
| 302 buffer_.Printf("%" Pd64 "", i); | 304 buffer_.Printf("%" Pd64 "", i); |
| 303 } | 305 } |
| 304 | 306 |
| 305 | 307 |
| 306 void JSONStream::PrintValueTimeMillis(int64_t millis) { | 308 void JSONStream::PrintValueTimeMillis(int64_t millis) { |
| 307 PrintValue(static_cast<double>(millis)); | 309 EnsureIntegerIsRepresentableInJavaScript(millis); |
| 310 PrintValue64(millis); |
| 308 } | 311 } |
| 309 | 312 |
| 310 | 313 |
| 311 void JSONStream::PrintValueTimeMicros(int64_t micros) { | 314 void JSONStream::PrintValueTimeMicros(int64_t micros) { |
| 315 EnsureIntegerIsRepresentableInJavaScript(micros); |
| 312 PrintValue64(micros); | 316 PrintValue64(micros); |
| 313 } | 317 } |
| 314 | 318 |
| 315 | 319 |
| 316 void JSONStream::PrintValue(double d) { | 320 void JSONStream::PrintValue(double d) { |
| 317 PrintCommaIfNeeded(); | 321 PrintCommaIfNeeded(); |
| 318 buffer_.Printf("%f", d); | 322 buffer_.Printf("%f", d); |
| 319 } | 323 } |
| 320 | 324 |
| 321 | 325 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 449 } |
| 446 | 450 |
| 447 | 451 |
| 448 void JSONStream::PrintPropertyBool(const char* name, bool b) { | 452 void JSONStream::PrintPropertyBool(const char* name, bool b) { |
| 449 PrintPropertyName(name); | 453 PrintPropertyName(name); |
| 450 PrintValueBool(b); | 454 PrintValueBool(b); |
| 451 } | 455 } |
| 452 | 456 |
| 453 | 457 |
| 454 void JSONStream::PrintProperty(const char* name, intptr_t i) { | 458 void JSONStream::PrintProperty(const char* name, intptr_t i) { |
| 455 ASSERT(Utils::IsJavascriptInt(i)); | |
| 456 PrintPropertyName(name); | 459 PrintPropertyName(name); |
| 457 PrintValue(i); | 460 PrintValue(i); |
| 458 } | 461 } |
| 459 | 462 |
| 460 | 463 |
| 461 void JSONStream::PrintProperty64(const char* name, int64_t i) { | 464 void JSONStream::PrintProperty64(const char* name, int64_t i) { |
| 462 ASSERT(Utils::IsJavascriptInt64(i)); | |
| 463 PrintPropertyName(name); | 465 PrintPropertyName(name); |
| 464 PrintValue64(i); | 466 PrintValue64(i); |
| 465 } | 467 } |
| 466 | 468 |
| 467 | 469 |
| 468 void JSONStream::PrintPropertyTimeMillis(const char* name, int64_t millis) { | 470 void JSONStream::PrintPropertyTimeMillis(const char* name, int64_t millis) { |
| 469 PrintProperty(name, static_cast<double>(millis)); | 471 PrintProperty64(name, millis); |
| 470 } | 472 } |
| 471 | 473 |
| 472 | 474 |
| 473 void JSONStream::PrintPropertyTimeMicros(const char* name, int64_t micros) { | 475 void JSONStream::PrintPropertyTimeMicros(const char* name, int64_t micros) { |
| 474 PrintProperty64(name, micros); | 476 PrintProperty64(name, micros); |
| 475 } | 477 } |
| 476 | 478 |
| 477 | 479 |
| 478 void JSONStream::PrintProperty(const char* name, double d) { | 480 void JSONStream::PrintProperty(const char* name, double d) { |
| 479 PrintPropertyName(name); | 481 PrintPropertyName(name); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 const char* buffer = buffer_.buf(); | 615 const char* buffer = buffer_.buf(); |
| 614 intptr_t length = buffer_.length(); | 616 intptr_t length = buffer_.length(); |
| 615 if (length == 0) { | 617 if (length == 0) { |
| 616 return false; | 618 return false; |
| 617 } | 619 } |
| 618 char ch = buffer[length-1]; | 620 char ch = buffer[length-1]; |
| 619 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); | 621 return (ch != '[') && (ch != '{') && (ch != ':') && (ch != ','); |
| 620 } | 622 } |
| 621 | 623 |
| 622 | 624 |
| 625 void JSONStream::EnsureIntegerIsRepresentableInJavaScript(int64_t i) { |
| 626 #ifdef DEBUG |
| 627 if (!Utils::IsJavascriptInt(i)) { |
| 628 OS::Print("JSONStream::EnsureIntegerIsRepresentableInJavaScript failed on " |
| 629 "%" Pd64 "\n", i); |
| 630 UNREACHABLE(); |
| 631 } |
| 632 #endif |
| 633 } |
| 634 |
| 635 |
| 623 void JSONStream::AddEscapedUTF8String(const char* s) { | 636 void JSONStream::AddEscapedUTF8String(const char* s) { |
| 624 if (s == NULL) { | 637 if (s == NULL) { |
| 625 return; | 638 return; |
| 626 } | 639 } |
| 627 intptr_t len = strlen(s); | 640 intptr_t len = strlen(s); |
| 628 AddEscapedUTF8String(s, len); | 641 AddEscapedUTF8String(s, len); |
| 629 } | 642 } |
| 630 | 643 |
| 631 | 644 |
| 632 void JSONStream::AddEscapedUTF8String(const char* s, intptr_t len) { | 645 void JSONStream::AddEscapedUTF8String(const char* s, intptr_t len) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); | 794 intptr_t len2 = OS::VSNPrint(p, len+1, format, args); |
| 782 va_end(args); | 795 va_end(args); |
| 783 ASSERT(len == len2); | 796 ASSERT(len == len2); |
| 784 stream_->buffer_.AddChar('"'); | 797 stream_->buffer_.AddChar('"'); |
| 785 stream_->AddEscapedUTF8String(p); | 798 stream_->AddEscapedUTF8String(p); |
| 786 stream_->buffer_.AddChar('"'); | 799 stream_->buffer_.AddChar('"'); |
| 787 free(p); | 800 free(p); |
| 788 } | 801 } |
| 789 | 802 |
| 790 } // namespace dart | 803 } // namespace dart |
| OLD | NEW |