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/dartutils.h" | 5 #include "bin/dartutils.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 | 9 |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 free(const_cast<uint8_t *>(buffer)); | 704 free(const_cast<uint8_t *>(buffer)); |
705 if (Dart_IsError(result)) { | 705 if (Dart_IsError(result)) { |
706 Dart_PropagateError(result); | 706 Dart_PropagateError(result); |
707 } | 707 } |
708 } | 708 } |
709 | 709 |
710 | 710 |
711 // Callback function, gets called from asynchronous script and library | 711 // Callback function, gets called from asynchronous script and library |
712 // reading code when there is an i/o error. | 712 // reading code when there is an i/o error. |
713 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { | 713 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { |
714 // Dart_Handle script_uri = Dart_GetNativeArgument(args, 0); | 714 // Dart_Handle source_uri = Dart_GetNativeArgument(args, 0); |
715 Dart_Handle error = Dart_GetNativeArgument(args, 1); | 715 Dart_Handle library_uri = Dart_GetNativeArgument(args, 1); |
716 Dart_Handle res = Dart_NewUnhandledExceptionError(error); | 716 Dart_Handle error = Dart_GetNativeArgument(args, 2); |
717 Dart_PropagateError(res); | 717 |
| 718 Dart_Handle library = Dart_LookupLibrary(library_uri); |
| 719 // If a library with the given uri exists, give it a chance to handle |
| 720 // the error. If the load requests stems from a deferred library load, |
| 721 // an IO error is not fatal. |
| 722 if (!Dart_IsError(library)) { |
| 723 ASSERT(Dart_IsLibrary(library)); |
| 724 Dart_Handle res = Dart_LibraryHandleError(library, error); |
| 725 if (Dart_IsNull(res)) { |
| 726 return; |
| 727 } |
| 728 } |
| 729 // The error was not handled above. Propagate an unhandled exception. |
| 730 error = Dart_NewUnhandledExceptionError(error); |
| 731 Dart_PropagateError(error); |
718 } | 732 } |
719 | 733 |
720 | 734 |
721 // Callback function that gets called from dartutils when the library | 735 // Callback function that gets called from dartutils when the library |
722 // source has been read. Loads the library or part into the VM. | 736 // source has been read. Loads the library or part into the VM. |
723 void FUNCTION_NAME(Builtin_LoadLibrarySource)(Dart_NativeArguments args) { | 737 void FUNCTION_NAME(Builtin_LoadLibrarySource)(Dart_NativeArguments args) { |
724 Dart_Handle tag_in = Dart_GetNativeArgument(args, 0); | 738 Dart_Handle tag_in = Dart_GetNativeArgument(args, 0); |
725 Dart_Handle resolved_script_uri = Dart_GetNativeArgument(args, 1); | 739 Dart_Handle resolved_script_uri = Dart_GetNativeArgument(args, 1); |
726 Dart_Handle library_uri = Dart_GetNativeArgument(args, 2); | 740 Dart_Handle library_uri = Dart_GetNativeArgument(args, 2); |
727 Dart_Handle sourceText = Dart_GetNativeArgument(args, 3); | 741 Dart_Handle sourceText = Dart_GetNativeArgument(args, 3); |
728 | 742 |
729 int64_t tag = DartUtils::GetIntegerValue(tag_in); | 743 int64_t tag = DartUtils::GetIntegerValue(tag_in); |
730 | 744 |
731 Dart_Handle result; | 745 Dart_Handle result; |
732 if (tag == Dart_kImportTag) { | 746 if (tag == Dart_kImportTag) { |
733 result = Dart_LoadLibrary(resolved_script_uri, sourceText); | 747 result = Dart_LoadLibrary(resolved_script_uri, sourceText); |
734 } else { | 748 } else { |
735 ASSERT(tag == Dart_kSourceTag); | 749 ASSERT(tag == Dart_kSourceTag); |
736 Dart_Handle library = Dart_LookupLibrary(library_uri); | 750 Dart_Handle library = Dart_LookupLibrary(library_uri); |
737 DART_CHECK_VALID(library); | 751 DART_CHECK_VALID(library); |
738 result = Dart_LoadSource(library, resolved_script_uri, sourceText); | 752 result = Dart_LoadSource(library, resolved_script_uri, sourceText); |
739 } | 753 } |
740 if (Dart_IsError(result)) Dart_PropagateError(result); | 754 if (Dart_IsError(result)) { |
| 755 // TODO(hausner): If compilation/loading errors are supposed to |
| 756 // be observable by the program, we need to mark the bad library |
| 757 // with the error instead of propagating it. |
| 758 Dart_PropagateError(result); |
| 759 } |
741 } | 760 } |
742 | 761 |
743 | 762 |
744 // Callback function that gets called from dartutils when there are | 763 // Callback function that gets called from dartutils when there are |
745 // no more outstanding load requests. | 764 // no more outstanding load requests. |
746 void FUNCTION_NAME(Builtin_DoneLoading)(Dart_NativeArguments args) { | 765 void FUNCTION_NAME(Builtin_DoneLoading)(Dart_NativeArguments args) { |
747 Dart_Handle res = Dart_FinalizeLoading(true); | 766 Dart_Handle res = Dart_FinalizeLoading(true); |
748 if (Dart_IsError(res)) { | 767 if (Dart_IsError(res)) { |
| 768 // TODO(hausner): If compilation/loading errors are supposed to |
| 769 // be observable by the program, we need to mark the bad library |
| 770 // with the error instead of propagating it. |
749 Dart_PropagateError(res); | 771 Dart_PropagateError(res); |
750 } | 772 } |
751 } | 773 } |
752 | 774 |
753 | 775 |
754 Dart_Handle DartUtils::LoadSource(Dart_Handle library, | 776 Dart_Handle DartUtils::LoadSource(Dart_Handle library, |
755 Dart_Handle url, | 777 Dart_Handle url, |
756 Dart_LibraryTag tag, | 778 Dart_LibraryTag tag, |
757 const char* url_string) { | 779 const char* url_string) { |
758 bool is_http_scheme_url = DartUtils::IsHttpSchemeURL(url_string); | 780 bool is_http_scheme_url = DartUtils::IsHttpSchemeURL(url_string); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 new CObjectString(CObject::NewString(os_error->message())); | 1182 new CObjectString(CObject::NewString(os_error->message())); |
1161 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1183 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1162 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1184 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1163 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1185 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1164 result->SetAt(2, error_message); | 1186 result->SetAt(2, error_message); |
1165 return result; | 1187 return result; |
1166 } | 1188 } |
1167 | 1189 |
1168 } // namespace bin | 1190 } // namespace bin |
1169 } // namespace dart | 1191 } // namespace dart |
OLD | NEW |