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_tools_api.h" | 8 #include "include/dart_tools_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 | 10 |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 void DartUtils::WriteMagicNumber(File* file) { | 475 void DartUtils::WriteMagicNumber(File* file) { |
476 // Write a magic number and version information into the snapshot file. | 476 // Write a magic number and version information into the snapshot file. |
477 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); | 477 bool bytes_written = file->WriteFully(magic_number, sizeof(magic_number)); |
478 ASSERT(bytes_written); | 478 ASSERT(bytes_written); |
479 } | 479 } |
480 | 480 |
481 | 481 |
482 Dart_Handle DartUtils::LoadScript(const char* script_uri, | 482 Dart_Handle DartUtils::LoadScript(const char* script_uri, |
483 Dart_Handle builtin_lib) { | 483 Dart_Handle builtin_lib) { |
484 Dart_Handle uri = Dart_NewStringFromCString(script_uri); | 484 Dart_Handle uri = Dart_NewStringFromCString(script_uri); |
485 | |
486 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); | |
487 if (load_port == ILLEGAL_PORT) { | |
488 return NewDartUnsupportedError("Service did not return load port."); | |
489 } | |
490 Builtin::SetLoadPort(load_port); | |
491 IsolateData* isolate_data = | 485 IsolateData* isolate_data = |
492 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 486 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
493 Dart_TimelineAsyncBegin("LoadScript", &(isolate_data->load_async_id)); | 487 Dart_TimelineAsyncBegin("LoadScript", &(isolate_data->load_async_id)); |
494 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib); | 488 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib); |
495 } | 489 } |
496 | 490 |
497 | 491 |
498 // Callback function, gets called from asynchronous script and library | 492 // Callback function, gets called from asynchronous script and library |
499 // reading code when there is an i/o error. | 493 // reading code when there is an i/o error. |
500 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { | 494 void FUNCTION_NAME(Builtin_AsyncLoadError)(Dart_NativeArguments args) { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 if (current != NULL) { | 619 if (current != NULL) { |
626 Dart_SetReturnValue(args, DartUtils::NewString(current)); | 620 Dart_SetReturnValue(args, DartUtils::NewString(current)); |
627 free(current); | 621 free(current); |
628 } else { | 622 } else { |
629 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); | 623 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); |
630 Dart_PropagateError(err); | 624 Dart_PropagateError(err); |
631 } | 625 } |
632 } | 626 } |
633 | 627 |
634 | 628 |
635 void DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 629 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
636 Dart_Handle internal_lib, | 630 Dart_Handle internal_lib, |
637 bool is_service_isolate, | 631 bool is_service_isolate, |
638 bool trace_loading, | 632 bool trace_loading, |
639 const char* package_root) { | 633 const char* package_root, |
| 634 const char* packages_file) { |
640 // Setup the internal library's 'internalPrint' function. | 635 // Setup the internal library's 'internalPrint' function. |
641 Dart_Handle print = Dart_Invoke( | 636 Dart_Handle print = Dart_Invoke( |
642 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 637 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
643 DART_CHECK_VALID(print); | 638 DART_CHECK_VALID(print); |
644 Dart_Handle result = | 639 Dart_Handle result = |
645 Dart_SetField(internal_lib, NewString("_printClosure"), print); | 640 Dart_SetField(internal_lib, NewString("_printClosure"), print); |
646 DART_CHECK_VALID(result); | 641 DART_CHECK_VALID(result); |
647 | 642 |
648 if (!is_service_isolate) { | 643 if (!is_service_isolate) { |
649 if (IsWindowsHost()) { | 644 if (IsWindowsHost()) { |
650 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); | 645 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); |
651 DART_CHECK_VALID(result); | 646 DART_CHECK_VALID(result); |
652 } | 647 } |
653 if (trace_loading) { | 648 if (trace_loading) { |
654 result = Dart_SetField(builtin_lib, | 649 result = Dart_SetField(builtin_lib, |
655 NewString("_traceLoading"), Dart_True()); | 650 NewString("_traceLoading"), Dart_True()); |
656 DART_CHECK_VALID(result); | 651 DART_CHECK_VALID(result); |
657 } | 652 } |
658 } | |
659 | |
660 if (!is_service_isolate) { | |
661 // Set current working directory. | 653 // Set current working directory. |
662 result = SetWorkingDirectory(builtin_lib); | 654 result = SetWorkingDirectory(builtin_lib); |
663 DART_CHECK_VALID(result); | 655 DART_CHECK_VALID(result); |
| 656 // Wait for the service isolate to initialize the load port. |
| 657 Dart_Port load_port = Dart_ServiceWaitForLoadPort(); |
| 658 if (load_port == ILLEGAL_PORT) { |
| 659 return NewDartUnsupportedError("Service did not return load port."); |
| 660 } |
| 661 Builtin::SetLoadPort(load_port); |
664 } | 662 } |
665 | 663 |
666 // Set up package root if specified. | 664 // Set up package root if specified. |
667 if (package_root != NULL) { | 665 if (package_root != NULL) { |
| 666 ASSERT(packages_file == NULL); |
668 result = NewString(package_root); | 667 result = NewString(package_root); |
669 DART_CHECK_VALID(result); | 668 DART_CHECK_VALID(result); |
670 const int kNumArgs = 1; | 669 const int kNumArgs = 1; |
671 Dart_Handle dart_args[kNumArgs]; | 670 Dart_Handle dart_args[kNumArgs]; |
672 dart_args[0] = result; | 671 dart_args[0] = result; |
673 result = Dart_Invoke(builtin_lib, | 672 result = Dart_Invoke(builtin_lib, |
674 NewString("_setPackageRoot"), | 673 NewString("_setPackageRoot"), |
675 kNumArgs, | 674 kNumArgs, |
676 dart_args); | 675 dart_args); |
677 DART_CHECK_VALID(result); | 676 DART_CHECK_VALID(result); |
| 677 } else if (packages_file != NULL) { |
| 678 result = NewString(packages_file); |
| 679 DART_CHECK_VALID(result); |
| 680 const int kNumArgs = 1; |
| 681 Dart_Handle dart_args[kNumArgs]; |
| 682 dart_args[0] = result; |
| 683 result = Dart_Invoke(builtin_lib, |
| 684 NewString("_loadPackagesMap"), |
| 685 kNumArgs, |
| 686 dart_args); |
| 687 DART_CHECK_VALID(result); |
678 } | 688 } |
| 689 return Dart_True(); |
679 } | 690 } |
680 | 691 |
681 | 692 |
682 void DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, | 693 void DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, |
683 Dart_Handle builtin_lib, | 694 Dart_Handle builtin_lib, |
684 bool is_service_isolate) { | 695 bool is_service_isolate) { |
685 if (!is_service_isolate) { | 696 if (!is_service_isolate) { |
686 // Setup the 'Uri.base' getter in dart:core. | 697 // Setup the 'Uri.base' getter in dart:core. |
687 Dart_Handle uri_base = Dart_Invoke( | 698 Dart_Handle uri_base = Dart_Invoke( |
688 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); | 699 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); |
(...skipping 22 matching lines...) Expand all Loading... |
711 DART_CHECK_VALID(Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL)); | 722 DART_CHECK_VALID(Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL)); |
712 } | 723 } |
713 | 724 |
714 | 725 |
715 void DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { | 726 void DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { |
716 DART_CHECK_VALID(Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL)); | 727 DART_CHECK_VALID(Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL)); |
717 } | 728 } |
718 | 729 |
719 | 730 |
720 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 731 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, |
| 732 const char* packages_file, |
721 bool is_service_isolate, | 733 bool is_service_isolate, |
722 bool trace_loading, | 734 bool trace_loading, |
723 Dart_Handle builtin_lib) { | 735 Dart_Handle builtin_lib) { |
724 // First ensure all required libraries are available. | 736 // First ensure all required libraries are available. |
725 Dart_Handle url = NewString(kCoreLibURL); | 737 Dart_Handle url = NewString(kCoreLibURL); |
726 DART_CHECK_VALID(url); | 738 DART_CHECK_VALID(url); |
727 Dart_Handle core_lib = Dart_LookupLibrary(url); | 739 Dart_Handle core_lib = Dart_LookupLibrary(url); |
728 DART_CHECK_VALID(core_lib); | 740 DART_CHECK_VALID(core_lib); |
729 url = NewString(kAsyncLibURL); | 741 url = NewString(kAsyncLibURL); |
730 DART_CHECK_VALID(url); | 742 DART_CHECK_VALID(url); |
731 Dart_Handle async_lib = Dart_LookupLibrary(url); | 743 Dart_Handle async_lib = Dart_LookupLibrary(url); |
732 DART_CHECK_VALID(async_lib); | 744 DART_CHECK_VALID(async_lib); |
733 url = NewString(kIsolateLibURL); | 745 url = NewString(kIsolateLibURL); |
734 DART_CHECK_VALID(url); | 746 DART_CHECK_VALID(url); |
735 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | 747 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
736 DART_CHECK_VALID(isolate_lib); | 748 DART_CHECK_VALID(isolate_lib); |
737 url = NewString(kInternalLibURL); | 749 url = NewString(kInternalLibURL); |
738 DART_CHECK_VALID(url); | 750 DART_CHECK_VALID(url); |
739 Dart_Handle internal_lib = Dart_LookupLibrary(url); | 751 Dart_Handle internal_lib = Dart_LookupLibrary(url); |
740 DART_CHECK_VALID(internal_lib); | 752 DART_CHECK_VALID(internal_lib); |
741 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 753 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
742 DART_CHECK_VALID(io_lib); | 754 DART_CHECK_VALID(io_lib); |
743 | 755 |
744 // We need to ensure that all the scripts loaded so far are finalized | 756 // We need to ensure that all the scripts loaded so far are finalized |
745 // as we are about to invoke some Dart code below to setup closures. | 757 // as we are about to invoke some Dart code below to setup closures. |
746 Dart_Handle result = Dart_FinalizeLoading(false); | 758 Dart_Handle result = Dart_FinalizeLoading(false); |
747 DART_CHECK_VALID(result); | 759 DART_CHECK_VALID(result); |
748 | 760 |
749 PrepareBuiltinLibrary(builtin_lib, | 761 result = PrepareBuiltinLibrary(builtin_lib, |
750 internal_lib, | 762 internal_lib, |
751 is_service_isolate, | 763 is_service_isolate, |
752 trace_loading, | 764 trace_loading, |
753 package_root); | 765 package_root, |
| 766 packages_file); |
| 767 DART_CHECK_VALID(result); |
| 768 |
754 PrepareAsyncLibrary(async_lib, isolate_lib); | 769 PrepareAsyncLibrary(async_lib, isolate_lib); |
755 PrepareCoreLibrary(core_lib, builtin_lib, is_service_isolate); | 770 PrepareCoreLibrary(core_lib, builtin_lib, is_service_isolate); |
756 PrepareIsolateLibrary(isolate_lib); | 771 PrepareIsolateLibrary(isolate_lib); |
757 PrepareIOLibrary(io_lib); | 772 PrepareIOLibrary(io_lib); |
758 return result; | 773 return result; |
759 } | 774 } |
760 | 775 |
761 | 776 |
762 void DartUtils::SetupIOLibrary(const char* script_uri) { | 777 void DartUtils::SetupIOLibrary(const char* script_uri) { |
763 Dart_Handle io_lib_url = NewString(kIOLibURL); | 778 Dart_Handle io_lib_url = NewString(kIOLibURL); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 new CObjectString(CObject::NewString(os_error->message())); | 1229 new CObjectString(CObject::NewString(os_error->message())); |
1215 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1230 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1216 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1231 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1217 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1232 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1218 result->SetAt(2, error_message); | 1233 result->SetAt(2, error_message); |
1219 return result; | 1234 return result; |
1220 } | 1235 } |
1221 | 1236 |
1222 } // namespace bin | 1237 } // namespace bin |
1223 } // namespace dart | 1238 } // namespace dart |
OLD | NEW |