| 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/extensions.h" | 7 #include "bin/extensions.h" |
| 8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
| 9 #include "bin/file.h" | 9 #include "bin/file.h" |
| 10 #include "bin/io_buffer.h" | 10 #include "bin/io_buffer.h" |
| 11 #include "include/dart_api.h" | 11 #include "include/dart_api.h" |
| 12 #include "platform/assert.h" | 12 #include "platform/assert.h" |
| 13 #include "platform/globals.h" | 13 #include "platform/globals.h" |
| 14 | 14 |
| 15 const char* DartUtils::original_working_directory = NULL; | 15 const char* DartUtils::original_working_directory = NULL; |
| 16 const char* DartUtils::kDartScheme = "dart:"; | 16 const char* DartUtils::kDartScheme = "dart:"; |
| 17 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; | 17 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; |
| 18 const char* DartUtils::kASyncLibURL = "dart:async"; | 18 const char* DartUtils::kASyncLibURL = "dart:async"; |
| 19 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; | 19 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; |
| 20 const char* DartUtils::kCoreLibURL = "dart:core"; | 20 const char* DartUtils::kCoreLibURL = "dart:core"; |
| 21 const char* DartUtils::kCryptoLibURL = "dart:crypto"; | |
| 22 const char* DartUtils::kIOLibURL = "dart:io"; | 21 const char* DartUtils::kIOLibURL = "dart:io"; |
| 23 const char* DartUtils::kIOLibPatchURL = "dart:io-patch"; | 22 const char* DartUtils::kIOLibPatchURL = "dart:io-patch"; |
| 24 const char* DartUtils::kJsonLibURL = "dart:json"; | |
| 25 const char* DartUtils::kUriLibURL = "dart:uri"; | 23 const char* DartUtils::kUriLibURL = "dart:uri"; |
| 26 const char* DartUtils::kUtfLibURL = "dart:utf"; | 24 const char* DartUtils::kUtfLibURL = "dart:utf"; |
| 27 const char* DartUtils::kIsolateLibURL = "dart:isolate"; | |
| 28 | |
| 29 | 25 |
| 30 const char* DartUtils::kIdFieldName = "_id"; | 26 const char* DartUtils::kIdFieldName = "_id"; |
| 31 | 27 |
| 32 | 28 |
| 33 static bool IsWindowsHost() { | 29 static bool IsWindowsHost() { |
| 34 #if defined(TARGET_OS_WINDOWS) | 30 #if defined(TARGET_OS_WINDOWS) |
| 35 return true; | 31 return true; |
| 36 #else // defined(TARGET_OS_WINDOWS) | 32 #else // defined(TARGET_OS_WINDOWS) |
| 37 return false; | 33 return false; |
| 38 #endif // defined(TARGET_OS_WINDOWS) | 34 #endif // defined(TARGET_OS_WINDOWS) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 138 |
| 143 bool DartUtils::IsDartExtensionSchemeURL(const char* url_name) { | 139 bool DartUtils::IsDartExtensionSchemeURL(const char* url_name) { |
| 144 static const intptr_t kDartExtensionSchemeLen = strlen(kDartExtensionScheme); | 140 static const intptr_t kDartExtensionSchemeLen = strlen(kDartExtensionScheme); |
| 145 // If the URL starts with "dartext:" then it is considered as a special | 141 // If the URL starts with "dartext:" then it is considered as a special |
| 146 // extension library URL which is handled differently from other URLs. | 142 // extension library URL which is handled differently from other URLs. |
| 147 return | 143 return |
| 148 (strncmp(url_name, kDartExtensionScheme, kDartExtensionSchemeLen) == 0); | 144 (strncmp(url_name, kDartExtensionScheme, kDartExtensionSchemeLen) == 0); |
| 149 } | 145 } |
| 150 | 146 |
| 151 | 147 |
| 152 bool DartUtils::IsDartCryptoLibURL(const char* url_name) { | |
| 153 return (strcmp(url_name, kCryptoLibURL) == 0); | |
| 154 } | |
| 155 | |
| 156 | |
| 157 bool DartUtils::IsDartIOLibURL(const char* url_name) { | 148 bool DartUtils::IsDartIOLibURL(const char* url_name) { |
| 158 return (strcmp(url_name, kIOLibURL) == 0); | 149 return (strcmp(url_name, kIOLibURL) == 0); |
| 159 } | 150 } |
| 160 | 151 |
| 161 | 152 |
| 162 bool DartUtils::IsDartBuiltinLibURL(const char* url_name) { | 153 bool DartUtils::IsDartBuiltinLibURL(const char* url_name) { |
| 163 return (strcmp(url_name, kBuiltinLibURL) == 0); | 154 return (strcmp(url_name, kBuiltinLibURL) == 0); |
| 164 } | 155 } |
| 165 | 156 |
| 166 | 157 |
| 167 bool DartUtils::IsDartJsonLibURL(const char* url_name) { | |
| 168 return (strcmp(url_name, kJsonLibURL) == 0); | |
| 169 } | |
| 170 | |
| 171 | |
| 172 bool DartUtils::IsDartUriLibURL(const char* url_name) { | |
| 173 return (strcmp(url_name, kUriLibURL) == 0); | |
| 174 } | |
| 175 | |
| 176 | |
| 177 bool DartUtils::IsDartUtfLibURL(const char* url_name) { | |
| 178 return (strcmp(url_name, kUtfLibURL) == 0); | |
| 179 } | |
| 180 | |
| 181 | |
| 182 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, | 158 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, |
| 183 Dart_Handle library, | 159 Dart_Handle library, |
| 184 const char* url_str) { | 160 const char* url_str) { |
| 185 // Get the url of the including library. | 161 // Get the url of the including library. |
| 186 Dart_Handle library_url = Dart_LibraryUrl(library); | 162 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 187 if (Dart_IsError(library_url)) { | 163 if (Dart_IsError(library_url)) { |
| 188 return Dart_Error("accessing library url failed"); | 164 return Dart_Error("accessing library url failed"); |
| 189 } | 165 } |
| 190 if (!Dart_IsString(library_url)) { | 166 if (!Dart_IsString(library_url)) { |
| 191 return Dart_Error("library url is not a string"); | 167 return Dart_Error("library url is not a string"); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 Dart_Handle library_url = Dart_LibraryUrl(library); | 283 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 308 if (Dart_IsError(library_url)) { | 284 if (Dart_IsError(library_url)) { |
| 309 return library_url; | 285 return library_url; |
| 310 } | 286 } |
| 311 return ResolveUri(library_url, url, builtin_lib); | 287 return ResolveUri(library_url, url, builtin_lib); |
| 312 } | 288 } |
| 313 if (is_dart_scheme_url) { | 289 if (is_dart_scheme_url) { |
| 314 if (tag == kImportTag) { | 290 if (tag == kImportTag) { |
| 315 // Handle imports of other built-in libraries present in the SDK. | 291 // Handle imports of other built-in libraries present in the SDK. |
| 316 Builtin::BuiltinLibraryId id; | 292 Builtin::BuiltinLibraryId id; |
| 317 if (DartUtils::IsDartCryptoLibURL(url_string)) { | 293 if (DartUtils::IsDartIOLibURL(url_string)) { |
| 318 id = Builtin::kCryptoLibrary; | |
| 319 } else if (DartUtils::IsDartIOLibURL(url_string)) { | |
| 320 id = Builtin::kIOLibrary; | 294 id = Builtin::kIOLibrary; |
| 321 } else if (DartUtils::IsDartJsonLibURL(url_string)) { | |
| 322 id = Builtin::kJsonLibrary; | |
| 323 } else if (DartUtils::IsDartUriLibURL(url_string)) { | |
| 324 id = Builtin::kUriLibrary; | |
| 325 } else if (DartUtils::IsDartUtfLibURL(url_string)) { | |
| 326 id = Builtin::kUtfLibrary; | |
| 327 } else { | 295 } else { |
| 328 return Dart_Error("Do not know how to load '%s'", url_string); | 296 return Dart_Error("Do not know how to load '%s'", url_string); |
| 329 } | 297 } |
| 330 return Builtin::LoadAndCheckLibrary(id); | 298 return Builtin::LoadAndCheckLibrary(id); |
| 331 } else { | 299 } else { |
| 332 ASSERT(tag == kSourceTag); | 300 ASSERT(tag == kSourceTag); |
| 333 return Dart_Error("Unable to load source '%s' ", url_string); | 301 return Dart_Error("Unable to load source '%s' ", url_string); |
| 334 } | 302 } |
| 335 } else { | 303 } else { |
| 336 // Get the file path out of the url. | 304 // Get the file path out of the url. |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 | 689 |
| 722 CObject* CObject::NewOSError(OSError* os_error) { | 690 CObject* CObject::NewOSError(OSError* os_error) { |
| 723 CObject* error_message = | 691 CObject* error_message = |
| 724 new CObjectString(CObject::NewString(os_error->message())); | 692 new CObjectString(CObject::NewString(os_error->message())); |
| 725 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 693 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 726 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 694 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 727 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 695 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 728 result->SetAt(2, error_message); | 696 result->SetAt(2, error_message); |
| 729 return result; | 697 return result; |
| 730 } | 698 } |
| OLD | NEW |