Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: runtime/vm/debugger_api_impl_test.cc

Issue 23067006: Evaluate expression in context of an object (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/debugger_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/thread.h" 8 #include "vm/thread.h"
9 #include "vm/unit_test.h" 9 #include "vm/unit_test.h"
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 43
44 static char const* ToCString(Dart_Handle str) { 44 static char const* ToCString(Dart_Handle str) {
45 EXPECT(Dart_IsString(str)); 45 EXPECT(Dart_IsString(str));
46 char const* c_str = NULL; 46 char const* c_str = NULL;
47 Dart_StringToCString(str, &c_str); 47 Dart_StringToCString(str, &c_str);
48 return c_str; 48 return c_str;
49 } 49 }
50 50
51 51
52 static int64_t ToInt64(Dart_Handle h) {
53 EXPECT(Dart_IsInteger(h));
54 int64_t i = 0;
55 Dart_Handle res = Dart_IntegerToInt64(h, &i);
56 EXPECT_VALID(res);
57 return i;
58 }
59
60
61 static double ToDouble(Dart_Handle h) {
62 EXPECT(Dart_IsDouble(h));
63 double d = 0.0;
64 Dart_Handle res = Dart_DoubleValue(h, &d);
65 EXPECT_VALID(res);
66 return d;
67 }
68
69
52 static char const* BreakpointInfo(Dart_StackTrace trace) { 70 static char const* BreakpointInfo(Dart_StackTrace trace) {
53 static char info_str[128]; 71 static char info_str[128];
54 Dart_ActivationFrame frame; 72 Dart_ActivationFrame frame;
55 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame); 73 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame);
56 EXPECT_TRUE(res); 74 EXPECT_TRUE(res);
57 Dart_Handle func_name; 75 Dart_Handle func_name;
58 Dart_Handle url; 76 Dart_Handle url;
59 intptr_t line_number = 0; 77 intptr_t line_number = 0;
60 intptr_t library_id = 0; 78 intptr_t library_id = 0;
61 res = Dart_ActivationFrameInfo( 79 res = Dart_ActivationFrameInfo(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 EXPECT(Dart_IsString(name_handle)); 162 EXPECT(Dart_IsString(name_handle));
145 OS::Print(" local var %s = ", ToCString(name_handle)); 163 OS::Print(" local var %s = ", ToCString(name_handle));
146 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1); 164 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1);
147 EXPECT_VALID(value_handle); 165 EXPECT_VALID(value_handle);
148 PrintValue(value_handle, true); 166 PrintValue(value_handle, true);
149 OS::Print("\n"); 167 OS::Print("\n");
150 } 168 }
151 } 169 }
152 170
153 171
172 static Dart_Handle GetLocalVariable(Dart_ActivationFrame frame,
173 const char* name) {
174 Dart_Handle locals = Dart_GetLocalVariables(frame);
175 EXPECT_VALID(locals);
176 intptr_t list_length = 0;
177 Dart_Handle ret = Dart_ListLength(locals, &list_length);
178 EXPECT_VALID(ret);
179 for (int i = 0; i + 1 < list_length; i += 2) {
180 Dart_Handle name_handle = Dart_ListGetAt(locals, i);
181 EXPECT_VALID(name_handle);
182 EXPECT(Dart_IsString(name_handle));
183 if (strcmp(ToCString(name_handle), name) == 0) {
184 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1);
185 EXPECT_VALID(value_handle);
186 return value_handle;
187 }
188 }
189 EXPECT(!"local variable not found");
190 return Dart_Null();
191 }
192
193
154 static void PrintStackTrace(Dart_StackTrace trace) { 194 static void PrintStackTrace(Dart_StackTrace trace) {
155 intptr_t trace_len; 195 intptr_t trace_len;
156 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 196 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
157 EXPECT_TRUE(res); 197 EXPECT_TRUE(res);
158 for (int i = 0; i < trace_len; i++) { 198 for (int i = 0; i < trace_len; i++) {
159 Dart_ActivationFrame frame; 199 Dart_ActivationFrame frame;
160 res = Dart_GetActivationFrame(trace, i, &frame); 200 res = Dart_GetActivationFrame(trace, i, &frame);
161 EXPECT_TRUE(res); 201 EXPECT_TRUE(res);
162 PrintActivationFrame(frame); 202 PrintActivationFrame(frame);
163 } 203 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // Set a breakpoint in function f1, then repeatedly step out until 377 // Set a breakpoint in function f1, then repeatedly step out until
338 // we get to main. We should see one breakpoint each in f1, 378 // we get to main. We should see one breakpoint each in f1,
339 // foo, main, but not in f2. 379 // foo, main, but not in f2.
340 SetBreakpointAtEntry("", "f1"); 380 SetBreakpointAtEntry("", "f1");
341 381
342 breakpoint_hit = false; 382 breakpoint_hit = false;
343 breakpoint_hit_counter = 0; 383 breakpoint_hit_counter = 0;
344 Dart_Handle retval = Invoke("main"); 384 Dart_Handle retval = Invoke("main");
345 EXPECT_VALID(retval); 385 EXPECT_VALID(retval);
346 EXPECT(Dart_IsInteger(retval)); 386 EXPECT(Dart_IsInteger(retval));
347 int64_t int_value = 0; 387 int64_t int_value = ToInt64(retval);
348 Dart_IntegerToInt64(retval, &int_value);
349 EXPECT_EQ(2, int_value); 388 EXPECT_EQ(2, int_value);
350 EXPECT(breakpoint_hit == true); 389 EXPECT(breakpoint_hit == true);
351 } 390 }
352 391
353 392
354 void TestStepIntoHandler(Dart_IsolateId isolate_id, 393 void TestStepIntoHandler(Dart_IsolateId isolate_id,
355 const Dart_CodeLocation& location) { 394 const Dart_CodeLocation& location) {
356 Dart_StackTrace trace; 395 Dart_StackTrace trace;
357 Dart_GetStackTrace(&trace); 396 Dart_GetStackTrace(&trace);
358 const char* expected_bpts[] = { 397 const char* expected_bpts[] = {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 458
420 LoadScript(kScriptChars); 459 LoadScript(kScriptChars);
421 Dart_SetPausedEventHandler(&TestStepIntoHandler); 460 Dart_SetPausedEventHandler(&TestStepIntoHandler);
422 461
423 SetBreakpointAtEntry("", "main"); 462 SetBreakpointAtEntry("", "main");
424 breakpoint_hit = false; 463 breakpoint_hit = false;
425 breakpoint_hit_counter = 0; 464 breakpoint_hit_counter = 0;
426 Dart_Handle retval = Invoke("main"); 465 Dart_Handle retval = Invoke("main");
427 EXPECT_VALID(retval); 466 EXPECT_VALID(retval);
428 EXPECT(Dart_IsInteger(retval)); 467 EXPECT(Dart_IsInteger(retval));
429 int64_t int_value = 0; 468 int64_t int_value = ToInt64(retval);
430 Dart_IntegerToInt64(retval, &int_value);
431 EXPECT_EQ(7, int_value); 469 EXPECT_EQ(7, int_value);
432 EXPECT(breakpoint_hit == true); 470 EXPECT(breakpoint_hit == true);
433 } 471 }
434 472
435 473
436 static void StepIntoHandler(Dart_IsolateId isolate_id, 474 static void StepIntoHandler(Dart_IsolateId isolate_id,
437 const Dart_CodeLocation& location) { 475 const Dart_CodeLocation& location) {
438 Dart_StackTrace trace; 476 Dart_StackTrace trace;
439 Dart_GetStackTrace(&trace); 477 Dart_GetStackTrace(&trace);
440 if (verbose) { 478 if (verbose) {
(...skipping 24 matching lines...) Expand all
465 LoadScript(kScriptChars); 503 LoadScript(kScriptChars);
466 Dart_SetPausedEventHandler(&StepIntoHandler); 504 Dart_SetPausedEventHandler(&StepIntoHandler);
467 505
468 SetBreakpointAtEntry("", "main"); 506 SetBreakpointAtEntry("", "main");
469 507
470 breakpoint_hit = false; 508 breakpoint_hit = false;
471 breakpoint_hit_counter = 0; 509 breakpoint_hit_counter = 0;
472 Dart_Handle retval = Invoke("main"); 510 Dart_Handle retval = Invoke("main");
473 EXPECT_VALID(retval); 511 EXPECT_VALID(retval);
474 EXPECT(Dart_IsInteger(retval)); 512 EXPECT(Dart_IsInteger(retval));
475 int64_t int_value = 0; 513 int64_t int_value = ToInt64(retval);
476 Dart_IntegerToInt64(retval, &int_value);
477 EXPECT_EQ(101, int_value); 514 EXPECT_EQ(101, int_value);
478 EXPECT(breakpoint_hit == true); 515 EXPECT(breakpoint_hit == true);
479 } 516 }
480 517
481 518
482 TEST_CASE(Debug_DeoptimizeFunction) { 519 TEST_CASE(Debug_DeoptimizeFunction) {
483 const char* kScriptChars = 520 const char* kScriptChars =
484 "foo(x) => 2 * x; \n" 521 "foo(x) => 2 * x; \n"
485 " \n" 522 " \n"
486 "warmup() { \n" 523 "warmup() { \n"
(...skipping 16 matching lines...) Expand all
503 540
504 // Now set breakpoint in main and then step into optimized function foo. 541 // Now set breakpoint in main and then step into optimized function foo.
505 SetBreakpointAtEntry("", "main"); 542 SetBreakpointAtEntry("", "main");
506 543
507 544
508 breakpoint_hit = false; 545 breakpoint_hit = false;
509 breakpoint_hit_counter = 0; 546 breakpoint_hit_counter = 0;
510 Dart_Handle retval = Invoke("main"); 547 Dart_Handle retval = Invoke("main");
511 EXPECT_VALID(retval); 548 EXPECT_VALID(retval);
512 EXPECT(Dart_IsInteger(retval)); 549 EXPECT(Dart_IsInteger(retval));
513 int64_t int_value = 0; 550 int64_t int_value = ToInt64(retval);
514 Dart_IntegerToInt64(retval, &int_value);
515 EXPECT_EQ(2 * 99, int_value); 551 EXPECT_EQ(2 * 99, int_value);
516 EXPECT(breakpoint_hit == true); 552 EXPECT(breakpoint_hit == true);
517 } 553 }
518 554
519 555
520 void TestSingleStepHandler(Dart_IsolateId isolate_id, 556 void TestSingleStepHandler(Dart_IsolateId isolate_id,
521 const Dart_CodeLocation& location) { 557 const Dart_CodeLocation& location) {
522 Dart_StackTrace trace; 558 Dart_StackTrace trace;
523 Dart_GetStackTrace(&trace); 559 Dart_GetStackTrace(&trace);
524 const char* expected_bpts[] = { 560 const char* expected_bpts[] = {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 "} \n"; 653 "} \n";
618 654
619 LoadScript(kScriptChars); 655 LoadScript(kScriptChars);
620 Dart_SetPausedEventHandler(&ClosureBreakpointHandler); 656 Dart_SetPausedEventHandler(&ClosureBreakpointHandler);
621 657
622 SetBreakpointAtEntry("", "callback"); 658 SetBreakpointAtEntry("", "callback");
623 659
624 breakpoint_hit_counter = 0; 660 breakpoint_hit_counter = 0;
625 Dart_Handle retval = Invoke("main"); 661 Dart_Handle retval = Invoke("main");
626 EXPECT_VALID(retval); 662 EXPECT_VALID(retval);
627 int64_t int_value = 0; 663 int64_t int_value = ToInt64(retval);
628 Dart_IntegerToInt64(retval, &int_value);
629 EXPECT_EQ(442, int_value); 664 EXPECT_EQ(442, int_value);
630 EXPECT_EQ(2, breakpoint_hit_counter); 665 EXPECT_EQ(2, breakpoint_hit_counter);
631 } 666 }
632 667
633 668
634 static void ExprClosureBreakpointHandler(Dart_IsolateId isolate_id, 669 static void ExprClosureBreakpointHandler(Dart_IsolateId isolate_id,
635 const Dart_CodeLocation& location) { 670 const Dart_CodeLocation& location) {
636 Dart_StackTrace trace; 671 Dart_StackTrace trace;
637 Dart_GetStackTrace(&trace); 672 Dart_GetStackTrace(&trace);
638 static const char* expected_trace[] = {"<anonymous closure>", "main"}; 673 static const char* expected_trace[] = {"<anonymous closure>", "main"};
(...skipping 25 matching lines...) Expand all
664 699
665 Dart_Handle script_url = NewString(TestCase::url()); 700 Dart_Handle script_url = NewString(TestCase::url());
666 intptr_t line_no = 5; // In closure 'add'. 701 intptr_t line_no = 5; // In closure 'add'.
667 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); 702 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
668 EXPECT_VALID(res); 703 EXPECT_VALID(res);
669 EXPECT(Dart_IsInteger(res)); 704 EXPECT(Dart_IsInteger(res));
670 705
671 breakpoint_hit_counter = 0; 706 breakpoint_hit_counter = 0;
672 Dart_Handle retval = Invoke("main"); 707 Dart_Handle retval = Invoke("main");
673 EXPECT_VALID(retval); 708 EXPECT_VALID(retval);
674 int64_t int_value = 0; 709 int64_t int_value = ToInt64(retval);
675 Dart_IntegerToInt64(retval, &int_value);
676 EXPECT_EQ(30, int_value); 710 EXPECT_EQ(30, int_value);
677 EXPECT_EQ(1, breakpoint_hit_counter); 711 EXPECT_EQ(1, breakpoint_hit_counter);
678 } 712 }
679 713
680 714
681 static intptr_t bp_id_to_be_deleted; 715 static intptr_t bp_id_to_be_deleted;
682 716
683 static void DeleteBreakpointHandler(Dart_IsolateId isolate_id, 717 static void DeleteBreakpointHandler(Dart_IsolateId isolate_id,
684 const Dart_CodeLocation& location) { 718 const Dart_CodeLocation& location) {
685 Dart_StackTrace trace; 719 Dart_StackTrace trace;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 LoadScript(kScriptChars); 764 LoadScript(kScriptChars);
731 765
732 Dart_Handle script_url = NewString(TestCase::url()); 766 Dart_Handle script_url = NewString(TestCase::url());
733 intptr_t line_no = 4; // In function 'foo'. 767 intptr_t line_no = 4; // In function 'foo'.
734 768
735 Dart_SetPausedEventHandler(&DeleteBreakpointHandler); 769 Dart_SetPausedEventHandler(&DeleteBreakpointHandler);
736 770
737 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); 771 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
738 EXPECT_VALID(res); 772 EXPECT_VALID(res);
739 EXPECT(Dart_IsInteger(res)); 773 EXPECT(Dart_IsInteger(res));
740 int64_t bp_id = 0; 774 int64_t bp_id = ToInt64(res);
741 Dart_IntegerToInt64(res, &bp_id);
742 775
743 // Function main() calls foo() 3 times. On the second iteration, the 776 // Function main() calls foo() 3 times. On the second iteration, the
744 // breakpoint is removed by the handler, so we expect the breakpoint 777 // breakpoint is removed by the handler, so we expect the breakpoint
745 // to fire twice only. 778 // to fire twice only.
746 bp_id_to_be_deleted = bp_id; 779 bp_id_to_be_deleted = bp_id;
747 breakpoint_hit_counter = 0; 780 breakpoint_hit_counter = 0;
748 Dart_Handle retval = Invoke("main"); 781 Dart_Handle retval = Invoke("main");
749 EXPECT_VALID(retval); 782 EXPECT_VALID(retval);
750 EXPECT_EQ(2, breakpoint_hit_counter); 783 EXPECT_EQ(2, breakpoint_hit_counter);
751 } 784 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 EXPECT(Dart_IsString(value_handle)); 914 EXPECT(Dart_IsString(value_handle));
882 char const* value; 915 char const* value;
883 Dart_StringToCString(value_handle, &value); 916 Dart_StringToCString(value_handle, &value);
884 OS::Print(" %s: %s\n", name, value); 917 OS::Print(" %s: %s\n", name, value);
885 } 918 }
886 919
887 // Check that an integer value returns an empty list of fields. 920 // Check that an integer value returns an empty list of fields.
888 Dart_Handle triple_six = Invoke("get_int"); 921 Dart_Handle triple_six = Invoke("get_int");
889 EXPECT_VALID(triple_six); 922 EXPECT_VALID(triple_six);
890 EXPECT(Dart_IsInteger(triple_six)); 923 EXPECT(Dart_IsInteger(triple_six));
891 int64_t int_value = 0; 924 int64_t int_value = ToInt64(triple_six);
892 Dart_IntegerToInt64(triple_six, &int_value);
893 EXPECT_EQ(666, int_value); 925 EXPECT_EQ(666, int_value);
894 fields = Dart_GetInstanceFields(triple_six); 926 fields = Dart_GetInstanceFields(triple_six);
895 EXPECT_VALID(fields); 927 EXPECT_VALID(fields);
896 EXPECT(Dart_IsList(fields)); 928 EXPECT(Dart_IsList(fields));
897 retval = Dart_ListLength(fields, &list_length); 929 retval = Dart_ListLength(fields, &list_length);
898 EXPECT_EQ(0, list_length); 930 EXPECT_EQ(0, list_length);
899 931
900 // Check static field of class B (one field named 'bla') 932 // Check static field of class B (one field named 'bla')
901 Dart_Handle class_B = Dart_GetObjClass(object_b); 933 Dart_Handle class_B = Dart_GetObjClass(object_b);
902 EXPECT_VALID(class_B); 934 EXPECT_VALID(class_B);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 1306
1275 Dart_Handle script_url = NewString(TestCase::url()); 1307 Dart_Handle script_url = NewString(TestCase::url());
1276 intptr_t line_no = 34; // In closure 'local_to_main'. 1308 intptr_t line_no = 34; // In closure 'local_to_main'.
1277 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); 1309 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
1278 EXPECT_VALID(res); 1310 EXPECT_VALID(res);
1279 EXPECT(Dart_IsInteger(res)); 1311 EXPECT(Dart_IsInteger(res));
1280 1312
1281 breakpoint_hit_counter = 0; 1313 breakpoint_hit_counter = 0;
1282 Dart_Handle retval = Invoke("main"); 1314 Dart_Handle retval = Invoke("main");
1283 EXPECT_VALID(retval); 1315 EXPECT_VALID(retval);
1284 int64_t int_value = 0; 1316 int64_t int_value = ToInt64(retval);
1285 Dart_IntegerToInt64(retval, &int_value);
1286 EXPECT_EQ(195, int_value); 1317 EXPECT_EQ(195, int_value);
1287 EXPECT_EQ(1, breakpoint_hit_counter); 1318 EXPECT_EQ(1, breakpoint_hit_counter);
1288 } 1319 }
1289 1320
1290 1321
1291 static void StackTraceDump2ExceptionHandler(Dart_IsolateId isolate_id, 1322 static void StackTraceDump2ExceptionHandler(Dart_IsolateId isolate_id,
1292 Dart_Handle exception_object, 1323 Dart_Handle exception_object,
1293 Dart_StackTrace trace) { 1324 Dart_StackTrace trace) {
1294 const int kStackTraceLen = 5; 1325 const int kStackTraceLen = 5;
1295 static const char* expected_trace[kStackTraceLen] = { 1326 static const char* expected_trace[kStackTraceLen] = {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 breakpoint_hit_counter = 0; 1472 breakpoint_hit_counter = 0;
1442 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); 1473 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions);
1443 1474
1444 Dart_Handle retval = Invoke("main"); 1475 Dart_Handle retval = Invoke("main");
1445 EXPECT(Dart_IsError(retval)); 1476 EXPECT(Dart_IsError(retval));
1446 EXPECT(Dart_IsUnhandledExceptionError(retval)); 1477 EXPECT(Dart_IsUnhandledExceptionError(retval));
1447 EXPECT_EQ(1, breakpoint_hit_counter); 1478 EXPECT_EQ(1, breakpoint_hit_counter);
1448 } 1479 }
1449 1480
1450 1481
1482 void TestEvaluateHandler(Dart_IsolateId isolate_id,
1483 const Dart_CodeLocation& location) {
1484 Dart_StackTrace trace;
1485 Dart_GetStackTrace(&trace);
1486 intptr_t trace_len;
1487 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
1488 EXPECT_VALID(res);
1489 EXPECT_EQ(1, trace_len);
1490 Dart_ActivationFrame frame;
1491 res = Dart_GetActivationFrame(trace, 0, &frame);
1492 EXPECT_VALID(res);
1493
1494 // Get the local variable p and evaluate an expression in the
1495 // context of p.
1496 Dart_Handle p = GetLocalVariable(frame, "p");
1497 EXPECT_VALID(p);
1498 EXPECT(!Dart_IsNull(p));
1499
1500 Dart_Handle r = Dart_EvaluateExpr(p, NewString("sqrt(x*x + y*this.y)"));
1501 EXPECT_VALID(r);
1502 EXPECT(Dart_IsNumber(r));
1503 EXPECT_EQ(5.0, ToDouble(r));
1504
1505 // Set top-level variable to a new value.
1506 Dart_Handle h = Dart_EvaluateExpr(p, NewString("_factor = 10"));
1507 EXPECT_VALID(h);
1508 EXPECT(Dart_IsInteger(h));
1509 EXPECT_EQ(10, ToInt64(h));
1510
1511 // Check that the side effect of the previous expression is
1512 // persistent.
1513 h = Dart_EvaluateExpr(p, NewString("_factor"));
1514 EXPECT_VALID(h);
1515 EXPECT(Dart_IsInteger(h));
1516 EXPECT_EQ(10, ToInt64(h));
1517
1518 breakpoint_hit = true;
1519 breakpoint_hit_counter++;
1520 }
1521
1522
1523 TEST_CASE(Debug_EvaluateExpr) {
1524 const char* kScriptChars =
1525 "import 'dart:math'; \n"
1526 "main() { \n"
1527 " var p = new Point(3, 4); \n"
1528 " l = [1, 2, 3]; /*BP*/ \n"
1529 " return p; \n"
1530 "} \n"
1531 "var _factor = 2; \n"
1532 "var l; \n"
1533 "class Point { \n"
1534 " var x, y; \n"
1535 " Point(this.x, this.y); \n"
1536 "} \n";
1537
1538 LoadScript(kScriptChars);
1539 Dart_SetPausedEventHandler(&TestEvaluateHandler);
1540
1541
1542 Dart_Handle script_url = NewString(TestCase::url());
1543 intptr_t line_no = 4;
1544 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
1545 EXPECT_VALID(res);
1546
1547 breakpoint_hit = false;
1548 Dart_Handle point = Invoke("main");
1549 EXPECT_VALID(point);
1550 EXPECT(breakpoint_hit == true);
1551
1552 Dart_Handle r =
1553 Dart_EvaluateExpr(point, NewString("_factor * sqrt(x*x + y*y)"));
1554 EXPECT_VALID(r);
1555 EXPECT(Dart_IsDouble(r));
1556 EXPECT_EQ(50.0, ToDouble(r));
1557
1558 Dart_Handle len = Dart_EvaluateExpr(point, NewString("l.length"));
1559 EXPECT_VALID(len);
1560 EXPECT(Dart_IsNumber(len));
1561 EXPECT_EQ(3, ToInt64(len));
1562 }
1563
1564
1451 TEST_CASE(Debug_GetSupertype) { 1565 TEST_CASE(Debug_GetSupertype) {
1452 const char* kScriptChars = 1566 const char* kScriptChars =
1453 "class Test {\n" 1567 "class Test {\n"
1454 "}\n" 1568 "}\n"
1455 "class Test1 extends Test {\n" 1569 "class Test1 extends Test {\n"
1456 "}\n" 1570 "}\n"
1457 "class Test2<T> {\n" 1571 "class Test2<T> {\n"
1458 "}\n" 1572 "}\n"
1459 "class Test3 extends Test2<int> {\n" 1573 "class Test3 extends Test2<int> {\n"
1460 "}\n" 1574 "}\n"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 1701
1588 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj); 1702 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj);
1589 Dart_Handle super_type = Dart_GetSupertype(list_type); 1703 Dart_Handle super_type = Dart_GetSupertype(list_type);
1590 EXPECT(!Dart_IsError(super_type)); 1704 EXPECT(!Dart_IsError(super_type));
1591 super_type = Dart_GetSupertype(super_type); 1705 super_type = Dart_GetSupertype(super_type);
1592 EXPECT(!Dart_IsError(super_type)); 1706 EXPECT(!Dart_IsError(super_type));
1593 EXPECT(super_type == Dart_Null()); 1707 EXPECT(super_type == Dart_Null());
1594 } 1708 }
1595 1709
1596 } // namespace dart 1710 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698