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/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 "['expr'], ['toString()']]"); | 601 "['expr'], ['toString()']]"); |
602 Service::HandleIsolateMessage(isolate, service_msg); | 602 Service::HandleIsolateMessage(isolate, service_msg); |
603 handler.HandleNextMessage(); | 603 handler.HandleNextMessage(); |
604 ExpectSubstringF(handler.msg(), "\"type\":\"Error\""); | 604 ExpectSubstringF(handler.msg(), "\"type\":\"Error\""); |
605 ExpectSubstringF( | 605 ExpectSubstringF( |
606 handler.msg(), | 606 handler.msg(), |
607 "\"message\":\"attempt to evaluate against internal VM object\\n\""); | 607 "\"message\":\"attempt to evaluate against internal VM object\\n\""); |
608 } | 608 } |
609 | 609 |
610 | 610 |
| 611 TEST_CASE(Service_RetainingPath) { |
| 612 const char* kScript = |
| 613 "var port;\n" // Set to our mock port by C++. |
| 614 "var id0;\n" // Set to an object id by C++. |
| 615 "var id1;\n" // Ditto. |
| 616 "var idElem;\n" // Ditto. |
| 617 "class Foo {\n" |
| 618 " String f0;\n" |
| 619 " String f1;\n" |
| 620 "}\n" |
| 621 "Foo foo;\n" |
| 622 "List<String> lst;\n" |
| 623 "main() {\n" |
| 624 " foo = new Foo();\n" |
| 625 " lst = new List<String>(100);\n" |
| 626 "}\n"; |
| 627 Isolate* isolate = Isolate::Current(); |
| 628 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
| 629 EXPECT_VALID(h_lib); |
| 630 Library& lib = Library::Handle(); |
| 631 lib ^= Api::UnwrapHandle(h_lib); |
| 632 EXPECT(!lib.IsNull()); |
| 633 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 634 EXPECT_VALID(result); |
| 635 const Class& class_foo = Class::Handle(GetClass(lib, "Foo")); |
| 636 EXPECT(!class_foo.IsNull()); |
| 637 Dart_Handle foo = Dart_GetField(h_lib, NewString("foo")); |
| 638 Dart_Handle lst = Dart_GetField(h_lib, NewString("lst")); |
| 639 const intptr_t kElemIndex = 42; |
| 640 { |
| 641 Dart_EnterScope(); |
| 642 ObjectIdRing* ring = isolate->object_id_ring(); |
| 643 { |
| 644 const String& foo0 = String::Handle(String::New("foo0", Heap::kOld)); |
| 645 Dart_Handle h_foo0 = Api::NewHandle(isolate, foo0.raw()); |
| 646 EXPECT_VALID(Dart_SetField(foo, NewString("f0"), h_foo0)); |
| 647 Dart_Handle id0 = Dart_NewInteger(ring->GetIdForObject(foo0.raw())); |
| 648 EXPECT_VALID(id0); |
| 649 EXPECT_VALID(Dart_SetField(h_lib, NewString("id0"), id0)); |
| 650 } |
| 651 { |
| 652 const String& foo1 = String::Handle(String::New("foo1", Heap::kOld)); |
| 653 Dart_Handle h_foo1 = Api::NewHandle(isolate, foo1.raw()); |
| 654 EXPECT_VALID(Dart_SetField(foo, NewString("f1"), h_foo1)); |
| 655 Dart_Handle id1 = Dart_NewInteger(ring->GetIdForObject(foo1.raw())); |
| 656 EXPECT_VALID(id1); |
| 657 EXPECT_VALID(Dart_SetField(h_lib, NewString("id1"), id1)); |
| 658 } |
| 659 { |
| 660 const String& elem = String::Handle(String::New("elem", Heap::kOld)); |
| 661 Dart_Handle h_elem = Api::NewHandle(isolate, elem.raw()); |
| 662 EXPECT_VALID(Dart_ListSetAt(lst, kElemIndex, h_elem)); |
| 663 Dart_Handle idElem = Dart_NewInteger(ring->GetIdForObject(elem.raw())); |
| 664 EXPECT_VALID(idElem); |
| 665 EXPECT_VALID(Dart_SetField(h_lib, NewString("idElem"), idElem)); |
| 666 } |
| 667 Dart_ExitScope(); |
| 668 } |
| 669 |
| 670 // Build a mock message handler and wrap it in a dart port. |
| 671 ServiceTestMessageHandler handler; |
| 672 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 673 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 674 EXPECT_VALID(port); |
| 675 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
| 676 Instance& service_msg = Instance::Handle(); |
| 677 |
| 678 // Retaining path to 'foo0', limit 2. |
| 679 service_msg = Eval( |
| 680 h_lib, |
| 681 "[0, port, ['objects', '$id0', 'retaining_path'], ['limit'], ['2']]"); |
| 682 Service::HandleIsolateMessage(isolate, service_msg); |
| 683 handler.HandleNextMessage(); |
| 684 ExpectSubstringF( |
| 685 handler.msg(), |
| 686 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2," |
| 687 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); |
| 688 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\""); |
| 689 ExpectSubstringF(handler.msg(), "\"name\":\"f0\""); |
| 690 ExpectSubstringF(handler.msg(), |
| 691 "{\"index\":1,\"value\":{\"type\":\"@Instance\""); |
| 692 |
| 693 // Retaining path to 'foo1', limit 2. |
| 694 service_msg = Eval( |
| 695 h_lib, |
| 696 "[0, port, ['objects', '$id1', 'retaining_path'], ['limit'], ['2']]"); |
| 697 Service::HandleIsolateMessage(isolate, service_msg); |
| 698 handler.HandleNextMessage(); |
| 699 ExpectSubstringF( |
| 700 handler.msg(), |
| 701 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2," |
| 702 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); |
| 703 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\""); |
| 704 ExpectSubstringF(handler.msg(), "\"name\":\"f1\""); |
| 705 ExpectSubstringF(handler.msg(), |
| 706 "{\"index\":1,\"value\":{\"type\":\"@Instance\""); |
| 707 |
| 708 // Retaining path to 'elem', limit 2. |
| 709 service_msg = Eval( |
| 710 h_lib, |
| 711 "[0, port, ['objects', '$idElem', 'retaining_path'], ['limit'], ['2']]"); |
| 712 Service::HandleIsolateMessage(isolate, service_msg); |
| 713 handler.HandleNextMessage(); |
| 714 ExpectSubstringF( |
| 715 handler.msg(), |
| 716 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2," |
| 717 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); |
| 718 ExpectSubstringF(handler.msg(), "\"parentListIndex\":%" Pd, kElemIndex); |
| 719 ExpectSubstringF(handler.msg(), |
| 720 "{\"index\":1,\"value\":{\"type\":\"@Array\""); |
| 721 } |
| 722 |
| 723 |
611 TEST_CASE(Service_Libraries) { | 724 TEST_CASE(Service_Libraries) { |
612 const char* kScript = | 725 const char* kScript = |
613 "var port;\n" // Set to our mock port by C++. | 726 "var port;\n" // Set to our mock port by C++. |
614 "var libVar = 54321;\n" | 727 "var libVar = 54321;\n" |
615 "\n" | 728 "\n" |
616 "main() {\n" | 729 "main() {\n" |
617 "}"; | 730 "}"; |
618 | 731 |
619 Isolate* isolate = Isolate::Current(); | 732 Isolate* isolate = Isolate::Current(); |
620 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | 733 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); | 1799 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); |
1687 Service::HandleIsolateMessage(isolate, service_msg); | 1800 Service::HandleIsolateMessage(isolate, service_msg); |
1688 handler.HandleNextMessage(); | 1801 handler.HandleNextMessage(); |
1689 // Expect error. | 1802 // Expect error. |
1690 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 1803 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
1691 } | 1804 } |
1692 | 1805 |
1693 #endif // !defined(TARGET_ARCH_ARM64) | 1806 #endif // !defined(TARGET_ARCH_ARM64) |
1694 | 1807 |
1695 } // namespace dart | 1808 } // namespace dart |
OLD | NEW |