Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 | 5 |
| 6 #include "bin/loader.h" | 6 #include "bin/loader.h" |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/dartutils.h" | 9 #include "bin/dartutils.h" |
| 10 #include "bin/extensions.h" | 10 #include "bin/extensions.h" |
| 11 #include "bin/file.h" | 11 #include "bin/file.h" |
| 12 #include "bin/lockers.h" | 12 #include "bin/lockers.h" |
| 13 #include "bin/utils.h" | 13 #include "bin/utils.h" |
| 14 #include "include/dart_tools_api.h" | 14 #include "include/dart_tools_api.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 namespace bin { | 17 namespace bin { |
| 18 | 18 |
| 19 // Development flag. | 19 // Development flag. |
| 20 static bool trace_loader = false; | 20 static bool trace_loader = false; |
| 21 // Keep in sync with loader.dart. | 21 // Keep in sync with loader.dart. |
| 22 static const intptr_t _Dart_kImportExtension = 9; | 22 static const intptr_t _Dart_kImportExtension = 9; |
| 23 static const intptr_t _Dart_kResolveAsFilePath = 10; | |
| 23 | 24 |
| 24 Loader::Loader(IsolateData* isolate_data) | 25 Loader::Loader(IsolateData* isolate_data) |
| 25 : port_(ILLEGAL_PORT), | 26 : port_(ILLEGAL_PORT), |
| 26 isolate_data_(isolate_data), | 27 isolate_data_(isolate_data), |
| 27 error_(Dart_Null()), | 28 error_(Dart_Null()), |
| 28 monitor_(NULL), | 29 monitor_(NULL), |
| 29 pending_operations_(0), | 30 pending_operations_(0), |
| 30 results_(NULL), | 31 results_(NULL), |
| 31 results_length_(0), | 32 results_length_(0), |
| 32 results_capacity_(0), | 33 results_capacity_(0), |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 // Remember the error if we encountered one. | 418 // Remember the error if we encountered one. |
| 418 loader->error_ = dart_result; | 419 loader->error_ = dart_result; |
| 419 return false; | 420 return false; |
| 420 } | 421 } |
| 421 } | 422 } |
| 422 | 423 |
| 423 return true; | 424 return true; |
| 424 } | 425 } |
| 425 | 426 |
| 426 | 427 |
| 427 bool Loader::ProcessUrlLoadResultLocked(Loader* loader, | 428 bool Loader::ProcessPayloadResultLocked(Loader* loader, |
| 428 Loader::IOResult* result) { | 429 Loader::IOResult* result) { |
| 429 // A negative result tag indicates a loading error occurred in the service | 430 // A negative result tag indicates a loading error occurred in the service |
| 430 // isolate. The payload is a C string of the error message. | 431 // isolate. The payload is a C string of the error message. |
| 431 if (result->tag < 0) { | 432 if (result->tag < 0) { |
| 432 Dart_Handle error = | 433 Dart_Handle error = |
| 433 Dart_NewStringFromUTF8(result->payload, result->payload_length); | 434 Dart_NewStringFromUTF8(result->payload, result->payload_length); |
| 434 loader->error_ = Dart_NewUnhandledExceptionError(error); | 435 loader->error_ = Dart_NewUnhandledExceptionError(error); |
| 435 return false; | 436 return false; |
| 436 } | 437 } |
| 437 loader->payload_length_ = result->payload_length; | 438 loader->payload_length_ = result->payload_length; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 loader = new Loader(isolate_data); | 531 loader = new Loader(isolate_data); |
| 531 loader->Init(isolate_data->package_root, isolate_data->packages_file, | 532 loader->Init(isolate_data->package_root, isolate_data->packages_file, |
| 532 DartUtils::original_working_directory, NULL); | 533 DartUtils::original_working_directory, NULL); |
| 533 ASSERT(loader != NULL); | 534 ASSERT(loader != NULL); |
| 534 ASSERT(isolate_data->HasLoader()); | 535 ASSERT(isolate_data->HasLoader()); |
| 535 | 536 |
| 536 // Now send a load request to the service isolate. | 537 // Now send a load request to the service isolate. |
| 537 loader->SendRequest(Dart_kScriptTag, url, Dart_Null()); | 538 loader->SendRequest(Dart_kScriptTag, url, Dart_Null()); |
| 538 | 539 |
| 539 // Wait for a reply to the load request. | 540 // Wait for a reply to the load request. |
| 540 loader->BlockUntilComplete(ProcessUrlLoadResultLocked); | 541 loader->BlockUntilComplete(ProcessPayloadResultLocked); |
| 541 | 542 |
| 542 // Copy fields from the loader before deleting it. | 543 // Copy fields from the loader before deleting it. |
| 543 // The payload array itself which was malloced above is freed by | 544 // The payload array itself which was malloced above is freed by |
| 545 // the caller of LoadUrlContents. | |
| 546 Dart_Handle error = loader->error(); | |
| 547 *payload = loader->payload_; | |
| 548 *payload_length = loader->payload_length_; | |
| 549 | |
| 550 // Destroy the loader. The destructor does a bunch of leg work. | |
| 551 delete loader; | |
| 552 | |
| 553 // An error occurred during loading. | |
| 554 if (!Dart_IsNull(error)) { | |
| 555 return error; | |
| 556 } | |
| 557 return Dart_Null(); | |
| 558 } | |
| 559 | |
| 560 | |
| 561 Dart_Handle Loader::ResolveAsFilePath(Dart_Handle url, | |
| 562 uint8_t** payload, | |
| 563 intptr_t* payload_length) { | |
| 564 IsolateData* isolate_data = | |
| 565 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | |
| 566 ASSERT(isolate_data != NULL); | |
| 567 ASSERT(!isolate_data->HasLoader()); | |
| 568 Loader* loader = NULL; | |
| 569 | |
| 570 // Setup the loader. The constructor does a bunch of leg work. | |
| 571 loader = new Loader(isolate_data); | |
| 572 loader->Init(isolate_data->package_root, isolate_data->packages_file, | |
| 573 DartUtils::original_working_directory, NULL); | |
| 574 ASSERT(loader != NULL); | |
| 575 ASSERT(isolate_data->HasLoader()); | |
| 576 | |
| 577 // Now send a load request to the service isolate. | |
| 578 // TODO(28863) The use of tags that aren't declared in dart_api.h's enum | |
| 579 // is undefined behavior. | |
| 580 Dart_LibraryTag tag = static_cast<Dart_LibraryTag>(_Dart_kResolveAsFilePath); | |
| 581 loader->SendRequest(tag, url, Dart_Null()); | |
| 582 | |
| 583 // Wait for a reply to the load request. | |
| 584 loader->BlockUntilComplete(ProcessPayloadResultLocked); | |
| 585 | |
| 586 // Copy fields from the loader before deleting it. | |
| 587 // The payload array itself which was malloced above is freed by | |
| 544 // the caller of LoadUrlContents. | 588 // the caller of LoadUrlContents. |
| 545 Dart_Handle error = loader->error(); | 589 Dart_Handle error = loader->error(); |
| 546 *payload = loader->payload_; | 590 *payload = loader->payload_; |
| 547 *payload_length = loader->payload_length_; | 591 *payload_length = loader->payload_length_; |
| 548 | 592 |
| 549 // Destroy the loader. The destructor does a bunch of leg work. | 593 // Destroy the loader. The destructor does a bunch of leg work. |
| 550 delete loader; | 594 delete loader; |
| 551 | 595 |
| 552 // An error occurred during loading. | 596 // An error occurred during loading. |
| 553 if (!Dart_IsNull(error)) { | 597 if (!Dart_IsNull(error)) { |
| 554 return error; | 598 return error; |
| 555 } | 599 } |
| 556 return Dart_Null(); | 600 return Dart_Null(); |
|
siva
2017/02/22 23:37:16
It looks like the core of this function can be fac
rmacnak
2017/02/23 19:00:17
Done.
| |
| 557 } | 601 } |
| 558 | 602 |
| 559 | 603 |
| 560 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, | 604 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, |
| 561 Dart_Handle library, | 605 Dart_Handle library, |
| 562 Dart_Handle url) { | 606 Dart_Handle url) { |
| 563 if (tag == Dart_kCanonicalizeUrl) { | 607 if (tag == Dart_kCanonicalizeUrl) { |
| 564 Dart_Handle library_url = Dart_LibraryUrl(library); | 608 Dart_Handle library_url = Dart_LibraryUrl(library); |
| 565 if (Dart_IsError(library_url)) { | 609 if (Dart_IsError(library_url)) { |
| 566 return library_url; | 610 return library_url; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 MutexLocker ml(loader_infos_lock_); | 865 MutexLocker ml(loader_infos_lock_); |
| 822 Loader* loader = LoaderForLocked(dest_port_id); | 866 Loader* loader = LoaderForLocked(dest_port_id); |
| 823 if (loader == NULL) { | 867 if (loader == NULL) { |
| 824 return; | 868 return; |
| 825 } | 869 } |
| 826 loader->QueueMessage(message); | 870 loader->QueueMessage(message); |
| 827 } | 871 } |
| 828 | 872 |
| 829 } // namespace bin | 873 } // namespace bin |
| 830 } // namespace dart | 874 } // namespace dart |
| OLD | NEW |