| OLD | NEW | 
|---|
| 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 940 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 951   name_handle = Dart_ListGetAt(fields, 2); | 951   name_handle = Dart_ListGetAt(fields, 2); | 
| 952   EXPECT_VALID(name_handle); | 952   EXPECT_VALID(name_handle); | 
| 953   EXPECT(Dart_IsString(name_handle)); | 953   EXPECT(Dart_IsString(name_handle)); | 
| 954   Dart_StringToCString(name_handle, &name); | 954   Dart_StringToCString(name_handle, &name); | 
| 955   EXPECT_STREQ("error", name); | 955   EXPECT_STREQ("error", name); | 
| 956   value_handle = Dart_ListGetAt(fields, 3); | 956   value_handle = Dart_ListGetAt(fields, 3); | 
| 957   EXPECT(Dart_IsError(value_handle)); | 957   EXPECT(Dart_IsError(value_handle)); | 
| 958 } | 958 } | 
| 959 | 959 | 
| 960 | 960 | 
| 961 TEST_CASE(Debug_LookupSourceLine) { |  | 
| 962   const char* kScriptChars = |  | 
| 963   /*1*/  "class A {                 \n" |  | 
| 964   /*2*/  "  static void foo() {     \n" |  | 
| 965   /*3*/  "    moo('good news');     \n" |  | 
| 966   /*4*/  "  }                       \n" |  | 
| 967   /*5*/  "}                         \n" |  | 
| 968   /*6*/  "                          \n" |  | 
| 969   /*7*/  "void main() {             \n" |  | 
| 970   /*8*/  "  A.foo();                \n" |  | 
| 971   /*9*/  "}                         \n" |  | 
| 972   /*10*/ "                          \n"; |  | 
| 973 |  | 
| 974   LoadScript(kScriptChars); |  | 
| 975 |  | 
| 976   const Library& test_lib = |  | 
| 977       Library::CheckedHandle(Api::UnwrapHandle(script_lib)); |  | 
| 978   const String& script_url = String::Handle(String::New(TestCase::url())); |  | 
| 979   Function& func = Function::Handle(); |  | 
| 980 |  | 
| 981   for (int line = 7; line <= 9; line++) { |  | 
| 982     func = test_lib.LookupFunctionInSource(script_url, line); |  | 
| 983     EXPECT(!func.IsNull()); |  | 
| 984     EXPECT_STREQ("main", String::Handle(func.name()).ToCString()); |  | 
| 985   } |  | 
| 986 |  | 
| 987   for (int line = 2; line <= 4; line++) { |  | 
| 988     func = test_lib.LookupFunctionInSource(script_url, 3); |  | 
| 989     EXPECT(!func.IsNull()); |  | 
| 990     EXPECT_STREQ("foo", String::Handle(func.name()).ToCString()); |  | 
| 991   } |  | 
| 992 |  | 
| 993   // The VM generates an implicit constructor for class A and |  | 
| 994   // locates it at the token position of the keyword 'class'. |  | 
| 995   func = test_lib.LookupFunctionInSource(script_url, 1); |  | 
| 996   EXPECT(!func.IsNull()); |  | 
| 997   EXPECT_STREQ("A.", String::Handle(func.name()).ToCString()); |  | 
| 998 |  | 
| 999   func = test_lib.LookupFunctionInSource(script_url, 6); |  | 
| 1000   EXPECT(func.IsNull()); |  | 
| 1001   func = test_lib.LookupFunctionInSource(script_url, 10); |  | 
| 1002   EXPECT(func.IsNull()); |  | 
| 1003 |  | 
| 1004   Dart_Handle libs = Dart_GetLibraryIds(); |  | 
| 1005   EXPECT(Dart_IsList(libs)); |  | 
| 1006   intptr_t num_libs; |  | 
| 1007   Dart_ListLength(libs, &num_libs); |  | 
| 1008   EXPECT(num_libs > 0); |  | 
| 1009   for (int i = 0; i < num_libs; i++) { |  | 
| 1010     Dart_Handle lib_id = Dart_ListGetAt(libs, i); |  | 
| 1011     EXPECT(Dart_IsInteger(lib_id)); |  | 
| 1012     int64_t id = 0; |  | 
| 1013     Dart_IntegerToInt64(lib_id, &id); |  | 
| 1014     Dart_Handle lib_url = Dart_GetLibraryURL(id); |  | 
| 1015     char const* chars; |  | 
| 1016     Dart_StringToCString(lib_url, &chars); |  | 
| 1017     OS::Print("Lib %d: %s\n", i, chars); |  | 
| 1018 |  | 
| 1019     Dart_Handle scripts = Dart_GetScriptURLs(lib_url); |  | 
| 1020     EXPECT(Dart_IsList(scripts)); |  | 
| 1021     intptr_t num_scripts; |  | 
| 1022     Dart_ListLength(scripts, &num_scripts); |  | 
| 1023     EXPECT(num_scripts >= 0); |  | 
| 1024     for (int i = 0; i < num_scripts; i++) { |  | 
| 1025       Dart_Handle script_url = Dart_ListGetAt(scripts, i); |  | 
| 1026       char const* chars; |  | 
| 1027       Dart_StringToCString(script_url, &chars); |  | 
| 1028       OS::Print("  script %d: '%s'\n", i + 1, chars); |  | 
| 1029     } |  | 
| 1030   } |  | 
| 1031 |  | 
| 1032   Dart_Handle lib_url = NewString(TestCase::url()); |  | 
| 1033   Dart_Handle source = Dart_ScriptGetSource((num_libs - 1), lib_url); |  | 
| 1034   EXPECT(Dart_IsString(source)); |  | 
| 1035   char const* source_chars; |  | 
| 1036   Dart_StringToCString(source, &source_chars); |  | 
| 1037   OS::Print("\n=== source: ===\n%s", source_chars); |  | 
| 1038   EXPECT_STREQ(kScriptChars, source_chars); |  | 
| 1039 } |  | 
| 1040 |  | 
| 1041 |  | 
| 1042 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID; | 961 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID; | 
| 1043 static int verify_callback = 0; | 962 static int verify_callback = 0; | 
| 1044 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) { | 963 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) { | 
| 1045   if (kind == kCreated) { | 964   if (kind == kCreated) { | 
| 1046     EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID); | 965     EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID); | 
| 1047     test_isolate_id = isolate_id; | 966     test_isolate_id = isolate_id; | 
| 1048     Dart_Isolate isolate = Dart_GetIsolate(isolate_id); | 967     Dart_Isolate isolate = Dart_GetIsolate(isolate_id); | 
| 1049     EXPECT(isolate == Dart_CurrentIsolate()); | 968     EXPECT(isolate == Dart_CurrentIsolate()); | 
| 1050     verify_callback |= 0x1;  // Register create callback. | 969     verify_callback |= 0x1;  // Register create callback. | 
| 1051   } else if (kind == kInterrupted) { | 970   } else if (kind == kInterrupted) { | 
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1522   breakpoint_hit_counter = 0; | 1441   breakpoint_hit_counter = 0; | 
| 1523   Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); | 1442   Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); | 
| 1524 | 1443 | 
| 1525   Dart_Handle retval = Invoke("main"); | 1444   Dart_Handle retval = Invoke("main"); | 
| 1526   EXPECT(Dart_IsError(retval)); | 1445   EXPECT(Dart_IsError(retval)); | 
| 1527   EXPECT(Dart_IsUnhandledExceptionError(retval)); | 1446   EXPECT(Dart_IsUnhandledExceptionError(retval)); | 
| 1528   EXPECT_EQ(1, breakpoint_hit_counter); | 1447   EXPECT_EQ(1, breakpoint_hit_counter); | 
| 1529 } | 1448 } | 
| 1530 | 1449 | 
| 1531 }  // namespace dart | 1450 }  // namespace dart | 
| OLD | NEW | 
|---|