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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 EXPECT_STREQ( | 49 EXPECT_STREQ( |
50 "Unhandled exception:\n" | 50 "Unhandled exception:\n" |
51 "Exception: bad news\n" | 51 "Exception: bad news\n" |
52 "#0 testMain (dart:test-lib:2:3)", | 52 "#0 testMain (dart:test-lib:2:3)", |
53 Dart_GetError(exception)); | 53 Dart_GetError(exception)); |
54 | 54 |
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 Dart_ExceptionStackTrace trace; |
60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); | 60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance, &trace))); |
61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); | 61 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error, &trace))); |
62 } | 62 EXPECT_VALID(Dart_ErrorGetStacktrace(exception, &trace)); |
63 | 63 } |
64 | 64 |
| 65 |
| 66 TEST_CASE(StacktraceInfo) { |
| 67 const char* kScriptChars = |
| 68 "bar() => throw new Error();\n" |
| 69 "foo() => bar();\n" |
| 70 "testMain() => foo();\n"; |
| 71 |
| 72 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 73 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 74 |
| 75 EXPECT(Dart_IsError(error)); |
| 76 |
| 77 Dart_ExceptionStackTrace stacktrace; |
| 78 Dart_Handle result = Dart_ErrorGetStacktrace(error, &stacktrace); |
| 79 EXPECT_VALID(result); |
| 80 |
| 81 intptr_t frame_count = 0; |
| 82 result = Dart_StacktraceLength(stacktrace, &frame_count); |
| 83 EXPECT_VALID(result); |
| 84 EXPECT_EQ(3, frame_count); |
| 85 |
| 86 Dart_Handle function_name; |
| 87 Dart_Handle script_url; |
| 88 intptr_t line_number = 0; |
| 89 intptr_t column_number = 0; |
| 90 const char* cstr = ""; |
| 91 |
| 92 result = Dart_StacktraceFrameInfo(stacktrace, |
| 93 0, |
| 94 &function_name, |
| 95 &script_url, |
| 96 &line_number, |
| 97 &column_number); |
| 98 EXPECT_VALID(result); |
| 99 Dart_StringToCString(function_name, &cstr); |
| 100 EXPECT_STREQ("bar", cstr); |
| 101 Dart_StringToCString(script_url, &cstr); |
| 102 EXPECT_STREQ("dart:test-lib", cstr); |
| 103 EXPECT_EQ(1, line_number); |
| 104 EXPECT_EQ(10, column_number); |
| 105 |
| 106 result = Dart_StacktraceFrameInfo(stacktrace, |
| 107 1, |
| 108 &function_name, |
| 109 &script_url, |
| 110 &line_number, |
| 111 &column_number); |
| 112 EXPECT_VALID(result); |
| 113 Dart_StringToCString(function_name, &cstr); |
| 114 EXPECT_STREQ("foo", cstr); |
| 115 Dart_StringToCString(script_url, &cstr); |
| 116 EXPECT_STREQ("dart:test-lib", cstr); |
| 117 EXPECT_EQ(2, line_number); |
| 118 EXPECT_EQ(13, column_number); |
| 119 |
| 120 result = Dart_StacktraceFrameInfo(stacktrace, |
| 121 2, |
| 122 &function_name, |
| 123 &script_url, |
| 124 &line_number, |
| 125 &column_number); |
| 126 EXPECT_VALID(result); |
| 127 Dart_StringToCString(function_name, &cstr); |
| 128 EXPECT_STREQ("testMain", cstr); |
| 129 Dart_StringToCString(script_url, &cstr); |
| 130 EXPECT_STREQ("dart:test-lib", cstr); |
| 131 EXPECT_EQ(3, line_number); |
| 132 EXPECT_EQ(18, column_number); |
| 133 |
| 134 result = Dart_StacktraceFrameInfo(stacktrace, |
| 135 frame_count + 1, |
| 136 &function_name, |
| 137 &script_url, |
| 138 &line_number, |
| 139 &column_number); |
| 140 EXPECT(Dart_IsError(result)); |
| 141 |
| 142 result = Dart_StacktraceFrameInfo(stacktrace, |
| 143 -1, |
| 144 &function_name, |
| 145 &script_url, |
| 146 &line_number, |
| 147 &column_number); |
| 148 EXPECT(Dart_IsError(result)); |
| 149 } |
| 150 |
| 151 |
| 152 TEST_CASE(DeepStacktraceInfo) { |
| 153 const char* kScriptChars = |
| 154 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n" |
| 155 "testMain() => foo(50);\n"; |
| 156 |
| 157 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 158 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 159 |
| 160 EXPECT(Dart_IsError(error)); |
| 161 |
| 162 Dart_ExceptionStackTrace stacktrace; |
| 163 Dart_Handle result = Dart_ErrorGetStacktrace(error, &stacktrace); |
| 164 EXPECT_VALID(result); |
| 165 |
| 166 intptr_t frame_count = 0; |
| 167 result = Dart_StacktraceLength(stacktrace, &frame_count); |
| 168 EXPECT_VALID(result); |
| 169 EXPECT_EQ(51, frame_count); |
| 170 // Test something bigger than the preallocated size to verify nothing was |
| 171 // truncated. |
| 172 EXPECT(51 > Stacktrace::kPreallocatedStackdepth); |
| 173 |
| 174 Dart_Handle function_name; |
| 175 Dart_Handle script_url; |
| 176 intptr_t line_number = 0; |
| 177 intptr_t column_number = 0; |
| 178 const char* cstr = ""; |
| 179 |
| 180 // Top frame at positioned at throw. |
| 181 result = Dart_StacktraceFrameInfo(stacktrace, |
| 182 0, |
| 183 &function_name, |
| 184 &script_url, |
| 185 &line_number, |
| 186 &column_number); |
| 187 EXPECT_VALID(result); |
| 188 Dart_StringToCString(function_name, &cstr); |
| 189 EXPECT_STREQ("foo", cstr); |
| 190 Dart_StringToCString(script_url, &cstr); |
| 191 EXPECT_STREQ("dart:test-lib", cstr); |
| 192 EXPECT_EQ(1, line_number); |
| 193 EXPECT_EQ(20, column_number); |
| 194 |
| 195 // Middle frames positioned at the recursive call. |
| 196 for (intptr_t frame_index = 1; |
| 197 frame_index < (frame_count - 1); |
| 198 frame_index++) { |
| 199 result = Dart_StacktraceFrameInfo(stacktrace, |
| 200 frame_index, |
| 201 &function_name, |
| 202 &script_url, |
| 203 &line_number, |
| 204 &column_number); |
| 205 EXPECT_VALID(result); |
| 206 Dart_StringToCString(function_name, &cstr); |
| 207 EXPECT_STREQ("foo", cstr); |
| 208 Dart_StringToCString(script_url, &cstr); |
| 209 EXPECT_STREQ("dart:test-lib", cstr); |
| 210 EXPECT_EQ(1, line_number); |
| 211 EXPECT_EQ(43, column_number); |
| 212 } |
| 213 |
| 214 // Bottom frame positioned at testMain(). |
| 215 result = Dart_StacktraceFrameInfo(stacktrace, |
| 216 frame_count - 1, |
| 217 &function_name, |
| 218 &script_url, |
| 219 &line_number, |
| 220 &column_number); |
| 221 EXPECT_VALID(result); |
| 222 Dart_StringToCString(function_name, &cstr); |
| 223 EXPECT_STREQ("testMain", cstr); |
| 224 Dart_StringToCString(script_url, &cstr); |
| 225 EXPECT_STREQ("dart:test-lib", cstr); |
| 226 EXPECT_EQ(2, line_number); |
| 227 EXPECT_EQ(18, column_number); |
| 228 |
| 229 // Out-of-bounds frames. |
| 230 result = Dart_StacktraceFrameInfo(stacktrace, |
| 231 frame_count, |
| 232 &function_name, |
| 233 &script_url, |
| 234 &line_number, |
| 235 &column_number); |
| 236 EXPECT(Dart_IsError(result)); |
| 237 result = Dart_StacktraceFrameInfo(stacktrace, |
| 238 -1, |
| 239 &function_name, |
| 240 &script_url, |
| 241 &line_number, |
| 242 &column_number); |
| 243 EXPECT(Dart_IsError(result)); |
| 244 } |
| 245 |
| 246 |
| 247 TEST_CASE(StackOverflowStacktraceInfo) { |
| 248 const char* kScriptChars = |
| 249 "class C {\n" |
| 250 " static foo() => foo();\n" |
| 251 "}\n" |
| 252 "testMain() => C.foo();\n"; |
| 253 |
| 254 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 255 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 256 |
| 257 EXPECT(Dart_IsError(error)); |
| 258 |
| 259 Dart_ExceptionStackTrace stacktrace; |
| 260 Dart_Handle result = Dart_ErrorGetStacktrace(error, &stacktrace); |
| 261 EXPECT_VALID(result); |
| 262 |
| 263 intptr_t frame_count = 0; |
| 264 result = Dart_StacktraceLength(stacktrace, &frame_count); |
| 265 EXPECT_VALID(result); |
| 266 EXPECT_EQ(Stacktrace::kPreallocatedStackdepth + 0, frame_count); |
| 267 |
| 268 Dart_Handle function_name; |
| 269 Dart_Handle script_url; |
| 270 intptr_t line_number = 0; |
| 271 intptr_t column_number = 0; |
| 272 const char* cstr = ""; |
| 273 |
| 274 result = Dart_StacktraceFrameInfo(stacktrace, |
| 275 0, |
| 276 &function_name, |
| 277 &script_url, |
| 278 &line_number, |
| 279 &column_number); |
| 280 EXPECT_VALID(result); |
| 281 Dart_StringToCString(function_name, &cstr); |
| 282 EXPECT_STREQ("C.foo", cstr); |
| 283 Dart_StringToCString(script_url, &cstr); |
| 284 EXPECT_STREQ("dart:test-lib", cstr); |
| 285 EXPECT_EQ(2, line_number); |
| 286 EXPECT_EQ(3, column_number); |
| 287 |
| 288 result = Dart_StacktraceFrameInfo(stacktrace, |
| 289 frame_count + 1, |
| 290 &function_name, |
| 291 &script_url, |
| 292 &line_number, |
| 293 &column_number); |
| 294 EXPECT(Dart_IsError(result)); |
| 295 |
| 296 result = Dart_StacktraceFrameInfo(stacktrace, |
| 297 -1, |
| 298 &function_name, |
| 299 &script_url, |
| 300 &line_number, |
| 301 &column_number); |
| 302 EXPECT(Dart_IsError(result)); |
| 303 } |
| 304 |
| 305 |
| 306 TEST_CASE(OutOfMemoryStacktraceInfo) { |
| 307 const char* kScriptChars = |
| 308 "var number_of_ints = 134000000;\n" |
| 309 "testMain() {\n" |
| 310 " new List<int>(number_of_ints)\n" |
| 311 "}\n"; |
| 312 |
| 313 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 314 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 315 |
| 316 EXPECT(Dart_IsError(error)); |
| 317 |
| 318 Dart_ExceptionStackTrace stacktrace; |
| 319 Dart_Handle result = Dart_ErrorGetStacktrace(error, &stacktrace); |
| 320 EXPECT(Dart_IsError(result)); // No Stacktrace for OutOfMemory. |
| 321 } |
| 322 |
| 323 |
| 324 TEST_CASE(CurrentStacktraceInfo) { |
| 325 const char* kScriptChars = |
| 326 "foo(n) => n == 1 ? throw new Error() : foo(n-1);\n" |
| 327 "testMain() => foo(50);\n"; |
| 328 |
| 329 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 330 Dart_Handle error = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 331 |
| 332 EXPECT(Dart_IsError(error)); |
| 333 |
| 334 Dart_ExceptionStackTrace stacktrace; |
| 335 Dart_Handle result = Dart_CurrentStacktrace(&stacktrace); |
| 336 EXPECT_VALID(result); |
| 337 |
| 338 intptr_t frame_count = 0; |
| 339 result = Dart_StacktraceLength(stacktrace, &frame_count); |
| 340 EXPECT_VALID(result); |
| 341 EXPECT_EQ(51, frame_count); |
| 342 // Test something bigger than the preallocated size to verify nothing was |
| 343 // truncated. |
| 344 EXPECT(51 > Stacktrace::kPreallocatedStackdepth); |
| 345 |
| 346 Dart_Handle function_name; |
| 347 Dart_Handle script_url; |
| 348 intptr_t line_number = 0; |
| 349 intptr_t column_number = 0; |
| 350 const char* cstr = ""; |
| 351 |
| 352 // Top frame at positioned at throw. |
| 353 result = Dart_StacktraceFrameInfo(stacktrace, |
| 354 0, |
| 355 &function_name, |
| 356 &script_url, |
| 357 &line_number, |
| 358 &column_number); |
| 359 EXPECT_VALID(result); |
| 360 Dart_StringToCString(function_name, &cstr); |
| 361 EXPECT_STREQ("foo", cstr); |
| 362 Dart_StringToCString(script_url, &cstr); |
| 363 EXPECT_STREQ("dart:test-lib", cstr); |
| 364 EXPECT_EQ(1, line_number); |
| 365 EXPECT_EQ(20, column_number); |
| 366 |
| 367 // Middle frames positioned at the recursive call. |
| 368 for (intptr_t frame_index = 1; |
| 369 frame_index < (frame_count - 1); |
| 370 frame_index++) { |
| 371 result = Dart_StacktraceFrameInfo(stacktrace, |
| 372 frame_index, |
| 373 &function_name, |
| 374 &script_url, |
| 375 &line_number, |
| 376 &column_number); |
| 377 EXPECT_VALID(result); |
| 378 Dart_StringToCString(function_name, &cstr); |
| 379 EXPECT_STREQ("foo", cstr); |
| 380 Dart_StringToCString(script_url, &cstr); |
| 381 EXPECT_STREQ("dart:test-lib", cstr); |
| 382 EXPECT_EQ(1, line_number); |
| 383 EXPECT_EQ(43, column_number); |
| 384 } |
| 385 |
| 386 // Bottom frame positioned at testMain(). |
| 387 result = Dart_StacktraceFrameInfo(stacktrace, |
| 388 frame_count - 1, |
| 389 &function_name, |
| 390 &script_url, |
| 391 &line_number, |
| 392 &column_number); |
| 393 EXPECT_VALID(result); |
| 394 Dart_StringToCString(function_name, &cstr); |
| 395 EXPECT_STREQ("testMain", cstr); |
| 396 Dart_StringToCString(script_url, &cstr); |
| 397 EXPECT_STREQ("dart:test-lib", cstr); |
| 398 EXPECT_EQ(2, line_number); |
| 399 EXPECT_EQ(18, column_number); |
| 400 |
| 401 // Out-of-bounds frames. |
| 402 result = Dart_StacktraceFrameInfo(stacktrace, |
| 403 frame_count, |
| 404 &function_name, |
| 405 &script_url, |
| 406 &line_number, |
| 407 &column_number); |
| 408 EXPECT(Dart_IsError(result)); |
| 409 result = Dart_StacktraceFrameInfo(stacktrace, |
| 410 -1, |
| 411 &function_name, |
| 412 &script_url, |
| 413 &line_number, |
| 414 &column_number); |
| 415 EXPECT(Dart_IsError(result)); |
| 416 } |
| 417 |
| 418 |
65 TEST_CASE(ErrorHandleTypes) { | 419 TEST_CASE(ErrorHandleTypes) { |
66 Isolate* isolate = Isolate::Current(); | 420 Isolate* isolate = Isolate::Current(); |
67 const String& compile_message = String::Handle(String::New("CompileError")); | 421 const String& compile_message = String::Handle(String::New("CompileError")); |
68 const String& fatal_message = String::Handle(String::New("FatalError")); | 422 const String& fatal_message = String::Handle(String::New("FatalError")); |
69 | 423 |
70 Dart_Handle not_error = NewString("NotError"); | 424 Dart_Handle not_error = NewString("NotError"); |
71 Dart_Handle api_error = Api::NewError("Api%s", "Error"); | 425 Dart_Handle api_error = Api::NewError("Api%s", "Error"); |
72 Dart_Handle exception_error = | 426 Dart_Handle exception_error = |
73 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); | 427 Dart_NewUnhandledExceptionError(NewString("ExceptionError")); |
74 Dart_Handle compile_error = | 428 Dart_Handle compile_error = |
(...skipping 7354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7429 NewString("main"), | 7783 NewString("main"), |
7430 1, | 7784 1, |
7431 dart_args); | 7785 dart_args); |
7432 int64_t value = 0; | 7786 int64_t value = 0; |
7433 result = Dart_IntegerToInt64(result, &value); | 7787 result = Dart_IntegerToInt64(result, &value); |
7434 EXPECT_VALID(result); | 7788 EXPECT_VALID(result); |
7435 EXPECT_EQ(6, value); | 7789 EXPECT_EQ(6, value); |
7436 } | 7790 } |
7437 | 7791 |
7438 } // namespace dart | 7792 } // namespace dart |
OLD | NEW |