| 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 | 9 |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 const int kNumArgs = 1; | 433 const int kNumArgs = 1; |
| 434 Dart_Handle dart_args[kNumArgs]; | 434 Dart_Handle dart_args[kNumArgs]; |
| 435 dart_args[0] = script_uri; | 435 dart_args[0] = script_uri; |
| 436 return Dart_Invoke(builtin_lib, | 436 return Dart_Invoke(builtin_lib, |
| 437 NewString("_filePathFromUri"), | 437 NewString("_filePathFromUri"), |
| 438 kNumArgs, | 438 kNumArgs, |
| 439 dart_args); | 439 dart_args); |
| 440 } | 440 } |
| 441 | 441 |
| 442 | 442 |
| 443 Dart_Handle DartUtils::ExtensionPathFromUri(Dart_Handle extension_uri, |
| 444 Dart_Handle builtin_lib) { |
| 445 const int kNumArgs = 1; |
| 446 Dart_Handle dart_args[kNumArgs]; |
| 447 dart_args[0] = extension_uri; |
| 448 return Dart_Invoke(builtin_lib, |
| 449 NewString("_extensionPathFromUri"), |
| 450 kNumArgs, |
| 451 dart_args); |
| 452 } |
| 453 |
| 454 |
| 443 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, | 455 Dart_Handle DartUtils::ResolveUri(Dart_Handle library_url, |
| 444 Dart_Handle url, | 456 Dart_Handle url, |
| 445 Dart_Handle builtin_lib) { | 457 Dart_Handle builtin_lib) { |
| 446 const int kNumArgs = 2; | 458 const int kNumArgs = 2; |
| 447 Dart_Handle dart_args[kNumArgs]; | 459 Dart_Handle dart_args[kNumArgs]; |
| 448 dart_args[0] = library_url; | 460 dart_args[0] = library_url; |
| 449 dart_args[1] = url; | 461 dart_args[1] = url; |
| 450 return Dart_Invoke( | 462 return Dart_Invoke( |
| 451 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); | 463 builtin_lib, NewString("_resolveUri"), kNumArgs, dart_args); |
| 452 } | 464 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 if (is_io_library) { | 524 if (is_io_library) { |
| 513 if (tag == Dart_kSourceTag) { | 525 if (tag == Dart_kSourceTag) { |
| 514 return Dart_LoadSource( | 526 return Dart_LoadSource( |
| 515 library, url, Builtin::PartSource(Builtin::kIOLibrary, url_string)); | 527 library, url, Builtin::PartSource(Builtin::kIOLibrary, url_string)); |
| 516 } else { | 528 } else { |
| 517 ASSERT(tag == Dart_kImportTag); | 529 ASSERT(tag == Dart_kImportTag); |
| 518 return NewError("Unable to import '%s' ", url_string); | 530 return NewError("Unable to import '%s' ", url_string); |
| 519 } | 531 } |
| 520 } | 532 } |
| 521 | 533 |
| 522 // Handle 'import' or 'part' requests for all other URIs. | |
| 523 // Get the file path out of the url. | |
| 524 Dart_Handle builtin_lib = | 534 Dart_Handle builtin_lib = |
| 525 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); | 535 Builtin::LoadAndCheckLibrary(Builtin::kBuiltinLibrary); |
| 526 Dart_Handle file_path = FilePathFromUri(url, builtin_lib); | |
| 527 if (Dart_IsError(file_path)) { | |
| 528 return file_path; | |
| 529 } | |
| 530 const char* final_path = NULL; | |
| 531 Dart_StringToCString(file_path, &final_path); | |
| 532 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 536 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
| 537 // Load a native code shared library to use in a native extension |
| 533 if (tag != Dart_kImportTag) { | 538 if (tag != Dart_kImportTag) { |
| 534 return NewError("Dart extensions must use import: '%s'", url_string); | 539 return NewError("Dart extensions must use import: '%s'", url_string); |
| 535 } | 540 } |
| 536 return Extensions::LoadExtension(final_path, library); | 541 Dart_Handle path_parts = DartUtils::ExtensionPathFromUri(url, builtin_lib); |
| 542 if (Dart_IsError(path_parts)) { |
| 543 return path_parts; |
| 544 } |
| 545 const char* extension_directory = NULL; |
| 546 Dart_StringToCString(Dart_ListGetAt(path_parts, 0), &extension_directory); |
| 547 const char* extension_filename = NULL; |
| 548 Dart_StringToCString(Dart_ListGetAt(path_parts, 1), &extension_filename); |
| 549 const char* extension_name = NULL; |
| 550 Dart_StringToCString(Dart_ListGetAt(path_parts, 2), &extension_name); |
| 551 |
| 552 return Extensions::LoadExtension(extension_directory, |
| 553 extension_filename, |
| 554 extension_name, |
| 555 library); |
| 556 } else { |
| 557 // Handle 'import' or 'part' requests for all other URIs. |
| 558 // Get the file path out of the url. |
| 559 Dart_Handle file_path = DartUtils::FilePathFromUri(url, builtin_lib); |
| 560 if (Dart_IsError(file_path)) { |
| 561 return file_path; |
| 562 } |
| 563 const char* final_path = NULL; |
| 564 Dart_StringToCString(file_path, &final_path); |
| 565 result = DartUtils::LoadSource(NULL, |
| 566 library, |
| 567 url, |
| 568 tag, |
| 569 final_path); |
| 570 return result; |
| 537 } | 571 } |
| 538 result = DartUtils::LoadSource(NULL, | |
| 539 library, | |
| 540 url, | |
| 541 tag, | |
| 542 final_path); | |
| 543 return result; | |
| 544 } | 572 } |
| 545 | 573 |
| 546 | 574 |
| 547 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, | 575 const uint8_t* DartUtils::SniffForMagicNumber(const uint8_t* text_buffer, |
| 548 intptr_t* buffer_len, | 576 intptr_t* buffer_len, |
| 549 bool* is_snapshot) { | 577 bool* is_snapshot) { |
| 550 intptr_t len = sizeof(magic_number); | 578 intptr_t len = sizeof(magic_number); |
| 551 for (intptr_t i = 0; i < len; i++) { | 579 for (intptr_t i = 0; i < len; i++) { |
| 552 if (text_buffer[i] != magic_number[i]) { | 580 if (text_buffer[i] != magic_number[i]) { |
| 553 *is_snapshot = false; | 581 *is_snapshot = false; |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 new CObjectString(CObject::NewString(os_error->message())); | 1110 new CObjectString(CObject::NewString(os_error->message())); |
| 1083 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1111 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1084 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1112 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1085 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1113 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1086 result->SetAt(2, error_message); | 1114 result->SetAt(2, error_message); |
| 1087 return result; | 1115 return result; |
| 1088 } | 1116 } |
| 1089 | 1117 |
| 1090 } // namespace bin | 1118 } // namespace bin |
| 1091 } // namespace dart | 1119 } // namespace dart |
| OLD | NEW |