| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
| 11 | 11 |
| 12 #include "bin/builtin.h" | 12 #include "bin/builtin.h" |
| 13 #include "bin/dartutils.h" | 13 #include "bin/dartutils.h" |
| 14 #include "bin/dbg_connection.h" | 14 #include "bin/dbg_connection.h" |
| 15 #include "bin/directory.h" | 15 #include "bin/directory.h" |
| 16 #include "bin/eventhandler.h" | 16 #include "bin/eventhandler.h" |
| 17 #include "bin/extensions.h" | 17 #include "bin/extensions.h" |
| 18 #include "bin/file.h" | 18 #include "bin/file.h" |
| 19 #include "bin/platform.h" | 19 #include "bin/platform.h" |
| 20 #include "bin/process.h" | 20 #include "bin/process.h" |
| 21 #include "platform/globals.h" | 21 #include "platform/globals.h" |
| 22 | 22 |
| 23 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 23 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
| 24 // it is initialized to NULL. | 24 // it is initialized to NULL. |
| 25 extern const uint8_t* snapshot_buffer; | 25 extern const uint8_t* snapshot_buffer; |
| 26 | 26 |
| 27 | 27 |
| 28 // Global state that stores a pointer to the application script file. | 28 // Global state that stores the original working directory.. |
| 29 static const char* original_script_name = NULL; | |
| 30 static const char* original_working_directory = NULL; | 29 static const char* original_working_directory = NULL; |
| 31 static const char* original_script_url = NULL; | |
| 32 | 30 |
| 33 | 31 |
| 34 // Global state that stores the import URL map specified on the | 32 // Global state that stores the import URL map specified on the |
| 35 // command line. | 33 // command line. |
| 36 static CommandLineOptions* import_map_options = NULL; | 34 static CommandLineOptions* import_map_options = NULL; |
| 37 | 35 |
| 38 | 36 |
| 39 // Global state that indicates whether pprof symbol information is | 37 // Global state that indicates whether pprof symbol information is |
| 40 // to be generated or not. | 38 // to be generated or not. |
| 41 static const char* generate_pprof_symbols_filename = NULL; | 39 static const char* generate_pprof_symbols_filename = NULL; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 60 // (This pointer points into an argv buffer and does not need to be | 58 // (This pointer points into an argv buffer and does not need to be |
| 61 // free'd.) | 59 // free'd.) |
| 62 static const char* package_root = NULL; | 60 static const char* package_root = NULL; |
| 63 | 61 |
| 64 | 62 |
| 65 // Global flag that is used to indicate that we want to compile all the | 63 // Global flag that is used to indicate that we want to compile all the |
| 66 // dart functions and not run anything. | 64 // dart functions and not run anything. |
| 67 static bool has_compile_all = false; | 65 static bool has_compile_all = false; |
| 68 | 66 |
| 69 | 67 |
| 68 static bool IsWindowsHost() { |
| 69 #if defined(TARGET_OS_WINDOWS) |
| 70 return true; |
| 71 #else // defined(TARGET_OS_WINDOWS) |
| 72 return false; |
| 73 #endif // defined(TARGET_OS_WINDOWS) |
| 74 } |
| 75 |
| 76 |
| 70 static bool IsValidFlag(const char* name, | 77 static bool IsValidFlag(const char* name, |
| 71 const char* prefix, | 78 const char* prefix, |
| 72 intptr_t prefix_length) { | 79 intptr_t prefix_length) { |
| 73 intptr_t name_length = strlen(name); | 80 intptr_t name_length = strlen(name); |
| 74 return ((name_length > prefix_length) && | 81 return ((name_length > prefix_length) && |
| 75 (strncmp(name, prefix, prefix_length) == 0)); | 82 (strncmp(name, prefix, prefix_length) == 0)); |
| 76 } | 83 } |
| 77 | 84 |
| 78 | 85 |
| 79 static void ProcessBreakpointOption(const char* funcname) { | 86 static void ProcessBreakpointOption(const char* funcname) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (buffer_size > 0) { | 297 if (buffer_size > 0) { |
| 291 ASSERT(buffer != NULL); | 298 ASSERT(buffer != NULL); |
| 292 pprof_file->WriteFully(buffer, buffer_size); | 299 pprof_file->WriteFully(buffer, buffer_size); |
| 293 } | 300 } |
| 294 delete pprof_file; // Closes the file. | 301 delete pprof_file; // Closes the file. |
| 295 Dart_ExitScope(); | 302 Dart_ExitScope(); |
| 296 } | 303 } |
| 297 } | 304 } |
| 298 | 305 |
| 299 | 306 |
| 307 |
| 308 static Dart_Handle ResolveScriptUri(Dart_Handle script_uri, |
| 309 Dart_Handle builtin_lib) { |
| 310 const int kNumArgs = 3; |
| 311 Dart_Handle dart_args[kNumArgs]; |
| 312 dart_args[0] = Dart_NewString(original_working_directory); |
| 313 dart_args[1] = script_uri; |
| 314 dart_args[2] = (IsWindowsHost() ? Dart_True() : Dart_False()); |
| 315 return Dart_Invoke( |
| 316 builtin_lib, Dart_NewString("_resolveScriptUri"), kNumArgs, dart_args); |
| 317 } |
| 318 |
| 319 |
| 320 static Dart_Handle FilePathFromUri(Dart_Handle script_uri, |
| 321 Dart_Handle builtin_lib) { |
| 322 const int kNumArgs = 2; |
| 323 Dart_Handle dart_args[kNumArgs]; |
| 324 dart_args[0] = script_uri; |
| 325 dart_args[1] = (IsWindowsHost() ? Dart_True() : Dart_False()); |
| 326 Dart_Handle script_path = Dart_Invoke( |
| 327 builtin_lib, Dart_NewString("_filePathFromUri"), kNumArgs, dart_args); |
| 328 return script_path; |
| 329 } |
| 330 |
| 331 |
| 300 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, | 332 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, |
| 301 Dart_Handle library, | 333 Dart_Handle library, |
| 302 Dart_Handle url, | 334 Dart_Handle url) { |
| 303 Dart_Handle import_map) { | |
| 304 if (!Dart_IsLibrary(library)) { | 335 if (!Dart_IsLibrary(library)) { |
| 305 return Dart_Error("not a library"); | 336 return Dart_Error("not a library"); |
| 306 } | 337 } |
| 307 if (!Dart_IsString8(url)) { | 338 if (!Dart_IsString8(url)) { |
| 308 return Dart_Error("url is not a string"); | 339 return Dart_Error("url is not a string"); |
| 309 } | 340 } |
| 310 const char* url_string = NULL; | 341 const char* url_string = NULL; |
| 311 Dart_Handle result = Dart_StringToCString(url, &url_string); | 342 Dart_Handle result = Dart_StringToCString(url, &url_string); |
| 312 if (Dart_IsError(result)) { | 343 if (Dart_IsError(result)) { |
| 313 return result; | 344 return result; |
| 314 } | 345 } |
| 315 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 346 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
| 316 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); | 347 bool is_dart_extension_url = DartUtils::IsDartExtensionSchemeURL(url_string); |
| 317 if (tag == kCanonicalizeUrl) { | 348 if (tag == kCanonicalizeUrl) { |
| 318 // If this is a Dart Scheme URL then it is not modified as it will be | 349 // If this is a Dart Scheme URL then it is not modified as it will be |
| 319 // handled by the VM internally. | 350 // handled by the VM internally. |
| 320 if (is_dart_scheme_url) { | 351 if (is_dart_scheme_url) { |
| 321 return url; | 352 return url; |
| 322 } | 353 } |
| 323 // Resolve the url within the context of the library's URL. | 354 // Resolve the url within the context of the library's URL. |
| 324 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 355 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 325 Dart_Handle library_url = Dart_LibraryUrl(library); | 356 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 326 if (Dart_IsError(library_url)) { | 357 if (Dart_IsError(library_url)) { |
| 327 return library_url; | 358 return library_url; |
| 328 } | 359 } |
| 329 Dart_Handle dart_args[2]; | 360 const int kNumArgs = 2; |
| 361 Dart_Handle dart_args[kNumArgs]; |
| 330 dart_args[0] = library_url; | 362 dart_args[0] = library_url; |
| 331 dart_args[1] = url; | 363 dart_args[1] = url; |
| 332 return Dart_Invoke( | 364 return Dart_Invoke( |
| 333 builtin_lib, Dart_NewString("_resolveUri"), 2, dart_args); | 365 builtin_lib, Dart_NewString("_resolveUri"), kNumArgs, dart_args); |
| 334 } | 366 } |
| 335 if (is_dart_scheme_url) { | 367 if (is_dart_scheme_url) { |
| 336 ASSERT(tag == kImportTag); | 368 ASSERT(tag == kImportTag); |
| 337 // Handle imports of other built-in libraries present in the SDK. | 369 // Handle imports of other built-in libraries present in the SDK. |
| 338 if (DartUtils::IsDartCryptoLibURL(url_string)) { | 370 if (DartUtils::IsDartCryptoLibURL(url_string)) { |
| 339 return Builtin::LoadLibrary(Builtin::kCryptoLibrary); | 371 return Builtin::LoadLibrary(Builtin::kCryptoLibrary); |
| 340 } else if (DartUtils::IsDartIOLibURL(url_string)) { | 372 } else if (DartUtils::IsDartIOLibURL(url_string)) { |
| 341 return Builtin::LoadLibrary(Builtin::kIOLibrary); | 373 return Builtin::LoadLibrary(Builtin::kIOLibrary); |
| 342 } else if (DartUtils::IsDartJsonLibURL(url_string)) { | 374 } else if (DartUtils::IsDartJsonLibURL(url_string)) { |
| 343 return Builtin::LoadLibrary(Builtin::kJsonLibrary); | 375 return Builtin::LoadLibrary(Builtin::kJsonLibrary); |
| 344 } else if (DartUtils::IsDartUriLibURL(url_string)) { | 376 } else if (DartUtils::IsDartUriLibURL(url_string)) { |
| 345 return Builtin::LoadLibrary(Builtin::kUriLibrary); | 377 return Builtin::LoadLibrary(Builtin::kUriLibrary); |
| 346 } else if (DartUtils::IsDartUtfLibURL(url_string)) { | 378 } else if (DartUtils::IsDartUtfLibURL(url_string)) { |
| 347 return Builtin::LoadLibrary(Builtin::kUtfLibrary); | 379 return Builtin::LoadLibrary(Builtin::kUtfLibrary); |
| 348 } else { | 380 } else { |
| 349 return Dart_Error("Do not know how to load '%s'", url_string); | 381 return Dart_Error("Do not know how to load '%s'", url_string); |
| 350 } | 382 } |
| 351 } else { | 383 } else { |
| 352 // Get the file path out of the url. | 384 // Get the file path out of the url. |
| 353 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 385 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 354 Dart_Handle dart_args[1]; | 386 Dart_Handle file_path = FilePathFromUri(url, builtin_lib); |
| 355 dart_args[0] = url; | |
| 356 Dart_Handle file_path = Dart_Invoke( | |
| 357 builtin_lib, Dart_NewString("_filePathFromUri"), 1, dart_args); | |
| 358 if (Dart_IsError(file_path)) { | 387 if (Dart_IsError(file_path)) { |
| 359 return file_path; | 388 return file_path; |
| 360 } | 389 } |
| 361 Dart_StringToCString(file_path, &url_string); | 390 Dart_StringToCString(file_path, &url_string); |
| 362 } | 391 } |
| 363 if (is_dart_extension_url) { | 392 if (is_dart_extension_url) { |
| 364 if (tag != kImportTag) { | 393 if (tag != kImportTag) { |
| 365 return Dart_Error("Dart extensions must use import: '%s'", url_string); | 394 return Dart_Error("Dart extensions must use import: '%s'", url_string); |
| 366 } | 395 } |
| 367 return Extensions::LoadExtension(url_string, library); | 396 return Extensions::LoadExtension(url_string, library); |
| 368 } | 397 } |
| 369 result = DartUtils::LoadSource(NULL, | 398 result = DartUtils::LoadSource(NULL, |
| 370 library, | 399 library, |
| 371 url, | 400 url, |
| 372 tag, | 401 tag, |
| 373 url_string, | 402 url_string); |
| 374 import_map); | |
| 375 if (!Dart_IsError(result) && (tag == kImportTag)) { | 403 if (!Dart_IsError(result) && (tag == kImportTag)) { |
| 376 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); | 404 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); |
| 377 } | 405 } |
| 378 return result; | 406 return result; |
| 379 } | 407 } |
| 380 | 408 |
| 381 | 409 |
| 382 static Dart_Handle LoadScript(Dart_Handle builtin_lib, | 410 static Dart_Handle ReadSource(Dart_Handle script_uri, |
| 383 CommandLineOptions* map) { | 411 Dart_Handle builtin_lib) { |
| 384 Dart_Handle dart_args[3]; | 412 Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib); |
| 385 dart_args[0] = Dart_NewString(original_working_directory); | |
| 386 dart_args[1] = Dart_NewString(original_script_name); | |
| 387 #if !defined(TARGET_OS_WINDOWS) | |
| 388 dart_args[2] = Dart_False(); | |
| 389 #else // !defined(TARGET_OS_WINDOWS) | |
| 390 dart_args[2] = Dart_True(); | |
| 391 #endif // !defined(TARGET_OS_WINDOWS) | |
| 392 Dart_Handle script_url = Dart_Invoke( | |
| 393 builtin_lib, Dart_NewString("_resolveScriptUri"), 3, dart_args); | |
| 394 if (Dart_IsError(script_url)) { | |
| 395 fprintf(stderr, "%s", Dart_GetError(script_url)); | |
| 396 return script_url; | |
| 397 } | |
| 398 if (original_script_url == NULL) { | |
| 399 const char* script_url_cstr; | |
| 400 Dart_StringToCString(script_url, &script_url_cstr); | |
| 401 original_script_url = strdup(script_url_cstr); | |
| 402 } | |
| 403 dart_args[0] = script_url; | |
| 404 Dart_Handle script_path = Dart_Invoke( | |
| 405 builtin_lib, Dart_NewString("_filePathFromUri"), 1, dart_args); | |
| 406 if (Dart_IsError(script_path)) { | 413 if (Dart_IsError(script_path)) { |
| 407 return script_path; | 414 return script_path; |
| 408 } | 415 } |
| 409 const char* script_path_cstr; | 416 const char* script_path_cstr; |
| 410 Dart_StringToCString(script_path, &script_path_cstr); | 417 Dart_StringToCString(script_path, &script_path_cstr); |
| 411 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); | 418 Dart_Handle source = DartUtils::ReadStringFromFile(script_path_cstr); |
| 419 return source; |
| 420 } |
| 421 |
| 422 |
| 423 static Dart_Handle LoadScript(const char* script_uri, |
| 424 bool resolve_script, |
| 425 Dart_Handle builtin_lib) { |
| 426 Dart_Handle resolved_script_uri; |
| 427 if (resolve_script) { |
| 428 resolved_script_uri = ResolveScriptUri(Dart_NewString(script_uri), |
| 429 builtin_lib); |
| 430 if (Dart_IsError(resolved_script_uri)) { |
| 431 return resolved_script_uri; |
| 432 } |
| 433 } else { |
| 434 resolved_script_uri = Dart_NewString(script_uri); |
| 435 } |
| 436 Dart_Handle source = ReadSource(resolved_script_uri, builtin_lib); |
| 412 if (Dart_IsError(source)) { | 437 if (Dart_IsError(source)) { |
| 413 return source; | 438 return source; |
| 414 } | 439 } |
| 440 return Dart_LoadScript(resolved_script_uri, source); |
| 441 } |
| 442 |
| 443 |
| 444 static Dart_Handle CreateImportMap(CommandLineOptions* map) { |
| 415 intptr_t length = (map == NULL) ? 0 : map->count(); | 445 intptr_t length = (map == NULL) ? 0 : map->count(); |
| 416 Dart_Handle import_map = Dart_NewList(length * 2); | 446 Dart_Handle import_map = Dart_NewList(length * 2); |
| 417 for (intptr_t i = 0; i < length; i++) { | 447 for (intptr_t i = 0; i < length; i++) { |
| 418 ASSERT(map->GetArgument(i) != NULL); | 448 ASSERT(map->GetArgument(i) != NULL); |
| 419 char* name = strdup(map->GetArgument(i)); | 449 char* name = strdup(map->GetArgument(i)); |
| 420 ASSERT(name != NULL); | 450 ASSERT(name != NULL); |
| 421 char* map_name = strchr(name, ','); | 451 char* map_name = strchr(name, ','); |
| 422 intptr_t index = i * 2; | 452 intptr_t index = i * 2; |
| 423 if (map_name != NULL) { | 453 if (map_name != NULL) { |
| 424 *map_name = '\0'; | 454 *map_name = '\0'; |
| 425 map_name += 1; | 455 map_name += 1; |
| 426 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 456 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 427 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); | 457 Dart_ListSetAt(import_map, (index + 1), Dart_NewString(map_name)); |
| 428 } else { | 458 } else { |
| 429 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 459 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 430 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); | 460 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); |
| 431 } | 461 } |
| 432 free(name); | 462 free(name); |
| 433 } | 463 } |
| 434 return Dart_LoadScript(script_url, source, import_map); | 464 return import_map; |
| 435 } | 465 } |
| 436 | 466 |
| 437 | 467 |
| 438 // Returns true on success, false on failure. | 468 // Returns true on success, false on failure. |
| 439 static bool CreateIsolateAndSetup(const char* name_prefix, | 469 static bool CreateIsolateAndSetupHelper(const char* script_uri, |
| 440 void* data, char** error) { | 470 const char* main, |
| 471 bool resolve_script, |
| 472 void* data, |
| 473 char** error) { |
| 441 Dart_Isolate isolate = | 474 Dart_Isolate isolate = |
| 442 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); | 475 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); |
| 443 if (isolate == NULL) { | 476 if (isolate == NULL) { |
| 444 return false; | 477 return false; |
| 445 } | 478 } |
| 446 | 479 |
| 447 Dart_EnterScope(); | 480 Dart_EnterScope(); |
| 448 | 481 |
| 449 if (snapshot_buffer != NULL) { | 482 if (snapshot_buffer != NULL) { |
| 450 // Setup the native resolver as the snapshot does not carry it. | 483 // Setup the native resolver as the snapshot does not carry it. |
| 451 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); | 484 Builtin::SetNativeResolver(Builtin::kBuiltinLibrary); |
| 452 Builtin::SetNativeResolver(Builtin::kIOLibrary); | 485 Builtin::SetNativeResolver(Builtin::kIOLibrary); |
| 453 } | 486 } |
| 454 | 487 |
| 455 // Set up the library tag handler for this isolate. | 488 // Set up the library tag handler for this isolate. |
| 456 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); | 489 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
| 457 if (Dart_IsError(result)) { | 490 if (Dart_IsError(result)) { |
| 458 *error = strdup(Dart_GetError(result)); | 491 *error = strdup(Dart_GetError(result)); |
| 492 Dart_ExitScope(); |
| 493 Dart_ShutdownIsolate(); |
| 494 return false; |
| 495 } |
| 496 |
| 497 // Set up the import map for this isolate. |
| 498 result = Dart_SetImportMap(CreateImportMap(import_map_options)); |
| 499 if (Dart_IsError(result)) { |
| 500 *error = strdup(Dart_GetError(result)); |
| 501 Dart_ExitScope(); |
| 502 Dart_ShutdownIsolate(); |
| 459 return false; | 503 return false; |
| 460 } | 504 } |
| 461 | 505 |
| 462 // Prepare builtin and its dependent libraries for use to resolve URIs. | 506 // Prepare builtin and its dependent libraries for use to resolve URIs. |
| 463 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); | 507 Dart_Handle uri_lib = Builtin::LoadLibrary(Builtin::kUriLibrary); |
| 464 if (Dart_IsError(uri_lib)) { | 508 if (Dart_IsError(uri_lib)) { |
| 465 *error = strdup(Dart_GetError(uri_lib)); | 509 *error = strdup(Dart_GetError(uri_lib)); |
| 510 Dart_ExitScope(); |
| 511 Dart_ShutdownIsolate(); |
| 466 return false; | 512 return false; |
| 467 } | 513 } |
| 468 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 514 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 469 if (Dart_IsError(builtin_lib)) { | 515 if (Dart_IsError(builtin_lib)) { |
| 470 *error = strdup(Dart_GetError(builtin_lib)); | 516 *error = strdup(Dart_GetError(builtin_lib)); |
| 517 Dart_ExitScope(); |
| 518 Dart_ShutdownIsolate(); |
| 471 return false; | 519 return false; |
| 472 } | 520 } |
| 473 | 521 |
| 474 if (package_root != NULL) { | 522 if (package_root != NULL) { |
| 475 Dart_Handle dart_args[1]; | 523 const int kNumArgs = 1; |
| 524 Dart_Handle dart_args[kNumArgs]; |
| 476 | 525 |
| 477 Dart_Handle handle = Dart_NewString(package_root); | 526 Dart_Handle handle = Dart_NewString(package_root); |
| 478 if (Dart_IsError(handle)) { | 527 if (Dart_IsError(handle)) { |
| 479 *error = strdup(Dart_GetError(handle)); | 528 *error = strdup(Dart_GetError(handle)); |
| 529 Dart_ExitScope(); |
| 530 Dart_ShutdownIsolate(); |
| 480 return false; | 531 return false; |
| 481 } | 532 } |
| 482 dart_args[0] = handle; | 533 dart_args[0] = handle; |
| 483 | 534 |
| 484 Dart_Handle result = Dart_Invoke(builtin_lib, | 535 Dart_Handle result = Dart_Invoke(builtin_lib, |
| 485 Dart_NewString("_setPackageRoot"), 1, dart_args); | 536 Dart_NewString("_setPackageRoot"), kNumArgs, dart_args); |
| 486 if (Dart_IsError(result)) { | 537 if (Dart_IsError(result)) { |
| 487 *error = strdup(Dart_GetError(result)); | 538 *error = strdup(Dart_GetError(result)); |
| 539 Dart_ExitScope(); |
| 540 Dart_ShutdownIsolate(); |
| 488 return false; | 541 return false; |
| 489 } | 542 } |
| 490 } | 543 } |
| 491 | 544 |
| 492 // Load the specified application script into the newly created isolate. | 545 // Load the specified application script into the newly created isolate. |
| 493 Dart_Handle library = LoadScript(builtin_lib, import_map_options); | 546 Dart_Handle library = LoadScript(script_uri, resolve_script, builtin_lib); |
| 494 if (Dart_IsError(library)) { | 547 if (Dart_IsError(library)) { |
| 495 *error = strdup(Dart_GetError(library)); | 548 *error = strdup(Dart_GetError(library)); |
| 496 Dart_ExitScope(); | 549 Dart_ExitScope(); |
| 497 Dart_ShutdownIsolate(); | 550 Dart_ShutdownIsolate(); |
| 498 return false; | 551 return false; |
| 499 } | 552 } |
| 500 if (!Dart_IsLibrary(library)) { | 553 if (!Dart_IsLibrary(library)) { |
| 501 char errbuf[256]; | 554 char errbuf[256]; |
| 502 snprintf(errbuf, sizeof(errbuf), | 555 snprintf(errbuf, sizeof(errbuf), |
| 503 "Expected a library when loading script: %s", | 556 "Expected a library when loading script: %s", |
| 504 original_script_name); | 557 script_uri); |
| 505 *error = strdup(errbuf); | 558 *error = strdup(errbuf); |
| 506 Dart_ExitScope(); | 559 Dart_ExitScope(); |
| 507 Dart_ShutdownIsolate(); | 560 Dart_ShutdownIsolate(); |
| 508 return false; | 561 return false; |
| 509 } | 562 } |
| 510 // Implicitly import builtin into app. | 563 // Implicitly import builtin into app. |
| 511 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary); | 564 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary); |
| 512 Dart_ExitScope(); | 565 Dart_ExitScope(); |
| 513 return true; | 566 return true; |
| 514 } | 567 } |
| 515 | 568 |
| 516 | 569 |
| 570 static bool CreateIsolateAndSetup(const char* script_uri, |
| 571 const char* main, |
| 572 void* data, char** error) { |
| 573 return CreateIsolateAndSetupHelper(script_uri, |
| 574 main, |
| 575 false, // script_uri already canonical. |
| 576 data, |
| 577 error); |
| 578 } |
| 579 |
| 580 |
| 517 static void PrintUsage() { | 581 static void PrintUsage() { |
| 518 fprintf(stderr, | 582 fprintf(stderr, |
| 519 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"); | 583 "dart [<vm-flags>] <dart-script-file> [<dart-options>]\n"); |
| 520 } | 584 } |
| 521 | 585 |
| 522 | 586 |
| 523 static Dart_Handle SetBreakpoint(const char* breakpoint_at, | 587 static Dart_Handle SetBreakpoint(const char* breakpoint_at, |
| 524 Dart_Handle library) { | 588 Dart_Handle library) { |
| 525 Dart_Handle result; | 589 Dart_Handle result; |
| 526 if (strchr(breakpoint_at, ':')) { | 590 if (strchr(breakpoint_at, ':')) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 640 |
| 577 | 641 |
| 578 static int ErrorExit(const char* format, ...) { | 642 static int ErrorExit(const char* format, ...) { |
| 579 va_list arguments; | 643 va_list arguments; |
| 580 va_start(arguments, format); | 644 va_start(arguments, format); |
| 581 vfprintf(stderr, format, arguments); | 645 vfprintf(stderr, format, arguments); |
| 582 va_end(arguments); | 646 va_end(arguments); |
| 583 | 647 |
| 584 Dart_ExitScope(); | 648 Dart_ExitScope(); |
| 585 Dart_ShutdownIsolate(); | 649 Dart_ShutdownIsolate(); |
| 586 | |
| 587 free(const_cast<char*>(original_script_name)); | |
| 588 free(const_cast<char*>(original_working_directory)); | 650 free(const_cast<char*>(original_working_directory)); |
| 589 free(const_cast<char*>(original_script_url)); | |
| 590 | 651 |
| 591 return kErrorExitCode; | 652 return kErrorExitCode; |
| 592 } | 653 } |
| 593 | 654 |
| 594 | 655 |
| 595 int main(int argc, char** argv) { | 656 int main(int argc, char** argv) { |
| 596 char* executable_name; | 657 char* executable_name; |
| 597 char* script_name; | 658 char* script_name; |
| 598 CommandLineOptions vm_options(argc); | 659 CommandLineOptions vm_options(argc); |
| 599 CommandLineOptions dart_options(argc); | 660 CommandLineOptions dart_options(argc); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 614 &dart_options) < 0) { | 675 &dart_options) < 0) { |
| 615 PrintUsage(); | 676 PrintUsage(); |
| 616 return kErrorExitCode; | 677 return kErrorExitCode; |
| 617 } | 678 } |
| 618 | 679 |
| 619 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 680 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
| 620 | 681 |
| 621 // Initialize the Dart VM. | 682 // Initialize the Dart VM. |
| 622 Dart_Initialize(CreateIsolateAndSetup, NULL); | 683 Dart_Initialize(CreateIsolateAndSetup, NULL); |
| 623 | 684 |
| 624 original_script_name = strdup(script_name); | |
| 625 original_working_directory = Directory::Current(); | 685 original_working_directory = Directory::Current(); |
| 626 | 686 |
| 627 // Call CreateIsolateAndSetup which creates an isolate and loads up | 687 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 628 // the specified application script. | 688 // the specified application script. |
| 629 char* error = NULL; | 689 char* error = NULL; |
| 630 char* isolate_name = BuildIsolateName(original_script_name, "main"); | 690 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 631 if (!CreateIsolateAndSetup(isolate_name, NULL, &error)) { | 691 if (!CreateIsolateAndSetupHelper(script_name, |
| 692 "main", |
| 693 true, // Canonicalize the script name. |
| 694 NULL, |
| 695 &error)) { |
| 632 fprintf(stderr, "%s\n", error); | 696 fprintf(stderr, "%s\n", error); |
| 633 free(const_cast<char*>(original_script_name)); | |
| 634 free(const_cast<char*>(original_working_directory)); | 697 free(const_cast<char*>(original_working_directory)); |
| 635 free(error); | 698 free(error); |
| 636 delete [] isolate_name; | 699 delete [] isolate_name; |
| 637 return 255; // Indicates we encountered an error. | 700 return 255; // Indicates we encountered an error. |
| 638 } | 701 } |
| 639 delete [] isolate_name; | 702 delete [] isolate_name; |
| 640 | 703 |
| 641 Dart_Isolate isolate = Dart_CurrentIsolate(); | 704 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| 642 ASSERT(isolate != NULL); | 705 ASSERT(isolate != NULL); |
| 643 Dart_Handle result; | 706 Dart_Handle result; |
| 644 | 707 |
| 645 Dart_EnterScope(); | 708 Dart_EnterScope(); |
| 646 | 709 |
| 647 if (has_compile_all) { | 710 if (has_compile_all) { |
| 648 result = Dart_CompileAll(); | 711 result = Dart_CompileAll(); |
| 649 if (Dart_IsError(result)) { | 712 if (Dart_IsError(result)) { |
| 650 return ErrorExit("%s\n", Dart_GetError(result)); | 713 return ErrorExit("%s\n", Dart_GetError(result)); |
| 651 } | 714 } |
| 652 } | 715 } |
| 653 | 716 |
| 654 // Create a dart options object that can be accessed from dart code. | 717 // Create a dart options object that can be accessed from dart code. |
| 655 Dart_Handle options_result = | 718 Dart_Handle options_result = |
| 656 SetupRuntimeOptions(&dart_options, executable_name, original_script_name); | 719 SetupRuntimeOptions(&dart_options, executable_name, script_name); |
| 657 if (Dart_IsError(options_result)) { | 720 if (Dart_IsError(options_result)) { |
| 658 return ErrorExit("%s\n", Dart_GetError(options_result)); | 721 return ErrorExit("%s\n", Dart_GetError(options_result)); |
| 659 } | 722 } |
| 660 // Lookup the library of the main script. | 723 // Lookup the library of the root script. |
| 661 Dart_Handle script_url = Dart_NewString(original_script_url); | 724 Dart_Handle library = Dart_RootLibrary(); |
| 662 Dart_Handle library = Dart_LookupLibrary(script_url); | 725 if (Dart_IsNull(library)) { |
| 663 if (Dart_IsError(library)) { | 726 return ErrorExit("Unable to find root library for '%s'\n", |
| 664 return ErrorExit("%s\n", Dart_GetError(library)); | 727 script_name); |
| 665 } | 728 } |
| 666 // Set debug breakpoint if specified on the command line. | 729 // Set debug breakpoint if specified on the command line. |
| 667 if (breakpoint_at != NULL) { | 730 if (breakpoint_at != NULL) { |
| 668 result = SetBreakpoint(breakpoint_at, library); | 731 result = SetBreakpoint(breakpoint_at, library); |
| 669 if (Dart_IsError(result)) { | 732 if (Dart_IsError(result)) { |
| 670 return ErrorExit("Error setting breakpoint at '%s': %s\n", | 733 return ErrorExit("Error setting breakpoint at '%s': %s\n", |
| 671 breakpoint_at, | 734 breakpoint_at, |
| 672 Dart_GetError(result)); | 735 Dart_GetError(result)); |
| 673 } | 736 } |
| 674 } | 737 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 691 } | 754 } |
| 692 | 755 |
| 693 Dart_ExitScope(); | 756 Dart_ExitScope(); |
| 694 // Dump symbol information for the profiler. | 757 // Dump symbol information for the profiler. |
| 695 DumpPprofSymbolInfo(); | 758 DumpPprofSymbolInfo(); |
| 696 // Shutdown the isolate. | 759 // Shutdown the isolate. |
| 697 Dart_ShutdownIsolate(); | 760 Dart_ShutdownIsolate(); |
| 698 // Terminate process exit-code handler. | 761 // Terminate process exit-code handler. |
| 699 Process::TerminateExitCodeHandler(); | 762 Process::TerminateExitCodeHandler(); |
| 700 | 763 |
| 701 free(const_cast<char*>(original_script_name)); | |
| 702 free(const_cast<char*>(original_working_directory)); | 764 free(const_cast<char*>(original_working_directory)); |
| 703 free(const_cast<char*>(original_script_url)); | |
| 704 | 765 |
| 705 return 0; | 766 return 0; |
| 706 } | 767 } |
| OLD | NEW |