| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 bool DartUtils::IsDartIOLibURL(const char* url_name) { | 173 bool DartUtils::IsDartIOLibURL(const char* url_name) { |
| 174 return (strcmp(url_name, kIOLibURL) == 0); | 174 return (strcmp(url_name, kIOLibURL) == 0); |
| 175 } | 175 } |
| 176 | 176 |
| 177 | 177 |
| 178 bool DartUtils::IsDartBuiltinLibURL(const char* url_name) { | 178 bool DartUtils::IsDartBuiltinLibURL(const char* url_name) { |
| 179 return (strcmp(url_name, kBuiltinLibURL) == 0); | 179 return (strcmp(url_name, kBuiltinLibURL) == 0); |
| 180 } | 180 } |
| 181 | 181 |
| 182 | 182 |
| 183 const char* DartUtils::RemoveScheme(const char* url) { |
| 184 const char* colon = strchr(url, ':'); |
| 185 if (colon == NULL) { |
| 186 return url; |
| 187 } else { |
| 188 return colon + 1; |
| 189 } |
| 190 } |
| 191 |
| 192 |
| 183 void* DartUtils::MapExecutable(const char* name, intptr_t* len) { | 193 void* DartUtils::MapExecutable(const char* name, intptr_t* len) { |
| 184 File* file = File::Open(name, File::kRead); | 194 File* file = File::Open(name, File::kRead); |
| 185 if (file == NULL) { | 195 if (file == NULL) { |
| 186 return NULL; | 196 return NULL; |
| 187 } | 197 } |
| 188 void* addr = file->MapExecutable(len); | 198 void* addr = file->MapExecutable(len); |
| 189 file->Release(); | 199 file->Release(); |
| 190 return addr; | 200 return addr; |
| 191 } | 201 } |
| 192 | 202 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 const int kNumArgs = 1; | 349 const int kNumArgs = 1; |
| 340 Dart_Handle dart_args[kNumArgs]; | 350 Dart_Handle dart_args[kNumArgs]; |
| 341 dart_args[0] = script_uri; | 351 dart_args[0] = script_uri; |
| 342 return Dart_Invoke(DartUtils::BuiltinLib(), | 352 return Dart_Invoke(DartUtils::BuiltinLib(), |
| 343 NewString("_filePathFromUri"), | 353 NewString("_filePathFromUri"), |
| 344 kNumArgs, | 354 kNumArgs, |
| 345 dart_args); | 355 dart_args); |
| 346 } | 356 } |
| 347 | 357 |
| 348 | 358 |
| 349 Dart_Handle DartUtils::ExtensionPathFromUri(Dart_Handle extension_uri) { | 359 Dart_Handle DartUtils::LibraryFilePath(Dart_Handle library_uri) { |
| 350 const int kNumArgs = 1; | 360 const int kNumArgs = 1; |
| 351 Dart_Handle dart_args[kNumArgs]; | 361 Dart_Handle dart_args[kNumArgs]; |
| 352 dart_args[0] = extension_uri; | 362 dart_args[0] = library_uri; |
| 353 return Dart_Invoke(DartUtils::BuiltinLib(), | 363 return Dart_Invoke(DartUtils::BuiltinLib(), |
| 354 NewString("_extensionPathFromUri"), | 364 NewString("_libraryFilePath"), |
| 355 kNumArgs, | 365 kNumArgs, |
| 356 dart_args); | 366 dart_args); |
| 357 } | 367 } |
| 358 | 368 |
| 359 | 369 |
| 360 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, Dart_Handle url) { | 370 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, Dart_Handle url) { |
| 361 const int kNumArgs = 2; | 371 const int kNumArgs = 2; |
| 362 Dart_Handle dart_args[kNumArgs]; | 372 Dart_Handle dart_args[kNumArgs]; |
| 363 dart_args[0] = library_url; | 373 dart_args[0] = library_url; |
| 364 dart_args[1] = url; | 374 dart_args[1] = url; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 if (tag == Dart_kCanonicalizeUrl) { | 455 if (tag == Dart_kCanonicalizeUrl) { |
| 446 // Resolve the url within the context of the library's URL. | 456 // Resolve the url within the context of the library's URL. |
| 447 return ResolveUri(library_url, url); | 457 return ResolveUri(library_url, url); |
| 448 } | 458 } |
| 449 | 459 |
| 450 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 460 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
| 451 // Load a native code shared library to use in a native extension | 461 // Load a native code shared library to use in a native extension |
| 452 if (tag != Dart_kImportTag) { | 462 if (tag != Dart_kImportTag) { |
| 453 return NewError("Dart extensions must use import: '%s'", url_string); | 463 return NewError("Dart extensions must use import: '%s'", url_string); |
| 454 } | 464 } |
| 455 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url); | 465 Dart_Handle library_file_path = DartUtils::LibraryFilePath(library_url); |
| 456 if (Dart_IsError(path_parts)) { | 466 const char* lib_path_str = NULL; |
| 457 return path_parts; | 467 Dart_StringToCString(library_file_path, &lib_path_str); |
| 468 const char* extension_path = DartUtils::RemoveScheme(url_string); |
| 469 if (strchr(extension_path, '/') != NULL || |
| 470 (IsWindowsHost() && strchr(extension_path, '\\') != NULL)) { |
| 471 return NewError( |
| 472 "Relative paths for dart extensions are not supported: '%s'", |
| 473 extension_path); |
| 458 } | 474 } |
| 459 #if defined(DEBUG) | 475 return Extensions::LoadExtension(lib_path_str, |
| 460 intptr_t path_parts_length; | 476 extension_path, |
| 461 result = Dart_ListLength(path_parts, &path_parts_length); | |
| 462 if (Dart_IsError(result)) { | |
| 463 return result; | |
| 464 } | |
| 465 ASSERT(path_parts_length == 2); | |
| 466 #endif | |
| 467 const char* extension_directory = NULL; | |
| 468 Dart_StringToCString(Dart_ListGetAt(path_parts, 0), &extension_directory); | |
| 469 const char* extension_name = NULL; | |
| 470 Dart_StringToCString(Dart_ListGetAt(path_parts, 1), &extension_name); | |
| 471 | |
| 472 return Extensions::LoadExtension(extension_directory, | |
| 473 extension_name, | |
| 474 library); | 477 library); |
| 475 } | 478 } |
| 476 | 479 |
| 477 // Handle 'import' or 'part' requests for all other URIs. Call dart code to | 480 // Handle 'import' or 'part' requests for all other URIs. Call dart code to |
| 478 // read the source code asynchronously. | 481 // read the source code asynchronously. |
| 479 return LoadDataAsync_Invoke(Dart_NewInteger(tag), url, library_url); | 482 return LoadDataAsync_Invoke(Dart_NewInteger(tag), url, library_url); |
| 480 } | 483 } |
| 481 | 484 |
| 482 | 485 |
| 483 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, | 486 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 new CObjectString(CObject::NewString(os_error->message())); | 1264 new CObjectString(CObject::NewString(os_error->message())); |
| 1262 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1265 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1263 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1266 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1264 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1267 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1265 result->SetAt(2, error_message); | 1268 result->SetAt(2, error_message); |
| 1266 return result; | 1269 return result; |
| 1267 } | 1270 } |
| 1268 | 1271 |
| 1269 } // namespace bin | 1272 } // namespace bin |
| 1270 } // namespace dart | 1273 } // namespace dart |
| OLD | NEW |