| 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" |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 // available here in the case of script snapshot loading. | 453 // available here in the case of script snapshot loading. |
| 454 Dart_Handle builtin_lib = | 454 Dart_Handle builtin_lib = |
| 455 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 455 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 456 CHECK_RESULT(builtin_lib); | 456 CHECK_RESULT(builtin_lib); |
| 457 | 457 |
| 458 // Prepare for script loading by setting up the 'print' and 'timer' | 458 // Prepare for script loading by setting up the 'print' and 'timer' |
| 459 // closures and setting up 'package root' for URI resolution. | 459 // closures and setting up 'package root' for URI resolution. |
| 460 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); | 460 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); |
| 461 CHECK_RESULT(result); | 461 CHECK_RESULT(result); |
| 462 | 462 |
| 463 Dart_Handle library = DartUtils::LoadScript(script_uri, builtin_lib); | 463 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(data); |
| 464 ASSERT(isolate_data != NULL); |
| 465 ASSERT(isolate_data->script_url != NULL); |
| 466 Dart_Handle library = DartUtils::LoadScript(isolate_data->script_url, |
| 467 builtin_lib); |
| 464 CHECK_RESULT(library); | 468 CHECK_RESULT(library); |
| 465 if (!Dart_IsLibrary(library)) { | 469 if (!Dart_IsLibrary(library)) { |
| 466 char errbuf[256]; | 470 char errbuf[256]; |
| 467 snprintf(errbuf, sizeof(errbuf), | 471 snprintf(errbuf, sizeof(errbuf), |
| 468 "Expected a library when loading script: %s", | 472 "Expected a library when loading script: %s", |
| 469 script_uri); | 473 script_uri); |
| 470 *error = strdup(errbuf); | 474 *error = strdup(errbuf); |
| 471 Dart_ExitScope(); | 475 Dart_ExitScope(); |
| 472 Dart_ShutdownIsolate(); | 476 Dart_ShutdownIsolate(); |
| 473 return NULL; | 477 return NULL; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 } | 511 } |
| 508 | 512 |
| 509 return isolate; | 513 return isolate; |
| 510 } | 514 } |
| 511 | 515 |
| 512 | 516 |
| 513 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | 517 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, |
| 514 const char* main, | 518 const char* main, |
| 515 void* data, char** error) { | 519 void* data, char** error) { |
| 516 bool is_compile_error = false; | 520 bool is_compile_error = false; |
| 521 if (script_uri == NULL) { |
| 522 if (data == NULL) { |
| 523 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
| 524 return NULL; |
| 525 } |
| 526 IsolateData* parent_isolate_data = reinterpret_cast<IsolateData*>(data); |
| 527 script_uri = parent_isolate_data->script_url; |
| 528 if (script_uri == NULL) { |
| 529 *error = strdup("Invalid 'callback_data' - Unable to spawn new isolate"); |
| 530 return NULL; |
| 531 } |
| 532 } |
| 533 IsolateData* isolate_data = new IsolateData(script_uri); |
| 517 return CreateIsolateAndSetupHelper(script_uri, | 534 return CreateIsolateAndSetupHelper(script_uri, |
| 518 main, | 535 main, |
| 519 new IsolateData(), | 536 isolate_data, |
| 520 error, | 537 error, |
| 521 &is_compile_error); | 538 &is_compile_error); |
| 522 } | 539 } |
| 523 | 540 |
| 524 | 541 |
| 525 static void PrintVersion() { | 542 static void PrintVersion() { |
| 526 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); | 543 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
| 527 } | 544 } |
| 528 | 545 |
| 529 | 546 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 Log::PrintErr("Could not start VM Service isolate %s\n", | 791 Log::PrintErr("Could not start VM Service isolate %s\n", |
| 775 VmService::GetErrorMessage()); | 792 VmService::GetErrorMessage()); |
| 776 } | 793 } |
| 777 } | 794 } |
| 778 | 795 |
| 779 // Call CreateIsolateAndSetup which creates an isolate and loads up | 796 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 780 // the specified application script. | 797 // the specified application script. |
| 781 char* error = NULL; | 798 char* error = NULL; |
| 782 bool is_compile_error = false; | 799 bool is_compile_error = false; |
| 783 char* isolate_name = BuildIsolateName(script_name, "main"); | 800 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 801 IsolateData* isolate_data = new IsolateData(script_name); |
| 784 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 802 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
| 785 "main", | 803 "main", |
| 786 new IsolateData(), | 804 isolate_data, |
| 787 &error, | 805 &error, |
| 788 &is_compile_error); | 806 &is_compile_error); |
| 789 if (isolate == NULL) { | 807 if (isolate == NULL) { |
| 790 Log::PrintErr("%s\n", error); | 808 Log::PrintErr("%s\n", error); |
| 791 free(error); | 809 free(error); |
| 792 delete [] isolate_name; | 810 delete [] isolate_name; |
| 793 return is_compile_error ? kCompilationErrorExitCode : kErrorExitCode; | 811 return is_compile_error ? kCompilationErrorExitCode : kErrorExitCode; |
| 794 } | 812 } |
| 795 delete [] isolate_name; | 813 delete [] isolate_name; |
| 796 | 814 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 | 919 |
| 902 return Process::GlobalExitCode(); | 920 return Process::GlobalExitCode(); |
| 903 } | 921 } |
| 904 | 922 |
| 905 } // namespace bin | 923 } // namespace bin |
| 906 } // namespace dart | 924 } // namespace dart |
| 907 | 925 |
| 908 int main(int argc, char** argv) { | 926 int main(int argc, char** argv) { |
| 909 return dart::bin::main(argc, argv); | 927 return dart::bin::main(argc, argv); |
| 910 } | 928 } |
| OLD | NEW |