| 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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 | 9 |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 } else { | 617 } else { |
| 618 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); | 618 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); |
| 619 Dart_PropagateError(err); | 619 Dart_PropagateError(err); |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 | 622 |
| 623 | 623 |
| 624 void DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 624 void DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
| 625 Dart_Handle internal_lib, | 625 Dart_Handle internal_lib, |
| 626 bool is_service_isolate, | 626 bool is_service_isolate, |
| 627 bool trace_loading, |
| 627 const char* package_root) { | 628 const char* package_root) { |
| 628 // Setup the internal library's 'internalPrint' function. | 629 // Setup the internal library's 'internalPrint' function. |
| 629 Dart_Handle print = Dart_Invoke( | 630 Dart_Handle print = Dart_Invoke( |
| 630 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 631 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
| 631 DART_CHECK_VALID(print); | 632 DART_CHECK_VALID(print); |
| 632 Dart_Handle result = | 633 Dart_Handle result = |
| 633 Dart_SetField(internal_lib, NewString("_printClosure"), print); | 634 Dart_SetField(internal_lib, NewString("_printClosure"), print); |
| 634 DART_CHECK_VALID(result); | 635 DART_CHECK_VALID(result); |
| 635 | 636 |
| 636 if (!is_service_isolate) { | 637 if (!is_service_isolate) { |
| 637 result = | 638 if (IsWindowsHost()) { |
| 638 Dart_SetField(builtin_lib, NewString("_isWindows"), | 639 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); |
| 639 IsWindowsHost() ? Dart_True() : Dart_False()); | 640 DART_CHECK_VALID(result); |
| 640 DART_CHECK_VALID(result); | 641 } |
| 642 if (trace_loading) { |
| 643 result = Dart_SetField(builtin_lib, |
| 644 NewString("_traceLoading"), Dart_True()); |
| 645 DART_CHECK_VALID(result); |
| 646 } |
| 641 } | 647 } |
| 642 | 648 |
| 643 if (!is_service_isolate) { | 649 if (!is_service_isolate) { |
| 644 // Set current working directory. | 650 // Set current working directory. |
| 645 result = SetWorkingDirectory(builtin_lib); | 651 result = SetWorkingDirectory(builtin_lib); |
| 646 DART_CHECK_VALID(result); | 652 DART_CHECK_VALID(result); |
| 647 } | 653 } |
| 648 | 654 |
| 649 // Set up package root if specified. | 655 // Set up package root if specified. |
| 650 if (package_root != NULL) { | 656 if (package_root != NULL) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 } | 701 } |
| 696 | 702 |
| 697 | 703 |
| 698 void DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { | 704 void DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { |
| 699 DART_CHECK_VALID(Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL)); | 705 DART_CHECK_VALID(Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL)); |
| 700 } | 706 } |
| 701 | 707 |
| 702 | 708 |
| 703 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 709 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, |
| 704 bool is_service_isolate, | 710 bool is_service_isolate, |
| 711 bool trace_loading, |
| 705 Dart_Handle builtin_lib) { | 712 Dart_Handle builtin_lib) { |
| 706 // First ensure all required libraries are available. | 713 // First ensure all required libraries are available. |
| 707 Dart_Handle url = NewString(kCoreLibURL); | 714 Dart_Handle url = NewString(kCoreLibURL); |
| 708 DART_CHECK_VALID(url); | 715 DART_CHECK_VALID(url); |
| 709 Dart_Handle core_lib = Dart_LookupLibrary(url); | 716 Dart_Handle core_lib = Dart_LookupLibrary(url); |
| 710 DART_CHECK_VALID(core_lib); | 717 DART_CHECK_VALID(core_lib); |
| 711 url = NewString(kAsyncLibURL); | 718 url = NewString(kAsyncLibURL); |
| 712 DART_CHECK_VALID(url); | 719 DART_CHECK_VALID(url); |
| 713 Dart_Handle async_lib = Dart_LookupLibrary(url); | 720 Dart_Handle async_lib = Dart_LookupLibrary(url); |
| 714 DART_CHECK_VALID(async_lib); | 721 DART_CHECK_VALID(async_lib); |
| 715 url = NewString(kIsolateLibURL); | 722 url = NewString(kIsolateLibURL); |
| 716 DART_CHECK_VALID(url); | 723 DART_CHECK_VALID(url); |
| 717 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | 724 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
| 718 DART_CHECK_VALID(isolate_lib); | 725 DART_CHECK_VALID(isolate_lib); |
| 719 url = NewString(kInternalLibURL); | 726 url = NewString(kInternalLibURL); |
| 720 DART_CHECK_VALID(url); | 727 DART_CHECK_VALID(url); |
| 721 Dart_Handle internal_lib = Dart_LookupLibrary(url); | 728 Dart_Handle internal_lib = Dart_LookupLibrary(url); |
| 722 DART_CHECK_VALID(internal_lib); | 729 DART_CHECK_VALID(internal_lib); |
| 723 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 730 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 724 DART_CHECK_VALID(io_lib); | 731 DART_CHECK_VALID(io_lib); |
| 725 | 732 |
| 726 // We need to ensure that all the scripts loaded so far are finalized | 733 // We need to ensure that all the scripts loaded so far are finalized |
| 727 // as we are about to invoke some Dart code below to setup closures. | 734 // as we are about to invoke some Dart code below to setup closures. |
| 728 Dart_Handle result = Dart_FinalizeLoading(false); | 735 Dart_Handle result = Dart_FinalizeLoading(false); |
| 729 DART_CHECK_VALID(result); | 736 DART_CHECK_VALID(result); |
| 730 | 737 |
| 731 PrepareBuiltinLibrary(builtin_lib, | 738 PrepareBuiltinLibrary(builtin_lib, |
| 732 internal_lib, | 739 internal_lib, |
| 733 is_service_isolate, | 740 is_service_isolate, |
| 741 trace_loading, |
| 734 package_root); | 742 package_root); |
| 735 PrepareAsyncLibrary(async_lib, isolate_lib); | 743 PrepareAsyncLibrary(async_lib, isolate_lib); |
| 736 PrepareCoreLibrary(core_lib, builtin_lib, is_service_isolate); | 744 PrepareCoreLibrary(core_lib, builtin_lib, is_service_isolate); |
| 737 PrepareIsolateLibrary(isolate_lib); | 745 PrepareIsolateLibrary(isolate_lib); |
| 738 PrepareIOLibrary(io_lib); | 746 PrepareIOLibrary(io_lib); |
| 739 return result; | 747 return result; |
| 740 } | 748 } |
| 741 | 749 |
| 742 | 750 |
| 743 void DartUtils::SetupIOLibrary(const char* script_uri) { | 751 void DartUtils::SetupIOLibrary(const char* script_uri) { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 new CObjectString(CObject::NewString(os_error->message())); | 1203 new CObjectString(CObject::NewString(os_error->message())); |
| 1196 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1204 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1197 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1205 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1198 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1206 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1199 result->SetAt(2, error_message); | 1207 result->SetAt(2, error_message); |
| 1200 return result; | 1208 return result; |
| 1201 } | 1209 } |
| 1202 | 1210 |
| 1203 } // namespace bin | 1211 } // namespace bin |
| 1204 } // namespace dart | 1212 } // namespace dart |
| OLD | NEW |