| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return file_path; | 458 return file_path; |
| 459 } | 459 } |
| 460 Dart_StringToCString(file_path, &url_string); | 460 Dart_StringToCString(file_path, &url_string); |
| 461 } | 461 } |
| 462 if (is_dart_extension_url) { | 462 if (is_dart_extension_url) { |
| 463 if (tag != kImportTag) { | 463 if (tag != kImportTag) { |
| 464 return Dart_Error("Dart extensions must use import: '%s'", url_string); | 464 return Dart_Error("Dart extensions must use import: '%s'", url_string); |
| 465 } | 465 } |
| 466 return Extensions::LoadExtension(url_string, library); | 466 return Extensions::LoadExtension(url_string, library); |
| 467 } | 467 } |
| 468 result = DartUtils::LoadSource(NULL, | 468 return DartUtils::LoadSource(NULL, |
| 469 library, | 469 library, |
| 470 url, | 470 url, |
| 471 tag, | 471 tag, |
| 472 url_string); | 472 url_string); |
| 473 if (!Dart_IsError(result) && (tag == kImportTag)) { | |
| 474 Builtin::ImportLibrary(result, Builtin::kBuiltinLibrary); | |
| 475 } | |
| 476 return result; | |
| 477 } | 473 } |
| 478 | 474 |
| 479 | 475 |
| 480 static Dart_Handle ReadSource(Dart_Handle script_uri, | 476 static Dart_Handle ReadSource(Dart_Handle script_uri, |
| 481 Dart_Handle builtin_lib) { | 477 Dart_Handle builtin_lib) { |
| 482 Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib); | 478 Dart_Handle script_path = FilePathFromUri(script_uri, builtin_lib); |
| 483 if (Dart_IsError(script_path)) { | 479 if (Dart_IsError(script_path)) { |
| 484 return script_path; | 480 return script_path; |
| 485 } | 481 } |
| 486 const char* script_path_cstr; | 482 const char* script_path_cstr; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 return false; | 580 return false; |
| 585 } | 581 } |
| 586 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); | 582 Dart_Handle builtin_lib = Builtin::LoadLibrary(Builtin::kBuiltinLibrary); |
| 587 if (Dart_IsError(builtin_lib)) { | 583 if (Dart_IsError(builtin_lib)) { |
| 588 *error = strdup(Dart_GetError(builtin_lib)); | 584 *error = strdup(Dart_GetError(builtin_lib)); |
| 589 Dart_ExitScope(); | 585 Dart_ExitScope(); |
| 590 Dart_ShutdownIsolate(); | 586 Dart_ShutdownIsolate(); |
| 591 return false; | 587 return false; |
| 592 } | 588 } |
| 593 | 589 |
| 590 // Setup the corelib 'print' function. |
| 591 Dart_Handle print = |
| 592 Dart_Invoke(builtin_lib, Dart_NewString("_getPrintClosure"), 0, 0); |
| 593 Dart_Handle coreimpl = Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); |
| 594 Dart_Handle print_impl = |
| 595 Dart_GetClass(coreimpl, Dart_NewString("PrintImplementation")); |
| 596 Dart_SetField(print_impl, Dart_NewString("_printClosure"), print); |
| 597 |
| 594 // Setup the IO library. | 598 // Setup the IO library. |
| 595 Dart_Handle io_lib = Builtin::LoadLibrary(Builtin::kIOLibrary); | 599 Dart_Handle io_lib = Builtin::LoadLibrary(Builtin::kIOLibrary); |
| 596 Builtin::SetupIOLibrary(io_lib); | 600 Builtin::SetupIOLibrary(io_lib); |
| 597 | 601 |
| 598 if (package_root != NULL) { | 602 if (package_root != NULL) { |
| 599 const int kNumArgs = 1; | 603 const int kNumArgs = 1; |
| 600 Dart_Handle dart_args[kNumArgs]; | 604 Dart_Handle dart_args[kNumArgs]; |
| 601 | 605 |
| 602 Dart_Handle handle = Dart_NewString(package_root); | 606 Dart_Handle handle = Dart_NewString(package_root); |
| 603 if (Dart_IsError(handle)) { | 607 if (Dart_IsError(handle)) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 629 if (!Dart_IsLibrary(library)) { | 633 if (!Dart_IsLibrary(library)) { |
| 630 char errbuf[256]; | 634 char errbuf[256]; |
| 631 snprintf(errbuf, sizeof(errbuf), | 635 snprintf(errbuf, sizeof(errbuf), |
| 632 "Expected a library when loading script: %s", | 636 "Expected a library when loading script: %s", |
| 633 script_uri); | 637 script_uri); |
| 634 *error = strdup(errbuf); | 638 *error = strdup(errbuf); |
| 635 Dart_ExitScope(); | 639 Dart_ExitScope(); |
| 636 Dart_ShutdownIsolate(); | 640 Dart_ShutdownIsolate(); |
| 637 return false; | 641 return false; |
| 638 } | 642 } |
| 639 // Implicitly import builtin into app. | |
| 640 Builtin::ImportLibrary(library, Builtin::kBuiltinLibrary); | |
| 641 Dart_ExitScope(); | 643 Dart_ExitScope(); |
| 642 return true; | 644 return true; |
| 643 } | 645 } |
| 644 | 646 |
| 645 | 647 |
| 646 static bool CreateIsolateAndSetup(const char* script_uri, | 648 static bool CreateIsolateAndSetup(const char* script_uri, |
| 647 const char* main, | 649 const char* main, |
| 648 void* data, char** error) { | 650 void* data, char** error) { |
| 649 return CreateIsolateAndSetupHelper(script_uri, | 651 return CreateIsolateAndSetupHelper(script_uri, |
| 650 main, | 652 main, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 DumpPprofSymbolInfo(); | 855 DumpPprofSymbolInfo(); |
| 854 // Shutdown the isolate. | 856 // Shutdown the isolate. |
| 855 Dart_ShutdownIsolate(); | 857 Dart_ShutdownIsolate(); |
| 856 // Terminate process exit-code handler. | 858 // Terminate process exit-code handler. |
| 857 Process::TerminateExitCodeHandler(); | 859 Process::TerminateExitCodeHandler(); |
| 858 | 860 |
| 859 free(const_cast<char*>(original_working_directory)); | 861 free(const_cast<char*>(original_working_directory)); |
| 860 | 862 |
| 861 return 0; | 863 return 0; |
| 862 } | 864 } |
| OLD | NEW |