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_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 441 |
442 EXPECT_STREQ("", Dart_GetError(not_error)); | 442 EXPECT_STREQ("", Dart_GetError(not_error)); |
443 EXPECT_STREQ("ApiError", Dart_GetError(api_error)); | 443 EXPECT_STREQ("ApiError", Dart_GetError(api_error)); |
444 EXPECT_SUBSTRING("Unhandled exception:\nExceptionError", | 444 EXPECT_SUBSTRING("Unhandled exception:\nExceptionError", |
445 Dart_GetError(exception_error)); | 445 Dart_GetError(exception_error)); |
446 EXPECT_STREQ("CompileError", Dart_GetError(compile_error)); | 446 EXPECT_STREQ("CompileError", Dart_GetError(compile_error)); |
447 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); | 447 EXPECT_STREQ("FatalError", Dart_GetError(fatal_error)); |
448 } | 448 } |
449 | 449 |
450 | 450 |
| 451 TEST_CASE(UnhandleExceptionError) { |
| 452 Isolate* isolate = Isolate::Current(); |
| 453 const char* exception_cstr = ""; |
| 454 |
| 455 // Test with an API Error. |
| 456 const char* kApiError = "Api Error Exception Test."; |
| 457 Dart_Handle api_error = Api::NewHandle( |
| 458 isolate, |
| 459 ApiError::New(String::Handle(String::New(kApiError)))); |
| 460 Dart_Handle exception_error = Dart_NewUnhandledExceptionError(api_error); |
| 461 EXPECT(!Dart_IsApiError(exception_error)); |
| 462 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
| 463 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
| 464 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
| 465 &exception_cstr)); |
| 466 EXPECT_STREQ(kApiError, exception_cstr); |
| 467 |
| 468 // Test with a Compilation Error. |
| 469 const char* kCompileError = "CompileError Exception Test."; |
| 470 const String& compile_message = |
| 471 String::Handle(String::New(kCompileError)); |
| 472 Dart_Handle compile_error = |
| 473 Api::NewHandle(isolate, LanguageError::New(compile_message)); |
| 474 exception_error = Dart_NewUnhandledExceptionError(compile_error); |
| 475 EXPECT(!Dart_IsApiError(exception_error)); |
| 476 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
| 477 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
| 478 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
| 479 &exception_cstr)); |
| 480 EXPECT_STREQ(kCompileError, exception_cstr); |
| 481 |
| 482 // Test with a Fatal Error. |
| 483 const String& fatal_message = |
| 484 String::Handle(String::New("FatalError Exception Test.")); |
| 485 Dart_Handle fatal_error = |
| 486 Api::NewHandle(isolate, UnwindError::New(fatal_message)); |
| 487 exception_error = Dart_NewUnhandledExceptionError(fatal_error); |
| 488 EXPECT(Dart_IsError(exception_error)); |
| 489 EXPECT(!Dart_IsUnhandledExceptionError(exception_error)); |
| 490 |
| 491 // Test with a Regular object. |
| 492 const char* kRegularString = "Regular String Exception Test."; |
| 493 Dart_Handle obj = Api::NewHandle(isolate, String::New(kRegularString)); |
| 494 exception_error = Dart_NewUnhandledExceptionError(obj); |
| 495 EXPECT(!Dart_IsApiError(exception_error)); |
| 496 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
| 497 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
| 498 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
| 499 &exception_cstr)); |
| 500 EXPECT_STREQ(kRegularString, exception_cstr); |
| 501 } |
| 502 |
| 503 |
451 void PropagateErrorNative(Dart_NativeArguments args) { | 504 void PropagateErrorNative(Dart_NativeArguments args) { |
452 Dart_EnterScope(); | 505 Dart_EnterScope(); |
453 Dart_Handle closure = Dart_GetNativeArgument(args, 0); | 506 Dart_Handle closure = Dart_GetNativeArgument(args, 0); |
454 EXPECT(Dart_IsClosure(closure)); | 507 EXPECT(Dart_IsClosure(closure)); |
455 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); | 508 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); |
456 EXPECT(Dart_IsError(result)); | 509 EXPECT(Dart_IsError(result)); |
457 result = Dart_PropagateError(result); | 510 result = Dart_PropagateError(result); |
458 EXPECT_VALID(result); // We do not expect to reach here. | 511 EXPECT_VALID(result); // We do not expect to reach here. |
459 UNREACHABLE(); | 512 UNREACHABLE(); |
460 } | 513 } |
(...skipping 8758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9219 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); | 9272 Dart_TimelineAsyncEnd("testAsyncEvent", async_id); |
9220 | 9273 |
9221 // Check that it is in the output. | 9274 // Check that it is in the output. |
9222 TimelineEventRecorder* recorder = isolate->timeline_event_recorder(); | 9275 TimelineEventRecorder* recorder = isolate->timeline_event_recorder(); |
9223 JSONStream js; | 9276 JSONStream js; |
9224 recorder->PrintJSON(&js); | 9277 recorder->PrintJSON(&js); |
9225 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); | 9278 EXPECT_SUBSTRING("testAsyncEvent", js.ToCString()); |
9226 } | 9279 } |
9227 | 9280 |
9228 } // namespace dart | 9281 } // namespace dart |
OLD | NEW |