Chromium Code Reviews| Index: runtime/bin/main.cc |
| diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc |
| index 59cf35a5a3199cefb7b9486f2950ca946d392468..d5ccd216aa0a9bd5fe67f78c8cc6b88f53d24e16 100644 |
| --- a/runtime/bin/main.cc |
| +++ b/runtime/bin/main.cc |
| @@ -524,26 +524,23 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, |
| return NULL; |
| } |
| + |
| Platform::SetPackageRoot(package_root); |
| - Dart_Handle io_lib_url = DartUtils::NewString("dart:io"); |
| + Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL); |
| CHECK_RESULT(io_lib_url); |
| Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); |
| CHECK_RESULT(io_lib); |
| - Dart_Handle platform_class_name = DartUtils::NewString("Platform"); |
| - CHECK_RESULT(platform_class_name); |
| - Dart_Handle platform_type = |
| - Dart_GetType(io_lib, platform_class_name, 0, NULL); |
| + Dart_Handle platform_type = DartUtils::GetDartType(DartUtils::kIOLibURL, |
| + "Platform"); |
| CHECK_RESULT(platform_type); |
| - Dart_Handle script_name_name = DartUtils::NewString("_nativeScript"); |
| - CHECK_RESULT(script_name_name); |
| + Dart_Handle script_name = DartUtils::NewString("_nativeScript"); |
| + CHECK_RESULT(script_name); |
| Dart_Handle dart_script = DartUtils::NewString(script_uri); |
| CHECK_RESULT(dart_script); |
| Dart_Handle set_script_name = |
| - Dart_SetField(platform_type, script_name_name, dart_script); |
| + Dart_SetField(platform_type, script_name, dart_script); |
| CHECK_RESULT(set_script_name); |
| - VmService::SendIsolateStartupMessage(); |
| - |
| // Make the isolate runnable so that it is ready to handle messages. |
| Dart_ExitScope(); |
| Dart_ExitIsolate(); |
| @@ -584,6 +581,58 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
| } |
| +static Dart_Isolate CreateServiceIsolate(void* data, char** error) { |
| + const char* script_uri = DartUtils::kVMServiceLibURL; |
| + // These two variables are used by the CHECK_RESULT macro. |
| + bool is_compile_error_ = false; |
| + bool *is_compile_error = &is_compile_error_; |
|
siva
2014/01/14 18:19:00
Instead of these dummy variables define a version
Cutch
2014/01/14 19:53:26
Done.
|
| + IsolateData* isolate_data = new IsolateData(script_uri); |
| + Dart_Isolate isolate = |
| + Dart_CreateIsolate(script_uri, "main", snapshot_buffer, isolate_data, |
| + error); |
| + if (isolate == NULL) { |
| + return NULL; |
| + } |
| + Dart_EnterScope(); |
| + if (snapshot_buffer != NULL) { |
| + // Setup the native resolver as the snapshot does not carry it. |
| + Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| + Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| + } |
| + // Set up the library tag handler for this isolate. |
| + Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| + CHECK_RESULT(result); |
| + result = Dart_SetEnvironmentCallback(EnvironmentCallback); |
| + CHECK_RESULT(result); |
| + // Prepare builtin and its dependent libraries for use to resolve URIs. |
| + Dart_Handle builtin_lib = |
| + Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| + CHECK_RESULT(builtin_lib); |
| + // Prepare for script loading by setting up the 'print' and 'timer' |
| + // closures and setting up 'package root' for URI resolution. |
| + result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); |
| + CHECK_RESULT(result); |
| + Platform::SetPackageRoot(package_root); |
| + Dart_Handle io_lib_url = DartUtils::NewString(DartUtils::kIOLibURL); |
| + CHECK_RESULT(io_lib_url); |
| + Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); |
| + CHECK_RESULT(io_lib); |
| + Dart_Handle platform_type = DartUtils::GetDartType(DartUtils::kIOLibURL, |
| + "Platform"); |
| + CHECK_RESULT(platform_type); |
| + Dart_Handle script_name = DartUtils::NewString("_nativeScript"); |
| + CHECK_RESULT(script_name); |
| + Dart_Handle dart_script = DartUtils::NewString(script_uri); |
| + CHECK_RESULT(dart_script); |
| + Dart_Handle set_script_name = |
| + Dart_SetField(platform_type, script_name, dart_script); |
| + CHECK_RESULT(set_script_name); |
| + Dart_ExitScope(); |
| + Dart_ExitIsolate(); |
| + return isolate; |
| +} |
|
siva
2014/01/14 18:19:00
Another point, this function above looks identical
|
| + |
| + |
| static void PrintVersion() { |
| Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
| } |
| @@ -716,7 +765,6 @@ static void DartExitOnError(Dart_Handle error) { |
| static void ShutdownIsolate(void* callback_data) { |
| - VmService::VmServiceShutdownCallback(callback_data); |
| IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
| delete isolate_data; |
| } |
| @@ -812,7 +860,8 @@ void main(int argc, char** argv) { |
| DartUtils::ReadFile, |
| DartUtils::WriteFile, |
| DartUtils::CloseFile, |
| - DartUtils::EntropySource)) { |
| + DartUtils::EntropySource, |
| + CreateServiceIsolate)) { |
|
siva
2014/01/14 18:19:00
Another option for the next round of refactoring i
Cutch
2014/01/14 19:53:26
Agreed, the next round of refactoring can clean th
|
| fprintf(stderr, "%s", "VM initialization failed\n"); |
| fflush(stderr); |
| exit(kErrorExitCode); |