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

Side by Side Diff: bin/process_script.cc

Issue 8343071: When generating snapshots for a specified script don't include the builtin library by default. Th... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « bin/process_script.h ('k') | vm/dart_api_impl.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Handle dart scripts. 5 // Handle dart scripts.
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 #include <stdio.h> 9 #include <stdio.h>
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return Dart_Error("Unable to fully read contents"); 79 return Dart_Error("Unable to fully read contents");
80 } 80 }
81 text_buffer[len] = '\0'; 81 text_buffer[len] = '\0';
82 delete file; 82 delete file;
83 Dart_Handle str = Dart_NewString(text_buffer); 83 Dart_Handle str = Dart_NewString(text_buffer);
84 free(text_buffer); 84 free(text_buffer);
85 return str; 85 return str;
86 } 86 }
87 87
88 88
89 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, 89 enum ImportBuiltin {
Anton Muhin 2011/10/31 17:48:34 nit: I would rather have two bool constants for it
siva 2011/10/31 21:09:32 Done.
90 Dart_Handle library, 90 kImportBuiltinLib = 0, // Import builtin library into all added libs.
91 Dart_Handle url) { 91 kDontImportBuiltinLib, // Do not import builtin lib into the added libs.
92 };
93
94
95 static Dart_Handle LibraryTagHandlerHelper(Dart_LibraryTag tag,
96 Dart_Handle library,
97 Dart_Handle url,
98 ImportBuiltin import_builtin_lib) {
92 if (!Dart_IsLibrary(library)) { 99 if (!Dart_IsLibrary(library)) {
93 return Dart_Error("not a library"); 100 return Dart_Error("not a library");
94 } 101 }
95 if (!Dart_IsString8(url)) { 102 if (!Dart_IsString8(url)) {
96 return Dart_Error("url is not a string"); 103 return Dart_Error("url is not a string");
97 } 104 }
98 const char* url_chars = NULL; 105 const char* url_chars = NULL;
99 Dart_Handle result = Dart_StringToCString(url, &url_chars); 106 Dart_Handle result = Dart_StringToCString(url, &url_chars);
100 if (!Dart_IsValid(result)) { 107 if (!Dart_IsValid(result)) {
101 return Dart_Error("accessing url characters failed"); 108 return Dart_Error("accessing url characters failed");
(...skipping 23 matching lines...) Expand all
125 132
126 return canon_url; 133 return canon_url;
127 } 134 }
128 135
129 // The tag is either an import or a source tag. Read the file based on the 136 // The tag is either an import or a source tag. Read the file based on the
130 // url chars. 137 // url chars.
131 Dart_Handle source = ReadStringFromFile(url_chars); 138 Dart_Handle source = ReadStringFromFile(url_chars);
132 if (!Dart_IsValid(source)) { 139 if (!Dart_IsValid(source)) {
133 return result; 140 return result;
134 } 141 }
135
136 if (tag == kImportTag) { 142 if (tag == kImportTag) {
137 Dart_Handle new_lib = Dart_LoadLibrary(url, source); 143 Dart_Handle new_lib = Dart_LoadLibrary(url, source);
138 if (Dart_IsValid(new_lib)) { 144 if ((import_builtin_lib == kImportBuiltinLib) && Dart_IsValid(new_lib)) {
139 // TODO(iposva): Should the builtin library be added to all libraries? 145 // TODO(iposva): Should the builtin library be added to all libraries?
Anton Muhin 2011/10/31 17:48:34 may TODO go away or get moved into MainLibraryTagH
siva 2011/10/31 21:09:32 Done.
140 Builtin_ImportLibrary(new_lib); 146 Builtin_ImportLibrary(new_lib);
141 } 147 }
142 return result; 148 return result;
143 } else if (tag == kSourceTag) { 149 } else if (tag == kSourceTag) {
144 return Dart_LoadSource(library, url, source); 150 return Dart_LoadSource(library, url, source);
145 } 151 }
146 return Dart_Error("wrong tag"); 152 return Dart_Error("wrong tag");
147 } 153 }
148 154
155 static Dart_Handle MainLibraryTagHandler(Dart_LibraryTag tag,
156 Dart_Handle library,
157 Dart_Handle url) {
158 return LibraryTagHandlerHelper(tag, library, url, kImportBuiltinLib);
159 }
160
161
162 static Dart_Handle CreateSnapshotLibraryTagHandler(Dart_LibraryTag tag,
163 Dart_Handle library,
164 Dart_Handle url) {
165 return LibraryTagHandlerHelper(tag, library, url, kDontImportBuiltinLib);
166 }
167
149 168
150 Dart_Handle LoadScript(const char* script_name) { 169 Dart_Handle LoadScript(const char* script_name) {
151 Dart_Handle source = ReadStringFromFile(script_name); 170 Dart_Handle source = ReadStringFromFile(script_name);
152 if (!Dart_IsValid(source)) { 171 if (!Dart_IsValid(source)) {
153 return source; 172 return source;
154 } 173 }
155 Dart_Handle url = Dart_NewString(script_name); 174 Dart_Handle url = Dart_NewString(script_name);
156 175
157 return Dart_LoadScript(url, source, LibraryTagHandler); 176 return Dart_LoadScript(url, source, MainLibraryTagHandler);
158 } 177 }
178
179
180 Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
181 Dart_Handle source = ReadStringFromFile(script_name);
182 if (!Dart_IsValid(source)) {
183 return source;
184 }
185 Dart_Handle url = Dart_NewString(script_name);
186
187 return Dart_LoadScript(url, source, CreateSnapshotLibraryTagHandler);
188 }
OLDNEW
« no previous file with comments | « bin/process_script.h ('k') | vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698