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 23 matching lines...) Expand all Loading... | |
34 const char* DartUtils::original_working_directory = NULL; | 34 const char* DartUtils::original_working_directory = NULL; |
35 const char* const DartUtils::kDartScheme = "dart:"; | 35 const char* const DartUtils::kDartScheme = "dart:"; |
36 const char* const DartUtils::kDartExtensionScheme = "dart-ext:"; | 36 const char* const DartUtils::kDartExtensionScheme = "dart-ext:"; |
37 const char* const DartUtils::kAsyncLibURL = "dart:async"; | 37 const char* const DartUtils::kAsyncLibURL = "dart:async"; |
38 const char* const DartUtils::kBuiltinLibURL = "dart:_builtin"; | 38 const char* const DartUtils::kBuiltinLibURL = "dart:_builtin"; |
39 const char* const DartUtils::kCoreLibURL = "dart:core"; | 39 const char* const DartUtils::kCoreLibURL = "dart:core"; |
40 const char* const DartUtils::kInternalLibURL = "dart:_internal"; | 40 const char* const DartUtils::kInternalLibURL = "dart:_internal"; |
41 const char* const DartUtils::kIsolateLibURL = "dart:isolate"; | 41 const char* const DartUtils::kIsolateLibURL = "dart:isolate"; |
42 const char* const DartUtils::kIOLibURL = "dart:io"; | 42 const char* const DartUtils::kIOLibURL = "dart:io"; |
43 const char* const DartUtils::kIOLibPatchURL = "dart:io-patch"; | 43 const char* const DartUtils::kIOLibPatchURL = "dart:io-patch"; |
44 const char* const DartUtils::kHTMLLibURL = "dart:html"; | |
siva
2016/04/25 23:38:31
Ditto.
Ivan Posva
2016/04/26 21:17:43
Done.
| |
44 const char* const DartUtils::kUriLibURL = "dart:uri"; | 45 const char* const DartUtils::kUriLibURL = "dart:uri"; |
45 const char* const DartUtils::kHttpScheme = "http:"; | 46 const char* const DartUtils::kHttpScheme = "http:"; |
46 const char* const DartUtils::kVMServiceLibURL = "dart:vmservice"; | 47 const char* const DartUtils::kVMServiceLibURL = "dart:vmservice"; |
47 | 48 |
48 const uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; | 49 const uint8_t DartUtils::magic_number[] = { 0xf5, 0xf5, 0xdc, 0xdc }; |
49 | 50 |
50 static bool IsWindowsHost() { | 51 static bool IsWindowsHost() { |
51 #if defined(TARGET_OS_WINDOWS) | 52 #if defined(TARGET_OS_WINDOWS) |
52 return true; | 53 return true; |
53 #else // defined(TARGET_OS_WINDOWS) | 54 #else // defined(TARGET_OS_WINDOWS) |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 return result; | 389 return result; |
389 } | 390 } |
390 Dart_Handle library_url = Dart_LibraryUrl(library); | 391 Dart_Handle library_url = Dart_LibraryUrl(library); |
391 const char* library_url_string = NULL; | 392 const char* library_url_string = NULL; |
392 result = Dart_StringToCString(library_url, &library_url_string); | 393 result = Dart_StringToCString(library_url, &library_url_string); |
393 if (Dart_IsError(result)) { | 394 if (Dart_IsError(result)) { |
394 return result; | 395 return result; |
395 } | 396 } |
396 | 397 |
397 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 398 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
398 bool is_io_library = DartUtils::IsDartIOLibURL(library_url_string); | 399 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); |
399 | 400 |
400 // Handle URI canonicalization requests. | 401 // Handle URI canonicalization requests. |
401 if (tag == Dart_kCanonicalizeUrl) { | 402 if (tag == Dart_kCanonicalizeUrl) { |
402 // If this is a Dart Scheme URL or 'part' of a io library | 403 // If this is a Dart Scheme URL or 'part' of a io library |
siva
2016/04/25 23:38:31
Comment needs to change from io library to 'part'
Ivan Posva
2016/04/26 21:17:43
Done.
| |
403 // then it is not modified as it will be handled internally. | 404 // then it is not modified as it will be handled internally. |
404 if (is_dart_scheme_url || is_io_library) { | 405 if (is_dart_scheme_url || is_dart_library) { |
405 return url; | 406 return url; |
406 } | 407 } |
407 // Resolve the url within the context of the library's URL. | 408 // Resolve the url within the context of the library's URL. |
408 return ResolveUri(library_url, url); | 409 return ResolveUri(library_url, url); |
409 } | 410 } |
410 | 411 |
411 // Handle 'import' of dart scheme URIs (i.e they start with 'dart:'). | 412 // Handle 'import' and 'part' of dart scheme URIs (i.e. they |
412 if (is_dart_scheme_url) { | 413 // start with 'dart:'). |
414 if (is_dart_scheme_url || is_dart_library) { | |
413 if (tag == Dart_kImportTag) { | 415 if (tag == Dart_kImportTag) { |
414 // Handle imports of other built-in libraries present in the SDK. | 416 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); |
415 if (DartUtils::IsDartIOLibURL(url_string)) { | 417 if (id == Builtin::kInvalidLibrary) { |
416 return Builtin::LoadLibrary(url, Builtin::kIOLibrary); | 418 return NewError("The built-in library '%s' is not available" |
419 " on the stand-alone VM.\n", url_string); | |
417 } | 420 } |
siva
2016/04/25 23:38:31
This FindId part can be hoisted out of the if (...
Ivan Posva
2016/05/03 21:46:40
Unfortunately not as for one case you are looking
| |
418 return NewError("The built-in library '%s' is not available" | 421 return Builtin::LoadLibrary(url, id); |
419 " on the stand-alone VM.\n", url_string); | |
420 } else { | 422 } else { |
421 ASSERT(tag == Dart_kSourceTag); | 423 ASSERT(tag == Dart_kSourceTag); |
422 return NewError("Unable to load source '%s' ", url_string); | 424 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); |
423 } | 425 if (id == Builtin::kInvalidLibrary) { |
424 } | 426 return NewError("The built-in library '%s' is not available" |
425 | 427 " on the stand-alone VM. Trying to load" |
426 // Handle 'part' of IO library. | 428 " '%s'.\n", library_url_string, url_string); |
427 if (is_io_library) { | 429 } |
428 if (tag == Dart_kSourceTag) { | |
429 // Prepend the library URI to form a unique script URI for the part. | 430 // Prepend the library URI to form a unique script URI for the part. |
430 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); | 431 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); |
431 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); | 432 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); |
432 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); | 433 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); |
433 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); | 434 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); |
434 free(part_uri); | 435 free(part_uri); |
435 return Dart_LoadSource( | 436 return Dart_LoadSource( |
436 library, | 437 library, |
437 part_uri_obj, | 438 part_uri_obj, |
438 Builtin::PartSource(Builtin::kIOLibrary, url_string), 0, 0); | 439 Builtin::PartSource(id, url_string), 0, 0); |
439 } else { | |
440 ASSERT(tag == Dart_kImportTag); | |
441 return NewError("Unable to import '%s' ", url_string); | |
442 } | 440 } |
443 } | 441 } |
444 | 442 |
443 // Handle 'part' of dart: library being supplied by the embedder. | |
444 if (is_dart_library) { | |
445 UNREACHABLE(); | |
446 } | |
siva
2016/04/25 23:38:31
This is not needed right?
Ivan Posva
2016/04/26 21:17:43
Refactored this code here and above...
| |
447 | |
445 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 448 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
446 // Load a native code shared library to use in a native extension | 449 // Load a native code shared library to use in a native extension |
447 if (tag != Dart_kImportTag) { | 450 if (tag != Dart_kImportTag) { |
448 return NewError("Dart extensions must use import: '%s'", url_string); | 451 return NewError("Dart extensions must use import: '%s'", url_string); |
449 } | 452 } |
450 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url); | 453 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url); |
451 if (Dart_IsError(path_parts)) { | 454 if (Dart_IsError(path_parts)) { |
452 return path_parts; | 455 return path_parts; |
453 } | 456 } |
454 #if defined(DEBUG) | 457 #if defined(DEBUG) |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 new CObjectString(CObject::NewString(os_error->message())); | 1259 new CObjectString(CObject::NewString(os_error->message())); |
1257 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1260 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1258 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1261 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1259 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1262 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1260 result->SetAt(2, error_message); | 1263 result->SetAt(2, error_message); |
1261 return result; | 1264 return result; |
1262 } | 1265 } |
1263 | 1266 |
1264 } // namespace bin | 1267 } // namespace bin |
1265 } // namespace dart | 1268 } // namespace dart |
OLD | NEW |