| 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" |
| 11 #include "platform/globals.h" | 11 #include "platform/globals.h" |
| 12 | 12 |
| 13 #include "bin/crypto.h" | 13 #include "bin/crypto.h" |
| 14 #include "bin/directory.h" | 14 #include "bin/directory.h" |
| 15 #include "bin/extensions.h" | 15 #include "bin/extensions.h" |
| 16 #include "bin/file.h" | 16 #include "bin/file.h" |
| 17 #include "bin/io_buffer.h" | 17 #include "bin/io_buffer.h" |
| 18 #include "bin/socket.h" | 18 #include "bin/socket.h" |
| 19 #include "bin/utils.h" | 19 #include "bin/utils.h" |
| 20 | 20 |
| 21 namespace dart { | 21 namespace dart { |
| 22 namespace bin { | 22 namespace bin { |
| 23 | 23 |
| 24 const char* DartUtils::original_working_directory = NULL; | 24 const char* DartUtils::original_working_directory = NULL; |
| 25 const char* DartUtils::kDartScheme = "dart:"; | 25 const char* DartUtils::kDartScheme = "dart:"; |
| 26 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; | 26 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; |
| 27 const char* DartUtils::kAsyncLibURL = "dart:async"; | 27 const char* DartUtils::kAsyncLibURL = "dart:async"; |
| 28 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; | 28 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; |
| 29 const char* DartUtils::kCollectionDevLibURL = "dart:_collection-dev"; |
| 29 const char* DartUtils::kCoreLibURL = "dart:core"; | 30 const char* DartUtils::kCoreLibURL = "dart:core"; |
| 31 const char* DartUtils::kIsolateLibURL = "dart:isolate"; |
| 30 const char* DartUtils::kIOLibURL = "dart:io"; | 32 const char* DartUtils::kIOLibURL = "dart:io"; |
| 31 const char* DartUtils::kIOLibPatchURL = "dart:io-patch"; | 33 const char* DartUtils::kIOLibPatchURL = "dart:io-patch"; |
| 32 const char* DartUtils::kUriLibURL = "dart:uri"; | 34 const char* DartUtils::kUriLibURL = "dart:uri"; |
| 33 const char* DartUtils::kHttpScheme = "http:"; | 35 const char* DartUtils::kHttpScheme = "http:"; |
| 34 | 36 |
| 35 const char* DartUtils::kIdFieldName = "_id"; | 37 const char* DartUtils::kIdFieldName = "_id"; |
| 36 | 38 |
| 37 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; | 39 uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; |
| 38 | 40 |
| 39 static bool IsWindowsHost() { | 41 static bool IsWindowsHost() { |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } else if (tag == Dart_kSourceTag) { | 673 } else if (tag == Dart_kSourceTag) { |
| 672 return Dart_LoadSource(library, url, source); | 674 return Dart_LoadSource(library, url, source); |
| 673 } | 675 } |
| 674 return Dart_NewApiError("wrong tag"); | 676 return Dart_NewApiError("wrong tag"); |
| 675 } | 677 } |
| 676 | 678 |
| 677 | 679 |
| 678 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, | 680 Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root, |
| 679 Dart_Handle builtin_lib) { | 681 Dart_Handle builtin_lib) { |
| 680 // Setup the internal library's 'internalPrint' function. | 682 // Setup the internal library's 'internalPrint' function. |
| 681 Dart_Handle internal_lib = | |
| 682 Dart_LookupLibrary(NewString("dart:_collection-dev")); | |
| 683 DART_CHECK_VALID(internal_lib); | |
| 684 Dart_Handle print = Dart_Invoke( | 683 Dart_Handle print = Dart_Invoke( |
| 685 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 684 builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
| 686 Dart_Handle result = Dart_SetField(internal_lib, | 685 Dart_Handle url = NewString(kCollectionDevLibURL); |
| 686 DART_CHECK_VALID(url); |
| 687 Dart_Handle collection_dev_lib = Dart_LookupLibrary(url); |
| 688 DART_CHECK_VALID(collection_dev_lib); |
| 689 Dart_Handle result = Dart_SetField(collection_dev_lib, |
| 687 NewString("_printClosure"), | 690 NewString("_printClosure"), |
| 688 print); | 691 print); |
| 689 DART_CHECK_VALID(result); | 692 DART_CHECK_VALID(result); |
| 690 | 693 |
| 691 // Setup the 'timer' factory. | 694 // Setup the 'timer' factory. |
| 692 Dart_Handle url = NewString(kAsyncLibURL); | 695 url = NewString(kAsyncLibURL); |
| 693 DART_CHECK_VALID(url); | 696 DART_CHECK_VALID(url); |
| 694 Dart_Handle async_lib = Dart_LookupLibrary(url); | 697 Dart_Handle async_lib = Dart_LookupLibrary(url); |
| 695 DART_CHECK_VALID(async_lib); | 698 DART_CHECK_VALID(async_lib); |
| 696 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); | 699 Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary); |
| 697 Dart_Handle timer_closure = | 700 Dart_Handle timer_closure = |
| 698 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL); | 701 Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL); |
| 699 Dart_Handle args[1]; | 702 Dart_Handle args[1]; |
| 700 args[0] = timer_closure; | 703 args[0] = timer_closure; |
| 701 DART_CHECK_VALID(Dart_Invoke( | 704 DART_CHECK_VALID(Dart_Invoke( |
| 702 async_lib, NewString("_setTimerFactoryClosure"), 1, args)); | 705 async_lib, NewString("_setTimerFactoryClosure"), 1, args)); |
| 703 | 706 |
| 707 // Setup the 'scheduleImmediate' closure. |
| 708 url = NewString(kIsolateLibURL); |
| 709 DART_CHECK_VALID(url); |
| 710 Dart_Handle isolate_lib = Dart_LookupLibrary(url); |
| 711 DART_CHECK_VALID(isolate_lib); |
| 712 Dart_Handle schedule_immediate_closure = |
| 713 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), |
| 714 0, NULL); |
| 715 args[0] = schedule_immediate_closure; |
| 716 DART_CHECK_VALID(Dart_Invoke( |
| 717 async_lib, NewString("_setScheduleImmediateClosure"), 1, args)); |
| 718 |
| 704 // Setup the corelib 'Uri.base' getter. | 719 // Setup the corelib 'Uri.base' getter. |
| 705 Dart_Handle corelib = Dart_LookupLibrary(NewString("dart:core")); | 720 url = NewString(kCoreLibURL); |
| 721 DART_CHECK_VALID(url); |
| 722 Dart_Handle corelib = Dart_LookupLibrary(url); |
| 706 DART_CHECK_VALID(corelib); | 723 DART_CHECK_VALID(corelib); |
| 707 Dart_Handle uri_base = Dart_Invoke( | 724 Dart_Handle uri_base = Dart_Invoke( |
| 708 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); | 725 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); |
| 709 DART_CHECK_VALID(uri_base); | 726 DART_CHECK_VALID(uri_base); |
| 710 result = Dart_SetField(corelib, | 727 result = Dart_SetField(corelib, |
| 711 NewString("_uriBaseClosure"), | 728 NewString("_uriBaseClosure"), |
| 712 uri_base); | 729 uri_base); |
| 713 DART_CHECK_VALID(result); | 730 DART_CHECK_VALID(result); |
| 714 | 731 |
| 715 if (IsWindowsHost()) { | 732 if (IsWindowsHost()) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 new CObjectString(CObject::NewString(os_error->message())); | 1076 new CObjectString(CObject::NewString(os_error->message())); |
| 1060 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1077 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1061 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1078 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1062 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1079 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1063 result->SetAt(2, error_message); | 1080 result->SetAt(2, error_message); |
| 1064 return result; | 1081 return result; |
| 1065 } | 1082 } |
| 1066 | 1083 |
| 1067 } // namespace bin | 1084 } // namespace bin |
| 1068 } // namespace dart | 1085 } // namespace dart |
| OLD | NEW |