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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 | 511 |
511 result = Extensions::LoadExtension(lib_path, extension_path, importer); | 512 result = Extensions::LoadExtension(lib_path, extension_path, importer); |
512 free(lib_path); | 513 free(lib_path); |
513 RETURN_ERROR(result); | 514 RETURN_ERROR(result); |
514 } | 515 } |
515 | 516 |
516 return Dart_True(); | 517 return Dart_True(); |
517 } | 518 } |
518 | 519 |
519 | 520 |
520 Dart_Handle Loader::LoadUrlContents(Dart_Handle url, | 521 Dart_Handle Loader::SendAndProcessReply(Dart_LibraryTag tag, |
521 uint8_t** payload, | 522 Dart_Handle url, |
522 intptr_t* payload_length) { | 523 uint8_t** payload, |
524 intptr_t* payload_length) { | |
523 IsolateData* isolate_data = | 525 IsolateData* isolate_data = |
524 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 526 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
525 ASSERT(isolate_data != NULL); | 527 ASSERT(isolate_data != NULL); |
526 ASSERT(!isolate_data->HasLoader()); | 528 ASSERT(!isolate_data->HasLoader()); |
527 Loader* loader = NULL; | 529 Loader* loader = NULL; |
528 | 530 |
529 // Setup the loader. The constructor does a bunch of leg work. | 531 // Setup the loader. The constructor does a bunch of leg work. |
530 loader = new Loader(isolate_data); | 532 loader = new Loader(isolate_data); |
531 loader->Init(isolate_data->package_root, isolate_data->packages_file, | 533 loader->Init(isolate_data->package_root, isolate_data->packages_file, |
532 DartUtils::original_working_directory, NULL); | 534 DartUtils::original_working_directory, NULL); |
533 ASSERT(loader != NULL); | 535 ASSERT(loader != NULL); |
534 ASSERT(isolate_data->HasLoader()); | 536 ASSERT(isolate_data->HasLoader()); |
535 | 537 |
536 // Now send a load request to the service isolate. | 538 // Now send a load request to the service isolate. |
537 loader->SendRequest(Dart_kScriptTag, url, Dart_Null()); | 539 loader->SendRequest(tag, url, Dart_Null()); |
538 | 540 |
539 // Wait for a reply to the load request. | 541 // Wait for a reply to the load request. |
540 loader->BlockUntilComplete(ProcessUrlLoadResultLocked); | 542 loader->BlockUntilComplete(ProcessPayloadResultLocked); |
541 | 543 |
542 // Copy fields from the loader before deleting it. | 544 // Copy fields from the loader before deleting it. |
543 // The payload array itself which was malloced above is freed by | 545 // The payload array itself which was malloced above is freed by |
544 // the caller of LoadUrlContents. | 546 // the caller of LoadUrlContents. |
545 Dart_Handle error = loader->error(); | 547 Dart_Handle error = loader->error(); |
546 *payload = loader->payload_; | 548 *payload = loader->payload_; |
547 *payload_length = loader->payload_length_; | 549 *payload_length = loader->payload_length_; |
548 | 550 |
549 // Destroy the loader. The destructor does a bunch of leg work. | 551 // Destroy the loader. The destructor does a bunch of leg work. |
550 delete loader; | 552 delete loader; |
551 | 553 |
552 // An error occurred during loading. | 554 // An error occurred during loading. |
553 if (!Dart_IsNull(error)) { | 555 if (!Dart_IsNull(error)) { |
554 return error; | 556 return error; |
555 } | 557 } |
556 return Dart_Null(); | 558 return Dart_Null(); |
557 } | 559 } |
558 | 560 |
559 | 561 |
562 Dart_Handle Loader::LoadUrlContents(Dart_Handle url, | |
563 uint8_t** payload, | |
564 intptr_t* payload_length) { | |
565 return SendAndProcessReply(Dart_kScriptTag, url, payload, payload_length); | |
566 } | |
567 | |
568 | |
569 Dart_Handle Loader::ResolveAsFilePath(Dart_Handle url, | |
570 uint8_t** payload, | |
571 intptr_t* payload_length) { | |
572 // TODO(28863) The use of tags that aren't declared in dart_api.h's enum | |
Cutch
2017/02/23 19:09:58
I don't understand the issue here? These tags are
rmacnak
2017/02/23 19:27:41
The cast here invokes undefined behavior because _
| |
573 // is undefined behavior. | |
574 Dart_LibraryTag tag = static_cast<Dart_LibraryTag>(_Dart_kResolveAsFilePath); | |
575 return SendAndProcessReply(tag, url, payload, payload_length); | |
576 } | |
577 | |
578 | |
560 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, | 579 Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, |
561 Dart_Handle library, | 580 Dart_Handle library, |
562 Dart_Handle url) { | 581 Dart_Handle url) { |
563 if (tag == Dart_kCanonicalizeUrl) { | 582 if (tag == Dart_kCanonicalizeUrl) { |
564 Dart_Handle library_url = Dart_LibraryUrl(library); | 583 Dart_Handle library_url = Dart_LibraryUrl(library); |
565 if (Dart_IsError(library_url)) { | 584 if (Dart_IsError(library_url)) { |
566 return library_url; | 585 return library_url; |
567 } | 586 } |
568 return Dart_DefaultCanonicalizeUrl(library_url, url); | 587 return Dart_DefaultCanonicalizeUrl(library_url, url); |
569 } | 588 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 MutexLocker ml(loader_infos_lock_); | 840 MutexLocker ml(loader_infos_lock_); |
822 Loader* loader = LoaderForLocked(dest_port_id); | 841 Loader* loader = LoaderForLocked(dest_port_id); |
823 if (loader == NULL) { | 842 if (loader == NULL) { |
824 return; | 843 return; |
825 } | 844 } |
826 loader->QueueMessage(message); | 845 loader->QueueMessage(message); |
827 } | 846 } |
828 | 847 |
829 } // namespace bin | 848 } // namespace bin |
830 } // namespace dart | 849 } // namespace dart |
OLD | NEW |