| 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 "include/dart_api.h" | 10 #include "include/dart_api.h" |
| 11 #include "platform/assert.h" | 11 #include "platform/assert.h" |
| 12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
| 13 | 13 |
| 14 const char* DartUtils::original_working_directory = NULL; | 14 const char* DartUtils::original_working_directory = NULL; |
| 15 const char* DartUtils::kDartScheme = "dart:"; | 15 const char* DartUtils::kDartScheme = "dart:"; |
| 16 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; | 16 const char* DartUtils::kDartExtensionScheme = "dart-ext:"; |
| 17 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; | 17 const char* DartUtils::kBuiltinLibURL = "dart:builtin"; |
| 18 const char* DartUtils::kCoreLibURL = "dart:core"; | 18 const char* DartUtils::kCoreLibURL = "dart:core"; |
| 19 const char* DartUtils::kCoreImplLibURL = "dart:coreimpl"; | 19 const char* DartUtils::kCoreImplLibURL = "dart:coreimpl"; |
| 20 const char* DartUtils::kCryptoLibURL = "dart:crypto"; | 20 const char* DartUtils::kCryptoLibURL = "dart:crypto"; |
| 21 const char* DartUtils::kIOLibURL = "dart:io"; | 21 const char* DartUtils::kIOLibURL = "dart:io"; |
| 22 const char* DartUtils::kJsonLibURL = "dart:json"; | 22 const char* DartUtils::kJsonLibURL = "dart:json"; |
| 23 const char* DartUtils::kUriLibURL = "dart:uri"; | 23 const char* DartUtils::kUriLibURL = "dart:uri"; |
| 24 const char* DartUtils::kUtfLibURL = "dart:utf"; | 24 const char* DartUtils::kUtfLibURL = "dart:utf"; |
| 25 const char* DartUtils::kIsolateLibURL = "dart:isolate"; | 25 const char* DartUtils::kIsolateLibURL = "dart:isolate"; |
| 26 const char* DartUtils::kWebLibURL = "dart:web"; |
| 26 | 27 |
| 27 | 28 |
| 28 const char* DartUtils::kIdFieldName = "_id"; | 29 const char* DartUtils::kIdFieldName = "_id"; |
| 29 | 30 |
| 30 | 31 |
| 31 static bool IsWindowsHost() { | 32 static bool IsWindowsHost() { |
| 32 #if defined(TARGET_OS_WINDOWS) | 33 #if defined(TARGET_OS_WINDOWS) |
| 33 return true; | 34 return true; |
| 34 #else // defined(TARGET_OS_WINDOWS) | 35 #else // defined(TARGET_OS_WINDOWS) |
| 35 return false; | 36 return false; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 bool DartUtils::IsDartUriLibURL(const char* url_name) { | 159 bool DartUtils::IsDartUriLibURL(const char* url_name) { |
| 159 return (strcmp(url_name, kUriLibURL) == 0); | 160 return (strcmp(url_name, kUriLibURL) == 0); |
| 160 } | 161 } |
| 161 | 162 |
| 162 | 163 |
| 163 bool DartUtils::IsDartUtfLibURL(const char* url_name) { | 164 bool DartUtils::IsDartUtfLibURL(const char* url_name) { |
| 164 return (strcmp(url_name, kUtfLibURL) == 0); | 165 return (strcmp(url_name, kUtfLibURL) == 0); |
| 165 } | 166 } |
| 166 | 167 |
| 167 | 168 |
| 169 bool DartUtils::IsDartWebLibURL(const char* url_name) { |
| 170 return (strcmp(url_name, kWebLibURL) == 0); |
| 171 } |
| 172 |
| 173 |
| 168 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, | 174 Dart_Handle DartUtils::CanonicalizeURL(CommandLineOptions* url_mapping, |
| 169 Dart_Handle library, | 175 Dart_Handle library, |
| 170 const char* url_str) { | 176 const char* url_str) { |
| 171 // Get the url of the including library. | 177 // Get the url of the including library. |
| 172 Dart_Handle library_url = Dart_LibraryUrl(library); | 178 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 173 if (Dart_IsError(library_url)) { | 179 if (Dart_IsError(library_url)) { |
| 174 return Dart_Error("accessing library url failed"); | 180 return Dart_Error("accessing library url failed"); |
| 175 } | 181 } |
| 176 if (!Dart_IsString8(library_url)) { | 182 if (!Dart_IsString8(library_url)) { |
| 177 return Dart_Error("library url is not a string"); | 183 return Dart_Error("library url is not a string"); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 if (DartUtils::IsDartCryptoLibURL(url_string)) { | 299 if (DartUtils::IsDartCryptoLibURL(url_string)) { |
| 294 id = Builtin::kCryptoLibrary; | 300 id = Builtin::kCryptoLibrary; |
| 295 } else if (DartUtils::IsDartIOLibURL(url_string)) { | 301 } else if (DartUtils::IsDartIOLibURL(url_string)) { |
| 296 id = Builtin::kIOLibrary; | 302 id = Builtin::kIOLibrary; |
| 297 } else if (DartUtils::IsDartJsonLibURL(url_string)) { | 303 } else if (DartUtils::IsDartJsonLibURL(url_string)) { |
| 298 id = Builtin::kJsonLibrary; | 304 id = Builtin::kJsonLibrary; |
| 299 } else if (DartUtils::IsDartUriLibURL(url_string)) { | 305 } else if (DartUtils::IsDartUriLibURL(url_string)) { |
| 300 id = Builtin::kUriLibrary; | 306 id = Builtin::kUriLibrary; |
| 301 } else if (DartUtils::IsDartUtfLibURL(url_string)) { | 307 } else if (DartUtils::IsDartUtfLibURL(url_string)) { |
| 302 id = Builtin::kUtfLibrary; | 308 id = Builtin::kUtfLibrary; |
| 309 } else if (DartUtils::IsDartWebLibURL(url_string)) { |
| 310 id = Builtin::kWebLibrary; |
| 303 } else { | 311 } else { |
| 304 return Dart_Error("Do not know how to load '%s'", url_string); | 312 return Dart_Error("Do not know how to load '%s'", url_string); |
| 305 } | 313 } |
| 306 return Builtin::LoadAndCheckLibrary(id); | 314 return Builtin::LoadAndCheckLibrary(id); |
| 307 } else { | 315 } else { |
| 308 // Get the file path out of the url. | 316 // Get the file path out of the url. |
| 309 Dart_Handle builtin_lib = | 317 Dart_Handle builtin_lib = |
| 310 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 318 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 311 Dart_Handle file_path = FilePathFromUri(url, builtin_lib); | 319 Dart_Handle file_path = FilePathFromUri(url, builtin_lib); |
| 312 if (Dart_IsError(file_path)) { | 320 if (Dart_IsError(file_path)) { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 | 660 |
| 653 CObject* CObject::NewOSError(OSError* os_error) { | 661 CObject* CObject::NewOSError(OSError* os_error) { |
| 654 CObject* error_message = | 662 CObject* error_message = |
| 655 new CObjectString(CObject::NewString(os_error->message())); | 663 new CObjectString(CObject::NewString(os_error->message())); |
| 656 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 664 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 657 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 665 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 658 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 666 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 659 result->SetAt(2, error_message); | 667 result->SetAt(2, error_message); |
| 660 return result; | 668 return result; |
| 661 } | 669 } |
| OLD | NEW |