| 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, |
| 160 import_map); | 161 import_map); |
| 161 } | 162 } |
| 162 | 163 |
| 163 | 164 |
| 164 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag, | 165 static Dart_Handle BuiltinLibraryTagHandler(Dart_LibraryTag tag, |
| 165 Dart_Handle library, | 166 Dart_Handle library, |
| 166 Dart_Handle url, | 167 Dart_Handle url, |
| 167 Dart_Handle import_map) { | 168 Dart_Handle import_map) { |
| 168 if (!Dart_IsLibrary(library)) { | 169 if (!Dart_IsLibrary(library)) { |
| 169 return Dart_Error("not a library"); | 170 return Dart_Error("not a library"); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 exit(255); | 270 exit(255); |
| 270 } | 271 } |
| 271 | 272 |
| 272 Dart_Handle result; | 273 Dart_Handle result; |
| 273 Dart_Handle library; | 274 Dart_Handle library; |
| 274 Dart_EnterScope(); | 275 Dart_EnterScope(); |
| 275 | 276 |
| 276 ASSERT(snapshot_filename != NULL); | 277 ASSERT(snapshot_filename != NULL); |
| 277 // Load up the script before a snapshot is created. | 278 // Load up the script before a snapshot is created. |
| 278 if (app_script_name != NULL) { | 279 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 } | |
| 287 // Load the specified script. | 280 // Load the specified script. |
| 288 library = LoadSnapshotCreationScript(app_script_name); | 281 library = LoadSnapshotCreationScript(app_script_name); |
| 289 VerifyLoaded(library); | 282 VerifyLoaded(library); |
| 290 } else { | 283 } else { |
| 291 // Set up the library tag handler for this isolate. | 284 // Load a dummy script as the script to setup the tag handler. |
| 292 result = Dart_SetLibraryTagHandler(BuiltinLibraryTagHandler); | 285 Dart_Handle empty_string = Dart_NewString(""); |
| 293 if (Dart_IsError(result)) { | 286 library = Dart_LoadScript(empty_string, |
| 294 fprintf(stderr, "%s", Dart_GetError(result)); | 287 empty_string, |
| 295 Dart_ExitScope(); | 288 BuiltinLibraryTagHandler, |
| 296 Dart_ShutdownIsolate(); | 289 Dart_Null()); |
| 297 exit(255); | 290 VerifyLoaded(library); |
| 298 } | |
| 299 // This is a generic dart snapshot which needs builtin library setup. | 291 // This is a generic dart snapshot which needs builtin library setup. |
| 300 Dart_Handle library = | 292 library = LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); |
| 301 LoadGenericSnapshotCreationScript(Builtin::kBuiltinLibrary); | |
| 302 VerifyLoaded(library); | 293 VerifyLoaded(library); |
| 303 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); | 294 library = LoadGenericSnapshotCreationScript(Builtin::kIOLibrary); |
| 304 VerifyLoaded(library); | 295 VerifyLoaded(library); |
| 305 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); | 296 library = LoadGenericSnapshotCreationScript(Builtin::kJsonLibrary); |
| 306 VerifyLoaded(library); | 297 VerifyLoaded(library); |
| 307 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); | 298 library = LoadGenericSnapshotCreationScript(Builtin::kUriLibrary); |
| 308 VerifyLoaded(library); | 299 VerifyLoaded(library); |
| 309 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary); | 300 library = LoadGenericSnapshotCreationScript(Builtin::kUtfLibrary); |
| 310 VerifyLoaded(library); | 301 VerifyLoaded(library); |
| 311 } | 302 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 322 exit(255); | 313 exit(255); |
| 323 } | 314 } |
| 324 // Now write the snapshot out to specified file and exit. | 315 // Now write the snapshot out to specified file and exit. |
| 325 WriteSnapshotFile(buffer, size); | 316 WriteSnapshotFile(buffer, size); |
| 326 Dart_ExitScope(); | 317 Dart_ExitScope(); |
| 327 | 318 |
| 328 // Shutdown the isolate. | 319 // Shutdown the isolate. |
| 329 Dart_ShutdownIsolate(); | 320 Dart_ShutdownIsolate(); |
| 330 return 0; | 321 return 0; |
| 331 } | 322 } |
| OLD | NEW |