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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 exception_error = Dart_NewUnhandledExceptionError(obj); | 493 exception_error = Dart_NewUnhandledExceptionError(obj); |
494 EXPECT(!Dart_IsApiError(exception_error)); | 494 EXPECT(!Dart_IsApiError(exception_error)); |
495 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); | 495 EXPECT(Dart_IsUnhandledExceptionError(exception_error)); |
496 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); | 496 EXPECT(Dart_IsString(Dart_ErrorGetException(exception_error))); |
497 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), | 497 EXPECT_VALID(Dart_StringToCString(Dart_ErrorGetException(exception_error), |
498 &exception_cstr)); | 498 &exception_cstr)); |
499 EXPECT_STREQ(kRegularString, exception_cstr); | 499 EXPECT_STREQ(kRegularString, exception_cstr); |
500 } | 500 } |
501 | 501 |
502 | 502 |
| 503 // Should we propagate the error via Dart_SetReturnValue? |
| 504 static bool use_set_return = false; |
| 505 |
| 506 // Should we propagate the error via Dart_ThrowException? |
| 507 static bool use_throw_exception = false; |
| 508 |
| 509 |
503 void PropagateErrorNative(Dart_NativeArguments args) { | 510 void PropagateErrorNative(Dart_NativeArguments args) { |
504 Dart_EnterScope(); | |
505 Dart_Handle closure = Dart_GetNativeArgument(args, 0); | 511 Dart_Handle closure = Dart_GetNativeArgument(args, 0); |
506 EXPECT(Dart_IsClosure(closure)); | 512 EXPECT(Dart_IsClosure(closure)); |
507 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); | 513 Dart_Handle result = Dart_InvokeClosure(closure, 0, NULL); |
508 EXPECT(Dart_IsError(result)); | 514 EXPECT(Dart_IsError(result)); |
509 result = Dart_PropagateError(result); | 515 if (use_set_return) { |
510 EXPECT_VALID(result); // We do not expect to reach here. | 516 Dart_SetReturnValue(args, result); |
511 UNREACHABLE(); | 517 } else if (use_throw_exception) { |
| 518 result = Dart_ThrowException(result); |
| 519 EXPECT_VALID(result); // We do not expect to reach here. |
| 520 UNREACHABLE(); |
| 521 } else { |
| 522 result = Dart_PropagateError(result); |
| 523 EXPECT_VALID(result); // We do not expect to reach here. |
| 524 UNREACHABLE(); |
| 525 } |
512 } | 526 } |
513 | 527 |
514 | 528 |
515 static Dart_NativeFunction PropagateError_native_lookup( | 529 static Dart_NativeFunction PropagateError_native_lookup( |
516 Dart_Handle name, int argument_count, bool* auto_setup_scope) { | 530 Dart_Handle name, int argument_count, bool* auto_setup_scope) { |
517 ASSERT(auto_setup_scope != NULL); | 531 ASSERT(auto_setup_scope != NULL); |
518 *auto_setup_scope = true; | 532 *auto_setup_scope = true; |
519 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); | 533 return reinterpret_cast<Dart_NativeFunction>(&PropagateErrorNative); |
520 } | 534 } |
521 | 535 |
(...skipping 14 matching lines...) Expand all Loading... |
536 " nativeFunc(() => raiseCompileError());\n" | 550 " nativeFunc(() => raiseCompileError());\n" |
537 "}\n" | 551 "}\n" |
538 "\n" | 552 "\n" |
539 "void Func2() {\n" | 553 "void Func2() {\n" |
540 " nativeFunc(() => throwException());\n" | 554 " nativeFunc(() => throwException());\n" |
541 "}\n"; | 555 "}\n"; |
542 Dart_Handle lib = TestCase::LoadTestScript( | 556 Dart_Handle lib = TestCase::LoadTestScript( |
543 kScriptChars, &PropagateError_native_lookup); | 557 kScriptChars, &PropagateError_native_lookup); |
544 Dart_Handle result; | 558 Dart_Handle result; |
545 | 559 |
| 560 // Use Dart_PropagateError to propagate the error. |
| 561 use_throw_exception = false; |
| 562 use_set_return = false; |
| 563 |
546 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); | 564 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); |
547 EXPECT(Dart_IsError(result)); | 565 EXPECT(Dart_IsError(result)); |
548 EXPECT(!Dart_ErrorHasException(result)); | 566 EXPECT(!Dart_ErrorHasException(result)); |
| 567 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); |
| 568 |
| 569 result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); |
| 570 EXPECT(Dart_IsError(result)); |
| 571 EXPECT(Dart_ErrorHasException(result)); |
| 572 EXPECT_SUBSTRING("myException", Dart_GetError(result)); |
| 573 |
| 574 // Use Dart_SetReturnValue to propagate the error. |
| 575 use_throw_exception = false; |
| 576 use_set_return = true; |
| 577 |
| 578 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); |
| 579 EXPECT(Dart_IsError(result)); |
| 580 EXPECT(!Dart_ErrorHasException(result)); |
| 581 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); |
| 582 |
| 583 result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); |
| 584 EXPECT(Dart_IsError(result)); |
| 585 EXPECT(Dart_ErrorHasException(result)); |
| 586 EXPECT_SUBSTRING("myException", Dart_GetError(result)); |
| 587 |
| 588 // Use Dart_ThrowException to propagate the error. |
| 589 use_throw_exception = true; |
| 590 use_set_return = false; |
| 591 |
| 592 result = Dart_Invoke(lib, NewString("Func1"), 0, NULL); |
| 593 EXPECT(Dart_IsError(result)); |
| 594 EXPECT(!Dart_ErrorHasException(result)); |
549 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); | 595 EXPECT_SUBSTRING("semicolon expected", Dart_GetError(result)); |
550 | 596 |
551 result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); | 597 result = Dart_Invoke(lib, NewString("Func2"), 0, NULL); |
552 EXPECT(Dart_IsError(result)); | 598 EXPECT(Dart_IsError(result)); |
553 EXPECT(Dart_ErrorHasException(result)); | 599 EXPECT(Dart_ErrorHasException(result)); |
554 EXPECT_SUBSTRING("myException", Dart_GetError(result)); | 600 EXPECT_SUBSTRING("myException", Dart_GetError(result)); |
555 } | 601 } |
556 | 602 |
557 | 603 |
558 TEST_CASE(Dart_Error) { | 604 TEST_CASE(Dart_Error) { |
(...skipping 9140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9699 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9745 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9700 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9746 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9701 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9747 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9702 | 9748 |
9703 // Heartbeat test for new events. | 9749 // Heartbeat test for new events. |
9704 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9750 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
9705 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9751 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9706 } | 9752 } |
9707 | 9753 |
9708 } // namespace dart | 9754 } // namespace dart |
OLD | NEW |