| 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 13 matching lines...) Expand all Loading... |
| 24 #define SHUTDOWN_ON_ERROR(handle) \ | 24 #define SHUTDOWN_ON_ERROR(handle) \ |
| 25 if (Dart_IsError(handle)) { \ | 25 if (Dart_IsError(handle)) { \ |
| 26 error_msg_ = strdup(Dart_GetError(handle)); \ | 26 error_msg_ = strdup(Dart_GetError(handle)); \ |
| 27 Dart_ExitScope(); \ | 27 Dart_ExitScope(); \ |
| 28 Dart_ShutdownIsolate(); \ | 28 Dart_ShutdownIsolate(); \ |
| 29 return false; \ | 29 return false; \ |
| 30 } | 30 } |
| 31 | 31 |
| 32 #define kLibrarySourceNamePrefix "/vmservice" | 32 #define kLibrarySourceNamePrefix "/vmservice" |
| 33 static const char* kVMServiceIOLibraryScriptResourceName = "vmservice_io.dart"; | 33 static const char* kVMServiceIOLibraryScriptResourceName = "vmservice_io.dart"; |
| 34 #define kClientResourceNamePrefix "/vmservice/observatory/deployed/web" |
| 34 | 35 |
| 35 struct ResourcesEntry { | 36 struct ResourcesEntry { |
| 36 const char* path_; | 37 const char* path_; |
| 37 const char* resource_; | 38 const char* resource_; |
| 38 int length_; | 39 int length_; |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 extern ResourcesEntry __service_bin_resources_[]; | 42 extern ResourcesEntry __service_bin_resources_[]; |
| 42 | 43 |
| 43 class Resources { | 44 class Resources { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 239 |
| 239 | 240 |
| 240 Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) { | 241 Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) { |
| 241 Dart_Handle url = Dart_NewStringFromCString(name); | 242 Dart_Handle url = Dart_NewStringFromCString(name); |
| 242 Dart_Handle source = GetSource(name); | 243 Dart_Handle source = GetSource(name); |
| 243 return Dart_LoadSource(library, url, source, 0, 0); | 244 return Dart_LoadSource(library, url, source, 0, 0); |
| 244 } | 245 } |
| 245 | 246 |
| 246 | 247 |
| 247 Dart_Handle VmService::LoadResource(Dart_Handle library, | 248 Dart_Handle VmService::LoadResource(Dart_Handle library, |
| 248 const char* resource_name) { | 249 const char* resource_name, |
| 250 const char* prefix) { |
| 251 intptr_t prefix_len = strlen(prefix); |
| 249 // Prepare for invoke call. | 252 // Prepare for invoke call. |
| 250 Dart_Handle name = Dart_NewStringFromCString(resource_name); | 253 Dart_Handle name = Dart_NewStringFromCString(resource_name+prefix_len); |
| 251 RETURN_ERROR_HANDLE(name); | 254 RETURN_ERROR_HANDLE(name); |
| 252 const char* data_buffer = NULL; | 255 const char* data_buffer = NULL; |
| 253 int data_buffer_length = Resources::ResourceLookup(resource_name, | 256 int data_buffer_length = Resources::ResourceLookup(resource_name, |
| 254 &data_buffer); | 257 &data_buffer); |
| 255 if (data_buffer_length == Resources::kNoSuchInstance) { | 258 if (data_buffer_length == Resources::kNoSuchInstance) { |
| 256 printf("Could not find %s %s\n", resource_name, resource_name); | 259 printf("Could not find %s %s\n", resource_name, resource_name+prefix_len); |
| 257 } | 260 } |
| 258 ASSERT(data_buffer_length != Resources::kNoSuchInstance); | 261 ASSERT(data_buffer_length != Resources::kNoSuchInstance); |
| 259 Dart_Handle data_list = Dart_NewTypedData(Dart_TypedData_kUint8, | 262 Dart_Handle data_list = Dart_NewTypedData(Dart_TypedData_kUint8, |
| 260 data_buffer_length); | 263 data_buffer_length); |
| 261 RETURN_ERROR_HANDLE(data_list); | 264 RETURN_ERROR_HANDLE(data_list); |
| 262 Dart_TypedData_Type type = Dart_TypedData_kInvalid; | 265 Dart_TypedData_Type type = Dart_TypedData_kInvalid; |
| 263 void* data_list_buffer = NULL; | 266 void* data_list_buffer = NULL; |
| 264 intptr_t data_list_buffer_length = 0; | 267 intptr_t data_list_buffer_length = 0; |
| 265 Dart_Handle result = Dart_TypedDataAcquireData(data_list, &type, | 268 Dart_Handle result = Dart_TypedDataAcquireData(data_list, &type, |
| 266 &data_list_buffer, | 269 &data_list_buffer, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 277 const intptr_t kNumArgs = 2; | 280 const intptr_t kNumArgs = 2; |
| 278 Dart_Handle args[kNumArgs] = { name, data_list }; | 281 Dart_Handle args[kNumArgs] = { name, data_list }; |
| 279 result = Dart_Invoke(library, Dart_NewStringFromCString("_addResource"), | 282 result = Dart_Invoke(library, Dart_NewStringFromCString("_addResource"), |
| 280 kNumArgs, args); | 283 kNumArgs, args); |
| 281 return result; | 284 return result; |
| 282 } | 285 } |
| 283 | 286 |
| 284 | 287 |
| 285 Dart_Handle VmService::LoadResources(Dart_Handle library) { | 288 Dart_Handle VmService::LoadResources(Dart_Handle library) { |
| 286 Dart_Handle result = Dart_Null(); | 289 Dart_Handle result = Dart_Null(); |
| 287 intptr_t prefixLen = strlen(kLibrarySourceNamePrefix); | 290 intptr_t prefixLen = strlen(kClientResourceNamePrefix); |
| 288 for (intptr_t i = 0; Resources::Path(i) != NULL; i++) { | 291 for (intptr_t i = 0; Resources::Path(i) != NULL; i++) { |
| 289 const char* path = Resources::Path(i); | 292 const char* path = Resources::Path(i); |
| 290 // If it doesn't begin with kLibrarySourceNamePrefix it is a frontend | 293 if (!strncmp(path, kClientResourceNamePrefix, prefixLen)) { |
| 291 // resource. | 294 result = LoadResource(library, path, kClientResourceNamePrefix); |
| 292 if (strncmp(path, kLibrarySourceNamePrefix, prefixLen) != 0) { | |
| 293 result = LoadResource(library, path); | |
| 294 if (Dart_IsError(result)) { | 295 if (Dart_IsError(result)) { |
| 295 break; | 296 break; |
| 296 } | 297 } |
| 297 } | 298 } |
| 298 } | 299 } |
| 299 return result; | 300 return result; |
| 300 } | 301 } |
| 301 | 302 |
| 302 | 303 |
| 303 Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag, | 304 Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 printf("Service exited with an error:\n%s\n", Dart_GetError(result)); | 348 printf("Service exited with an error:\n%s\n", Dart_GetError(result)); |
| 348 } | 349 } |
| 349 Dart_ExitScope(); | 350 Dart_ExitScope(); |
| 350 Dart_ExitIsolate(); | 351 Dart_ExitIsolate(); |
| 351 } | 352 } |
| 352 | 353 |
| 353 | 354 |
| 354 | 355 |
| 355 } // namespace bin | 356 } // namespace bin |
| 356 } // namespace dart | 357 } // namespace dart |
| OLD | NEW |