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_tools_api.h" | 7 #include "include/dart_tools_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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 Service::HandleIsolateMessage(isolate, service_msg); | 433 Service::HandleIsolateMessage(isolate, service_msg); |
434 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 434 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
435 // Check type. | 435 // Check type. |
436 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 436 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
437 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); | 437 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); |
438 // Check for members array. | 438 // Check for members array. |
439 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 439 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
440 } | 440 } |
441 | 441 |
442 | 442 |
| 443 |
| 444 static void WeakHandleFinalizer(void* isolate_callback_data, |
| 445 Dart_WeakPersistentHandle handle, |
| 446 void* peer) { |
| 447 } |
| 448 |
| 449 |
| 450 TEST_CASE(Service_PersistentHandles) { |
| 451 const char* kScript = |
| 452 "var port;\n" // Set to our mock port by C++. |
| 453 "\n" |
| 454 "class A {\n" |
| 455 " var a;\n" |
| 456 "}\n" |
| 457 "var global = new A();\n" |
| 458 "main() {\n" |
| 459 " return global;\n" |
| 460 "}"; |
| 461 |
| 462 Isolate* isolate = thread->isolate(); |
| 463 isolate->set_is_runnable(true); |
| 464 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 465 EXPECT_VALID(lib); |
| 466 Library& vmlib = Library::Handle(); |
| 467 vmlib ^= Api::UnwrapHandle(lib); |
| 468 EXPECT(!vmlib.IsNull()); |
| 469 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 470 EXPECT_VALID(result); |
| 471 |
| 472 // Create a persistent handle to global. |
| 473 Dart_PersistentHandle persistent_handle = Dart_NewPersistentHandle(result); |
| 474 |
| 475 // Create a weak persistent handle to global. |
| 476 Dart_WeakPersistentHandle weak_persistent_handle = |
| 477 Dart_NewWeakPersistentHandle(result, |
| 478 reinterpret_cast<void*>(0xdeadbeef), |
| 479 128, |
| 480 WeakHandleFinalizer); |
| 481 |
| 482 // Build a mock message handler and wrap it in a dart port. |
| 483 ServiceTestMessageHandler handler; |
| 484 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 485 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
| 486 EXPECT_VALID(port); |
| 487 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 488 |
| 489 Array& service_msg = Array::Handle(); |
| 490 |
| 491 // Get persistent handles. |
| 492 service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]"); |
| 493 Service::HandleIsolateMessage(isolate, service_msg); |
| 494 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
| 495 // Look for a heart beat. |
| 496 EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg()); |
| 497 EXPECT_SUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg()); |
| 498 EXPECT_SUBSTRING("\"name\":\"A\"", handler.msg()); |
| 499 EXPECT_SUBSTRING("\"externalSize\":\"128\"", handler.msg()); |
| 500 |
| 501 // Delete persistent handles. |
| 502 Dart_DeletePersistentHandle(persistent_handle); |
| 503 Dart_DeleteWeakPersistentHandle(Dart_CurrentIsolate(), |
| 504 weak_persistent_handle); |
| 505 |
| 506 // Get persistent handles (again). |
| 507 service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]"); |
| 508 Service::HandleIsolateMessage(isolate, service_msg); |
| 509 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
| 510 EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg()); |
| 511 // Verify that old persistent handles are not present. |
| 512 EXPECT_NOTSUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg()); |
| 513 EXPECT_NOTSUBSTRING("\"name\":\"A\"", handler.msg()); |
| 514 EXPECT_NOTSUBSTRING("\"externalSize\":\"128\"", handler.msg()); |
| 515 } |
| 516 |
| 517 |
443 TEST_CASE(Service_Address) { | 518 TEST_CASE(Service_Address) { |
444 const char* kScript = | 519 const char* kScript = |
445 "var port;\n" // Set to our mock port by C++. | 520 "var port;\n" // Set to our mock port by C++. |
446 "\n" | 521 "\n" |
447 "main() {\n" | 522 "main() {\n" |
448 "}"; | 523 "}"; |
449 | 524 |
450 Isolate* isolate = thread->isolate(); | 525 Isolate* isolate = thread->isolate(); |
451 isolate->set_is_runnable(true); | 526 isolate->set_is_runnable(true); |
452 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 527 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 717 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
643 // Expect error. | 718 // Expect error. |
644 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 719 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
645 } | 720 } |
646 | 721 |
647 #endif // !defined(TARGET_ARCH_ARM64) | 722 #endif // !defined(TARGET_ARCH_ARM64) |
648 | 723 |
649 #endif // !PRODUCT | 724 #endif // !PRODUCT |
650 | 725 |
651 } // namespace dart | 726 } // namespace dart |
OLD | NEW |