Chromium Code Reviews| Index: runtime/bin/vmservice_impl.cc |
| diff --git a/runtime/bin/vmservice_impl.cc b/runtime/bin/vmservice_impl.cc |
| index 69c2d4868cd34c48db657602f2615e73b4fe4b87..8c6b2b20f2f64b2a874a13b8af07496d294ea816 100644 |
| --- a/runtime/bin/vmservice_impl.cc |
| +++ b/runtime/bin/vmservice_impl.cc |
| @@ -42,19 +42,10 @@ extern const uint8_t* snapshot_buffer; |
| } |
| #define kLibraryResourceNamePrefix "/vmservice" |
| -static const char* kLibraryScriptResourceName = |
| +static const char* kVMServiceIOLibraryScriptResourceName = |
| + kLibraryResourceNamePrefix "/vmservice_io.dart"; |
| +static const char* kVMServiceLibraryName = |
| kLibraryResourceNamePrefix "/vmservice.dart"; |
| -static const char* kLibrarySourceResourceNames[] = { |
| - kLibraryResourceNamePrefix "/constants.dart", |
| - kLibraryResourceNamePrefix "/resources.dart", |
| - kLibraryResourceNamePrefix "/running_isolate.dart", |
| - kLibraryResourceNamePrefix "/running_isolates.dart", |
| - kLibraryResourceNamePrefix "/server.dart", |
| - kLibraryResourceNamePrefix "/service_request.dart", |
| - kLibraryResourceNamePrefix "/service_request_router.dart", |
| - kLibraryResourceNamePrefix "/vmservice_io.dart", |
| - NULL |
| -}; |
| #define kClientResourceNamePrefix "/client/web/out" |
| @@ -110,7 +101,7 @@ bool VmService::_Start(intptr_t server_port) { |
| } |
| // Set up the library tag handler for this isolate. |
| - Dart_Handle result = Dart_SetLibraryTagHandler(DartUtils::LibraryTagHandler); |
| + Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
| SHUTDOWN_ON_ERROR(result); |
| // Load the specified application script into the newly created isolate. |
| @@ -129,10 +120,8 @@ bool VmService::_Start(intptr_t server_port) { |
| { |
| // Load source into service isolate. |
| - Dart_Handle library = LoadScript(kLibraryScriptResourceName); |
| + Dart_Handle library = LoadScript(kVMServiceIOLibraryScriptResourceName); |
| SHUTDOWN_ON_ERROR(library); |
| - result = LoadSources(library, kLibrarySourceResourceNames); |
| - SHUTDOWN_ON_ERROR(result); |
| } |
| // Make the isolate runnable so that it is ready to handle messages. |
| @@ -154,9 +143,6 @@ bool VmService::_Start(intptr_t server_port) { |
| Dart_Handle library = Dart_RootLibrary(); |
| // Set requested port. |
| DartUtils::SetIntegerField(library, "_port", server_port); |
| - // Install native resolver. |
| - result = Dart_SetNativeResolver(library, VmServiceNativeResolver); |
| - SHUTDOWN_ON_ERROR(result); |
| result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| SHUTDOWN_ON_ERROR(result); |
| @@ -194,25 +180,24 @@ bool VmService::IsRunning() { |
| } |
| -Dart_Handle VmService::LoadScript(const char* name) { |
| - Dart_Handle url = Dart_NewStringFromCString(name); |
| +Dart_Handle VmService::GetSource(const char* name) { |
| const char* vmservice_source = NULL; |
| int r = Resources::ResourceLookup(name, &vmservice_source); |
| ASSERT(r != Resources::kNoSuchInstance); |
| - Dart_Handle source = Dart_NewStringFromCString(vmservice_source); |
| + return Dart_NewStringFromCString(vmservice_source); |
| +} |
| + |
| + |
| +Dart_Handle VmService::LoadScript(const char* name) { |
| + Dart_Handle url = Dart_NewStringFromCString(name); |
| + Dart_Handle source = GetSource(name); |
| return Dart_LoadScript(url, source, 0, 0); |
| } |
| Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) { |
| Dart_Handle url = Dart_NewStringFromCString(name); |
| - const char* vmservice_source = NULL; |
| - int r = Resources::ResourceLookup(name, &vmservice_source); |
| - if (r == Resources::kNoSuchInstance) { |
| - printf("Can't find %s\n", name); |
| - } |
| - ASSERT(r != Resources::kNoSuchInstance); |
| - Dart_Handle source = Dart_NewStringFromCString(vmservice_source); |
| + Dart_Handle source = GetSource(name); |
| return Dart_LoadSource(library, url, source); |
| } |
| @@ -285,6 +270,76 @@ Dart_Handle VmService::LoadResources(Dart_Handle library) { |
| } |
| +Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag, |
| + Dart_Handle library, |
| + Dart_Handle url) { |
| + if (!Dart_IsLibrary(library)) { |
| + return Dart_Error("not a library"); |
| + } |
| + if (!Dart_IsString(url)) { |
| + return Dart_Error("url is not a string"); |
| + } |
| + const char* url_string = NULL; |
| + Dart_Handle result = Dart_StringToCString(url, &url_string); |
| + if (Dart_IsError(result)) { |
| + return result; |
| + } |
| + Dart_Handle library_url = Dart_LibraryUrl(library); |
| + const char* library_url_string = NULL; |
| + result = Dart_StringToCString(library_url, &library_url_string); |
| + if (Dart_IsError(result)) { |
| + return result; |
| + } |
| + bool is_vm_service_url = |
| + (strncmp(kLibraryResourceNamePrefix, url_string, |
| + strlen(kLibraryResourceNamePrefix)) == 0); |
| + bool is_vm_service_library = |
| + (strcmp(kVMServiceLibraryName, url_string) == 0); |
|
siva
2013/08/02 21:32:44
This seems to be computed too eagerly. Is is neede
Cutch
2013/08/02 21:39:13
Done.
|
| + if (!is_vm_service_url) { |
| + // Pass to DartUtils. |
| + return DartUtils::LibraryTagHandler(tag, library, url); |
| + } |
| + switch (tag) { |
| + case Dart_kCanonicalizeUrl: |
| + // The URL is already canonicalized. |
| + return url; |
| + break; |
| + case Dart_kImportTag: { |
| + Dart_Handle source = GetSource(url_string); |
| + if (Dart_IsError(source)) { |
| + return source; |
| + } |
| + Dart_Handle lib = Dart_LoadLibrary(url, source); |
| + if (Dart_IsError(lib)) { |
| + return lib; |
| + } |
| + if (is_vm_service_library) { |
| + // Install native resolver for this library. |
| + result = Dart_SetNativeResolver(lib, VmServiceNativeResolver); |
| + if (Dart_IsError(result)) { |
| + return result; |
| + } |
| + } |
| + return lib; |
| + } |
| + break; |
| + case Dart_kSourceTag: { |
| + Dart_Handle source = GetSource(url_string); |
| + if (Dart_IsError(source)) { |
| + return source; |
| + } |
| + return Dart_LoadSource(library, url, source); |
| + } |
| + break; |
| + default: |
| + UNIMPLEMENTED(); |
| + break; |
| + } |
| + UNREACHABLE(); |
| + return result; |
| +} |
| + |
| + |
| void VmService::ThreadMain(uword parameters) { |
| ASSERT(Dart_CurrentIsolate() == NULL); |
| ASSERT(isolate_ == NULL); |