Chromium Code Reviews| Index: runtime/bin/vmservice_impl.cc |
| diff --git a/runtime/bin/vmservice_impl.cc b/runtime/bin/vmservice_impl.cc |
| index 320d3dacdf6e60e1b694fc5e09964004870b161a..297b19f92d07a0ba66e7508cfe7ada38823bf6a4 100644 |
| --- a/runtime/bin/vmservice_impl.cc |
| +++ b/runtime/bin/vmservice_impl.cc |
| @@ -141,10 +141,36 @@ bool VmService::_Start(intptr_t server_port) { |
| Dart_Handle library = Dart_RootLibrary(); |
| - // Set requested port. |
| + // Set requested TCP port. |
| DartUtils::SetIntegerField(library, "_port", server_port); |
| result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| SHUTDOWN_ON_ERROR(result); |
| + // Retrieve the ReceivePort that the service is waiting on. The _receivePort |
| + // variable is setup in the call to main. |
| + Dart_Handle receivePort = Dart_GetField(library, |
|
Ivan Posva
2013/10/25 00:30:27
I generally find this mix of external C API and in
Cutch
2013/10/25 01:21:57
The external API does not offer functionality to m
|
| + DartUtils::NewString("_receivePort")); |
| + SHUTDOWN_ON_ERROR(receivePort); |
| + |
| + { |
| + // Extract the Dart_Port from the receive port. |
| + HANDLESCOPE(Isolate::Current()); |
| + const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); |
| + const Instance& rp = Instance::Cast(unwrapped_rp); |
| + // Extract ReceivePort port id. |
| + const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp)); |
| + if (rp_id_obj.IsError()) { |
| + const Error& error = Error::Cast(rp_id_obj); |
| + error_msg_ = strdup(error.ToErrorCString()); |
| + Dart_ExitScope(); |
| + Dart_ShutdownIsolate(); |
| + return false; |
| + } |
| + ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint()); |
| + Integer& id = Integer::Handle(); |
| + id ^= rp_id_obj.raw(); |
| + port_ = static_cast<Dart_Port>(id.AsInt64Value()); |
| + } |
| + |
| Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName); |
| library = Dart_LookupLibrary(library_name); |
| @@ -154,8 +180,6 @@ bool VmService::_Start(intptr_t server_port) { |
| result = Dart_CompileAll(); |
|
Ivan Posva
2013/10/25 00:30:27
Please remove this or at least make it optional ba
Cutch
2013/10/25 01:21:57
Done.
|
| SHUTDOWN_ON_ERROR(result); |
| - port_ = Dart_GetMainPortId(); |
| - |
| Dart_ExitScope(); |
| Dart_ExitIsolate(); |
| @@ -406,31 +430,38 @@ static Dart_Handle MakeServiceControlMessage(Dart_Port port, intptr_t code) { |
| } |
| -bool VmService::SendIsolateStartupMessage(Dart_Port port, Dart_Handle name) { |
| +bool VmService::SendIsolateStartupMessage() { |
| if (!IsRunning()) { |
| return false; |
| } |
| - Dart_Isolate isolate = Dart_CurrentIsolate(); |
| + Isolate* isolate = Isolate::Current(); |
| ASSERT(isolate != NULL); |
| - ASSERT(Dart_GetMainPortId() == port); |
| + StackZone zone(isolate); |
|
Ivan Posva
2013/10/25 00:30:27
ditto.
Cutch
2013/10/25 01:21:57
Done.
|
| + HANDLESCOPE(isolate); |
| + Dart_Port service_port = isolate->service_port(); |
| Dart_Handle list = |
| - MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID); |
| + MakeServiceControlMessage(service_port, |
| + VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID); |
| ASSERT(!Dart_IsError(list)); |
| + Dart_Handle name = Api::NewHandle(isolate, String::New(isolate->name())); |
| Dart_Handle result = Dart_ListSetAt(list, 2, name); |
| ASSERT(!Dart_IsError(result)); |
| return Dart_Post(port_, list); |
| } |
| -bool VmService::SendIsolateShutdownMessage(Dart_Port port) { |
| +bool VmService::SendIsolateShutdownMessage() { |
| if (!IsRunning()) { |
| return false; |
| } |
| - Dart_Isolate isolate = Dart_CurrentIsolate(); |
| + Isolate* isolate = Isolate::Current(); |
| ASSERT(isolate != NULL); |
| - ASSERT(Dart_GetMainPortId() == port); |
| + StackZone zone(isolate); |
| + HANDLESCOPE(isolate); |
| + Dart_Port service_port = isolate->service_port(); |
| Dart_Handle list = |
| - MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID); |
| + MakeServiceControlMessage(service_port, |
| + VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID); |
| ASSERT(!Dart_IsError(list)); |
| return Dart_Post(port_, list); |
| } |
| @@ -439,7 +470,7 @@ bool VmService::SendIsolateShutdownMessage(Dart_Port port) { |
| void VmService::VmServiceShutdownCallback(void* callback_data) { |
| ASSERT(Dart_CurrentIsolate() != NULL); |
| Dart_EnterScope(); |
| - VmService::SendIsolateShutdownMessage(Dart_GetMainPortId()); |
| + VmService::SendIsolateShutdownMessage(); |
| Dart_ExitScope(); |
| } |