| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "bin/dartutils.h" | 10 #include "bin/dartutils.h" |
| 11 | 11 |
| 12 static void ImportBuiltinLibIntoLib( | 12 static void ImportBuiltinLibIntoLib( |
| 13 const char* liburl, Dart_Handle builtin_lib) { | 13 const char* liburl, Dart_Handle builtin_lib) { |
| 14 Dart_Handle url = Dart_NewString(liburl); | 14 Dart_Handle url = Dart_NewString(liburl); |
| 15 Dart_Handle lib = Dart_LookupLibrary(url); | 15 Dart_Handle lib = Dart_LookupLibrary(url); |
| 16 DART_CHECK_VALID(lib); | 16 DART_CHECK_VALID(lib); |
| 17 DART_CHECK_VALID(Dart_LibraryImportLibrary(lib, builtin_lib)); | 17 DART_CHECK_VALID(Dart_LibraryImportLibrary(lib, builtin_lib)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 Dart_Handle Builtin::Source(BuiltinLibraryId id) { | 21 Dart_Handle Builtin::Source(BuiltinLibraryId id) { |
| 22 Dart_Handle source; | 22 Dart_Handle source; |
| 23 switch (id) { | 23 switch (id) { |
| 24 case kBuiltinLibrary: | 24 case kBuiltinLibrary: |
| 25 source = Dart_NewString(Builtin::builtin_source_); | 25 source = Dart_NewString(Builtin::builtin_source_); |
| 26 break; | 26 break; |
| 27 case kCryptoLibrary: |
| 28 source = Dart_NewString(Builtin::crypto_source_); |
| 29 break; |
| 27 case kIOLibrary: | 30 case kIOLibrary: |
| 28 source = Dart_NewString(Builtin::io_source_); | 31 source = Dart_NewString(Builtin::io_source_); |
| 29 break; | 32 break; |
| 30 case kJsonLibrary: | 33 case kJsonLibrary: |
| 31 source = Dart_NewString(Builtin::json_source_); | 34 source = Dart_NewString(Builtin::json_source_); |
| 32 break; | 35 break; |
| 33 case kUriLibrary: | 36 case kUriLibrary: |
| 34 source = Dart_NewString(Builtin::uri_source_); | 37 source = Dart_NewString(Builtin::uri_source_); |
| 35 break; | 38 break; |
| 36 case kUtfLibrary: | 39 case kUtfLibrary: |
| 37 source = Dart_NewString(Builtin::utf_source_); | 40 source = Dart_NewString(Builtin::utf_source_); |
| 38 break; | 41 break; |
| 39 default: | 42 default: |
| 40 return Dart_Error("Unknown builtin source requested."); | 43 return Dart_Error("Unknown builtin source requested."); |
| 41 } | 44 } |
| 42 return source; | 45 return source; |
| 43 } | 46 } |
| 44 | 47 |
| 45 | 48 |
| 46 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { | 49 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { |
| 47 if ((id == kJsonLibrary) || (id == kUriLibrary) || (id == kUtfLibrary)) { | 50 if ((id == kCryptoLibrary) || |
| 51 (id == kJsonLibrary) || |
| 52 (id == kUriLibrary) || |
| 53 (id == kUtfLibrary)) { |
| 48 // No native resolver for these pure Dart libraries. | 54 // No native resolver for these pure Dart libraries. |
| 49 return; | 55 return; |
| 50 } else if (id == kBuiltinLibrary) { | 56 } else if (id == kBuiltinLibrary) { |
| 51 // Import the builtin library into the core and isolate libraries. | 57 // Import the builtin library into the core and isolate libraries. |
| 52 ImportBuiltinLibIntoLib(DartUtils::kCoreLibURL, library); | 58 ImportBuiltinLibIntoLib(DartUtils::kCoreLibURL, library); |
| 53 ImportBuiltinLibIntoLib(DartUtils::kCoreImplLibURL, library); | 59 ImportBuiltinLibIntoLib(DartUtils::kCoreImplLibURL, library); |
| 54 ImportBuiltinLibIntoLib(DartUtils::kIsolateLibURL, library); | 60 ImportBuiltinLibIntoLib(DartUtils::kIsolateLibURL, library); |
| 55 } | 61 } |
| 56 // Setup the native resolver for built in library functions. | 62 // Setup the native resolver for built in library functions. |
| 57 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); | 63 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); |
| 58 } | 64 } |
| 59 | 65 |
| 60 | 66 |
| 61 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { | 67 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { |
| 62 Dart_Handle url; | 68 Dart_Handle url; |
| 63 switch (id) { | 69 switch (id) { |
| 64 case kBuiltinLibrary: | 70 case kBuiltinLibrary: |
| 65 url = Dart_NewString(DartUtils::kBuiltinLibURL); | 71 url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| 66 break; | 72 break; |
| 73 case kCryptoLibrary: |
| 74 url = Dart_NewString(DartUtils::kCryptoLibURL); |
| 75 break; |
| 67 case kIOLibrary: | 76 case kIOLibrary: |
| 68 url = Dart_NewString(DartUtils::kIOLibURL); | 77 url = Dart_NewString(DartUtils::kIOLibURL); |
| 69 break; | 78 break; |
| 70 case kJsonLibrary: | 79 case kJsonLibrary: |
| 71 url = Dart_NewString(DartUtils::kJsonLibURL); | 80 url = Dart_NewString(DartUtils::kJsonLibURL); |
| 72 break; | 81 break; |
| 73 case kUriLibrary: | 82 case kUriLibrary: |
| 74 url = Dart_NewString(DartUtils::kUriLibURL); | 83 url = Dart_NewString(DartUtils::kUriLibURL); |
| 75 break; | 84 break; |
| 76 case kUtfLibrary: | 85 case kUtfLibrary: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 90 DART_CHECK_VALID(library); | 99 DART_CHECK_VALID(library); |
| 91 return library; | 100 return library; |
| 92 } | 101 } |
| 93 | 102 |
| 94 | 103 |
| 95 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { | 104 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { |
| 96 Dart_Handle imported_library = LoadLibrary(id); | 105 Dart_Handle imported_library = LoadLibrary(id); |
| 97 // Import the library into current library. | 106 // Import the library into current library. |
| 98 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); | 107 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); |
| 99 } | 108 } |
| OLD | NEW |