Chromium Code Reviews| 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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 #else | 792 #else |
| 793 // Always create the service isolate in DEBUG and RELEASE modes for profiling, | 793 // Always create the service isolate in DEBUG and RELEASE modes for profiling, |
| 794 // even if we don't need it for loading. | 794 // even if we don't need it for loading. |
| 795 const bool run_service_isolate = true; | 795 const bool run_service_isolate = true; |
| 796 #endif // PRODUCT | 796 #endif // PRODUCT |
| 797 if (!run_service_isolate && | 797 if (!run_service_isolate && |
| 798 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { | 798 (strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0)) { |
| 799 return NULL; | 799 return NULL; |
| 800 } | 800 } |
| 801 | 801 |
| 802 // If the script is Dart Kernel IL, then we will try to bootstrap from the | |
| 803 // script. | |
| 804 const uint8_t* kernel_file = NULL; | |
| 805 intptr_t kernel_length = -1; | |
| 806 const bool is_kernel = | |
| 807 !run_app_snapshot && | |
| 808 TryReadKernel(script_uri, &kernel_file, &kernel_length); | |
|
hausner
2016/11/09 00:42:49
What if the uri scheme is not a file?
Vyacheslav Egorov (Google)
2016/11/09 14:43:15
We don't support loading kernel from non local URI
| |
| 809 | |
| 802 IsolateData* isolate_data = | 810 IsolateData* isolate_data = |
| 803 new IsolateData(script_uri, package_root, packages_config); | 811 new IsolateData(script_uri, package_root, packages_config); |
| 804 Dart_Isolate isolate = Dart_CreateIsolate( | 812 Dart_Isolate isolate = |
| 805 script_uri, main, isolate_snapshot_buffer, flags, isolate_data, error); | 813 is_kernel ? Dart_CreateIsolateFromKernel(script_uri, main, kernel_file, |
| 814 kernel_length, flags, | |
| 815 isolate_data, error) | |
| 816 : Dart_CreateIsolate(script_uri, main, isolate_snapshot_buffer, | |
| 817 flags, isolate_data, error); | |
| 818 if (is_kernel) { | |
| 819 free(const_cast<uint8_t*>(kernel_file)); | |
| 820 } | |
| 821 | |
| 806 if (isolate == NULL) { | 822 if (isolate == NULL) { |
| 807 delete isolate_data; | 823 delete isolate_data; |
| 808 return NULL; | 824 return NULL; |
| 809 } | 825 } |
| 810 | 826 |
| 811 Dart_EnterScope(); | 827 Dart_EnterScope(); |
| 812 | 828 |
| 813 if (isolate_snapshot_buffer != NULL) { | 829 // Set up the library tag handler for this isolate. |
| 830 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | |
| 831 CHECK_RESULT(result); | |
| 832 | |
| 833 if (is_kernel) { | |
| 834 // TODO(27590): We should not read the kernel file again! | |
| 835 if (!TryReadKernel(script_uri, &kernel_file, &kernel_length)) { | |
| 836 FATAL("Failed to read kernel second time"); | |
| 837 } | |
| 838 Dart_Handle result = Dart_LoadKernel(kernel_file, kernel_length); | |
| 839 free(const_cast<uint8_t*>(kernel_file)); | |
| 840 CHECK_RESULT(result); | |
| 841 } | |
| 842 if (is_kernel || (isolate_snapshot_buffer != NULL)) { | |
| 814 // Setup the native resolver as the snapshot does not carry it. | 843 // Setup the native resolver as the snapshot does not carry it. |
| 815 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 844 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 816 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 845 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 817 } | 846 } |
| 818 | 847 |
| 819 // Set up the library tag handler for this isolate. | |
| 820 Dart_Handle result = Dart_SetLibraryTagHandler(Loader::LibraryTagHandler); | |
| 821 CHECK_RESULT(result); | |
| 822 | |
| 823 if (Dart_IsServiceIsolate(isolate)) { | 848 if (Dart_IsServiceIsolate(isolate)) { |
| 824 // If this is the service isolate, load embedder specific bits and return. | 849 // If this is the service isolate, load embedder specific bits and return. |
| 825 bool skip_library_load = run_app_snapshot; | 850 bool skip_library_load = run_app_snapshot; |
| 826 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, | 851 if (!VmService::Setup(vm_service_server_ip, vm_service_server_port, |
| 827 skip_library_load, vm_service_dev_mode)) { | 852 skip_library_load, vm_service_dev_mode)) { |
| 828 *error = strdup(VmService::GetErrorMessage()); | 853 *error = strdup(VmService::GetErrorMessage()); |
| 829 return NULL; | 854 return NULL; |
| 830 } | 855 } |
| 831 if (compile_all) { | 856 if (compile_all) { |
| 832 result = Dart_CompileAll(); | 857 result = Dart_CompileAll(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 859 | 884 |
| 860 if (run_app_snapshot) { | 885 if (run_app_snapshot) { |
| 861 result = DartUtils::SetupIOLibrary(script_uri); | 886 result = DartUtils::SetupIOLibrary(script_uri); |
| 862 CHECK_RESULT(result); | 887 CHECK_RESULT(result); |
| 863 Loader::InitForSnapshot(script_uri); | 888 Loader::InitForSnapshot(script_uri); |
| 864 } else { | 889 } else { |
| 865 // Load the specified application script into the newly created isolate. | 890 // Load the specified application script into the newly created isolate. |
| 866 Dart_Handle uri = | 891 Dart_Handle uri = |
| 867 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); | 892 DartUtils::ResolveScript(Dart_NewStringFromCString(script_uri)); |
| 868 CHECK_RESULT(uri); | 893 CHECK_RESULT(uri); |
| 869 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); | 894 if (!is_kernel) { |
| 870 CHECK_RESULT(result); | 895 result = Loader::LibraryTagHandler(Dart_kScriptTag, Dart_Null(), uri); |
| 896 CHECK_RESULT(result); | |
| 897 } | |
| 871 | 898 |
| 872 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), | 899 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), |
| 873 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0, | 900 Dart_GetMainPortId(), Dart_Timeline_Event_Async_End, 0, |
| 874 NULL, NULL); | 901 NULL, NULL); |
| 875 | 902 |
| 876 result = DartUtils::SetupIOLibrary(script_uri); | 903 result = DartUtils::SetupIOLibrary(script_uri); |
| 877 CHECK_RESULT(result); | 904 CHECK_RESULT(result); |
| 878 } | 905 } |
| 879 | 906 |
| 880 // Make the isolate runnable so that it is ready to handle messages. | 907 // Make the isolate runnable so that it is ready to handle messages. |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1912 Platform::Exit(Process::GlobalExitCode()); | 1939 Platform::Exit(Process::GlobalExitCode()); |
| 1913 } | 1940 } |
| 1914 | 1941 |
| 1915 } // namespace bin | 1942 } // namespace bin |
| 1916 } // namespace dart | 1943 } // namespace dart |
| 1917 | 1944 |
| 1918 int main(int argc, char** argv) { | 1945 int main(int argc, char** argv) { |
| 1919 dart::bin::main(argc, argv); | 1946 dart::bin::main(argc, argv); |
| 1920 UNREACHABLE(); | 1947 UNREACHABLE(); |
| 1921 } | 1948 } |
| OLD | NEW |