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