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 "bin/file.h" | 7 #include "bin/file.h" |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 Dart_Handle str = Dart_NewString(text_buffer); | 198 Dart_Handle str = Dart_NewString(text_buffer); |
199 free(text_buffer); | 199 free(text_buffer); |
200 return str; | 200 return str; |
201 } | 201 } |
202 | 202 |
203 | 203 |
204 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping, | 204 Dart_Handle DartUtils::LoadSource(CommandLineOptions* url_mapping, |
205 Dart_Handle library, | 205 Dart_Handle library, |
206 Dart_Handle url, | 206 Dart_Handle url, |
207 Dart_LibraryTag tag, | 207 Dart_LibraryTag tag, |
208 const char* url_string) { | 208 const char* url_string, |
| 209 Dart_Handle import_map) { |
209 if (url_mapping != NULL && IsDartSchemeURL(url_string)) { | 210 if (url_mapping != NULL && IsDartSchemeURL(url_string)) { |
210 const char* mapped_url_string = MapLibraryUrl(url_mapping, url_string); | 211 const char* mapped_url_string = MapLibraryUrl(url_mapping, url_string); |
211 if (mapped_url_string == NULL) { | 212 if (mapped_url_string == NULL) { |
212 return Dart_Error("Do not know how to load %s", url_string); | 213 return Dart_Error("Do not know how to load %s", url_string); |
213 } | 214 } |
214 // We have a URL mapping specified, just read the file that the | 215 // We have a URL mapping specified, just read the file that the |
215 // URL mapping specifies and load it. | 216 // URL mapping specifies and load it. |
216 url_string = mapped_url_string; | 217 url_string = mapped_url_string; |
217 } | 218 } |
218 // The tag is either an import or a source tag. | 219 // The tag is either an import or a source tag. |
219 // Read the file and load it according to the specified tag. | 220 // Read the file and load it according to the specified tag. |
220 Dart_Handle source = DartUtils::ReadStringFromFile(url_string); | 221 Dart_Handle source = DartUtils::ReadStringFromFile(url_string); |
221 if (Dart_IsError(source)) { | 222 if (Dart_IsError(source)) { |
222 return source; // source contains the error string. | 223 return source; // source contains the error string. |
223 } | 224 } |
224 if (tag == kImportTag) { | 225 if (tag == kImportTag) { |
225 // Return library object or an error string. | 226 // Return library object or an error string. |
226 return Dart_LoadLibrary(url, source); | 227 return Dart_LoadLibrary(url, source, import_map); |
227 } else if (tag == kSourceTag) { | 228 } else if (tag == kSourceTag) { |
228 return Dart_LoadSource(library, url, source); | 229 return Dart_LoadSource(library, url, source); |
229 } | 230 } |
230 return Dart_Error("wrong tag"); | 231 return Dart_Error("wrong tag"); |
231 } | 232 } |
232 | 233 |
233 | 234 |
234 const char* DartUtils::GetCanonicalPath(const char* reference_dir, | 235 const char* DartUtils::GetCanonicalPath(const char* reference_dir, |
235 const char* filename) { | 236 const char* filename) { |
236 if (File::IsAbsolutePath(filename)) { | 237 if (File::IsAbsolutePath(filename)) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 439 |
439 CObject* CObject::NewOSError(OSError* os_error) { | 440 CObject* CObject::NewOSError(OSError* os_error) { |
440 CObject* error_message = | 441 CObject* error_message = |
441 new CObjectString(CObject::NewString(os_error->message())); | 442 new CObjectString(CObject::NewString(os_error->message())); |
442 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 443 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
443 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 444 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
444 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 445 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
445 result->SetAt(2, error_message); | 446 result->SetAt(2, error_message); |
446 return result; | 447 return result; |
447 } | 448 } |
OLD | NEW |