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

Unified Diff: runtime/bin/main.cc

Issue 889443002: Service isolate rework take 2 (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
« no previous file with comments | « runtime/bin/io_impl_sources.gypi ('k') | runtime/bin/platform.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/main.cc
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index ed4726300561835410a8fc9a814a0b11b6516024..72012bafc59f5cf4bc524f96530a1c9f969b88e2 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -546,6 +546,7 @@ static Dart_Handle EnvironmentCallback(Dart_Handle name) {
return NULL; \
} \
+
// Returns true on success, false on failure.
static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
const char* main,
@@ -554,8 +555,14 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
bool* is_compile_error) {
ASSERT(script_uri != NULL);
IsolateData* isolate_data = new IsolateData(script_uri, package_root);
- Dart_Isolate isolate = Dart_CreateIsolate(
- script_uri, main, snapshot_buffer, isolate_data, error);
+ Dart_Isolate isolate = NULL;
+
+ isolate = Dart_CreateIsolate(script_uri,
+ main,
+ snapshot_buffer,
+ isolate_data,
+ error);
+
if (isolate == NULL) {
return NULL;
}
@@ -568,15 +575,23 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
Builtin::SetNativeResolver(Builtin::kIOLibrary);
}
+ if (Dart_IsServiceIsolate(isolate)) {
+ // If this is the service isolate, load embedder specific bits and return.
+ if (!VmService::Setup(vm_service_server_ip, vm_service_server_port)) {
+ *error = strdup(VmService::GetErrorMessage());
+ return NULL;
+ }
+ Dart_ExitScope();
+ Dart_ExitIsolate();
+ return isolate;
+ }
+
+ // Load the specified application script into the newly created isolate.
+
// 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);
-
- // Load the specified application script into the newly created isolate.
-
// Prepare builtin and its dependent libraries for use to resolve URIs.
// The builtin library is part of the core snapshot and would already be
// available here in the case of script snapshot loading.
@@ -586,9 +601,13 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
// 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);
+ result = DartUtils::PrepareForScriptLoading(package_root, false, builtin_lib);
+ CHECK_RESULT(result);
+
+ result = Dart_SetEnvironmentCallback(EnvironmentCallback);
CHECK_RESULT(result);
+ // Load the script.
result = DartUtils::LoadScript(script_uri, builtin_lib);
CHECK_RESULT(result);
@@ -597,20 +616,8 @@ static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri,
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);
+
+ DartUtils::SetupIOLibrary(script_uri);
// Make the isolate runnable so that it is ready to handle messages.
Dart_ExitScope();
@@ -646,7 +653,11 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
}
}
if (package_root == NULL) {
- package_root = parent_isolate_data->package_root;
+ if (parent_isolate_data != NULL) {
+ package_root = parent_isolate_data->package_root;
+ } else {
+ package_root = ".";
+ }
}
return CreateIsolateAndSetupHelper(script_uri,
main,
@@ -656,50 +667,6 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri,
}
-#define CHECK_RESULT(result) \
- if (Dart_IsError(result)) { \
- *error = strdup(Dart_GetError(result)); \
- Dart_ExitScope(); \
- Dart_ShutdownIsolate(); \
- return NULL; \
- } \
-
-static Dart_Isolate CreateServiceIsolate(void* data, char** error) {
- const char* script_uri = DartUtils::kVMServiceLibURL;
- IsolateData* isolate_data = new IsolateData(script_uri, NULL);
- 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(NULL, builtin_lib);
- CHECK_RESULT(result);
-
- Dart_ExitScope();
- Dart_ExitIsolate();
- return isolate;
-}
-
-#undef CHECK_RESULT
-
static void PrintVersion() {
Log::PrintErr("Dart VM version: %s\n", Dart_VersionString());
}
@@ -980,21 +947,22 @@ void main(int argc, char** argv) {
Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
+ // Start event handler.
+ EventHandler::Start();
+
// Initialize the Dart VM.
if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate,
DartUtils::OpenFile,
DartUtils::ReadFile,
DartUtils::WriteFile,
DartUtils::CloseFile,
- DartUtils::EntropySource,
- CreateServiceIsolate)) {
+ DartUtils::EntropySource)) {
fprintf(stderr, "%s", "VM initialization failed\n");
fflush(stderr);
exit(kErrorExitCode);
}
- // Start event handler.
- EventHandler::Start();
+
// Start the debugger wire protocol handler if necessary.
if (start_debugger) {
@@ -1004,23 +972,12 @@ void main(int argc, char** argv) {
if (print_msg) {
Log::Print("Debugger listening on port %d\n", debug_port);
}
+ } else {
+ DebuggerConnectionHandler::InitForVmService();
}
- ASSERT(Dart_CurrentIsolate() == NULL);
- // Start the VM service isolate, if necessary.
- if (start_vm_service) {
- if (!start_debugger) {
- DebuggerConnectionHandler::InitForVmService();
- }
- bool r = VmService::Start(vm_service_server_ip, vm_service_server_port);
- if (!r) {
- Log::PrintErr("Could not start VM Service isolate %s\n",
- VmService::GetErrorMessage());
- }
- Dart_RegisterIsolateServiceRequestCallback(
+ Dart_RegisterIsolateServiceRequestCallback(
"io", &ServiceRequestHandler, NULL);
- }
- ASSERT(Dart_CurrentIsolate() == NULL);
// Call CreateIsolateAndSetup which creates an isolate and loads up
// the specified application script.
« no previous file with comments | « runtime/bin/io_impl_sources.gypi ('k') | runtime/bin/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698