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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_tools_api.h" | 10 #include "include/dart_tools_api.h" |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 Dart_ExitScope(); \ | 699 Dart_ExitScope(); \ |
700 Dart_ShutdownIsolate(); \ | 700 Dart_ShutdownIsolate(); \ |
701 return NULL; \ | 701 return NULL; \ |
702 } \ | 702 } \ |
703 | 703 |
704 | 704 |
705 // Returns true on success, false on failure. | 705 // Returns true on success, false on failure. |
706 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 706 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
707 const char* main, | 707 const char* main, |
708 const char* package_root, | 708 const char* package_root, |
| 709 const char** package_map, |
709 const char* packages_file, | 710 const char* packages_file, |
710 Dart_IsolateFlags* flags, | 711 Dart_IsolateFlags* flags, |
711 char** error, | 712 char** error, |
712 int* exit_code) { | 713 int* exit_code) { |
713 ASSERT(script_uri != NULL); | 714 ASSERT(script_uri != NULL); |
714 IsolateData* isolate_data = new IsolateData(script_uri, | 715 IsolateData* isolate_data = new IsolateData(script_uri, |
715 package_root, | 716 package_root, |
716 packages_file); | 717 packages_file); |
717 Dart_Isolate isolate = NULL; | 718 Dart_Isolate isolate = NULL; |
718 | 719 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 // Prepare builtin and its dependent libraries for use to resolve URIs. | 761 // Prepare builtin and its dependent libraries for use to resolve URIs. |
761 // The builtin library is part of the core snapshot and would already be | 762 // The builtin library is part of the core snapshot and would already be |
762 // available here in the case of script snapshot loading. | 763 // available here in the case of script snapshot loading. |
763 Dart_Handle builtin_lib = | 764 Dart_Handle builtin_lib = |
764 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 765 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
765 CHECK_RESULT(builtin_lib); | 766 CHECK_RESULT(builtin_lib); |
766 | 767 |
767 // Prepare for script loading by setting up the 'print' and 'timer' | 768 // Prepare for script loading by setting up the 'print' and 'timer' |
768 // closures and setting up 'package root' for URI resolution. | 769 // closures and setting up 'package root' for URI resolution. |
769 result = DartUtils::PrepareForScriptLoading(package_root, | 770 result = DartUtils::PrepareForScriptLoading(package_root, |
| 771 package_map, |
770 packages_file, | 772 packages_file, |
771 false, | 773 false, |
772 has_trace_loading, | 774 has_trace_loading, |
773 builtin_lib); | 775 builtin_lib); |
774 CHECK_RESULT(result); | 776 CHECK_RESULT(result); |
775 | 777 |
776 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 778 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
777 CHECK_RESULT(result); | 779 CHECK_RESULT(result); |
778 | 780 |
779 if (!has_run_precompiled_snapshot) { | 781 if (!has_run_precompiled_snapshot) { |
(...skipping 28 matching lines...) Expand all Loading... |
808 | 810 |
809 return isolate; | 811 return isolate; |
810 } | 812 } |
811 | 813 |
812 #undef CHECK_RESULT | 814 #undef CHECK_RESULT |
813 | 815 |
814 | 816 |
815 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 817 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
816 const char* main, | 818 const char* main, |
817 const char* package_root, | 819 const char* package_root, |
| 820 const char** package_map, |
818 Dart_IsolateFlags* flags, | 821 Dart_IsolateFlags* flags, |
819 void* data, char** error) { | 822 void* data, char** error) { |
820 // The VM should never call the isolate helper with a NULL flags. | 823 // The VM should never call the isolate helper with a NULL flags. |
821 ASSERT(flags != NULL); | 824 ASSERT(flags != NULL); |
822 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); | 825 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); |
| 826 if ((package_root != NULL) && (package_map != NULL)) { |
| 827 *error = strdup("Invalid arguments - Cannot simultaneously specify " |
| 828 "package root and package map."); |
| 829 return NULL; |
| 830 } |
823 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data); | 831 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data); |
824 int exit_code = 0; | |
825 if (script_uri == NULL) { | 832 if (script_uri == NULL) { |
826 if (data == NULL) { | 833 if (data == NULL) { |
827 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | 834 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
828 return NULL; | 835 return NULL; |
829 } | 836 } |
830 script_uri = parent_isolate_data->script_url; | 837 script_uri = parent_isolate_data->script_url; |
831 if (script_uri == NULL) { | 838 if (script_uri == NULL) { |
832 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | 839 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
833 return NULL; | 840 return NULL; |
834 } | 841 } |
835 } | 842 } |
836 const char* packages_file = NULL; | 843 const char* packages_file = NULL; |
837 if (package_root == NULL) { | 844 // If neither a package root nor a package map are requested pass on the |
| 845 // inherited values. |
| 846 if ((package_root == NULL) && (package_map == NULL)) { |
838 if (parent_isolate_data != NULL) { | 847 if (parent_isolate_data != NULL) { |
839 package_root = parent_isolate_data->package_root; | 848 package_root = parent_isolate_data->package_root; |
840 packages_file = parent_isolate_data->packages_file; | 849 packages_file = parent_isolate_data->packages_file; |
841 } | 850 } |
842 } | 851 } |
| 852 |
| 853 int exit_code = 0; |
843 return CreateIsolateAndSetupHelper(script_uri, | 854 return CreateIsolateAndSetupHelper(script_uri, |
844 main, | 855 main, |
845 package_root, | 856 package_root, |
| 857 package_map, |
846 packages_file, | 858 packages_file, |
847 flags, | 859 flags, |
848 error, | 860 error, |
849 &exit_code); | 861 &exit_code); |
850 } | 862 } |
851 | 863 |
852 | 864 |
853 static void PrintVersion() { | 865 static void PrintVersion() { |
854 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 866 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
855 } | 867 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 bool RunMainIsolate(const char* script_name, | 1121 bool RunMainIsolate(const char* script_name, |
1110 CommandLineOptions* dart_options) { | 1122 CommandLineOptions* dart_options) { |
1111 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1123 // Call CreateIsolateAndSetup which creates an isolate and loads up |
1112 // the specified application script. | 1124 // the specified application script. |
1113 char* error = NULL; | 1125 char* error = NULL; |
1114 int exit_code = 0; | 1126 int exit_code = 0; |
1115 char* isolate_name = BuildIsolateName(script_name, "main"); | 1127 char* isolate_name = BuildIsolateName(script_name, "main"); |
1116 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1128 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
1117 "main", | 1129 "main", |
1118 commandline_package_root, | 1130 commandline_package_root, |
| 1131 NULL, |
1119 commandline_packages_file, | 1132 commandline_packages_file, |
1120 NULL, | 1133 NULL, |
1121 &error, | 1134 &error, |
1122 &exit_code); | 1135 &exit_code); |
1123 if (isolate == NULL) { | 1136 if (isolate == NULL) { |
1124 delete [] isolate_name; | 1137 delete [] isolate_name; |
1125 if (exit_code == kRestartRequestExitCode) { | 1138 if (exit_code == kRestartRequestExitCode) { |
1126 free(error); | 1139 free(error); |
1127 return true; | 1140 return true; |
1128 } | 1141 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 exit(Process::GlobalExitCode()); | 1456 exit(Process::GlobalExitCode()); |
1444 } | 1457 } |
1445 | 1458 |
1446 } // namespace bin | 1459 } // namespace bin |
1447 } // namespace dart | 1460 } // namespace dart |
1448 | 1461 |
1449 int main(int argc, char** argv) { | 1462 int main(int argc, char** argv) { |
1450 dart::bin::main(argc, argv); | 1463 dart::bin::main(argc, argv); |
1451 UNREACHABLE(); | 1464 UNREACHABLE(); |
1452 } | 1465 } |
OLD | NEW |