| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 break; | 31 break; |
| 32 case kIOLibrary: | 32 case kIOLibrary: |
| 33 source = Dart_NewString(Builtin::io_source_); | 33 source = Dart_NewString(Builtin::io_source_); |
| 34 break; | 34 break; |
| 35 case kJsonLibrary: | 35 case kJsonLibrary: |
| 36 source = Dart_NewString(Builtin::json_source_); | 36 source = Dart_NewString(Builtin::json_source_); |
| 37 break; | 37 break; |
| 38 case kUriLibrary: | 38 case kUriLibrary: |
| 39 source = Dart_NewString(Builtin::uri_source_); | 39 source = Dart_NewString(Builtin::uri_source_); |
| 40 break; | 40 break; |
| 41 case kUtf8Library: | 41 case kUtfLibrary: |
| 42 source = Dart_NewString(Builtin::utf8_source_); | 42 source = Dart_NewString(Builtin::utf_source_); |
| 43 break; | 43 break; |
| 44 default: | 44 default: |
| 45 return Dart_Error("Unknown builtin source requested."); | 45 return Dart_Error("Unknown builtin source requested."); |
| 46 } | 46 } |
| 47 return source; | 47 return source; |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { | 51 void Builtin::SetupLibrary(Dart_Handle library, BuiltinLibraryId id) { |
| 52 if ((id == kJsonLibrary) || (id == kUriLibrary) || (id == kUtf8Library)) { | 52 if ((id == kJsonLibrary) || (id == kUriLibrary) || (id == kUtfLibrary)) { |
| 53 // No native resolver for these pure Dart libraries. | 53 // No native resolver for these pure Dart libraries. |
| 54 return; | 54 return; |
| 55 } else if (id == kBuiltinLibrary) { | 55 } else if (id == kBuiltinLibrary) { |
| 56 // Setup core lib, builtin import structure. | 56 // Setup core lib, builtin import structure. |
| 57 SetupCorelibImports(library); | 57 SetupCorelibImports(library); |
| 58 } | 58 } |
| 59 // Setup the native resolver for built in library functions. | 59 // Setup the native resolver for built in library functions. |
| 60 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); | 60 DART_CHECK_VALID(Dart_SetNativeResolver(library, NativeLookup)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 | 63 |
| 64 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { | 64 Dart_Handle Builtin::LoadLibrary(BuiltinLibraryId id) { |
| 65 Dart_Handle url; | 65 Dart_Handle url; |
| 66 switch (id) { | 66 switch (id) { |
| 67 case kBuiltinLibrary: | 67 case kBuiltinLibrary: |
| 68 url = Dart_NewString(DartUtils::kBuiltinLibURL); | 68 url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| 69 break; | 69 break; |
| 70 case kIOLibrary: | 70 case kIOLibrary: |
| 71 url = Dart_NewString(DartUtils::kIOLibURL); | 71 url = Dart_NewString(DartUtils::kIOLibURL); |
| 72 break; | 72 break; |
| 73 case kJsonLibrary: | 73 case kJsonLibrary: |
| 74 url = Dart_NewString(DartUtils::kJsonLibURL); | 74 url = Dart_NewString(DartUtils::kJsonLibURL); |
| 75 break; | 75 break; |
| 76 case kUriLibrary: | 76 case kUriLibrary: |
| 77 url = Dart_NewString(DartUtils::kUriLibURL); | 77 url = Dart_NewString(DartUtils::kUriLibURL); |
| 78 break; | 78 break; |
| 79 case kUtf8Library: | 79 case kUtfLibrary: |
| 80 url = Dart_NewString(DartUtils::kUtf8LibURL); | 80 url = Dart_NewString(DartUtils::kUtfLibURL); |
| 81 break; | 81 break; |
| 82 default: | 82 default: |
| 83 return Dart_Error("Unknown builtin library requested."); | 83 return Dart_Error("Unknown builtin library requested."); |
| 84 } | 84 } |
| 85 Dart_Handle library = Dart_LookupLibrary(url); | 85 Dart_Handle library = Dart_LookupLibrary(url); |
| 86 if (Dart_IsError(library)) { | 86 if (Dart_IsError(library)) { |
| 87 Dart_Handle import_map = Dart_NewList(0); | 87 Dart_Handle import_map = Dart_NewList(0); |
| 88 library = Dart_LoadLibrary(url, Source(id), import_map); | 88 library = Dart_LoadLibrary(url, Source(id), import_map); |
| 89 if (!Dart_IsError(library)) { | 89 if (!Dart_IsError(library)) { |
| 90 SetupLibrary(library, id); | 90 SetupLibrary(library, id); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 DART_CHECK_VALID(library); | 93 DART_CHECK_VALID(library); |
| 94 return library; | 94 return library; |
| 95 } | 95 } |
| 96 | 96 |
| 97 | 97 |
| 98 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { | 98 void Builtin::ImportLibrary(Dart_Handle library, BuiltinLibraryId id) { |
| 99 Dart_Handle imported_library = LoadLibrary(id); | 99 Dart_Handle imported_library = LoadLibrary(id); |
| 100 // Import the library into current library. | 100 // Import the library into current library. |
| 101 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); | 101 DART_CHECK_VALID(Dart_LibraryImportLibrary(library, imported_library)); |
| 102 } | 102 } |
| OLD | NEW |