Chromium Code Reviews| 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
| 8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); | 55 EXPECT(Dart_IsError(Dart_ErrorGetException(instance))); |
| 56 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); | 56 EXPECT(Dart_IsError(Dart_ErrorGetException(error))); |
| 57 EXPECT_VALID(Dart_ErrorGetException(exception)); | 57 EXPECT_VALID(Dart_ErrorGetException(exception)); |
| 58 | 58 |
| 59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); | 59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); |
| 60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); | 60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); |
| 61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); | 61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 TEST_CASE(StacktraceInfo) { | |
| 66 const char* kScriptChars = | |
| 67 "bar() => throw new Error();\n" | |
| 68 "foo() => bar();\n" | |
| 69 "testMain() => foo();\n"; | |
| 70 | |
| 71 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 72 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | |
| 73 | |
| 74 EXPECT(Dart_IsError(error)); | |
| 75 | |
| 76 Dart_StackTrace stacktrace; | |
| 77 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); | |
| 78 EXPECT_VALID(result); | |
| 79 | |
| 80 intptr_t frame_count = 0; | |
| 81 result = Dart_StackTraceLength(stacktrace, &frame_count); | |
| 82 EXPECT_VALID(result); | |
| 83 EXPECT_EQ(3, frame_count); | |
| 84 | |
| 85 Dart_Handle function_name; | |
| 86 Dart_Handle script_url; | |
| 87 intptr_t line_number = 0; | |
| 88 intptr_t column_number = 0; | |
| 89 const char* cstr = ""; | |
| 90 | |
| 91 Dart_ActivationFrame frame; | |
| 92 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | |
| 93 EXPECT_VALID(result); | |
| 94 result = Dart_ActivationFrameInfoWithColumn( | |
| 95 frame, &function_name, &script_url, &line_number, &column_number); | |
| 96 EXPECT_VALID(result); | |
| 97 Dart_StringToCString(function_name, &cstr); | |
| 98 EXPECT_STREQ("bar", cstr); | |
| 99 Dart_StringToCString(script_url, &cstr); | |
| 100 EXPECT_STREQ("dart:test-lib", cstr); | |
| 101 EXPECT_EQ(1, line_number); | |
| 102 EXPECT_EQ(10, column_number); | |
| 103 | |
| 104 result = Dart_GetActivationFrame(stacktrace, 1, &frame); | |
| 105 EXPECT_VALID(result); | |
| 106 result = Dart_ActivationFrameInfoWithColumn( | |
| 107 frame, &function_name, &script_url, &line_number, &column_number); | |
| 108 EXPECT_VALID(result); | |
| 109 Dart_StringToCString(function_name, &cstr); | |
| 110 EXPECT_STREQ("foo", cstr); | |
| 111 Dart_StringToCString(script_url, &cstr); | |
| 112 EXPECT_STREQ("dart:test-lib", cstr); | |
| 113 EXPECT_EQ(2, line_number); | |
| 114 EXPECT_EQ(13, column_number); | |
| 115 | |
| 116 result = Dart_GetActivationFrame(stacktrace, 2, &frame); | |
| 117 EXPECT_VALID(result); | |
| 118 result = Dart_ActivationFrameInfoWithColumn( | |
| 119 frame, &function_name, &script_url, &line_number, &column_number); | |
| 120 EXPECT_VALID(result); | |
| 121 Dart_StringToCString(function_name, &cstr); | |
| 122 EXPECT_STREQ("testMain", cstr); | |
| 123 Dart_StringToCString(script_url, &cstr); | |
| 124 EXPECT_STREQ("dart:test-lib", cstr); | |
| 125 EXPECT_EQ(3, line_number); | |
| 126 EXPECT_EQ(18, column_number); | |
| 127 | |
| 128 // Out-of-bounds frames. | |
| 129 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | |
| 130 EXPECT(Dart_IsError(result)); | |
| 131 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | |
| 132 EXPECT(Dart_IsError(result)); | |
| 133 } | |
| 134 | |
| 135 | |
| 136 TEST_CASE(DeepStacktraceInfo) { | |
| 137 const char* kScriptChars = | |
| 138 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n" | |
| 139 "testMain() => foo(50);\n"; | |
| 140 | |
| 141 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 142 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | |
| 143 | |
| 144 EXPECT(Dart_IsError(error)); | |
| 145 | |
| 146 Dart_StackTrace stacktrace; | |
| 147 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); | |
| 148 EXPECT_VALID(result); | |
| 149 | |
| 150 intptr_t frame_count = 0; | |
| 151 result = Dart_StackTraceLength(stacktrace, &frame_count); | |
| 152 EXPECT_VALID(result); | |
| 153 EXPECT_EQ(51, frame_count); | |
|
rmacnak
2013/11/12 00:05:16
Broken after refactoring to share with the debugge
siva
2013/11/12 16:00:43
If you print the stacktrace object returned what d
rmacnak
2013/11/12 22:32:40
Woops, this comment was supposed to be attached to
| |
| 154 // Test something bigger than the preallocated size to verify nothing was | |
| 155 // truncated. | |
| 156 EXPECT(51 > Stacktrace::kPreallocatedStackdepth); | |
| 157 | |
| 158 Dart_Handle function_name; | |
| 159 Dart_Handle script_url; | |
| 160 intptr_t line_number = 0; | |
| 161 intptr_t column_number = 0; | |
| 162 const char* cstr = ""; | |
| 163 | |
| 164 // Top frame at positioned at throw. | |
| 165 Dart_ActivationFrame frame; | |
| 166 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | |
| 167 EXPECT_VALID(result); | |
| 168 result = Dart_ActivationFrameInfoWithColumn( | |
| 169 frame, &function_name, &script_url, &line_number, &column_number); | |
| 170 EXPECT_VALID(result); | |
| 171 Dart_StringToCString(function_name, &cstr); | |
| 172 EXPECT_STREQ("foo", cstr); | |
| 173 Dart_StringToCString(script_url, &cstr); | |
| 174 EXPECT_STREQ("dart:test-lib", cstr); | |
| 175 EXPECT_EQ(1, line_number); | |
| 176 EXPECT_EQ(20, column_number); | |
| 177 | |
| 178 // Middle frames positioned at the recursive call. | |
| 179 for (intptr_t frame_index = 1; | |
| 180 frame_index < (frame_count - 1); | |
| 181 frame_index++) { | |
| 182 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); | |
| 183 EXPECT_VALID(result); | |
| 184 result = Dart_ActivationFrameInfoWithColumn( | |
| 185 frame, &function_name, &script_url, &line_number, &column_number); | |
| 186 EXPECT_VALID(result); | |
| 187 Dart_StringToCString(function_name, &cstr); | |
| 188 EXPECT_STREQ("foo", cstr); | |
| 189 Dart_StringToCString(script_url, &cstr); | |
| 190 EXPECT_STREQ("dart:test-lib", cstr); | |
| 191 EXPECT_EQ(1, line_number); | |
| 192 EXPECT_EQ(43, column_number); | |
| 193 } | |
| 194 | |
| 195 // Bottom frame positioned at testMain(). | |
| 196 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); | |
| 197 EXPECT_VALID(result); | |
| 198 result = Dart_ActivationFrameInfoWithColumn( | |
| 199 frame, &function_name, &script_url, &line_number, &column_number); | |
| 200 EXPECT_VALID(result); | |
| 201 Dart_StringToCString(function_name, &cstr); | |
| 202 EXPECT_STREQ("testMain", cstr); | |
| 203 Dart_StringToCString(script_url, &cstr); | |
| 204 EXPECT_STREQ("dart:test-lib", cstr); | |
| 205 EXPECT_EQ(2, line_number); | |
| 206 EXPECT_EQ(18, column_number); | |
| 207 | |
| 208 // Out-of-bounds frames. | |
| 209 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | |
| 210 EXPECT(Dart_IsError(result)); | |
| 211 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | |
| 212 EXPECT(Dart_IsError(result)); | |
| 213 } | |
| 214 | |
| 215 | |
| 216 TEST_CASE(StackOverflowStacktraceInfo) { | |
| 217 const char* kScriptChars = | |
| 218 "class C {\n" | |
| 219 " static foo() => foo();\n" | |
| 220 "}\n" | |
| 221 "testMain() => C.foo();\n"; | |
| 222 | |
| 223 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 224 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | |
| 225 | |
| 226 EXPECT(Dart_IsError(error)); | |
| 227 | |
| 228 Dart_StackTrace stacktrace; | |
| 229 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); | |
| 230 EXPECT_VALID(result); | |
| 231 | |
| 232 intptr_t frame_count = 0; | |
| 233 result = Dart_StackTraceLength(stacktrace, &frame_count); | |
| 234 EXPECT_VALID(result); | |
| 235 EXPECT_EQ(Stacktrace::kPreallocatedStackdepth - 1, frame_count); | |
| 236 | |
| 237 Dart_Handle function_name; | |
| 238 Dart_Handle script_url; | |
| 239 intptr_t line_number = 0; | |
| 240 intptr_t column_number = 0; | |
| 241 const char* cstr = ""; | |
| 242 | |
| 243 // Top frame at recursive call. | |
| 244 Dart_ActivationFrame frame; | |
| 245 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | |
| 246 EXPECT_VALID(result); | |
| 247 result = Dart_ActivationFrameInfoWithColumn( | |
| 248 frame, &function_name, &script_url, &line_number, &column_number); | |
| 249 EXPECT_VALID(result); | |
| 250 Dart_StringToCString(function_name, &cstr); | |
| 251 EXPECT_STREQ("C.foo", cstr); | |
| 252 Dart_StringToCString(script_url, &cstr); | |
| 253 EXPECT_STREQ("dart:test-lib", cstr); | |
| 254 EXPECT_EQ(2, line_number); | |
| 255 EXPECT_EQ(3, column_number); | |
| 256 | |
| 257 // Out-of-bounds frames. | |
| 258 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | |
| 259 EXPECT(Dart_IsError(result)); | |
| 260 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | |
| 261 EXPECT(Dart_IsError(result)); | |
| 262 } | |
| 263 | |
| 264 | |
| 265 TEST_CASE(OutOfMemoryStacktraceInfo) { | |
| 266 const char* kScriptChars = | |
| 267 "var number_of_ints = 134000000;\n" | |
| 268 "testMain() {\n" | |
| 269 " new List<int>(number_of_ints)\n" | |
| 270 "}\n"; | |
| 271 | |
| 272 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 273 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | |
| 274 | |
| 275 EXPECT(Dart_IsError(error)); | |
| 276 | |
| 277 Dart_StackTrace stacktrace; | |
| 278 Dart_Handle result = Dart_GetStackTraceFromError(error, &stacktrace); | |
| 279 EXPECT(Dart_IsError(result)); // No Stacktrace for OutOfMemory. | |
| 280 } | |
| 281 | |
| 282 | |
| 283 TEST_CASE(CurrentStacktraceInfo) { | |
| 284 const char* kScriptChars = | |
| 285 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n" | |
| 286 "testMain() => foo(50);\n"; | |
| 287 | |
| 288 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 289 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | |
| 290 | |
| 291 EXPECT(Dart_IsError(error)); | |
| 292 | |
| 293 Dart_StackTrace stacktrace; | |
| 294 Dart_Handle result = Dart_GetStackTrace(&stacktrace); | |
| 295 EXPECT_VALID(result); | |
| 296 | |
| 297 intptr_t frame_count = 0; | |
| 298 result = Dart_StackTraceLength(stacktrace, &frame_count); | |
| 299 EXPECT_VALID(result); | |
| 300 EXPECT_EQ(51, frame_count); | |
| 301 // Test something bigger than the preallocated size to verify nothing was | |
| 302 // truncated. | |
| 303 EXPECT(51 > Stacktrace::kPreallocatedStackdepth); | |
| 304 | |
| 305 Dart_Handle function_name; | |
| 306 Dart_Handle script_url; | |
| 307 intptr_t line_number = 0; | |
| 308 intptr_t column_number = 0; | |
| 309 const char* cstr = ""; | |
| 310 | |
| 311 // Top frame at positioned at throw. | |
| 312 Dart_ActivationFrame frame; | |
| 313 result = Dart_GetActivationFrame(stacktrace, 0, &frame); | |
| 314 EXPECT_VALID(result); | |
| 315 result = Dart_ActivationFrameInfoWithColumn( | |
| 316 frame, &function_name, &script_url, &line_number, &column_number); | |
| 317 EXPECT_VALID(result); | |
| 318 Dart_StringToCString(function_name, &cstr); | |
| 319 EXPECT_STREQ("foo", cstr); | |
| 320 Dart_StringToCString(script_url, &cstr); | |
| 321 EXPECT_STREQ("dart:test-lib", cstr); | |
| 322 EXPECT_EQ(1, line_number); | |
| 323 EXPECT_EQ(20, column_number); | |
| 324 | |
| 325 // Middle frames positioned at the recursive call. | |
| 326 for (intptr_t frame_index = 1; | |
| 327 frame_index < (frame_count - 1); | |
| 328 frame_index++) { | |
| 329 result = Dart_GetActivationFrame(stacktrace, frame_index, &frame); | |
| 330 EXPECT_VALID(result); | |
| 331 result = Dart_ActivationFrameInfoWithColumn( | |
| 332 frame, &function_name, &script_url, &line_number, &column_number); | |
| 333 EXPECT_VALID(result); | |
| 334 Dart_StringToCString(function_name, &cstr); | |
| 335 EXPECT_STREQ("foo", cstr); | |
| 336 Dart_StringToCString(script_url, &cstr); | |
| 337 EXPECT_STREQ("dart:test-lib", cstr); | |
| 338 EXPECT_EQ(1, line_number); | |
| 339 EXPECT_EQ(43, column_number); | |
| 340 } | |
| 341 | |
| 342 // Bottom frame positioned at testMain(). | |
| 343 result = Dart_GetActivationFrame(stacktrace, frame_count - 1, &frame); | |
| 344 EXPECT_VALID(result); | |
| 345 result = Dart_ActivationFrameInfoWithColumn( | |
| 346 frame, &function_name, &script_url, &line_number, &column_number); | |
| 347 EXPECT_VALID(result); | |
| 348 Dart_StringToCString(function_name, &cstr); | |
| 349 EXPECT_STREQ("testMain", cstr); | |
| 350 Dart_StringToCString(script_url, &cstr); | |
| 351 EXPECT_STREQ("dart:test-lib", cstr); | |
| 352 EXPECT_EQ(2, line_number); | |
| 353 EXPECT_EQ(18, column_number); | |
| 354 | |
| 355 // Out-of-bounds frames. | |
| 356 result = Dart_GetActivationFrame(stacktrace, frame_count, &frame); | |
| 357 EXPECT(Dart_IsError(result)); | |
| 358 result = Dart_GetActivationFrame(stacktrace, -1, &frame); | |
| 359 EXPECT(Dart_IsError(result)); | |
| 360 } | |
| 361 | |
| 362 | |
| 65 TEST_CASE(ErrorHandleTypes) { | 363 TEST_CASE(ErrorHandleTypes) { |
| 66 Isolate* isolate = Isolate::Current(); | 364 Isolate* isolate = Isolate::Current(); |
| 67 const String& compile_message = String::Handle(String::New("CompileError")); | 365 const String& compile_message = String::Handle(String::New("CompileError")); |
| 68 const String& fatal_message = String::Handle(String::New("FatalError")); | 366 const String& fatal_message = String::Handle(String::New("FatalError")); |
| 69 | 367 |
| 70 Dart_Handle not_error = NewString("NotError"); | 368 Dart_Handle not_error = NewString("NotError"); |
| 71 Dart_Handle api_error = Api::NewError("Api%s", "Error"); | 369 Dart_Handle api_error = Api::NewError("Api%s", "Error"); |
| 72 Dart_Handle exception_error = | 370 Dart_Handle exception_error = |
| 73 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); | 371 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); |
| 74 Dart_Handle compile_error = | 372 Dart_Handle compile_error = |
| (...skipping 7354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7429 NewString("main"), | 7727 NewString("main"), |
| 7430 1, | 7728 1, |
| 7431 dart_args); | 7729 dart_args); |
| 7432 int64_t value = 0; | 7730 int64_t value = 0; |
| 7433 result = Dart_IntegerToInt64(result, &value); | 7731 result = Dart_IntegerToInt64(result, &value); |
| 7434 EXPECT_VALID(result); | 7732 EXPECT_VALID(result); |
| 7435 EXPECT_EQ(6, value); | 7733 EXPECT_EQ(6, value); |
| 7436 } | 7734 } |
| 7437 | 7735 |
| 7438 } // namespace dart | 7736 } // namespace dart |
| OLD | NEW |