Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Dart_Handle result = Dart_SetLibraryTagHandler( | |
| 281 CreateSnapshotLibraryTagHandler); | |
| 282 if (Dart_IsError(result)) { | |
| 283 fprintf(stderr, "%s", Dart_GetError(result)); | |
| 284 Dart_ExitScope(); | |
| 285 Dart_ShutdownIsolate(); | |
| 286 exit(255); | |
| 287 } | |
| 280 // Load the specified script. | 288 // Load the specified script. |
| 281 library = LoadSnapshotCreationScript(app_script_name); | 289 library = LoadSnapshotCreationScript(app_script_name); |
| 282 VerifyLoaded(library); | 290 VerifyLoaded(library); |
| 283 } else { | 291 } else { |
| 284 // Load a dummy script as the script to setup the tag handler. | 292 // Set up the library tag handler for this isolate. |
| 285 Dart_Handle empty_string = Dart_NewString(""); | 293 Dart_Handle result = Dart_SetLibraryTagHandler(BuiltinLibraryTagHandler); |
|
regis
2012/05/03 21:35:30
This declaration shadows the one above.
siva
2012/05/03 22:16:56
Done.
| |
| 286 library = Dart_LoadScript(empty_string, | 294 if (Dart_IsError(result)) { |
| 287 empty_string, | 295 fprintf(stderr, "%s", Dart_GetError(result)); |
| 288 BuiltinLibraryTagHandler, | 296 Dart_ExitScope(); |
| 289 Dart_Null()); | 297 Dart_ShutdownIsolate(); |
| 290 VerifyLoaded(library); | 298 exit(255); |
| 299 } | |
| 291 // This is a generic dart snapshot which needs builtin library setup. | 300 // This is a generic dart snapshot which needs builtin library setup. |
| 292 library = LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | 301 Dart_Handle library = |
|
regis
2012/05/03 21:35:30
This declaration shadows the one above.
siva
2012/05/03 22:16:56
Done.
| |
| 302 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | |
| 293 VerifyLoaded(library); | 303 VerifyLoaded(library); |
| 294 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); | 304 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); |
| 295 VerifyLoaded(library); | 305 VerifyLoaded(library); |
| 296 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); | 306 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); |
| 297 VerifyLoaded(library); | 307 VerifyLoaded(library); |
| 298 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); | 308 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); |
| 299 VerifyLoaded(library); | 309 VerifyLoaded(library); |
| 300 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary); | 310 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary); |
| 301 VerifyLoaded(library); | 311 VerifyLoaded(library); |
| 302 } | 312 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 313 exit(255); | 323 exit(255); |
| 314 } | 324 } |
| 315 // Now write the snapshot out to specified file and exit. | 325 // Now write the snapshot out to specified file and exit. |
| 316 WriteSnapshotFile(buffer, size); | 326 WriteSnapshotFile(buffer, size); |
| 317 Dart_ExitScope(); | 327 Dart_ExitScope(); |
| 318 | 328 |
| 319 // Shutdown the isolate. | 329 // Shutdown the isolate. |
| 320 Dart_ShutdownIsolate(); | 330 Dart_ShutdownIsolate(); |
| 321 return 0; | 331 return 0; |
| 322 } | 332 } |
| OLD | NEW |