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 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 Dart_ExitScope(); \ | 697 Dart_ExitScope(); \ |
698 Dart_ShutdownIsolate(); \ | 698 Dart_ShutdownIsolate(); \ |
699 return NULL; \ | 699 return NULL; \ |
700 } \ | 700 } \ |
701 | 701 |
702 | 702 |
703 // Returns true on success, false on failure. | 703 // Returns true on success, false on failure. |
704 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | 704 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
705 const char* main, | 705 const char* main, |
706 const char* package_root, | 706 const char* package_root, |
707 const char** package_map, | 707 const char* packages_config, |
708 const char* packages_file, | |
709 Dart_IsolateFlags* flags, | 708 Dart_IsolateFlags* flags, |
710 char** error, | 709 char** error, |
711 int* exit_code) { | 710 int* exit_code) { |
712 ASSERT(script_uri != NULL); | 711 ASSERT(script_uri != NULL); |
713 IsolateData* isolate_data = new IsolateData(script_uri, | 712 IsolateData* isolate_data = new IsolateData(script_uri, |
714 package_root, | 713 package_root, |
715 packages_file); | 714 packages_config); |
716 Dart_Isolate isolate = NULL; | 715 Dart_Isolate isolate = NULL; |
717 | 716 |
718 isolate = Dart_CreateIsolate(script_uri, | 717 isolate = Dart_CreateIsolate(script_uri, |
719 main, | 718 main, |
720 isolate_snapshot_buffer, | 719 isolate_snapshot_buffer, |
721 flags, | 720 flags, |
722 isolate_data, | 721 isolate_data, |
723 error); | 722 error); |
724 | 723 |
725 if (isolate == NULL) { | 724 if (isolate == NULL) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 // Prepare builtin and its dependent libraries for use to resolve URIs. | 760 // Prepare builtin and its dependent libraries for use to resolve URIs. |
762 // The builtin library is part of the core snapshot and would already be | 761 // The builtin library is part of the core snapshot and would already be |
763 // available here in the case of script snapshot loading. | 762 // available here in the case of script snapshot loading. |
764 Dart_Handle builtin_lib = | 763 Dart_Handle builtin_lib = |
765 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 764 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
766 CHECK_RESULT(builtin_lib); | 765 CHECK_RESULT(builtin_lib); |
767 | 766 |
768 // Prepare for script loading by setting up the 'print' and 'timer' | 767 // Prepare for script loading by setting up the 'print' and 'timer' |
769 // closures and setting up 'package root' for URI resolution. | 768 // closures and setting up 'package root' for URI resolution. |
770 result = DartUtils::PrepareForScriptLoading(package_root, | 769 result = DartUtils::PrepareForScriptLoading(package_root, |
771 package_map, | 770 packages_config, |
772 packages_file, | |
773 false, | 771 false, |
774 has_trace_loading, | 772 has_trace_loading, |
775 builtin_lib); | 773 builtin_lib); |
776 CHECK_RESULT(result); | 774 CHECK_RESULT(result); |
777 | 775 |
778 result = Dart_SetEnvironmentCallback(EnvironmentCallback); | 776 result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
779 CHECK_RESULT(result); | 777 CHECK_RESULT(result); |
780 | 778 |
781 if (!has_run_precompiled_snapshot) { | 779 if (!has_run_precompiled_snapshot) { |
782 // Load the script. | 780 // Load the script. |
(...skipping 25 matching lines...) Expand all Loading... |
808 | 806 |
809 return isolate; | 807 return isolate; |
810 } | 808 } |
811 | 809 |
812 #undef CHECK_RESULT | 810 #undef CHECK_RESULT |
813 | 811 |
814 | 812 |
815 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 813 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
816 const char* main, | 814 const char* main, |
817 const char* package_root, | 815 const char* package_root, |
818 const char** package_map, | 816 const char* package_config, |
819 Dart_IsolateFlags* flags, | 817 Dart_IsolateFlags* flags, |
820 void* data, char** error) { | 818 void* data, char** error) { |
821 // The VM should never call the isolate helper with a NULL flags. | 819 // The VM should never call the isolate helper with a NULL flags. |
822 ASSERT(flags != NULL); | 820 ASSERT(flags != NULL); |
823 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); | 821 ASSERT(flags->version == DART_FLAGS_CURRENT_VERSION); |
824 if ((package_root != NULL) && (package_map != NULL)) { | 822 if ((package_root != NULL) && (package_config != NULL)) { |
825 *error = strdup("Invalid arguments - Cannot simultaneously specify " | 823 *error = strdup("Invalid arguments - Cannot simultaneously specify " |
826 "package root and package map."); | 824 "package root and package map."); |
827 return NULL; | 825 return NULL; |
828 } | 826 } |
829 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data); | |
830 if (script_uri == NULL) { | |
831 if (data == NULL) { | |
832 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | |
833 return NULL; | |
834 } | |
835 script_uri = parent_isolate_data->script_url; | |
836 if (script_uri == NULL) { | |
837 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); | |
838 return NULL; | |
839 } | |
840 } | |
841 const char* packages_file = NULL; | |
842 // If neither a package root nor a package map are requested pass on the | |
843 // inherited values. | |
844 if ((package_root == NULL) && (package_map == NULL)) { | |
845 if (parent_isolate_data != NULL) { | |
846 package_root = parent_isolate_data->package_root; | |
847 packages_file = parent_isolate_data->packages_file; | |
848 } | |
849 } | |
850 | 827 |
851 int exit_code = 0; | 828 int exit_code = 0; |
852 return CreateIsolateAndSetupHelper(script_uri, | 829 return CreateIsolateAndSetupHelper(script_uri, |
853 main, | 830 main, |
854 package_root, | 831 package_root, |
855 package_map, | 832 package_config, |
856 packages_file, | |
857 flags, | 833 flags, |
858 error, | 834 error, |
859 &exit_code); | 835 &exit_code); |
860 } | 836 } |
861 | 837 |
862 | 838 |
863 static void PrintVersion() { | 839 static void PrintVersion() { |
864 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 840 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
865 } | 841 } |
866 | 842 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 bool RunMainIsolate(const char* script_name, | 1135 bool RunMainIsolate(const char* script_name, |
1160 CommandLineOptions* dart_options) { | 1136 CommandLineOptions* dart_options) { |
1161 // Call CreateIsolateAndSetup which creates an isolate and loads up | 1137 // Call CreateIsolateAndSetup which creates an isolate and loads up |
1162 // the specified application script. | 1138 // the specified application script. |
1163 char* error = NULL; | 1139 char* error = NULL; |
1164 int exit_code = 0; | 1140 int exit_code = 0; |
1165 char* isolate_name = BuildIsolateName(script_name, "main"); | 1141 char* isolate_name = BuildIsolateName(script_name, "main"); |
1166 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 1142 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
1167 "main", | 1143 "main", |
1168 commandline_package_root, | 1144 commandline_package_root, |
1169 NULL, | |
1170 commandline_packages_file, | 1145 commandline_packages_file, |
1171 NULL, | 1146 NULL, |
1172 &error, | 1147 &error, |
1173 &exit_code); | 1148 &exit_code); |
1174 if (isolate == NULL) { | 1149 if (isolate == NULL) { |
1175 delete [] isolate_name; | 1150 delete [] isolate_name; |
1176 if (exit_code == kRestartRequestExitCode) { | 1151 if (exit_code == kRestartRequestExitCode) { |
1177 free(error); | 1152 free(error); |
1178 return true; | 1153 return true; |
1179 } | 1154 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 } | 1205 } |
1231 | 1206 |
1232 if (has_noopt || has_gen_precompiled_snapshot) { | 1207 if (has_noopt || has_gen_precompiled_snapshot) { |
1233 Dart_QualifiedFunctionName standalone_entry_points[] = { | 1208 Dart_QualifiedFunctionName standalone_entry_points[] = { |
1234 { "dart:_builtin", "::", "_getMainClosure" }, | 1209 { "dart:_builtin", "::", "_getMainClosure" }, |
1235 { "dart:_builtin", "::", "_getPrintClosure" }, | 1210 { "dart:_builtin", "::", "_getPrintClosure" }, |
1236 { "dart:_builtin", "::", "_getUriBaseClosure" }, | 1211 { "dart:_builtin", "::", "_getUriBaseClosure" }, |
1237 { "dart:_builtin", "::", "_resolveUri" }, | 1212 { "dart:_builtin", "::", "_resolveUri" }, |
1238 { "dart:_builtin", "::", "_setWorkingDirectory" }, | 1213 { "dart:_builtin", "::", "_setWorkingDirectory" }, |
1239 { "dart:_builtin", "::", "_setPackageRoot" }, | 1214 { "dart:_builtin", "::", "_setPackageRoot" }, |
1240 { "dart:_builtin", "::", "_addPackageMapEntry" }, | |
1241 { "dart:_builtin", "::", "_loadPackagesMap" }, | 1215 { "dart:_builtin", "::", "_loadPackagesMap" }, |
1242 { "dart:_builtin", "::", "_loadDataAsync" }, | 1216 { "dart:_builtin", "::", "_loadDataAsync" }, |
1243 { "dart:io", "::", "_makeUint8ListView" }, | 1217 { "dart:io", "::", "_makeUint8ListView" }, |
1244 { "dart:io", "::", "_makeDatagram" }, | 1218 { "dart:io", "::", "_makeDatagram" }, |
1245 { "dart:io", "::", "_setupHooks" }, | 1219 { "dart:io", "::", "_setupHooks" }, |
1246 { "dart:io", "::", "_getWatchSignalInternal" }, | 1220 { "dart:io", "::", "_getWatchSignalInternal" }, |
1247 { "dart:io", "CertificateException", "CertificateException." }, | 1221 { "dart:io", "CertificateException", "CertificateException." }, |
1248 { "dart:io", "Directory", "Directory." }, | 1222 { "dart:io", "Directory", "Directory." }, |
1249 { "dart:io", "File", "File." }, | 1223 { "dart:io", "File", "File." }, |
1250 { "dart:io", "FileSystemException", "FileSystemException." }, | 1224 { "dart:io", "FileSystemException", "FileSystemException." }, |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 Platform::Exit(Process::GlobalExitCode()); | 1531 Platform::Exit(Process::GlobalExitCode()); |
1558 } | 1532 } |
1559 | 1533 |
1560 } // namespace bin | 1534 } // namespace bin |
1561 } // namespace dart | 1535 } // namespace dart |
1562 | 1536 |
1563 int main(int argc, char** argv) { | 1537 int main(int argc, char** argv) { |
1564 dart::bin::main(argc, argv); | 1538 dart::bin::main(argc, argv); |
1565 UNREACHABLE(); | 1539 UNREACHABLE(); |
1566 } | 1540 } |
OLD | NEW |