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 #include "bin/platform.h" | 11 #include "bin/platform.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 namespace bin { | 14 namespace bin { |
15 | 15 |
16 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = { | 16 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = { |
17 /* { url_, source_, patch_url_, patch_source_, has_natives_ } */ | 17 /* { url_, source_, patch_url_, patch_source_, has_natives_ } */ |
18 { DartUtils::kBuiltinLibURL, _builtin_source_paths_, NULL, NULL, true }, | 18 { DartUtils::kBuiltinLibURL, _builtin_source_paths_, NULL, NULL, true }, |
19 { DartUtils::kIOLibURL, io_source_paths_, | 19 { DartUtils::kIOLibURL, io_source_paths_, |
20 DartUtils::kIOLibPatchURL, io_patch_paths_, true }, | 20 DartUtils::kIOLibPatchURL, io_patch_paths_, true }, |
| 21 |
| 22 #if defined(DART_NO_SNAPSHOT) |
| 23 // Only include these libraries in the dart_bootstrap case for now. |
| 24 { "dart:html", html_source_paths_, NULL, NULL, true }, |
| 25 { "dart:html_common", html_common_source_paths_, NULL, NULL, true}, |
| 26 { "dart:js", js_source_paths_, NULL, NULL, true}, |
| 27 { "dart:_blink", blink_source_paths_, NULL, NULL, true }, |
| 28 { "dart:indexed_db", indexeddb_source_paths_, NULL, NULL, true }, |
| 29 { "cached_patches.dart", cached_patches_source_paths_, NULL, NULL, true }, |
| 30 { "dart:web_gl", web_gl_source_paths_, NULL, NULL, true }, |
| 31 { "metadata.dart", metadata_source_paths_, NULL, NULL, true }, |
| 32 { "dart:web_sql", websql_source_paths_, NULL, NULL, true }, |
| 33 { "dart:svg", svg_source_paths_, NULL, NULL, true }, |
| 34 { "dart:web_audio", webaudio_source_paths_, NULL, NULL, true }, |
| 35 #endif // defined(DART_NO_SNAPSHOT) |
| 36 |
| 37 // End marker. |
| 38 { NULL, NULL, NULL, NULL, false } |
21 }; | 39 }; |
22 | 40 |
23 Dart_Port Builtin::load_port_ = ILLEGAL_PORT; | 41 Dart_Port Builtin::load_port_ = ILLEGAL_PORT; |
24 | 42 |
25 // Patch all the specified patch files in the array 'patch_files' into the | 43 // Patch all the specified patch files in the array 'patch_files' into the |
26 // library specified in 'library'. | 44 // library specified in 'library'. |
27 static void LoadPatchFiles(Dart_Handle library, | 45 static void LoadPatchFiles(Dart_Handle library, |
28 const char* patch_uri, | 46 const char* patch_uri, |
29 const char** patch_files) { | 47 const char** patch_files) { |
30 for (intptr_t j = 0; patch_files[j] != NULL; j += 3) { | 48 for (intptr_t j = 0; patch_files[j] != NULL; j += 3) { |
(...skipping 11 matching lines...) Expand all Loading... |
42 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); | 60 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); |
43 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); | 61 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); |
44 | 62 |
45 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); | 63 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); |
46 } | 64 } |
47 } | 65 } |
48 | 66 |
49 | 67 |
50 Dart_Handle Builtin::Source(BuiltinLibraryId id) { | 68 Dart_Handle Builtin::Source(BuiltinLibraryId id) { |
51 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == | 69 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == |
52 kInvalidLibrary); | 70 kInvalidLibrary + 1); |
53 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); | 71 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); |
54 | 72 |
55 // Try to read the source using the path specified for the uri. | 73 // Try to read the source using the path specified for the uri. |
56 const char* uri = builtin_libraries_[id].url_; | 74 const char* uri = builtin_libraries_[id].url_; |
57 const char** source_paths = builtin_libraries_[id].source_paths_; | 75 const char** source_paths = builtin_libraries_[id].source_paths_; |
58 return GetSource(source_paths, uri); | 76 return GetSource(source_paths, uri); |
59 } | 77 } |
60 | 78 |
61 | 79 |
62 Dart_Handle Builtin::PartSource(BuiltinLibraryId id, const char* part_uri) { | 80 Dart_Handle Builtin::PartSource(BuiltinLibraryId id, const char* part_uri) { |
63 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == | 81 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == |
64 kInvalidLibrary); | 82 kInvalidLibrary + 1); |
65 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); | 83 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); |
66 | 84 |
67 // Try to read the source using the path specified for the uri. | 85 // Try to read the source using the path specified for the uri. |
68 const char** source_paths = builtin_libraries_[id].source_paths_; | 86 const char** source_paths = builtin_libraries_[id].source_paths_; |
69 return GetSource(source_paths, part_uri); | 87 return GetSource(source_paths, part_uri); |
70 } | 88 } |
71 | 89 |
72 | 90 |
73 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { | 91 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { |
74 if (source_paths == NULL) { | 92 if (source_paths == NULL) { |
(...skipping 15 matching lines...) Expand all Loading... |
90 return Dart_Null(); // Uri does not exist in path mapping information. | 108 return Dart_Null(); // Uri does not exist in path mapping information. |
91 } | 109 } |
92 | 110 |
93 | 111 |
94 void Builtin::SetNativeResolver(BuiltinLibraryId id) { | 112 void Builtin::SetNativeResolver(BuiltinLibraryId id) { |
95 UNREACHABLE(); | 113 UNREACHABLE(); |
96 } | 114 } |
97 | 115 |
98 | 116 |
99 Dart_Handle Builtin::LoadLibrary(Dart_Handle url, BuiltinLibraryId id) { | 117 Dart_Handle Builtin::LoadLibrary(Dart_Handle url, BuiltinLibraryId id) { |
| 118 ASSERT(static_cast<int>(id) >= 0); |
| 119 ASSERT(static_cast<int>(id) < kInvalidLibrary); |
| 120 |
100 Dart_Handle library = Dart_LoadLibrary(url, Source(id), 0, 0); | 121 Dart_Handle library = Dart_LoadLibrary(url, Source(id), 0, 0); |
101 if (!Dart_IsError(library) && (builtin_libraries_[id].has_natives_)) { | 122 if (!Dart_IsError(library) && (builtin_libraries_[id].has_natives_)) { |
102 // Setup the native resolver for built in library functions. | 123 // Setup the native resolver for built in library functions. |
103 DART_CHECK_VALID( | 124 DART_CHECK_VALID( |
104 Dart_SetNativeResolver(library, NativeLookup, NativeSymbol)); | 125 Dart_SetNativeResolver(library, NativeLookup, NativeSymbol)); |
105 } | 126 } |
106 if (builtin_libraries_[id].patch_url_ != NULL) { | 127 if (builtin_libraries_[id].patch_url_ != NULL) { |
107 ASSERT(builtin_libraries_[id].patch_paths_ != NULL); | 128 ASSERT(builtin_libraries_[id].patch_paths_ != NULL); |
108 LoadPatchFiles(library, | 129 LoadPatchFiles(library, |
109 builtin_libraries_[id].patch_url_, | 130 builtin_libraries_[id].patch_url_, |
110 builtin_libraries_[id].patch_paths_); | 131 builtin_libraries_[id].patch_paths_); |
111 } | 132 } |
112 return library; | 133 return library; |
113 } | 134 } |
114 | 135 |
115 | 136 |
| 137 Builtin::BuiltinLibraryId Builtin::FindId(const char* url_string) { |
| 138 int id = 0; |
| 139 while (true) { |
| 140 if (builtin_libraries_[id].url_ == NULL) { |
| 141 return kInvalidLibrary; |
| 142 } |
| 143 if (strcmp(url_string, builtin_libraries_[id].url_) == 0) { |
| 144 return static_cast<BuiltinLibraryId>(id); |
| 145 } |
| 146 id++; |
| 147 } |
| 148 } |
| 149 |
| 150 |
116 Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) { | 151 Dart_Handle Builtin::LoadAndCheckLibrary(BuiltinLibraryId id) { |
117 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == | 152 ASSERT((sizeof(builtin_libraries_) / sizeof(builtin_lib_props)) == |
118 kInvalidLibrary); | 153 kInvalidLibrary + 1); |
119 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); | 154 ASSERT(id >= kBuiltinLibrary && id < kInvalidLibrary); |
120 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); | 155 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); |
121 Dart_Handle library = Dart_LookupLibrary(url); | 156 Dart_Handle library = Dart_LookupLibrary(url); |
122 if (Dart_IsError(library)) { | 157 if (Dart_IsError(library)) { |
123 library = LoadLibrary(url, id); | 158 library = LoadLibrary(url, id); |
124 } | 159 } |
125 return library; | 160 return library; |
126 } | 161 } |
127 | 162 |
128 } // namespace bin | 163 } // namespace bin |
129 } // namespace dart | 164 } // namespace dart |
OLD | NEW |