| 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 *error = strdup(Dart_GetError(result)); \ | 392 *error = strdup(Dart_GetError(result)); \ |
| 393 Dart_ExitScope(); \ | 393 Dart_ExitScope(); \ |
| 394 Dart_ShutdownIsolate(); \ | 394 Dart_ShutdownIsolate(); \ |
| 395 return false; \ | 395 return false; \ |
| 396 } \ | 396 } \ |
| 397 | 397 |
| 398 | 398 |
| 399 // Returns true on success, false on failure. | 399 // Returns true on success, false on failure. |
| 400 static bool CreateIsolateAndSetupHelper(const char* script_uri, | 400 static bool CreateIsolateAndSetupHelper(const char* script_uri, |
| 401 const char* main, | 401 const char* main, |
| 402 bool resolve_script, | |
| 403 void* data, | 402 void* data, |
| 404 char** error) { | 403 char** error) { |
| 405 Dart_Isolate isolate = | 404 Dart_Isolate isolate = |
| 406 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); | 405 Dart_CreateIsolate(script_uri, main, snapshot_buffer, data, error); |
| 407 if (isolate == NULL) { | 406 if (isolate == NULL) { |
| 408 return false; | 407 return false; |
| 409 } | 408 } |
| 410 | 409 |
| 411 Dart_EnterScope(); | 410 Dart_EnterScope(); |
| 412 | 411 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 CHECK_RESULT(uri_lib); | 458 CHECK_RESULT(uri_lib); |
| 460 Dart_Handle builtin_lib = | 459 Dart_Handle builtin_lib = |
| 461 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 460 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 462 CHECK_RESULT(builtin_lib); | 461 CHECK_RESULT(builtin_lib); |
| 463 | 462 |
| 464 // Prepare for script loading by setting up the 'print' and 'timer' | 463 // Prepare for script loading by setting up the 'print' and 'timer' |
| 465 // closures and setting up 'package root' for URI resolution. | 464 // closures and setting up 'package root' for URI resolution. |
| 466 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); | 465 result = DartUtils::PrepareForScriptLoading(package_root, builtin_lib); |
| 467 CHECK_RESULT(result); | 466 CHECK_RESULT(result); |
| 468 | 467 |
| 469 library = DartUtils::LoadScript(script_uri, resolve_script, builtin_lib); | 468 library = DartUtils::LoadScript(script_uri, builtin_lib); |
| 470 } | 469 } |
| 471 CHECK_RESULT(library); | 470 CHECK_RESULT(library); |
| 472 if (!Dart_IsLibrary(library)) { | 471 if (!Dart_IsLibrary(library)) { |
| 473 char errbuf[256]; | 472 char errbuf[256]; |
| 474 snprintf(errbuf, sizeof(errbuf), | 473 snprintf(errbuf, sizeof(errbuf), |
| 475 "Expected a library when loading script: %s", | 474 "Expected a library when loading script: %s", |
| 476 script_uri); | 475 script_uri); |
| 477 *error = strdup(errbuf); | 476 *error = strdup(errbuf); |
| 478 Dart_ExitScope(); | 477 Dart_ExitScope(); |
| 479 Dart_ShutdownIsolate(); | 478 Dart_ShutdownIsolate(); |
| 480 return false; | 479 return false; |
| 481 } | 480 } |
| 482 Dart_ExitScope(); | 481 Dart_ExitScope(); |
| 483 return true; | 482 return true; |
| 484 } | 483 } |
| 485 | 484 |
| 486 | 485 |
| 487 static bool CreateIsolateAndSetup(const char* script_uri, | 486 static bool CreateIsolateAndSetup(const char* script_uri, |
| 488 const char* main, | 487 const char* main, |
| 489 void* data, char** error) { | 488 void* data, char** error) { |
| 490 return CreateIsolateAndSetupHelper(script_uri, | 489 return CreateIsolateAndSetupHelper(script_uri, |
| 491 main, | 490 main, |
| 492 false, // script_uri already canonical. | |
| 493 new IsolateData(), | 491 new IsolateData(), |
| 494 error); | 492 error); |
| 495 } | 493 } |
| 496 | 494 |
| 497 | 495 |
| 498 static void PrintVersion() { | 496 static void PrintVersion() { |
| 499 fprintf(stderr, "Dart VM version: %s\n", Dart_VersionString()); | 497 fprintf(stderr, "Dart VM version: %s\n", Dart_VersionString()); |
| 500 } | 498 } |
| 501 | 499 |
| 502 | 500 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 ASSERT(debug_port != 0); | 675 ASSERT(debug_port != 0); |
| 678 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); | 676 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); |
| 679 } | 677 } |
| 680 | 678 |
| 681 // Call CreateIsolateAndSetup which creates an isolate and loads up | 679 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 682 // the specified application script. | 680 // the specified application script. |
| 683 char* error = NULL; | 681 char* error = NULL; |
| 684 char* isolate_name = BuildIsolateName(script_name, "main"); | 682 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 685 if (!CreateIsolateAndSetupHelper(script_name, | 683 if (!CreateIsolateAndSetupHelper(script_name, |
| 686 "main", | 684 "main", |
| 687 true, // Canonicalize the script name. | |
| 688 new IsolateData(), | 685 new IsolateData(), |
| 689 &error)) { | 686 &error)) { |
| 690 fprintf(stderr, "%s\n", error); | 687 fprintf(stderr, "%s\n", error); |
| 691 free(error); | 688 free(error); |
| 692 delete [] isolate_name; | 689 delete [] isolate_name; |
| 693 return kErrorExitCode; // Indicates we encountered an error. | 690 return kErrorExitCode; // Indicates we encountered an error. |
| 694 } | 691 } |
| 695 delete [] isolate_name; | 692 delete [] isolate_name; |
| 696 | 693 |
| 697 Dart_Isolate isolate = Dart_CurrentIsolate(); | 694 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 Dart_ExitScope(); | 740 Dart_ExitScope(); |
| 744 // Dump symbol information for the profiler. | 741 // Dump symbol information for the profiler. |
| 745 DumpPprofSymbolInfo(); | 742 DumpPprofSymbolInfo(); |
| 746 // Shutdown the isolate. | 743 // Shutdown the isolate. |
| 747 Dart_ShutdownIsolate(); | 744 Dart_ShutdownIsolate(); |
| 748 // Terminate process exit-code handler. | 745 // Terminate process exit-code handler. |
| 749 Process::TerminateExitCodeHandler(); | 746 Process::TerminateExitCodeHandler(); |
| 750 | 747 |
| 751 return 0; | 748 return 0; |
| 752 } | 749 } |
| OLD | NEW |