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_tools_api.h" | 8 #include "include/dart_tools_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 | 10 |
11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
13 | 13 |
14 #include "bin/crypto.h" | 14 #include "bin/crypto.h" |
15 #include "bin/directory.h" | 15 #include "bin/directory.h" |
16 #include "bin/extensions.h" | 16 #include "bin/extensions.h" |
17 #include "bin/file.h" | 17 #include "bin/file.h" |
18 #include "bin/io_buffer.h" | 18 #include "bin/io_buffer.h" |
19 #include "bin/isolate_data.h" | 19 #include "bin/isolate_data.h" |
20 #include "bin/platform.h" | 20 #include "bin/platform.h" |
21 #include "bin/socket.h" | 21 #include "bin/socket.h" |
22 #include "bin/utils.h" | 22 #include "bin/utils.h" |
23 | 23 |
| 24 // Return the error from the containing function if handle is in error handle. |
| 25 #define RETURN_IF_ERROR(handle) \ |
| 26 { \ |
| 27 Dart_Handle __handle = handle; \ |
| 28 if (Dart_IsError((__handle))) { \ |
| 29 return __handle; \ |
| 30 } \ |
| 31 } |
| 32 |
24 namespace dart { | 33 namespace dart { |
25 namespace bin { | 34 namespace bin { |
26 | 35 |
27 const char* DartUtils::original_working_directory = NULL; | 36 const char* DartUtils::original_working_directory = NULL; |
28 const char* DartUtils::kDartScheme = "dart:"; | 37 const char* DartUtils::kDartScheme = "dart:"; |
29 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; | 38 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; |
30 const char* DartUtils::kAsyncLibURL = "dart:async"; | 39 const char* DartUtils::kAsyncLibURL = "dart:async"; |
31 const char* DartUtils::kBuiltinLibURL = "dart:_builtin"; | 40 const char* DartUtils::kBuiltinLibURL = "dart:_builtin"; |
32 const char* DartUtils::kCoreLibURL = "dart:core"; | 41 const char* DartUtils::kCoreLibURL = "dart:core"; |
33 const char* DartUtils::kInternalLibURL = "dart:_internal"; | 42 const char* DartUtils::kInternalLibURL = "dart:_internal"; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 128 |
120 | 129 |
121 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { | 130 bool DartUtils::GetBooleanValue(Dart_Handle bool_obj) { |
122 bool value = false; | 131 bool value = false; |
123 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); | 132 Dart_Handle result = Dart_BooleanValue(bool_obj, &value); |
124 if (Dart_IsError(result)) Dart_PropagateError(result); | 133 if (Dart_IsError(result)) Dart_PropagateError(result); |
125 return value; | 134 return value; |
126 } | 135 } |
127 | 136 |
128 | 137 |
129 void DartUtils::SetIntegerField(Dart_Handle handle, | 138 Dart_Handle DartUtils::SetIntegerField(Dart_Handle handle, |
130 const char* name, | 139 const char* name, |
131 int64_t val) { | 140 int64_t val) { |
132 Dart_Handle result = Dart_SetField(handle, | 141 return Dart_SetField(handle, NewString(name), Dart_NewInteger(val)); |
133 NewString(name), | |
134 Dart_NewInteger(val)); | |
135 if (Dart_IsError(result)) Dart_PropagateError(result); | |
136 } | 142 } |
137 | 143 |
138 | 144 |
139 void DartUtils::SetStringField(Dart_Handle handle, | 145 Dart_Handle DartUtils::SetStringField(Dart_Handle handle, |
140 const char* name, | 146 const char* name, |
141 const char* val) { | 147 const char* val) { |
142 Dart_Handle result = Dart_SetField(handle, NewString(name), NewString(val)); | 148 return Dart_SetField(handle, NewString(name), NewString(val)); |
143 if (Dart_IsError(result)) Dart_PropagateError(result); | |
144 } | 149 } |
145 | 150 |
146 | 151 |
147 bool DartUtils::IsDartSchemeURL(const char* url_name) { | 152 bool DartUtils::IsDartSchemeURL(const char* url_name) { |
148 static const intptr_t kDartSchemeLen = strlen(kDartScheme); | 153 static const intptr_t kDartSchemeLen = strlen(kDartScheme); |
149 // If the URL starts with "dart:" then it is considered as a special | 154 // If the URL starts with "dart:" then it is considered as a special |
150 // library URL which is handled differently from other URLs. | 155 // library URL which is handled differently from other URLs. |
151 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); | 156 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); |
152 } | 157 } |
153 | 158 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 // Handle URI canonicalization requests. | 381 // Handle URI canonicalization requests. |
377 if (tag == Dart_kCanonicalizeUrl) { | 382 if (tag == Dart_kCanonicalizeUrl) { |
378 // If this is a Dart Scheme URL or 'part' of a io library | 383 // If this is a Dart Scheme URL or 'part' of a io library |
379 // then it is not modified as it will be handled internally. | 384 // then it is not modified as it will be handled internally. |
380 if (is_dart_scheme_url || is_io_library) { | 385 if (is_dart_scheme_url || is_io_library) { |
381 return url; | 386 return url; |
382 } | 387 } |
383 // Resolve the url within the context of the library's URL. | 388 // Resolve the url within the context of the library's URL. |
384 Dart_Handle builtin_lib = | 389 Dart_Handle builtin_lib = |
385 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 390 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
386 DART_CHECK_VALID(builtin_lib); | 391 RETURN_IF_ERROR(builtin_lib); |
387 return ResolveUri(library_url, url, builtin_lib); | 392 return ResolveUri(library_url, url, builtin_lib); |
388 } | 393 } |
389 | 394 |
390 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). | 395 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). |
391 if (is_dart_scheme_url) { | 396 if (is_dart_scheme_url) { |
392 if (tag == Dart_kImportTag) { | 397 if (tag == Dart_kImportTag) { |
393 // Handle imports of other built-in libraries present in the SDK. | 398 // Handle imports of other built-in libraries present in the SDK. |
394 if (DartUtils::IsDartIOLibURL(url_string)) { | 399 if (DartUtils::IsDartIOLibURL(url_string)) { |
395 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); | 400 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); |
396 } | 401 } |
(...skipping 19 matching lines...) Expand all Loading... |
416 part_uri_obj, | 421 part_uri_obj, |
417 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); | 422 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); |
418 } else { | 423 } else { |
419 ASSERT(tag == Dart_kImportTag); | 424 ASSERT(tag == Dart_kImportTag); |
420 return NewError("Unable to import '%s' ", url_string); | 425 return NewError("Unable to import '%s' ", url_string); |
421 } | 426 } |
422 } | 427 } |
423 | 428 |
424 Dart_Handle builtin_lib = | 429 Dart_Handle builtin_lib = |
425 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 430 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
426 DART_CHECK_VALID(builtin_lib); | 431 RETURN_IF_ERROR(builtin_lib); |
427 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 432 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
428 // Load a native code shared library to use in a native extension | 433 // Load a native code shared library to use in a native extension |
429 if (tag != Dart_kImportTag) { | 434 if (tag != Dart_kImportTag) { |
430 return NewError("Dart extensions must use import: '%s'", url_string); | 435 return NewError("Dart extensions must use import: '%s'", url_string); |
431 } | 436 } |
432 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url, builtin_lib); | 437 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url, builtin_lib); |
433 if (Dart_IsError(path_parts)) { | 438 if (Dart_IsError(path_parts)) { |
434 return path_parts; | 439 return path_parts; |
435 } | 440 } |
436 const char* extension_directory = NULL; | 441 const char* extension_directory = NULL; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 Dart_Handle source = Dart_NewStringFromUTF8(data, num_bytes); | 567 Dart_Handle source = Dart_NewStringFromUTF8(data, num_bytes); |
563 if (Dart_IsError(source)) { | 568 if (Dart_IsError(source)) { |
564 result = DartUtils::NewError("%s is not a valid UTF-8 script", | 569 result = DartUtils::NewError("%s is not a valid UTF-8 script", |
565 resolved_script_uri); | 570 resolved_script_uri); |
566 } else { | 571 } else { |
567 if (tag == Dart_kImportTag) { | 572 if (tag == Dart_kImportTag) { |
568 result = Dart_LoadLibrary(resolved_script_uri, source, 0, 0); | 573 result = Dart_LoadLibrary(resolved_script_uri, source, 0, 0); |
569 } else { | 574 } else { |
570 ASSERT(tag == Dart_kSourceTag); | 575 ASSERT(tag == Dart_kSourceTag); |
571 Dart_Handle library = Dart_LookupLibrary(library_uri); | 576 Dart_Handle library = Dart_LookupLibrary(library_uri); |
572 DART_CHECK_VALID(library); | 577 if (Dart_IsError(library)) { |
| 578 Dart_PropagateError(library); |
| 579 } |
573 result = Dart_LoadSource(library, resolved_script_uri, source, 0, 0); | 580 result = Dart_LoadSource(library, resolved_script_uri, source, 0, 0); |
574 } | 581 } |
575 } | 582 } |
576 } | 583 } |
577 | 584 |
578 if (buffer_copy != NULL) { | 585 if (buffer_copy != NULL) { |
579 free(const_cast<uint8_t *>(buffer_copy)); | 586 free(const_cast<uint8_t *>(buffer_copy)); |
580 } | 587 } |
581 | 588 |
582 if (Dart_IsError(result)) { | 589 if (Dart_IsError(result)) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 | 630 |
624 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 631 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
625 Dart_Handle internal_lib, | 632 Dart_Handle internal_lib, |
626 bool is_service_isolate, | 633 bool is_service_isolate, |
627 bool trace_loading, | 634 bool trace_loading, |
628 const char* package_root, | 635 const char* package_root, |
629 const char* packages_file) { | 636 const char* packages_file) { |
630 // Setup the internal library's 'internalPrint' function. | 637 // Setup the internal library's 'internalPrint' function. |
631 Dart_Handle print = Dart_Invoke( | 638 Dart_Handle print = Dart_Invoke( |
632 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 639 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
633 DART_CHECK_VALID(print); | 640 RETURN_IF_ERROR(print); |
634 Dart_Handle result = | 641 Dart_Handle result = |
635 Dart_SetField(internal_lib, NewString("_printClosure"), print); | 642 Dart_SetField(internal_lib, NewString("_printClosure"), print); |
636 DART_CHECK_VALID(result); | 643 RETURN_IF_ERROR(result); |
637 | 644 |
638 if (!is_service_isolate) { | 645 if (!is_service_isolate) { |
639 if (IsWindowsHost()) { | 646 if (IsWindowsHost()) { |
640 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); | 647 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); |
641 DART_CHECK_VALID(result); | 648 RETURN_IF_ERROR(result); |
642 } | 649 } |
643 if (trace_loading) { | 650 if (trace_loading) { |
644 result = Dart_SetField(builtin_lib, | 651 result = Dart_SetField(builtin_lib, |
645 NewString("_traceLoading"), Dart_True()); | 652 NewString("_traceLoading"), Dart_True()); |
646 DART_CHECK_VALID(result); | 653 RETURN_IF_ERROR(result); |
647 } | 654 } |
648 // Set current working directory. | 655 // Set current working directory. |
649 result = SetWorkingDirectory(builtin_lib); | 656 result = SetWorkingDirectory(builtin_lib); |
650 DART_CHECK_VALID(result); | 657 RETURN_IF_ERROR(result); |
651 // Wait for the service isolate to initialize the load port. | 658 // Wait for the service isolate to initialize the load port. |
652 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); | 659 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); |
653 if (load_port == ILLEGAL_PORT) { | 660 if (load_port == ILLEGAL_PORT) { |
654 return NewDartUnsupportedError("Service did not return load port."); | 661 return NewDartUnsupportedError("Service did not return load port."); |
655 } | 662 } |
656 Builtin::SetLoadPort(load_port); | 663 result = Builtin::SetLoadPort(load_port); |
| 664 RETURN_IF_ERROR(result); |
657 } | 665 } |
658 | 666 |
659 // Set up package root if specified. | 667 // Set up package root if specified. |
660 if (package_root != NULL) { | 668 if (package_root != NULL) { |
661 ASSERT(packages_file == NULL); | 669 ASSERT(packages_file == NULL); |
662 result = NewString(package_root); | 670 result = NewString(package_root); |
663 DART_CHECK_VALID(result); | 671 RETURN_IF_ERROR(result); |
664 const int kNumArgs = 1; | 672 const int kNumArgs = 1; |
665 Dart_Handle dart_args[kNumArgs]; | 673 Dart_Handle dart_args[kNumArgs]; |
666 dart_args[0] = result; | 674 dart_args[0] = result; |
667 result = Dart_Invoke(builtin_lib, | 675 result = Dart_Invoke(builtin_lib, |
668 NewString("_setPackageRoot"), | 676 NewString("_setPackageRoot"), |
669 kNumArgs, | 677 kNumArgs, |
670 dart_args); | 678 dart_args); |
671 DART_CHECK_VALID(result); | 679 RETURN_IF_ERROR(result); |
672 } else if (packages_file != NULL) { | 680 } else if (packages_file != NULL) { |
673 result = NewString(packages_file); | 681 result = NewString(packages_file); |
674 DART_CHECK_VALID(result); | 682 RETURN_IF_ERROR(result); |
675 const int kNumArgs = 1; | 683 const int kNumArgs = 1; |
676 Dart_Handle dart_args[kNumArgs]; | 684 Dart_Handle dart_args[kNumArgs]; |
677 dart_args[0] = result; | 685 dart_args[0] = result; |
678 result = Dart_Invoke(builtin_lib, | 686 result = Dart_Invoke(builtin_lib, |
679 NewString("_loadPackagesMap"), | 687 NewString("_loadPackagesMap"), |
680 kNumArgs, | 688 kNumArgs, |
681 dart_args); | 689 dart_args); |
682 DART_CHECK_VALID(result); | 690 RETURN_IF_ERROR(result); |
683 } | 691 } |
684 return Dart_True(); | 692 return Dart_True(); |
685 } | 693 } |
686 | 694 |
687 | 695 |
688 void DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, | 696 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, |
689 Dart_Handle builtin_lib, | 697 Dart_Handle builtin_lib, |
690 bool is_service_isolate) { | 698 bool is_service_isolate) { |
691 if (!is_service_isolate) { | 699 if (!is_service_isolate) { |
692 // Setup the 'Uri.base' getter in dart:core. | 700 // Setup the 'Uri.base' getter in dart:core. |
693 Dart_Handle uri_base = Dart_Invoke( | 701 Dart_Handle uri_base = Dart_Invoke( |
694 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); | 702 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); |
695 DART_CHECK_VALID(uri_base); | 703 RETURN_IF_ERROR(uri_base); |
696 Dart_Handle result = Dart_SetField(core_lib, | 704 Dart_Handle result = Dart_SetField(core_lib, |
697 NewString("_uriBaseClosure"), | 705 NewString("_uriBaseClosure"), |
698 uri_base); | 706 uri_base); |
699 DART_CHECK_VALID(result); | 707 RETURN_IF_ERROR(result); |
700 } | 708 } |
| 709 return Dart_True(); |
701 } | 710 } |
702 | 711 |
703 | 712 |
704 void DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib, | 713 Dart_Handle DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib, |
705 Dart_Handle isolate_lib) { | 714 Dart_Handle isolate_lib) { |
706 Dart_Handle schedule_immediate_closure = | 715 Dart_Handle schedule_immediate_closure = |
707 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), | 716 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), |
708 0, NULL); | 717 0, NULL); |
| 718 RETURN_IF_ERROR(schedule_immediate_closure); |
709 Dart_Handle args[1]; | 719 Dart_Handle args[1]; |
710 args[0] = schedule_immediate_closure; | 720 args[0] = schedule_immediate_closure; |
711 DART_CHECK_VALID(Dart_Invoke( | 721 return Dart_Invoke( |
712 async_lib, NewString("_setScheduleImmediateClosure"), 1, args)); | 722 async_lib, NewString("_setScheduleImmediateClosure"), 1, args); |
713 } | 723 } |
714 | 724 |
715 | 725 |
716 void DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { | 726 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { |
717 DART_CHECK_VALID(Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL)); | 727 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); |
718 } | 728 } |
719 | 729 |
720 | 730 |
721 void DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { | 731 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { |
722 DART_CHECK_VALID(Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL)); | 732 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); |
723 } | 733 } |
724 | 734 |
725 | 735 |
726 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 736 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, |
727 const char* packages_file, | 737 const char* packages_file, |
728 bool is_service_isolate, | 738 bool is_service_isolate, |
729 bool trace_loading, | 739 bool trace_loading, |
730 Dart_Handle builtin_lib) { | 740 Dart_Handle builtin_lib) { |
731 // First ensure all required libraries are available. | 741 // First ensure all required libraries are available. |
732 Dart_Handle url = NewString(kCoreLibURL); | 742 Dart_Handle url = NewString(kCoreLibURL); |
733 DART_CHECK_VALID(url); | 743 RETURN_IF_ERROR(url); |
734 Dart_Handle core_lib = Dart_LookupLibrary(url); | 744 Dart_Handle core_lib = Dart_LookupLibrary(url); |
735 DART_CHECK_VALID(core_lib); | 745 RETURN_IF_ERROR(core_lib); |
736 url = NewString(kAsyncLibURL); | 746 url = NewString(kAsyncLibURL); |
737 DART_CHECK_VALID(url); | 747 RETURN_IF_ERROR(url); |
738 Dart_Handle async_lib = Dart_LookupLibrary(url); | 748 Dart_Handle async_lib = Dart_LookupLibrary(url); |
739 DART_CHECK_VALID(async_lib); | 749 RETURN_IF_ERROR(async_lib); |
740 url = NewString(kIsolateLibURL); | 750 url = NewString(kIsolateLibURL); |
741 DART_CHECK_VALID(url); | 751 RETURN_IF_ERROR(url); |
742 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | 752 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
743 DART_CHECK_VALID(isolate_lib); | 753 RETURN_IF_ERROR(isolate_lib); |
744 url = NewString(kInternalLibURL); | 754 url = NewString(kInternalLibURL); |
745 DART_CHECK_VALID(url); | 755 RETURN_IF_ERROR(url); |
746 Dart_Handle internal_lib = Dart_LookupLibrary(url); | 756 Dart_Handle internal_lib = Dart_LookupLibrary(url); |
747 DART_CHECK_VALID(internal_lib); | 757 RETURN_IF_ERROR(internal_lib); |
748 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 758 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
749 DART_CHECK_VALID(io_lib); | 759 RETURN_IF_ERROR(io_lib); |
750 | 760 |
751 // We need to ensure that all the scripts loaded so far are finalized | 761 // We need to ensure that all the scripts loaded so far are finalized |
752 // as we are about to invoke some Dart code below to setup closures. | 762 // as we are about to invoke some Dart code below to setup closures. |
753 Dart_Handle result = Dart_FinalizeLoading(false); | 763 Dart_Handle result = Dart_FinalizeLoading(false); |
754 DART_CHECK_VALID(result); | 764 RETURN_IF_ERROR(result); |
755 | 765 |
756 result = PrepareBuiltinLibrary(builtin_lib, | 766 result = PrepareBuiltinLibrary(builtin_lib, |
757 internal_lib, | 767 internal_lib, |
758 is_service_isolate, | 768 is_service_isolate, |
759 trace_loading, | 769 trace_loading, |
760 package_root, | 770 package_root, |
761 packages_file); | 771 packages_file); |
762 DART_CHECK_VALID(result); | 772 RETURN_IF_ERROR(result); |
763 | 773 |
764 PrepareAsyncLibrary(async_lib, isolate_lib); | 774 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); |
765 PrepareCoreLibrary(core_lib, builtin_lib, is_service_isolate); | 775 RETURN_IF_ERROR(PrepareCoreLibrary( |
766 PrepareIsolateLibrary(isolate_lib); | 776 core_lib, builtin_lib, is_service_isolate)); |
767 PrepareIOLibrary(io_lib); | 777 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); |
| 778 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); |
768 return result; | 779 return result; |
769 } | 780 } |
770 | 781 |
771 | 782 |
772 void DartUtils::SetupIOLibrary(const char* script_uri) { | 783 Dart_Handle DartUtils::SetupIOLibrary(const char* script_uri) { |
773 Dart_Handle io_lib_url = NewString(kIOLibURL); | 784 Dart_Handle io_lib_url = NewString(kIOLibURL); |
774 DART_CHECK_VALID(io_lib_url); | 785 RETURN_IF_ERROR(io_lib_url); |
775 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); | 786 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); |
776 DART_CHECK_VALID(io_lib); | 787 RETURN_IF_ERROR(io_lib); |
777 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform"); | 788 Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform"); |
778 DART_CHECK_VALID(platform_type); | 789 RETURN_IF_ERROR(platform_type); |
779 Dart_Handle script_name = NewString("_nativeScript"); | 790 Dart_Handle script_name = NewString("_nativeScript"); |
780 DART_CHECK_VALID(script_name); | 791 RETURN_IF_ERROR(script_name); |
781 Dart_Handle dart_script = NewString(script_uri); | 792 Dart_Handle dart_script = NewString(script_uri); |
782 DART_CHECK_VALID(dart_script); | 793 RETURN_IF_ERROR(dart_script); |
783 Dart_Handle set_script_name = | 794 Dart_Handle set_script_name = |
784 Dart_SetField(platform_type, script_name, dart_script); | 795 Dart_SetField(platform_type, script_name, dart_script); |
785 DART_CHECK_VALID(set_script_name); | 796 RETURN_IF_ERROR(set_script_name); |
| 797 return Dart_Null(); |
786 } | 798 } |
787 | 799 |
788 | 800 |
789 bool DartUtils::PostNull(Dart_Port port_id) { | 801 bool DartUtils::PostNull(Dart_Port port_id) { |
790 // Post a message with just the null object. | 802 // Post a message with just the null object. |
791 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject()); | 803 return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject()); |
792 } | 804 } |
793 | 805 |
794 | 806 |
795 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { | 807 bool DartUtils::PostInt32(Dart_Port port_id, int32_t value) { |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 new CObjectString(CObject::NewString(os_error->message())); | 1236 new CObjectString(CObject::NewString(os_error->message())); |
1225 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1237 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1226 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1238 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1227 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1239 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1228 result->SetAt(2, error_message); | 1240 result->SetAt(2, error_message); |
1229 return result; | 1241 return result; |
1230 } | 1242 } |
1231 | 1243 |
1232 } // namespace bin | 1244 } // namespace bin |
1233 } // namespace dart | 1245 } // namespace dart |
OLD | NEW |