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

Side by Side Diff: bin/gen_snapshot.cc

Issue 10302020: Fix issue 2888. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 7 months 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 | « no previous file | bin/main.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 // 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) { 150 static Dart_Handle LoadSnapshotCreationScript(const char* script_name) {
151 Dart_Handle source = DartUtils::ReadStringFromFile(script_name); 151 Dart_Handle source = DartUtils::ReadStringFromFile(script_name);
152 if (Dart_IsError(source)) { 152 if (Dart_IsError(source)) {
153 return source; // source contains the error string. 153 return source; // source contains the error string.
154 } 154 }
155 Dart_Handle url = Dart_NewString(script_name); 155 Dart_Handle url = Dart_NewString(script_name);
156 Dart_Handle import_map = Dart_NewList(0); 156 Dart_Handle import_map = Dart_NewList(0);
157 157
158 return Dart_LoadScript(url, 158 return Dart_LoadScript(url,
159 source, 159 source,
160 CreateSnapshotLibraryTagHandler,
161 import_map); 160 import_map);
162 } 161 }
163 162
164 163
165 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag, 164 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag,
166 Dart_Handle library, 165 Dart_Handle library,
167 Dart_Handle url, 166 Dart_Handle url,
168 Dart_Handle import_map) { 167 Dart_Handle import_map) {
169 if (!Dart_IsLibrary(library)) { 168 if (!Dart_IsLibrary(library)) {
170 return Dart_Error("not a library"); 169 return Dart_Error("not a library");
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 exit(255); 269 exit(255);
271 } 270 }
272 271
273 Dart_Handle result; 272 Dart_Handle result;
274 Dart_Handle library; 273 Dart_Handle library;
275 Dart_EnterScope(); 274 Dart_EnterScope();
276 275
277 ASSERT(snapshot_filename != NULL); 276 ASSERT(snapshot_filename != NULL);
278 // Load up the script before a snapshot is created. 277 // Load up the script before a snapshot is created.
279 if (app_script_name != NULL) { 278 if (app_script_name != NULL) {
279 // Set up the library tag handler for this isolate.
280 result = Dart_SetLibraryTagHandler(CreateSnapshotLibraryTagHandler);
281 if (Dart_IsError(result)) {
282 fprintf(stderr, "%s", Dart_GetError(result));
283 Dart_ExitScope();
284 Dart_ShutdownIsolate();
285 exit(255);
286 }
280 // Load the specified script. 287 // Load the specified script.
281 library = LoadSnapshotCreationScript(app_script_name); 288 library = LoadSnapshotCreationScript(app_script_name);
282 VerifyLoaded(library); 289 VerifyLoaded(library);
283 } else { 290 } else {
284 // Load a dummy script as the script to setup the tag handler. 291 // Set up the library tag handler for this isolate.
285 Dart_Handle empty_string = Dart_NewString(""); 292 result = Dart_SetLibraryTagHandler(BuiltinLibraryTagHandler);
286 library = Dart_LoadScript(empty_string, 293 if (Dart_IsError(result)) {
287 empty_string, 294 fprintf(stderr, "%s", Dart_GetError(result));
288 BuiltinLibraryTagHandler, 295 Dart_ExitScope();
289 Dart_Null()); 296 Dart_ShutdownIsolate();
290 VerifyLoaded(library); 297 exit(255);
298 }
291 // This is a generic dart snapshot which needs builtin library setup. 299 // This is a generic dart snapshot which needs builtin library setup.
292 library = LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); 300 Dart_Handle library =
301 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary);
293 VerifyLoaded(library); 302 VerifyLoaded(library);
294 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); 303 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary);
295 VerifyLoaded(library); 304 VerifyLoaded(library);
296 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); 305 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary);
297 VerifyLoaded(library); 306 VerifyLoaded(library);
298 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); 307 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary);
299 VerifyLoaded(library); 308 VerifyLoaded(library);
300 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary); 309 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary);
301 VerifyLoaded(library); 310 VerifyLoaded(library);
302 } 311 }
(...skipping 10 matching lines...) Expand all
313 exit(255); 322 exit(255);
314 } 323 }
315 // Now write the snapshot out to specified file and exit. 324 // Now write the snapshot out to specified file and exit.
316 WriteSnapshotFile(buffer, size); 325 WriteSnapshotFile(buffer, size);
317 Dart_ExitScope(); 326 Dart_ExitScope();
318 327
319 // Shutdown the isolate. 328 // Shutdown the isolate.
320 Dart_ShutdownIsolate(); 329 Dart_ShutdownIsolate();
321 return 0; 330 return 0;
322 } 331 }
OLDNEW
« no previous file with comments | « no previous file | bin/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698