| 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 <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (!file->WriteFully(buffer, size)) { | 164 if (!file->WriteFully(buffer, size)) { |
| 165 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); | 165 Log::PrintErr("Error: Failed to write snapshot file.\n\n"); |
| 166 } | 166 } |
| 167 delete file; | 167 delete file; |
| 168 } | 168 } |
| 169 | 169 |
| 170 | 170 |
| 171 class UriResolverIsolateScope { | 171 class UriResolverIsolateScope { |
| 172 public: | 172 public: |
| 173 UriResolverIsolateScope() { | 173 UriResolverIsolateScope() { |
| 174 ASSERT(isolate != NULL); | 174 ASSERT(isolate != DART_ILLEGAL_ISOLATE); |
| 175 snapshotted_isolate_ = Dart_CurrentIsolate(); | 175 snapshotted_isolate_ = Dart_CurrentIsolate(); |
| 176 Dart_ExitIsolate(); | 176 Dart_ExitIsolate(); |
| 177 Dart_EnterIsolate(isolate); | 177 Dart_EnterIsolate(isolate); |
| 178 Dart_EnterScope(); | 178 Dart_EnterScope(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 ~UriResolverIsolateScope() { | 181 ~UriResolverIsolateScope() { |
| 182 ASSERT(snapshotted_isolate_ != NULL); | 182 ASSERT(snapshotted_isolate_ != DART_ILLEGAL_ISOLATE); |
| 183 Dart_ExitScope(); | 183 Dart_ExitScope(); |
| 184 Dart_ExitIsolate(); | 184 Dart_ExitIsolate(); |
| 185 Dart_EnterIsolate(snapshotted_isolate_); | 185 Dart_EnterIsolate(snapshotted_isolate_); |
| 186 } | 186 } |
| 187 | 187 |
| 188 static Dart_Isolate isolate; | 188 static Dart_Isolate isolate; |
| 189 | 189 |
| 190 private: | 190 private: |
| 191 Dart_Isolate snapshotted_isolate_; | 191 Dart_Isolate snapshotted_isolate_; |
| 192 | 192 |
| 193 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); | 193 DISALLOW_COPY_AND_ASSIGN(UriResolverIsolateScope); |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 Dart_Isolate UriResolverIsolateScope::isolate = NULL; | 196 Dart_Isolate UriResolverIsolateScope::isolate = DART_ILLEGAL_ISOLATE; |
| 197 | 197 |
| 198 | 198 |
| 199 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { | 199 static Dart_Handle ResolveUriInWorkingDirectory(const char* script_uri) { |
| 200 bool failed = false; | 200 bool failed = false; |
| 201 char* result_string = NULL; | 201 char* result_string = NULL; |
| 202 | 202 |
| 203 { | 203 { |
| 204 UriResolverIsolateScope scope; | 204 UriResolverIsolateScope scope; |
| 205 | 205 |
| 206 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver | 206 // Run DartUtils::ResolveUriInWorkingDirectory in context of uri resolver |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 DartUtils::ReadFile, | 545 DartUtils::ReadFile, |
| 546 DartUtils::WriteFile, | 546 DartUtils::WriteFile, |
| 547 DartUtils::CloseFile, | 547 DartUtils::CloseFile, |
| 548 DartUtils::EntropySource)) { | 548 DartUtils::EntropySource)) { |
| 549 Log::PrintErr("VM initialization failed\n"); | 549 Log::PrintErr("VM initialization failed\n"); |
| 550 return 255; | 550 return 255; |
| 551 } | 551 } |
| 552 | 552 |
| 553 char* error; | 553 char* error; |
| 554 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); | 554 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error); |
| 555 if (isolate == NULL) { | 555 if (isolate == DART_ILLEGAL_ISOLATE) { |
| 556 Log::PrintErr("Error: %s", error); | 556 Log::PrintErr("Error: %s", error); |
| 557 free(error); | 557 free(error); |
| 558 exit(255); | 558 exit(255); |
| 559 } | 559 } |
| 560 | 560 |
| 561 Dart_Handle result; | 561 Dart_Handle result; |
| 562 Dart_Handle library; | 562 Dart_Handle library; |
| 563 Dart_EnterScope(); | 563 Dart_EnterScope(); |
| 564 | 564 |
| 565 ASSERT(vm_isolate_snapshot_filename != NULL); | 565 ASSERT(vm_isolate_snapshot_filename != NULL); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 590 false, | 590 false, |
| 591 builtin_lib); | 591 builtin_lib); |
| 592 CHECK_RESULT(result); | 592 CHECK_RESULT(result); |
| 593 Dart_ExitScope(); | 593 Dart_ExitScope(); |
| 594 Dart_ExitIsolate(); | 594 Dart_ExitIsolate(); |
| 595 | 595 |
| 596 UriResolverIsolateScope::isolate = isolate; | 596 UriResolverIsolateScope::isolate = isolate; |
| 597 | 597 |
| 598 // Now we create an isolate into which we load all the code that needs to | 598 // Now we create an isolate into which we load all the code that needs to |
| 599 // be in the snapshot. | 599 // be in the snapshot. |
| 600 if (Dart_CreateIsolate(NULL, NULL, NULL, NULL, &error) == NULL) { | 600 if (Dart_CreateIsolate( |
| 601 NULL, NULL, NULL, NULL, &error) == DART_ILLEGAL_ISOLATE) { |
| 601 fprintf(stderr, "%s", error); | 602 fprintf(stderr, "%s", error); |
| 602 free(error); | 603 free(error); |
| 603 exit(255); | 604 exit(255); |
| 604 } | 605 } |
| 605 Dart_EnterScope(); | 606 Dart_EnterScope(); |
| 606 | 607 |
| 607 // Set up the library tag handler in such a manner that it will use the | 608 // Set up the library tag handler in such a manner that it will use the |
| 608 // URL mapping specified on the command line to load the libraries. | 609 // URL mapping specified on the command line to load the libraries. |
| 609 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); | 610 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler); |
| 610 CHECK_RESULT(result); | 611 CHECK_RESULT(result); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 624 } | 625 } |
| 625 return 0; | 626 return 0; |
| 626 } | 627 } |
| 627 | 628 |
| 628 } // namespace bin | 629 } // namespace bin |
| 629 } // namespace dart | 630 } // namespace dart |
| 630 | 631 |
| 631 int main(int argc, char** argv) { | 632 int main(int argc, char** argv) { |
| 632 return dart::bin::main(argc, argv); | 633 return dart::bin::main(argc, argv); |
| 633 } | 634 } |
| OLD | NEW |