| 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/crypto.h" | 7 #include "bin/crypto.h" |
| 8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
| 9 #include "bin/extensions.h" | 9 #include "bin/extensions.h" |
| 10 #include "bin/file.h" | 10 #include "bin/file.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 return result; | 399 return result; |
| 400 } | 400 } |
| 401 Dart_Handle library_url = Dart_LibraryUrl(library); | 401 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 402 const char* library_url_string = NULL; | 402 const char* library_url_string = NULL; |
| 403 result = Dart_StringToCString(library_url, &library_url_string); | 403 result = Dart_StringToCString(library_url, &library_url_string); |
| 404 if (Dart_IsError(result)) { | 404 if (Dart_IsError(result)) { |
| 405 return result; | 405 return result; |
| 406 } | 406 } |
| 407 | 407 |
| 408 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 408 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
| 409 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 409 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); |
| 410 | 410 |
| 411 // Handle URI canonicalization requests. | 411 // Handle canonicalization, 'import' and 'part' of 'dart:' libraries. |
| 412 if (tag == Dart_kCanonicalizeUrl) { | 412 if (is_dart_scheme_url || is_dart_library) { |
| 413 // If this is a Dart Scheme URL or 'part' of a io library | 413 if (tag == Dart_kCanonicalizeUrl) { |
| 414 // then it is not modified as it will be handled internally. | 414 // These will be handled internally. |
| 415 if (is_dart_scheme_url || is_io_library) { | |
| 416 return url; | 415 return url; |
| 417 } | 416 } else if (tag == Dart_kImportTag) { |
| 418 // Resolve the url within the context of the library's URL. | 417 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); |
| 419 return ResolveUri(library_url, url); | 418 if (id == Builtin::kInvalidLibrary) { |
| 420 } | 419 return NewError("The built-in library '%s' is not available" |
| 421 | 420 " on the stand-alone VM.\n", url_string); |
| 422 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). | |
| 423 if (is_dart_scheme_url) { | |
| 424 if (tag == Dart_kImportTag) { | |
| 425 // Handle imports of other built-in libraries present in the SDK. | |
| 426 if (DartUtils::IsDartIOLibURL(url_string)) { | |
| 427 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); | |
| 428 } | 421 } |
| 429 return NewError("The built-in library '%s' is not available" | 422 return Builtin::LoadLibrary(url, id); |
| 430 " on the stand-alone VM.\n", url_string); | |
| 431 } else { | 423 } else { |
| 432 ASSERT(tag == Dart_kSourceTag); | 424 ASSERT(tag == Dart_kSourceTag); |
| 433 return NewError("Unable to load source '%s' ", url_string); | 425 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); |
| 434 } | 426 if (id == Builtin::kInvalidLibrary) { |
| 435 } | 427 return NewError("The built-in library '%s' is not available" |
| 436 | 428 " on the stand-alone VM. Trying to load" |
| 437 // Handle 'part' of IO library. | 429 " '%s'.\n", library_url_string, url_string); |
| 438 if (is_io_library) { | 430 } |
| 439 if (tag == Dart_kSourceTag) { | |
| 440 // Prepend the library URI to form a unique script URI for the part. | 431 // Prepend the library URI to form a unique script URI for the part. |
| 441 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); | 432 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); |
| 442 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); | 433 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); |
| 443 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); | 434 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); |
| 444 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); | 435 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); |
| 445 free(part_uri); | 436 free(part_uri); |
| 446 return Dart_LoadSource( | 437 return Dart_LoadSource(library, |
| 447 library, | 438 part_uri_obj, |
| 448 part_uri_obj, | 439 Builtin::PartSource(id, url_string), 0, 0); |
| 449 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); | |
| 450 } else { | |
| 451 ASSERT(tag == Dart_kImportTag); | |
| 452 return NewError("Unable to import '%s' ", url_string); | |
| 453 } | 440 } |
| 441 // All cases should have been handled above. |
| 442 UNREACHABLE(); |
| 443 } |
| 444 |
| 445 if (tag == Dart_kCanonicalizeUrl) { |
| 446 // Resolve the url within the context of the library's URL. |
| 447 return ResolveUri(library_url, url); |
| 454 } | 448 } |
| 455 | 449 |
| 456 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 450 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
| 457 // Load a native code shared library to use in a native extension | 451 // Load a native code shared library to use in a native extension |
| 458 if (tag != Dart_kImportTag) { | 452 if (tag != Dart_kImportTag) { |
| 459 return NewError("Dart extensions must use import: '%s'", url_string); | 453 return NewError("Dart extensions must use import: '%s'", url_string); |
| 460 } | 454 } |
| 461 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url); | 455 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url); |
| 462 if (Dart_IsError(path_parts)) { | 456 if (Dart_IsError(path_parts)) { |
| 463 return path_parts; | 457 return path_parts; |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 new CObjectString(CObject::NewString(os_error->message())); | 1261 new CObjectString(CObject::NewString(os_error->message())); |
| 1268 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1262 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1269 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1263 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1270 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1264 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1271 result->SetAt(2, error_message); | 1265 result->SetAt(2, error_message); |
| 1272 return result; | 1266 return result; |
| 1273 } | 1267 } |
| 1274 | 1268 |
| 1275 } // namespace bin | 1269 } // namespace bin |
| 1276 } // namespace dart | 1270 } // namespace dart |
| OLD | NEW |