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 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 return Dart_LoadLibrary(url, source); | 774 return Dart_LoadLibrary(url, source); |
775 } else if (tag == Dart_kSourceTag) { | 775 } else if (tag == Dart_kSourceTag) { |
776 return Dart_LoadSource(library, url, source); | 776 return Dart_LoadSource(library, url, source); |
777 } | 777 } |
778 return Dart_NewApiError("wrong tag"); | 778 return Dart_NewApiError("wrong tag"); |
779 } | 779 } |
780 | 780 |
781 | 781 |
782 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 782 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, |
783 Dart_Handle builtin_lib) { | 783 Dart_Handle builtin_lib) { |
784 // Setup the internal library's 'internalPrint' function. | 784 // First ensure all required libraries are available. |
785 Dart_Handle print = Dart_Invoke( | 785 Dart_Handle url = NewString(kAsyncLibURL); |
786 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | |
787 Dart_Handle url = NewString(kInternalLibURL); | |
788 DART_CHECK_VALID(url); | |
789 Dart_Handle internal_lib = Dart_LookupLibrary(url); | |
790 DART_CHECK_VALID(internal_lib); | |
791 Dart_Handle result = Dart_SetField(internal_lib, | |
792 NewString("_printClosure"), | |
793 print); | |
794 DART_CHECK_VALID(result); | |
795 | |
796 // Setup the 'timer' factory. | |
797 url = NewString(kAsyncLibURL); | |
798 DART_CHECK_VALID(url); | 786 DART_CHECK_VALID(url); |
799 Dart_Handle async_lib = Dart_LookupLibrary(url); | 787 Dart_Handle async_lib = Dart_LookupLibrary(url); |
800 DART_CHECK_VALID(async_lib); | 788 DART_CHECK_VALID(async_lib); |
801 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 789 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
802 | 790 |
803 // We need to ensure that all the scripts loaded so far are finalized | 791 // We need to ensure that all the scripts loaded so far are finalized |
804 // as we are about to invoke some Dart code below to setup closures. | 792 // as we are about to invoke some Dart code below to setup closures. |
805 result = Dart_FinalizeLoading(false); | 793 Dart_Handle result = Dart_FinalizeLoading(false); |
806 DART_CHECK_VALID(result); | 794 DART_CHECK_VALID(result); |
807 | 795 |
| 796 // Setup the internal library's 'internalPrint' function. |
| 797 Dart_Handle print = Dart_Invoke( |
| 798 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
| 799 url = NewString(kInternalLibURL); |
| 800 DART_CHECK_VALID(url); |
| 801 Dart_Handle internal_lib = Dart_LookupLibrary(url); |
| 802 DART_CHECK_VALID(internal_lib); |
| 803 result = Dart_SetField(internal_lib, |
| 804 NewString("_printClosure"), |
| 805 print); |
| 806 DART_CHECK_VALID(result); |
| 807 |
| 808 // Setup the 'timer' factory. |
808 Dart_Handle timer_closure = | 809 Dart_Handle timer_closure = |
809 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL); | 810 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL); |
810 Dart_Handle args[1]; | 811 Dart_Handle args[1]; |
811 args[0] = timer_closure; | 812 args[0] = timer_closure; |
812 DART_CHECK_VALID(Dart_Invoke( | 813 DART_CHECK_VALID(Dart_Invoke( |
813 async_lib, NewString("_setTimerFactoryClosure"), 1, args)); | 814 async_lib, NewString("_setTimerFactoryClosure"), 1, args)); |
814 | 815 |
815 // Setup the 'scheduleImmediate' closure. | 816 // Setup the 'scheduleImmediate' closure. |
816 url = NewString(kIsolateLibURL); | 817 url = NewString(kIsolateLibURL); |
817 DART_CHECK_VALID(url); | 818 DART_CHECK_VALID(url); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 new CObjectString(CObject::NewString(os_error->message())); | 1160 new CObjectString(CObject::NewString(os_error->message())); |
1160 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1161 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1161 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1162 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1162 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1163 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1163 result->SetAt(2, error_message); | 1164 result->SetAt(2, error_message); |
1164 return result; | 1165 return result; |
1165 } | 1166 } |
1166 | 1167 |
1167 } // namespace bin | 1168 } // namespace bin |
1168 } // namespace dart | 1169 } // namespace dart |
OLD | NEW |