Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Unified Diff: runtime/bin/vmservice_impl.cc

Issue 584023004: Service isolate rework (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice_impl.cc
diff --git a/runtime/bin/vmservice_impl.cc b/runtime/bin/vmservice_impl.cc
index 18f06c1c3c02f446abe6527511e188de646bad62..513103d9077f793112eb1f9b13983547455a9ff5 100644
--- a/runtime/bin/vmservice_impl.cc
+++ b/runtime/bin/vmservice_impl.cc
@@ -129,36 +129,24 @@ static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name,
const char* VmService::error_msg_ = NULL;
-bool VmService::Start(const char *server_ip, intptr_t server_port) {
- bool r = _Start(server_ip, server_port);
- if (!r) {
- return r;
- }
- // Start processing messages in a new thread.
- Thread::Start(ThreadMain, static_cast<uword>(NULL));
- return true;
-}
+bool VmService::Setup(const char* server_ip, intptr_t server_port) {
+ Dart_Isolate isolate = Dart_CurrentIsolate();
+ ASSERT(isolate != NULL);
-bool VmService::_Start(const char *server_ip, intptr_t server_port) {
- ASSERT(Dart_CurrentIsolate() == NULL);
- Dart_Isolate isolate = Dart_GetServiceIsolate(NULL);
- if (isolate == NULL) {
- error_msg_ = "Dart_GetServiceIsolate failed.";
- return false;
- }
- Dart_EnterIsolate(isolate);
- Dart_EnterScope();
- // Install our own library tag handler.
- Dart_SetLibraryTagHandler(LibraryTagHandler);
Dart_Handle result;
- Dart_Handle library;
- library = LoadScript(kVMServiceIOLibraryScriptResourceName);
- // Expect a library.
+
+ // Load main script.
+ Dart_SetLibraryTagHandler(LibraryTagHandler);
+ Dart_Handle library = LoadScript(kVMServiceIOLibraryScriptResourceName);
ASSERT(library != Dart_Null());
SHUTDOWN_ON_ERROR(library);
+ result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL);
+ SHUTDOWN_ON_ERROR(result);
result = Dart_FinalizeLoading(false);
- ASSERT(!Dart_IsError(result));
+ SHUTDOWN_ON_ERROR(result);
+
+ // Make runnable.
Dart_ExitScope();
Dart_ExitIsolate();
bool retval = Dart_IsolateMakeRunnable(isolate);
@@ -168,13 +156,13 @@ bool VmService::_Start(const char *server_ip, intptr_t server_port) {
error_msg_ = "Invalid isolate state - Unable to make it runnable.";
return false;
}
-
Dart_EnterIsolate(isolate);
Dart_EnterScope();
+
library = Dart_RootLibrary();
- result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL);
- ASSERT(!Dart_IsError(result));
- // Set requested TCP port.
+ SHUTDOWN_ON_ERROR(library);
+
+ // Set HTTP server state.
DartUtils::SetStringField(library, "_ip", server_ip);
// If we have a port specified, start the server immediately.
bool auto_start = server_port >= 0;
@@ -183,33 +171,37 @@ bool VmService::_Start(const char *server_ip, intptr_t server_port) {
// port when the HTTP server is started.
server_port = 0;
}
- // Set initial state.
DartUtils::SetIntegerField(library, "_port", server_port);
- Dart_SetField(library,
- DartUtils::NewString("_autoStart"),
- Dart_NewBoolean(auto_start));
- // We cannot register for signals on windows.
+ result = Dart_SetField(library,
+ DartUtils::NewString("_autoStart"),
+ Dart_NewBoolean(auto_start));
+ SHUTDOWN_ON_ERROR(result);
+
+ // Are we running on Windows?
#if defined(TARGET_OS_WINDOWS)
Dart_Handle is_windows = Dart_True();
#else
Dart_Handle is_windows = Dart_False();
#endif
- Dart_SetField(library, DartUtils::NewString("_isWindows"), is_windows);
-
+ result =
+ Dart_SetField(library, DartUtils::NewString("_isWindows"), is_windows);
+ SHUTDOWN_ON_ERROR(result);
// Get _getWatchSignalInternal from dart:io.
Dart_Handle dart_io_str = Dart_NewStringFromCString(DartUtils::kIOLibURL);
+ SHUTDOWN_ON_ERROR(dart_io_str);
Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str);
+ SHUTDOWN_ON_ERROR(io_lib);
Dart_Handle function_name =
Dart_NewStringFromCString("_getWatchSignalInternal");
+ SHUTDOWN_ON_ERROR(function_name);
Dart_Handle signal_watch = Dart_Invoke(io_lib, function_name, 0, NULL);
- // Invoke main.
- result = Dart_Invoke(library, DartUtils::NewString("main"), 1, &signal_watch);
- SHUTDOWN_ON_ERROR(result);
-
- Dart_ExitScope();
- Dart_ExitIsolate();
-
+ SHUTDOWN_ON_ERROR(signal_watch);
+ Dart_Handle field_name = Dart_NewStringFromCString("_signalWatch");
+ SHUTDOWN_ON_ERROR(field_name);
+ result =
+ Dart_SetField(library, field_name, signal_watch);
+ SHUTDOWN_ON_ERROR(field_name);
return true;
}
@@ -337,20 +329,5 @@ Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag,
}
-void VmService::ThreadMain(uword parameters) {
- ASSERT(Dart_CurrentIsolate() == NULL);
- Dart_Isolate service_isolate = Dart_GetServiceIsolate(NULL);
- Dart_EnterIsolate(service_isolate);
- Dart_EnterScope();
- Dart_Handle result = Dart_RunLoop();
- if (Dart_IsError(result)) {
- printf("Service exited with an error:\n%s\n", Dart_GetError(result));
- }
- Dart_ExitScope();
- Dart_ExitIsolate();
-}
-
-
-
} // namespace bin
} // namespace dart

Powered by Google App Engine
This is Rietveld 408576698