| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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/vmservice_dartium.h" | 5 #include "bin/vmservice_dartium.h" |
| 6 | 6 |
| 7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
| 8 #include "bin/dartutils.h" | 8 #include "bin/dartutils.h" |
| 9 #include "bin/eventhandler.h" | 9 #include "bin/eventhandler.h" |
| 10 #include "bin/platform.h" | 10 #include "bin/platform.h" |
| 11 #include "bin/thread.h" | 11 #include "bin/thread.h" |
| 12 #include "bin/vmservice_impl.h" | 12 #include "bin/vmservice_impl.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 namespace bin { | 15 namespace bin { |
| 16 | 16 |
| 17 #define CHECK_RESULT(result) \ | 17 #define CHECK_RESULT(result) \ |
| 18 if (Dart_IsError(result)) { \ | 18 if (Dart_IsError(result)) { \ |
| 19 fprintf(stderr, "CHECK_RESULT failed: %s", Dart_GetError(result)); \ | 19 fprintf(stderr, "CHECK_RESULT failed: %s", Dart_GetError(result)); \ |
| 20 Dart_ExitScope(); \ | 20 Dart_ExitScope(); \ |
| 21 Dart_ShutdownIsolate(); \ | 21 Dart_ShutdownIsolate(); \ |
| 22 return 0; \ | 22 return 0; \ |
| 23 } \ | 23 } \ |
| 24 | 24 |
| 25 | 25 |
| 26 | 26 |
| 27 // isolate_snapshot_buffer points to a snapshot if we link in a snapshot | |
| 28 // otherwise it is initialized to NULL. | |
| 29 extern const uint8_t* isolate_snapshot_buffer; | |
| 30 | |
| 31 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; | 27 static const char* DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
| 32 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 0; | 28 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 0; |
| 33 | 29 |
| 34 void VmServiceServer::Bootstrap() { | 30 void VmServiceServer::Bootstrap() { |
| 35 if (!Platform::Initialize()) { | 31 if (!Platform::Initialize()) { |
| 36 fprintf(stderr, "Platform::Initialize() failed\n"); | 32 fprintf(stderr, "Platform::Initialize() failed\n"); |
| 37 } | 33 } |
| 38 DartUtils::SetOriginalWorkingDirectory(); | 34 DartUtils::SetOriginalWorkingDirectory(); |
| 39 Thread::InitOnce(); | 35 Thread::InitOnce(); |
| 40 EventHandler::Start(); | 36 EventHandler::Start(); |
| 41 } | 37 } |
| 42 | 38 |
| 43 | 39 |
| 44 Dart_Isolate VmServiceServer::CreateIsolate() { | 40 Dart_Isolate VmServiceServer::CreateIsolate(const uint8_t* snapshot_buffer) { |
| 45 ASSERT(isolate_snapshot_buffer != NULL); | 41 ASSERT(snapshot_buffer != NULL); |
| 46 // Create the isolate. | 42 // Create the isolate. |
| 47 char* error = 0; | 43 char* error = 0; |
| 48 Dart_Isolate isolate = Dart_CreateIsolate(DART_VM_SERVICE_ISOLATE_NAME, | 44 Dart_Isolate isolate = Dart_CreateIsolate(DART_VM_SERVICE_ISOLATE_NAME, |
| 49 "main", | 45 "main", |
| 50 dart::bin::isolate_snapshot_buffer, | 46 snapshot_buffer, |
| 51 NULL, | 47 NULL, |
| 52 &error); | 48 &error); |
| 53 if (!isolate) { | 49 if (!isolate) { |
| 54 fprintf(stderr, "Dart_CreateIsolate failed: %s\n", error); | 50 fprintf(stderr, "Dart_CreateIsolate failed: %s\n", error); |
| 55 return 0; | 51 return 0; |
| 56 } | 52 } |
| 57 | 53 |
| 58 Dart_EnterScope(); | 54 Dart_EnterScope(); |
| 59 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | |
| 60 Builtin::SetNativeResolver(Builtin::kIOLibrary); | |
| 61 | 55 |
| 56 Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| 62 Dart_Handle builtin_lib = | 57 Dart_Handle builtin_lib = |
| 63 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 58 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 64 CHECK_RESULT(builtin_lib); | 59 CHECK_RESULT(builtin_lib); |
| 60 Dart_Handle io_lib = |
| 61 Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 62 CHECK_RESULT(io_lib); |
| 65 | 63 |
| 66 Dart_Handle result; | 64 Dart_Handle result; |
| 67 | 65 |
| 68 // Prepare for script loading by setting up the 'print' and 'timer' | 66 // Prepare for script loading by setting up the 'print' and 'timer' |
| 69 // closures and setting up 'package root' for URI resolution. | 67 // closures and setting up 'package root' for URI resolution. |
| 70 result = DartUtils::PrepareForScriptLoading(NULL, true, false, builtin_lib); | 68 result = DartUtils::PrepareForScriptLoading(NULL, true, false, builtin_lib); |
| 71 CHECK_RESULT(result); | 69 CHECK_RESULT(result); |
| 72 | 70 |
| 73 ASSERT(Dart_IsServiceIsolate(isolate)); | 71 ASSERT(Dart_IsServiceIsolate(isolate)); |
| 74 if (!VmService::Setup(DEFAULT_VM_SERVICE_SERVER_IP, | 72 if (!VmService::Setup(DEFAULT_VM_SERVICE_SERVER_IP, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 94 | 92 |
| 95 | 93 |
| 96 /* DISALLOW_ALLOCATION */ | 94 /* DISALLOW_ALLOCATION */ |
| 97 void VmServiceServer::operator delete(void* pointer) { | 95 void VmServiceServer::operator delete(void* pointer) { |
| 98 fprintf(stderr, "unreachable code\n"); | 96 fprintf(stderr, "unreachable code\n"); |
| 99 abort(); | 97 abort(); |
| 100 } | 98 } |
| 101 | 99 |
| 102 } // namespace bin | 100 } // namespace bin |
| 103 } // namespace dart | 101 } // namespace dart |
| OLD | NEW |