Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: runtime/bin/builtin.cc

Issue 1449163003: - Include sources in gen_snapshot and dart_no_snapshot to allow (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Simplify logic. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/bin/builtin_in.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
11 #include "bin/platform.h" 11 #include "bin/platform.h"
12 12
13 namespace dart { 13 namespace dart {
14 namespace bin { 14 namespace bin {
15 15
16 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = { 16 Builtin::builtin_lib_props Builtin::builtin_libraries_[] = {
17 /* { url_, source_, patch_url_, patch_source_, has_natives_ } */ 17 /* { url_, source_, patch_url_, patch_source_, has_natives_ } */
18 { DartUtils::kBuiltinLibURL, _builtin_source_paths_, NULL, NULL, true }, 18 { DartUtils::kBuiltinLibURL, _builtin_source_paths_, NULL, NULL, true },
19 { DartUtils::kIOLibURL, io_source_paths_, 19 { DartUtils::kIOLibURL, io_source_paths_,
20 DartUtils::kIOLibPatchURL, io_patch_paths_, true }, 20 DartUtils::kIOLibPatchURL, io_patch_paths_, true },
21 }; 21 };
22 22
23 Dart_Port Builtin::load_port_ = ILLEGAL_PORT; 23 Dart_Port Builtin::load_port_ = ILLEGAL_PORT;
24 24
25 // Patch all the specified patch files in the array 'patch_files' into the 25 // Patch all the specified patch files in the array 'patch_files' into the
26 // library specified in 'library'. 26 // library specified in 'library'.
27 static void LoadPatchFiles(Dart_Handle library, 27 static void LoadPatchFiles(Dart_Handle library,
28 const char* patch_uri, 28 const char* patch_uri,
29 const char** patch_files) { 29 const char** patch_files) {
30 for (intptr_t j = 0; patch_files[j] != NULL; j += 2) { 30 for (intptr_t j = 0; patch_files[j] != NULL; j += 3) {
31 Dart_Handle patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]); 31 Dart_Handle patch_src = DartUtils::ReadStringFromFile(patch_files[j + 1]);
32 if (!Dart_IsString(patch_src)) {
33 // In case reading the file caused an error, use the sources directly.
34 const char* source = patch_files[j + 2];
35 patch_src = Dart_NewStringFromUTF8(
36 reinterpret_cast<const uint8_t*>(source), strlen(source));
37 }
32 38
33 // Prepend the patch library URI to form a unique script URI for the patch. 39 // Prepend the patch library URI to form a unique script URI for the patch.
34 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]); 40 intptr_t len = snprintf(NULL, 0, "%s/%s", patch_uri, patch_files[j]);
35 char* patch_filename = reinterpret_cast<char*>(malloc(len + 1)); 41 char* patch_filename = reinterpret_cast<char*>(malloc(len + 1));
36 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]); 42 snprintf(patch_filename, len + 1, "%s/%s", patch_uri, patch_files[j]);
37 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename); 43 Dart_Handle patch_file_uri = DartUtils::NewString(patch_filename);
38 free(patch_filename); 44 free(patch_filename);
39 45
40 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src)); 46 DART_CHECK_VALID(Dart_LibraryLoadPatch(library, patch_file_uri, patch_src));
41 } 47 }
(...skipping 20 matching lines...) Expand all
62 // Try to read the source using the path specified for the uri. 68 // Try to read the source using the path specified for the uri.
63 const char** source_paths = builtin_libraries_[id].source_paths_; 69 const char** source_paths = builtin_libraries_[id].source_paths_;
64 return GetSource(source_paths, part_uri); 70 return GetSource(source_paths, part_uri);
65 } 71 }
66 72
67 73
68 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) { 74 Dart_Handle Builtin::GetSource(const char** source_paths, const char* uri) {
69 if (source_paths == NULL) { 75 if (source_paths == NULL) {
70 return Dart_Null(); // No path mapping information exists for library. 76 return Dart_Null(); // No path mapping information exists for library.
71 } 77 }
72 const char* source_path = NULL; 78 for (intptr_t i = 0; source_paths[i] != NULL; i += 3) {
73 for (intptr_t i = 0; source_paths[i] != NULL; i += 2) {
74 if (!strcmp(uri, source_paths[i])) { 79 if (!strcmp(uri, source_paths[i])) {
75 source_path = source_paths[i + 1]; 80 const char* source_path = source_paths[i + 1];
76 break; 81 Dart_Handle src = DartUtils::ReadStringFromFile(source_path);
82 if (!Dart_IsString(src)) {
83 // In case reading the file caused an error, use the sources directly.
84 const char* source = source_paths[i + 2];
85 src = Dart_NewStringFromUTF8(
86 reinterpret_cast<const uint8_t*>(source), strlen(source));
87 }
88 return src;
77 } 89 }
78 } 90 }
79 if (source_path == NULL) { 91 return Dart_Null(); // Uri does not exist in path mapping information.
80 return Dart_Null(); // Uri does not exist in path mapping information.
81 }
82 return DartUtils::ReadStringFromFile(source_path);
83 } 92 }
84 93
85 94
86 void Builtin::SetNativeResolver(BuiltinLibraryId id) { 95 void Builtin::SetNativeResolver(BuiltinLibraryId id) {
87 UNREACHABLE(); 96 UNREACHABLE();
88 } 97 }
89 98
90 99
91 Dart_Handle Builtin::LoadLibrary(Dart_Handle url, BuiltinLibraryId id) { 100 Dart_Handle Builtin::LoadLibrary(Dart_Handle url, BuiltinLibraryId id) {
92 Dart_Handle library = Dart_LoadLibrary(url, Source(id), 0, 0); 101 Dart_Handle library = Dart_LoadLibrary(url, Source(id), 0, 0);
(...skipping 19 matching lines...) Expand all
112 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_); 121 Dart_Handle url = DartUtils::NewString(builtin_libraries_[id].url_);
113 Dart_Handle library = Dart_LookupLibrary(url); 122 Dart_Handle library = Dart_LookupLibrary(url);
114 if (Dart_IsError(library)) { 123 if (Dart_IsError(library)) {
115 library = LoadLibrary(url, id); 124 library = LoadLibrary(url, id);
116 } 125 }
117 return library; 126 return library;
118 } 127 }
119 128
120 } // namespace bin 129 } // namespace bin
121 } // namespace dart 130 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/builtin_in.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698