| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Generate a snapshot file after loading all the scripts specified on the | 5 // Generate a snapshot file after loading all the scripts specified on the |
| 6 // command line. | 6 // command line. |
| 7 | 7 |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 if (Dart_IsError(resolved_uri)) { | 484 if (Dart_IsError(resolved_uri)) { |
| 485 return resolved_uri; | 485 return resolved_uri; |
| 486 } | 486 } |
| 487 // Now load the contents of the specified uri. | 487 // Now load the contents of the specified uri. |
| 488 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); | 488 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_uri); |
| 489 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 489 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
| 490 if (Dart_IsError(source)) { | 490 if (Dart_IsError(source)) { |
| 491 return source; | 491 return source; |
| 492 } | 492 } |
| 493 if (IsSnapshottingForPrecompilation()) { | 493 if (IsSnapshottingForPrecompilation()) { |
| 494 return Dart_LoadScript(resolved_uri, source, 0, 0); | 494 return Dart_LoadScript(resolved_uri, Dart_Null(), source, 0, 0); |
| 495 } else { | 495 } else { |
| 496 return Dart_LoadLibrary(resolved_uri, source, 0, 0); | 496 return Dart_LoadLibrary(resolved_uri, Dart_Null(), source, 0, 0); |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 | 499 |
| 500 | 500 |
| 501 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { | 501 static Builtin::BuiltinLibraryId BuiltinId(const char* url) { |
| 502 if (DartUtils::IsDartBuiltinLibURL(url)) { | 502 if (DartUtils::IsDartBuiltinLibURL(url)) { |
| 503 return Builtin::kBuiltinLibrary; | 503 return Builtin::kBuiltinLibrary; |
| 504 } | 504 } |
| 505 if (DartUtils::IsDartIOLibURL(url)) { | 505 if (DartUtils::IsDartIOLibURL(url)) { |
| 506 return Builtin::kIOLibrary; | 506 return Builtin::kIOLibrary; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 if (tag == Dart_kImportTag) { | 551 if (tag == Dart_kImportTag) { |
| 552 return Builtin::LoadLibrary(url, builtinId); | 552 return Builtin::LoadLibrary(url, builtinId); |
| 553 } | 553 } |
| 554 ASSERT(tag == Dart_kSourceTag); | 554 ASSERT(tag == Dart_kSourceTag); |
| 555 return DartUtils::NewError("Unable to part '%s' ", url_string); | 555 return DartUtils::NewError("Unable to part '%s' ", url_string); |
| 556 } | 556 } |
| 557 | 557 |
| 558 if (libraryBuiltinId != Builtin::kInvalidLibrary) { | 558 if (libraryBuiltinId != Builtin::kInvalidLibrary) { |
| 559 // Special case for parting sources of a builtin library. | 559 // Special case for parting sources of a builtin library. |
| 560 if (tag == Dart_kSourceTag) { | 560 if (tag == Dart_kSourceTag) { |
| 561 return Dart_LoadSource(library, url, | 561 return Dart_LoadSource(library, url, Dart_Null(), |
| 562 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0); | 562 Builtin::PartSource(libraryBuiltinId, url_string), 0, 0); |
| 563 } | 563 } |
| 564 ASSERT(tag == Dart_kImportTag); | 564 ASSERT(tag == Dart_kImportTag); |
| 565 return DartUtils::NewError("Unable to import '%s' ", url_string); | 565 return DartUtils::NewError("Unable to import '%s' ", url_string); |
| 566 } | 566 } |
| 567 | 567 |
| 568 Dart_Handle resolved_url = url; | 568 Dart_Handle resolved_url = url; |
| 569 if (mapped_url_string != NULL) { | 569 if (mapped_url_string != NULL) { |
| 570 // Mapped urls are relative to working directory. | 570 // Mapped urls are relative to working directory. |
| 571 resolved_url = ResolveUriInWorkingDirectory(mapped_url_string); | 571 resolved_url = ResolveUriInWorkingDirectory(mapped_url_string); |
| 572 if (Dart_IsError(resolved_url)) { | 572 if (Dart_IsError(resolved_url)) { |
| 573 return resolved_url; | 573 return resolved_url; |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_url); | 576 const char* resolved_uri_string = DartUtils::GetStringValue(resolved_url); |
| 577 Dart_Handle source = LoadUrlContents(resolved_uri_string); | 577 Dart_Handle source = LoadUrlContents(resolved_uri_string); |
| 578 if (Dart_IsError(source)) { | 578 if (Dart_IsError(source)) { |
| 579 return source; | 579 return source; |
| 580 } | 580 } |
| 581 if (tag == Dart_kImportTag) { | 581 if (tag == Dart_kImportTag) { |
| 582 return Dart_LoadLibrary(url, source, 0, 0); | 582 return Dart_LoadLibrary(url, Dart_Null(), source, 0, 0); |
| 583 } else { | 583 } else { |
| 584 ASSERT(tag == Dart_kSourceTag); | 584 ASSERT(tag == Dart_kSourceTag); |
| 585 return Dart_LoadSource(library, url, source, 0, 0); | 585 return Dart_LoadSource(library, url, Dart_Null(), source, 0, 0); |
| 586 } | 586 } |
| 587 } | 587 } |
| 588 | 588 |
| 589 | 589 |
| 590 static Dart_Handle LoadGenericSnapshotCreationScript( | 590 static Dart_Handle LoadGenericSnapshotCreationScript( |
| 591 Builtin::BuiltinLibraryId id) { | 591 Builtin::BuiltinLibraryId id) { |
| 592 Dart_Handle source = Builtin::Source(id); | 592 Dart_Handle source = Builtin::Source(id); |
| 593 if (Dart_IsError(source)) { | 593 if (Dart_IsError(source)) { |
| 594 return source; // source contains the error string. | 594 return source; // source contains the error string. |
| 595 } | 595 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 "import '%s';", | 714 "import '%s';", |
| 715 DartUtils::GetStringValue(library_string)); | 715 DartUtils::GetStringValue(library_string)); |
| 716 Dart_Handle script_handle = Dart_NewStringFromCString(load_buffer); | 716 Dart_Handle script_handle = Dart_NewStringFromCString(load_buffer); |
| 717 memset(load_buffer, 0, kLoadBufferMaxSize); | 717 memset(load_buffer, 0, kLoadBufferMaxSize); |
| 718 snprintf(load_buffer, | 718 snprintf(load_buffer, |
| 719 kLoadBufferMaxSize, | 719 kLoadBufferMaxSize, |
| 720 "dart:_snapshot_%zu", | 720 "dart:_snapshot_%zu", |
| 721 lib_index); | 721 lib_index); |
| 722 Dart_Handle script_url = Dart_NewStringFromCString(load_buffer); | 722 Dart_Handle script_url = Dart_NewStringFromCString(load_buffer); |
| 723 free(load_buffer); | 723 free(load_buffer); |
| 724 Dart_Handle loaded = Dart_LoadLibrary(script_url, script_handle, 0, 0); | 724 Dart_Handle loaded = Dart_LoadLibrary(script_url, Dart_Null(), |
| 725 script_handle, 0, 0); |
| 725 DART_CHECK_VALID(loaded); | 726 DART_CHECK_VALID(loaded); |
| 726 | 727 |
| 727 // Do a fresh lookup | 728 // Do a fresh lookup |
| 728 library = Dart_LookupLibrary(library_string); | 729 library = Dart_LookupLibrary(library_string); |
| 729 } | 730 } |
| 730 | 731 |
| 731 DART_CHECK_VALID(library); | 732 DART_CHECK_VALID(library); |
| 732 Dart_Handle result = Dart_SetNativeResolver(library, | 733 Dart_Handle result = Dart_SetNativeResolver(library, |
| 733 &StubNativeLookup, | 734 &StubNativeLookup, |
| 734 &StubNativeSymbol); | 735 &StubNativeSymbol); |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 EventHandler::Stop(); | 1355 EventHandler::Stop(); |
| 1355 return 0; | 1356 return 0; |
| 1356 } | 1357 } |
| 1357 | 1358 |
| 1358 } // namespace bin | 1359 } // namespace bin |
| 1359 } // namespace dart | 1360 } // namespace dart |
| 1360 | 1361 |
| 1361 int main(int argc, char** argv) { | 1362 int main(int argc, char** argv) { |
| 1362 return dart::bin::main(argc, argv); | 1363 return dart::bin::main(argc, argv); |
| 1363 } | 1364 } |
| OLD | NEW |