Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_impl.h" | 5 #include "bin/vmservice_impl.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 Dart_ShutdownIsolate(); | 136 Dart_ShutdownIsolate(); |
| 137 error_msg_ = "Invalid isolate state - Unable to make it runnable."; | 137 error_msg_ = "Invalid isolate state - Unable to make it runnable."; |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 | 140 |
| 141 Dart_EnterIsolate(isolate_); | 141 Dart_EnterIsolate(isolate_); |
| 142 Dart_EnterScope(); | 142 Dart_EnterScope(); |
| 143 | 143 |
| 144 | 144 |
| 145 Dart_Handle library = Dart_RootLibrary(); | 145 Dart_Handle library = Dart_RootLibrary(); |
| 146 // Set requested port. | 146 // Set requested TCP port. |
| 147 DartUtils::SetIntegerField(library, "_port", server_port); | 147 DartUtils::SetIntegerField(library, "_port", server_port); |
| 148 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | 148 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| 149 SHUTDOWN_ON_ERROR(result); | 149 SHUTDOWN_ON_ERROR(result); |
| 150 | 150 |
| 151 // Retrieve the ReceivePort that the service is waiting on. The _receivePort | |
| 152 // variable is setup in the call to main. | |
| 153 Dart_Handle receivePort = Dart_GetField(library, | |
| 154 DartUtils::NewString("_receivePort")); | |
| 155 SHUTDOWN_ON_ERROR(receivePort); | |
| 156 | |
| 157 { | |
| 158 // Extract the Dart_Port from the receive port. | |
| 159 HANDLESCOPE(Isolate::Current()); | |
| 160 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); | |
| 161 const Instance& rp = Instance::Cast(unwrapped_rp); | |
| 162 // Extract ReceivePort port id. | |
| 163 const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp)); | |
| 164 if (rp_id_obj.IsError()) { | |
| 165 const Error& error = Error::Cast(rp_id_obj); | |
| 166 error_msg_ = strdup(error.ToErrorCString()); | |
| 167 Dart_ExitScope(); | |
| 168 Dart_ShutdownIsolate(); | |
| 169 return false; | |
| 170 } | |
| 171 ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint()); | |
| 172 Integer& id = Integer::Handle(); | |
| 173 id ^= rp_id_obj.raw(); | |
| 174 port_ = static_cast<Dart_Port>(id.AsInt64Value()); | |
| 175 } | |
| 176 | |
| 151 Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName); | 177 Dart_Handle library_name = Dart_NewStringFromCString(kVMServiceLibraryName); |
| 152 library = Dart_LookupLibrary(library_name); | 178 library = Dart_LookupLibrary(library_name); |
| 153 SHUTDOWN_ON_ERROR(library); | 179 SHUTDOWN_ON_ERROR(library); |
| 154 result = LoadResources(library); | 180 result = LoadResources(library); |
| 155 SHUTDOWN_ON_ERROR(result); | 181 SHUTDOWN_ON_ERROR(result); |
| 156 result = Dart_CompileAll(); | |
| 157 SHUTDOWN_ON_ERROR(result); | |
| 158 | |
| 159 port_ = Dart_GetMainPortId(); | |
| 160 | 182 |
| 161 Dart_ExitScope(); | 183 Dart_ExitScope(); |
| 162 Dart_ExitIsolate(); | 184 Dart_ExitIsolate(); |
| 163 | 185 |
| 164 return true; | 186 return true; |
| 165 } | 187 } |
| 166 | 188 |
| 167 | 189 |
| 168 void VmService::_Stop() { | 190 void VmService::_Stop() { |
| 169 port_ = ILLEGAL_PORT; | 191 port_ = ILLEGAL_PORT; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 printf("VmService has exited with an error:\n%s\n", Dart_GetError(result)); | 407 printf("VmService has exited with an error:\n%s\n", Dart_GetError(result)); |
| 386 } | 408 } |
| 387 | 409 |
| 388 _Stop(); | 410 _Stop(); |
| 389 | 411 |
| 390 Dart_ExitScope(); | 412 Dart_ExitScope(); |
| 391 Dart_ExitIsolate(); | 413 Dart_ExitIsolate(); |
| 392 } | 414 } |
| 393 | 415 |
| 394 | 416 |
| 395 static Dart_Handle MakeServiceControlMessage(Dart_Port port, intptr_t code) { | 417 static Dart_Handle MakeServiceControlMessage(Dart_Port port_id, intptr_t code) { |
| 396 Dart_Handle result; | 418 Dart_Handle result; |
| 397 Dart_Handle list = Dart_NewList(3); | 419 Dart_Handle list = Dart_NewList(4); |
|
Ivan Posva
2013/10/29 03:35:50
You only set 3 values in an array of 4 elements. I
Cutch
2013/10/29 05:24:57
Done.
| |
| 398 ASSERT(!Dart_IsError(list)); | 420 ASSERT(!Dart_IsError(list)); |
| 399 Dart_Handle codeHandle = Dart_NewInteger(code); | 421 Dart_Handle code_handle = Dart_NewInteger(code); |
| 400 ASSERT(!Dart_IsError(codeHandle)); | 422 ASSERT(!Dart_IsError(code_handle)); |
| 401 result = Dart_ListSetAt(list, 0, codeHandle); | 423 result = Dart_ListSetAt(list, 0, code_handle); |
| 402 ASSERT(!Dart_IsError(result)); | 424 ASSERT(!Dart_IsError(result)); |
| 403 Dart_Handle sendPort = Dart_NewSendPort(port); | 425 Dart_Handle port_id_handle = Dart_NewInteger(port_id); |
| 426 ASSERT(!Dart_IsError(port_id_handle)); | |
| 427 result = Dart_ListSetAt(list, 1, port_id_handle); | |
|
Ivan Posva
2013/10/29 03:35:50
Why are you sending both the port_id and the SendP
Cutch
2013/10/29 05:24:57
Discussed offline: port_id is the unique key that
| |
| 428 ASSERT(!Dart_IsError(result)); | |
| 429 Dart_Handle sendPort = Dart_NewSendPort(port_id); | |
| 404 ASSERT(!Dart_IsError(sendPort)); | 430 ASSERT(!Dart_IsError(sendPort)); |
| 405 result = Dart_ListSetAt(list, 1, sendPort); | 431 result = Dart_ListSetAt(list, 2, sendPort); |
| 406 ASSERT(!Dart_IsError(result)); | 432 ASSERT(!Dart_IsError(result)); |
| 407 return list; | 433 return list; |
| 408 } | 434 } |
| 409 | 435 |
| 410 | 436 |
| 411 bool VmService::SendIsolateStartupMessage(Dart_Port port, Dart_Handle name) { | 437 bool VmService::SendIsolateStartupMessage() { |
| 412 if (!IsRunning()) { | 438 if (!IsRunning()) { |
| 413 return false; | 439 return false; |
| 414 } | 440 } |
| 415 Dart_Isolate isolate = Dart_CurrentIsolate(); | 441 Isolate* isolate = Isolate::Current(); |
| 416 ASSERT(isolate != NULL); | 442 ASSERT(isolate != NULL); |
| 417 ASSERT(Dart_GetMainPortId() == port); | 443 HANDLESCOPE(isolate); |
| 418 Dart_Handle list = | 444 Dart_Handle list = |
| 419 MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID); | 445 MakeServiceControlMessage(Dart_GetMainPortId(), |
| 446 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID); | |
| 420 ASSERT(!Dart_IsError(list)); | 447 ASSERT(!Dart_IsError(list)); |
| 421 Dart_Handle result = Dart_ListSetAt(list, 2, name); | 448 Dart_Handle name = Api::NewHandle(isolate, String::New(isolate->name())); |
| 449 Dart_Handle result = Dart_ListSetAt(list, 3, name); | |
| 422 ASSERT(!Dart_IsError(result)); | 450 ASSERT(!Dart_IsError(result)); |
| 423 return Dart_Post(port_, list); | 451 return Dart_Post(port_, list); |
| 424 } | 452 } |
| 425 | 453 |
| 426 | 454 |
| 427 bool VmService::SendIsolateShutdownMessage(Dart_Port port) { | 455 bool VmService::SendIsolateShutdownMessage() { |
| 428 if (!IsRunning()) { | 456 if (!IsRunning()) { |
| 429 return false; | 457 return false; |
| 430 } | 458 } |
| 431 Dart_Isolate isolate = Dart_CurrentIsolate(); | 459 Isolate* isolate = Isolate::Current(); |
| 432 ASSERT(isolate != NULL); | 460 ASSERT(isolate != NULL); |
| 433 ASSERT(Dart_GetMainPortId() == port); | 461 HANDLESCOPE(isolate); |
| 434 Dart_Handle list = | 462 Dart_Handle list = |
| 435 MakeServiceControlMessage(port, VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID); | 463 MakeServiceControlMessage(Dart_GetMainPortId(), |
| 464 VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID); | |
| 436 ASSERT(!Dart_IsError(list)); | 465 ASSERT(!Dart_IsError(list)); |
| 437 return Dart_Post(port_, list); | 466 return Dart_Post(port_, list); |
| 438 } | 467 } |
| 439 | 468 |
| 440 | 469 |
| 441 void VmService::VmServiceShutdownCallback(void* callback_data) { | 470 void VmService::VmServiceShutdownCallback(void* callback_data) { |
| 442 ASSERT(Dart_CurrentIsolate() != NULL); | 471 ASSERT(Dart_CurrentIsolate() != NULL); |
| 443 Dart_EnterScope(); | 472 Dart_EnterScope(); |
| 444 VmService::SendIsolateShutdownMessage(Dart_GetMainPortId()); | 473 VmService::SendIsolateShutdownMessage(); |
| 445 Dart_ExitScope(); | 474 Dart_ExitScope(); |
| 446 } | 475 } |
| 447 | 476 |
| 448 | 477 |
| 449 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 478 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| 450 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 479 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 451 return reinterpret_cast<uint8_t*>(new_ptr); | 480 return reinterpret_cast<uint8_t*>(new_ptr); |
| 452 } | 481 } |
| 453 | 482 |
| 454 | 483 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 if (!strcmp(function_name, entry.name) && | 550 if (!strcmp(function_name, entry.name) && |
| 522 (num_arguments == entry.num_arguments)) { | 551 (num_arguments == entry.num_arguments)) { |
| 523 return entry.function; | 552 return entry.function; |
| 524 } | 553 } |
| 525 } | 554 } |
| 526 return NULL; | 555 return NULL; |
| 527 } | 556 } |
| 528 | 557 |
| 529 } // namespace bin | 558 } // namespace bin |
| 530 } // namespace dart | 559 } // namespace dart |
| OLD | NEW |